From 05df58bc2832e91c8191a678e55e2418fed104ea Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Tue, 24 Sep 2024 18:13:33 -0400 Subject: [PATCH 1/2] Add transaction fee tests --- .../subcommands/stake/test_stake_add_remove.py | 10 ++++++++++ tests/e2e_tests/subcommands/wallet/test_transfer.py | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/tests/e2e_tests/subcommands/stake/test_stake_add_remove.py b/tests/e2e_tests/subcommands/stake/test_stake_add_remove.py index 2598f1feaa..b59c170225 100644 --- a/tests/e2e_tests/subcommands/stake/test_stake_add_remove.py +++ b/tests/e2e_tests/subcommands/stake/test_stake_add_remove.py @@ -54,6 +54,10 @@ def test_stake_add(local_chain): == 0 ), "TotalHotkeyStake is not 0" + # Check coldkey balance before adding stake + acc_before = local_chain.query("System", "Account", [wallet.coldkey.ss58_address]) + print("================= Balance before: ", acc_before.value["data"]["free"]) + stake_amount = 2 exec_command(StakeCommand, ["stake", "add", "--amount", str(stake_amount)]) exact_stake = local_chain.query( @@ -66,6 +70,12 @@ def test_stake_add(local_chain): stake_amount_in_rao - withdraw_loss < exact_stake <= stake_amount_in_rao ), f"Stake amount mismatch: expected {exact_stake} to be between {stake_amount_in_rao - withdraw_loss} and {stake_amount_in_rao}" + # Ensure fees are not withdrawn for the add_stake extrinsic, i.e. balance is exactly lower by stake amount + acc_after = local_chain.query("System", "Account", [wallet.coldkey.ss58_address]) + assert ( + acc_before.value["data"]["free"] - acc_after.value["data"]["free"] == stake_amount * 1_000_000_000 + ), f"Expected no transaction fees for add_stake" + # we can test remove after set the stake rate limit larger than 1 remove_amount = 1 diff --git a/tests/e2e_tests/subcommands/wallet/test_transfer.py b/tests/e2e_tests/subcommands/wallet/test_transfer.py index 9d1bd2692c..0543378539 100644 --- a/tests/e2e_tests/subcommands/wallet/test_transfer.py +++ b/tests/e2e_tests/subcommands/wallet/test_transfer.py @@ -32,4 +32,11 @@ def test_transfer(local_chain): assert ( expected_transfer <= actual_difference <= expected_transfer + tolerance ), f"Expected transfer with tolerance: {expected_transfer} <= {actual_difference} <= {expected_transfer + tolerance}" + + # Ensure the transaction fees are withdrawn + fees_lower_boundary = 50_000 # Transfer fees should be at least 50 microTAO + assert ( + expected_transfer + fees_lower_boundary <= actual_difference + ), f"Expected transfer fees: {expected_transfer + fees_lower_boundary} <= {actual_difference}" + logging.info("Passed test_transfer") From 5b889d66c0856c2d98032b90b852eeedac3f73c8 Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Wed, 25 Sep 2024 13:57:40 -0400 Subject: [PATCH 2/2] Format --- tests/e2e_tests/subcommands/stake/test_stake_add_remove.py | 3 ++- tests/e2e_tests/subcommands/wallet/test_transfer.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/e2e_tests/subcommands/stake/test_stake_add_remove.py b/tests/e2e_tests/subcommands/stake/test_stake_add_remove.py index b59c170225..9ec3e3f6ea 100644 --- a/tests/e2e_tests/subcommands/stake/test_stake_add_remove.py +++ b/tests/e2e_tests/subcommands/stake/test_stake_add_remove.py @@ -73,7 +73,8 @@ def test_stake_add(local_chain): # Ensure fees are not withdrawn for the add_stake extrinsic, i.e. balance is exactly lower by stake amount acc_after = local_chain.query("System", "Account", [wallet.coldkey.ss58_address]) assert ( - acc_before.value["data"]["free"] - acc_after.value["data"]["free"] == stake_amount * 1_000_000_000 + acc_before.value["data"]["free"] - acc_after.value["data"]["free"] + == stake_amount * 1_000_000_000 ), f"Expected no transaction fees for add_stake" # we can test remove after set the stake rate limit larger than 1 diff --git a/tests/e2e_tests/subcommands/wallet/test_transfer.py b/tests/e2e_tests/subcommands/wallet/test_transfer.py index 0543378539..034baba638 100644 --- a/tests/e2e_tests/subcommands/wallet/test_transfer.py +++ b/tests/e2e_tests/subcommands/wallet/test_transfer.py @@ -34,7 +34,7 @@ def test_transfer(local_chain): ), f"Expected transfer with tolerance: {expected_transfer} <= {actual_difference} <= {expected_transfer + tolerance}" # Ensure the transaction fees are withdrawn - fees_lower_boundary = 50_000 # Transfer fees should be at least 50 microTAO + fees_lower_boundary = 50_000 # Transfer fees should be at least 50 microTAO assert ( expected_transfer + fees_lower_boundary <= actual_difference ), f"Expected transfer fees: {expected_transfer + fees_lower_boundary} <= {actual_difference}"