Skip to content

Commit

Permalink
Use get_plain_value instead of graphql query
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Oct 17, 2024
1 parent dd25d0c commit 3103662
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 59 deletions.
21 changes: 9 additions & 12 deletions tests/graphql_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def test_prepare_reward_assets(fx_test_client, celery_session_worker, fx_session
{"decimalPlaces": 0, "ticker": "RUNESTONE_FENRIR1", "quantity": 406545},
{"decimalPlaces": 0, "ticker": "RUNESTONE_FENRIR2", "quantity": 111715},
{"decimalPlaces": 0, "ticker": "RUNESTONE_FENRIR3", "quantity": 23890},
{"decimalPlaces": 0, "ticker": "Item_NT_500000", "quantity": 300},
]
reward = WorldBossReward()
reward.avatar_address = "avatar_address"
Expand All @@ -244,18 +245,18 @@ def test_prepare_reward_assets(fx_test_client, celery_session_worker, fx_session
reward.ranking = 1

for i, asset in enumerate(assets):
reward_amount = WorldBossRewardAmount()
reward_amount.amount = asset["quantity"]
reward_amount.ticker = asset["ticker"]
reward_amount.decimal_places = asset["decimalPlaces"]
reward_amount.reward = reward
tx_id = i
reward_amount.tx_id = tx_id
transaction = Transaction()
tx_id = i
transaction.tx_id = tx_id
transaction.signer = "signer"
transaction.payload = "payload"
transaction.nonce = i
reward_amount = WorldBossRewardAmount()
reward_amount.amount = asset["quantity"]
reward_amount.ticker = asset["ticker"]
reward_amount.decimal_places = asset["decimalPlaces"]
reward_amount.reward = reward
reward_amount.transaction = transaction
fx_session.add(transaction)
result.append(reward_amount)
fx_session.commit()
Expand All @@ -270,11 +271,7 @@ def test_prepare_reward_assets(fx_test_client, celery_session_worker, fx_session

m.assert_called_once_with(
channel=config.slack_channel_id,
text="world boss season 3 prepareRewardAssets\n```plain_value:{'type_id': 'prepare_reward_assets', 'values': {'a': "
"[], 'r': "
"b'%1\\xe5\\xe0l\\xbd\\x11\\xafT\\xf9\\x8d9W\\x89\\x90qo\\xfc}\\xba'}}\n"
"\n"
"6475373a747970655f69647532313a707265706172655f7265776172645f61737365747375363a76616c7565736475313a616c6575313a7232303a2531e5e06cbd11af54f98d39578990716ffc7dba6565```",
text="world boss season 3 prepareRewardAssets\n```plain_value:{'type_id': 'prepare_reward_assets', 'values': {'r': b'%1\\xe5\\xe0l\\xbd\\x11\\xafT\\xf9\\x8d9W\\x89\\x90qo\\xfc}\\xba', 'a': [[{'decimalPlaces': b'\\x12', 'minters': None, 'ticker': 'FAV__CRYSTAL'}, 109380000000000000000000000], [{'decimalPlaces': b'\\x00', 'minters': None, 'ticker': 'Item_NT_500000'}, 300], [{'decimalPlaces': b'\\x00', 'minters': None, 'ticker': 'FAV__RUNESTONE_FENRIR1'}, 406545], [{'decimalPlaces': b'\\x00', 'minters': None, 'ticker': 'FAV__RUNESTONE_FENRIR2'}, 111715], [{'decimalPlaces': b'\\x00', 'minters': None, 'ticker': 'FAV__RUNESTONE_FENRIR3'}, 23890]]}}\n\n6475373a747970655f69647532313a707265706172655f7265776172645f61737365747375363a76616c7565736475313a616c6c647531333a646563696d616c506c61636573313a1275373a6d696e746572736e75363a7469636b65727531323a4641565f5f4352595354414c656931303933383030303030303030303030303030303030303030303065656c647531333a646563696d616c506c61636573313a0075373a6d696e746572736e75363a7469636b65727531343a4974656d5f4e545f353030303030656933303065656c647531333a646563696d616c506c61636573313a0075373a6d696e746572736e75363a7469636b65727532323a4641565f5f52554e4553544f4e455f46454e52495231656934303635343565656c647531333a646563696d616c506c61636573313a0075373a6d696e746572736e75363a7469636b65727532323a4641565f5f52554e4553544f4e455f46454e52495232656931313137313565656c647531333a646563696d616c506c61636573313a0075373a6d696e746572736e75363a7469636b65727532323a4641565f5f52554e4553544f4e455f46454e524952336569323338393065656575313a7232303a2531e5e06cbd11af54f98d39578990716ffc7dba6565```",
)


Expand Down
25 changes: 1 addition & 24 deletions tests/kms_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
from decimal import Decimal
from typing import List

import bencodex
import pytest
Expand All @@ -11,7 +10,7 @@
from world_boss.app.kms import signer
from world_boss.app.models import Transaction, WorldBossReward, WorldBossRewardAmount
from world_boss.app.raid import get_currencies
from world_boss.app.stubs import AmountDictionary, Recipient
from world_boss.app.stubs import Recipient


def test_address():
Expand Down Expand Up @@ -68,28 +67,6 @@ async def test_check_transaction_status_async(fx_session, fx_mainnet_transaction
assert transaction.tx_result == "INCLUDED"


@pytest.mark.parametrize(
"network_type",
[
NetworkType.INTERNAL,
NetworkType.MAIN,
],
)
def test_prepare_reward_assets(fx_app, network_type: NetworkType):
headless_url = config.headless_url
assets: List[AmountDictionary] = [
{"decimalPlaces": 18, "ticker": "CRYSTAL", "quantity": 109380000},
{"decimalPlaces": 0, "ticker": "RUNESTONE_FENRIR1", "quantity": 406545},
{"decimalPlaces": 0, "ticker": "RUNESTONE_FENRIR2", "quantity": 111715},
{"decimalPlaces": 0, "ticker": "RUNESTONE_FENRIR3", "quantity": 23890},
]
result = signer.prepare_reward_assets(headless_url, assets)
assert (
result
== "6475373a747970655f69647532313a707265706172655f7265776172645f61737365747375363a76616c7565736475313a616c6c647531333a646563696d616c506c61636573313a1275373a6d696e746572736e75363a7469636b657275373a4352595354414c656931303933383030303030303030303030303030303030303030303065656c647531333a646563696d616c506c61636573313a0075373a6d696e746572736e75363a7469636b65727531373a52554e4553544f4e455f46454e52495231656934303635343565656c647531333a646563696d616c506c61636573313a0075373a6d696e746572736e75363a7469636b65727531373a52554e4553544f4e455f46454e52495232656931313137313565656c647531333a646563696d616c506c61636573313a0075373a6d696e746572736e75363a7469636b65727531373a52554e4553544f4e455f46454e524952336569323338393065656575313a7232303a2531e5e06cbd11af54f98d39578990716ffc7dba6565"
)


def test_stage_transaction(fx_session, fx_mainnet_transactions):
tx = fx_mainnet_transactions[0]
fx_session.add(tx)
Expand Down
21 changes: 1 addition & 20 deletions world_boss/app/kms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
get_jwt_auth_header,
get_transfer_assets_plain_value,
)
from world_boss.app.stubs import AmountDictionary, CurrencyDictionary, Recipient
from world_boss.app.stubs import CurrencyDictionary, Recipient


class KmsWorldBossSigner:
Expand Down Expand Up @@ -122,25 +122,6 @@ def transfer_assets(
)
return self._sign_and_save(unsigned_transaction, nonce, db)

def prepare_reward_assets(
self, headless_url: str, assets: typing.List[AmountDictionary]
) -> str:
client = self._get_client(headless_url)
with client as session:
assert client.schema is not None
ds = DSLSchema(client.schema)
query = dsl_gql(
DSLQuery(
ds.StandaloneQuery.actionQuery().select(
ds.ActionQuery.prepareRewardAssets.args(
rewardPoolAddress=self.address, assets=assets
)
)
)
)
result = session.execute(query)
return result["actionQuery"]["prepareRewardAssets"]

def stage_transaction(self, headless_url: str, transaction: Transaction) -> str:
client = self._get_client(headless_url)
with client as session:
Expand Down
7 changes: 4 additions & 3 deletions world_boss/app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
get_latest_raid_id,
get_next_month_last_day,
get_next_tx_nonce,
get_prepare_reward_assets_plain_value,
get_reward_count,
get_tx_delay_factor,
update_agent_address,
Expand Down Expand Up @@ -170,11 +171,11 @@ def insert_world_boss_rewards(rows: List[RecipientRow], signer_address: str):
def upload_prepare_reward_assets(channel_id: str, raid_id: int):
with TaskSessionLocal() as db:
assets = get_assets(raid_id, db)
result = signer.prepare_reward_assets(config.headless_url, assets)
decoded = bencodex.loads(bytes.fromhex(result))
result = get_prepare_reward_assets_plain_value(signer.address, assets)
serialized = bencodex.dumps(result).hex()
client.chat_postMessage(
channel=channel_id,
text=f"world boss season {raid_id} prepareRewardAssets\n```plain_value:{decoded}\n\n{result}```",
text=f"world boss season {raid_id} prepareRewardAssets\n```plain_value:{result}\n\n{serialized}```",
)


Expand Down

0 comments on commit 3103662

Please sign in to comment.