11from bittensor .utils .balance import Balance
22from bittensor .utils .btlogging import logging
3+ from tests .e2e_tests .utils .set_subnet_moving_price import (
4+ increase_subnet_ema ,
5+ async_increase_subnet_ema ,
6+ )
37from tests .e2e_tests .utils import (
48 AdminUtils ,
59 NETUID ,
1721PROOF_COUNTER = 2
1822
1923
20- @pytest .mark .skip (reason = "we need to figure out how to emulate behavior" )
2124def test_root_claim_swap (subtensor , alice_wallet , bob_wallet , charlie_wallet ):
2225 """Tests root claim Swap logic.
2326
@@ -51,6 +54,9 @@ def test_root_claim_swap(subtensor, alice_wallet, bob_wallet, charlie_wallet):
5154 ]
5255 )
5356
57+ # Here is the damn magic with EMA
58+ assert increase_subnet_ema (subtensor = subtensor , sudo_wallet = alice_wallet )
59+
5460 stake_balance = Balance .from_tao (10 )
5561
5662 # Stake to Alice in ROOT
@@ -112,7 +118,6 @@ def test_root_claim_swap(subtensor, alice_wallet, bob_wallet, charlie_wallet):
112118 proof_counter -= 1
113119
114120
115- @pytest .mark .skip (reason = "we need to figure out how to emulate behavior" )
116121@pytest .mark .asyncio
117122async def test_root_claim_swap_async (
118123 async_subtensor , alice_wallet , bob_wallet , charlie_wallet
@@ -149,6 +154,11 @@ async def test_root_claim_swap_async(
149154 ]
150155 )
151156
157+ # Here is the damn magic with EMA
158+ assert await async_increase_subnet_ema (
159+ subtensor = async_subtensor , sudo_wallet = alice_wallet
160+ )
161+
152162 stake_balance = Balance .from_tao (10 )
153163
154164 # Stake to Alice in ROOT
@@ -214,7 +224,6 @@ async def test_root_claim_swap_async(
214224 proof_counter -= 1
215225
216226
217- @pytest .mark .skip (reason = "we need to figure out how to emulate behavior" )
218227def test_root_claim_keep_with_zero_num_root_auto_claims (
219228 subtensor , alice_wallet , bob_wallet , charlie_wallet
220229):
@@ -280,6 +289,9 @@ def test_root_claim_keep_with_zero_num_root_auto_claims(
280289 == "Keep"
281290 )
282291
292+ # Here is the damn magic with EMA
293+ assert increase_subnet_ema (subtensor = subtensor , sudo_wallet = alice_wallet )
294+
283295 stake_balance = Balance .from_tao (1000 ) # just a dream - stake 1000 TAO to SN0 :D
284296
285297 # Stake from Charlie to Alice in ROOT
@@ -376,7 +388,6 @@ def test_root_claim_keep_with_zero_num_root_auto_claims(
376388 logging .console .info (f"SN2 Stake: { stake_after_charlie } " )
377389
378390
379- @pytest .mark .skip (reason = "we need to figure out how to emulate behavior" )
380391@pytest .mark .asyncio
381392async def test_root_claim_keep_with_zero_num_root_auto_claims_async (
382393 async_subtensor , alice_wallet , bob_wallet , charlie_wallet
@@ -445,6 +456,11 @@ async def test_root_claim_keep_with_zero_num_root_auto_claims_async(
445456 == "Keep"
446457 )
447458
459+ # Here is the damn magic with EMA
460+ assert await async_increase_subnet_ema (
461+ subtensor = async_subtensor , sudo_wallet = alice_wallet
462+ )
463+
448464 stake_balance = Balance .from_tao (1000 ) # just a dream - stake 1000 TAO to SN0 :D
449465
450466 # Stake from Charlie to Alice in ROOT
@@ -547,7 +563,6 @@ async def test_root_claim_keep_with_zero_num_root_auto_claims_async(
547563 logging .console .info (f"SN2 Stake: { stake_after_charlie } " )
548564
549565
550- @pytest .mark .skip (reason = "we need to figure out how to emulate behavior" )
551566def test_root_claim_keep_with_random_auto_claims (
552567 subtensor , alice_wallet , bob_wallet , charlie_wallet , dave_wallet
553568):
@@ -610,7 +625,10 @@ def test_root_claim_keep_with_random_auto_claims(
610625 == "Keep"
611626 )
612627
613- stake_balance = Balance .from_tao (1000 ) # just a dream - stake 1000 TAO to SN0 :D
628+ # Set EMA to enable root_sell_flag
629+ assert increase_subnet_ema (subtensor = subtensor , sudo_wallet = alice_wallet )
630+
631+ stake_balance = Balance .from_tao (1000 )
614632
615633 # Stake from Charlie to Alice in ROOT
616634 response = subtensor .staking .add_stake (
@@ -621,6 +639,13 @@ def test_root_claim_keep_with_random_auto_claims(
621639 )
622640 assert response .success , response .message
623641
642+ # Skip the epoch in which stake was installed. Emission doesn't occur in the same epoch as stake installation
643+ logging .console .info ("Skipping stake epoch" )
644+ next_epoch_start_block = subtensor .subnets .get_next_epoch_start_block (
645+ netuid = root_sn .netuid
646+ )
647+ subtensor .wait_for_block (next_epoch_start_block )
648+
624649 proof_counter = PROOF_COUNTER
625650
626651 prev_claimed_stake_charlie = subtensor .staking .get_stake (
@@ -635,8 +660,7 @@ def test_root_claim_keep_with_random_auto_claims(
635660 netuid = sn2 .netuid ,
636661 )
637662
638- # proof that ROOT stake increases each epoch even RootClaimType is Keep bc of random auto claim takes min 5 coldkeys
639- # to do release emissions
663+ # Wait for epochs and check that stake increases due to random auto claims
640664 while proof_counter > 0 :
641665 next_epoch_start_block = subtensor .subnets .get_next_epoch_start_block (
642666 root_sn .netuid
@@ -649,21 +673,24 @@ def test_root_claim_keep_with_random_auto_claims(
649673 hotkey_ss58 = alice_wallet .hotkey .ss58_address ,
650674 netuid = sn2 .netuid ,
651675 )
652- assert claimed_stake_charlie > prev_claimed_stake_charlie
676+ assert claimed_stake_charlie > prev_claimed_stake_charlie , (
677+ f"Stake did not increase: { claimed_stake_charlie } <= { prev_claimed_stake_charlie } "
678+ )
653679 prev_claimed_stake_charlie = claimed_stake_charlie
654680
655681 root_claimed_charlie = subtensor .staking .get_root_claimed (
656682 coldkey_ss58 = charlie_wallet .coldkey .ss58_address ,
657683 hotkey_ss58 = alice_wallet .hotkey .ss58_address ,
658684 netuid = sn2 .netuid ,
659685 )
660- assert root_claimed_charlie > prev_root_claimed_charlie
686+ assert root_claimed_charlie > prev_root_claimed_charlie , (
687+ f"Root claimed did not increase: { root_claimed_charlie } <= { prev_root_claimed_charlie } "
688+ )
661689 prev_root_claimed_charlie = root_claimed_charlie
662690
663691 proof_counter -= 1
664692
665693
666- @pytest .mark .skip (reason = "we need to figure out how to emulate behavior" )
667694@pytest .mark .asyncio
668695async def test_root_claim_keep_with_random_auto_claims_async (
669696 async_subtensor , alice_wallet , bob_wallet , charlie_wallet , dave_wallet
@@ -729,6 +756,11 @@ async def test_root_claim_keep_with_random_auto_claims_async(
729756 == "Keep"
730757 )
731758
759+ # Here is the damn magic with EMA
760+ assert await async_increase_subnet_ema (
761+ subtensor = async_subtensor , sudo_wallet = alice_wallet
762+ )
763+
732764 stake_balance = Balance .from_tao (1000 ) # just a dream - stake 1000 TAO to SN0 :D
733765
734766 # Stake from Charlie to Alice in ROOT
@@ -740,6 +772,13 @@ async def test_root_claim_keep_with_random_auto_claims_async(
740772 )
741773 assert response .success , response .message
742774
775+ # Skip the epoch in which stake was installed. Emission doesn't occur in the same epoch as stake installation
776+ logging .console .info ("Skipping stake epoch" )
777+ next_epoch_start_block = await async_subtensor .subnets .get_next_epoch_start_block (
778+ netuid = root_sn .netuid
779+ )
780+ await async_subtensor .wait_for_block (next_epoch_start_block )
781+
743782 proof_counter = PROOF_COUNTER
744783
745784 prev_claimed_stake_charlie = await async_subtensor .staking .get_stake (
@@ -754,8 +793,7 @@ async def test_root_claim_keep_with_random_auto_claims_async(
754793 netuid = sn2 .netuid ,
755794 )
756795
757- # proof that ROOT stake increases each epoch even RootClaimType is Keep bc of random auto claim takes min 5 coldkeys
758- # to do release emissions
796+ # Wait for epochs and check that stake increases due to random auto claims
759797 while proof_counter > 0 :
760798 next_epoch_start_block = (
761799 await async_subtensor .subnets .get_next_epoch_start_block (root_sn .netuid )
@@ -768,15 +806,19 @@ async def test_root_claim_keep_with_random_auto_claims_async(
768806 hotkey_ss58 = alice_wallet .hotkey .ss58_address ,
769807 netuid = sn2 .netuid ,
770808 )
771- assert claimed_stake_charlie > prev_claimed_stake_charlie
809+ assert claimed_stake_charlie > prev_claimed_stake_charlie , (
810+ f"Stake did not increase: { claimed_stake_charlie } <= { prev_claimed_stake_charlie } "
811+ )
772812 prev_claimed_stake_charlie = claimed_stake_charlie
773813
774814 root_claimed_charlie = await async_subtensor .staking .get_root_claimed (
775815 coldkey_ss58 = charlie_wallet .coldkey .ss58_address ,
776816 hotkey_ss58 = alice_wallet .hotkey .ss58_address ,
777817 netuid = sn2 .netuid ,
778818 )
779- assert root_claimed_charlie > prev_root_claimed_charlie
819+ assert root_claimed_charlie > prev_root_claimed_charlie , (
820+ f"Root claimed did not increase: { root_claimed_charlie } <= { prev_root_claimed_charlie } "
821+ )
780822 prev_root_claimed_charlie = root_claimed_charlie
781823
782824 proof_counter -= 1
0 commit comments