diff --git a/tests/graphql_test.py b/tests/graphql_test.py index 09a95e0..b97e069 100644 --- a/tests/graphql_test.py +++ b/tests/graphql_test.py @@ -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" @@ -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() @@ -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```", ) diff --git a/tests/kms_test.py b/tests/kms_test.py index 48ba59b..7039002 100644 --- a/tests/kms_test.py +++ b/tests/kms_test.py @@ -1,6 +1,5 @@ import datetime from decimal import Decimal -from typing import List import bencodex import pytest @@ -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(): @@ -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) diff --git a/world_boss/app/kms.py b/world_boss/app/kms.py index b3ccd2e..78bc536 100644 --- a/world_boss/app/kms.py +++ b/world_boss/app/kms.py @@ -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: @@ -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: diff --git a/world_boss/app/tasks.py b/world_boss/app/tasks.py index 32c8dd6..cd77c2c 100644 --- a/world_boss/app/tasks.py +++ b/world_boss/app/tasks.py @@ -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, @@ -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}```", )