2
2
from bittensor .core .chain_data .stake_info import StakeInfo
3
3
from bittensor .utils .balance import Balance
4
4
from tests .e2e_tests .utils .chain_interactions import get_dynamic_balance
5
- from tests .helpers .helpers import ApproxBalance
6
5
from tests .e2e_tests .utils .e2e_test_utils import wait_to_start_call
7
6
8
7
@@ -173,7 +172,7 @@ def test_single_operation(subtensor, alice_wallet, bob_wallet):
173
172
174
173
# all balances have been unstaked
175
174
assert stake == Balance (0 ).set_unit (alice_subnet_netuid )
176
- logging .console .success (f "✅ Test [green]test_single_operation[/green] passed" )
175
+ logging .console .success ("✅ Test [green]test_single_operation[/green] passed" )
177
176
178
177
179
178
def test_batch_operations (subtensor , alice_wallet , bob_wallet ):
@@ -216,7 +215,7 @@ def test_batch_operations(subtensor, alice_wallet, bob_wallet):
216
215
netuid = netuid ,
217
216
)
218
217
219
- assert stake == Balance (0 ), f"netuid={ netuid } stake={ stake } "
218
+ assert stake == Balance (0 ). set_unit ( netuid ) , f"netuid={ netuid } stake={ stake } "
220
219
221
220
balances = subtensor .get_balances (
222
221
alice_wallet .coldkey .ss58_address ,
@@ -255,7 +254,7 @@ def test_batch_operations(subtensor, alice_wallet, bob_wallet):
255
254
]
256
255
257
256
for netuid , stake in zip (netuids , stakes ):
258
- assert stake > Balance (0 ), f"netuid={ netuid } stake={ stake } "
257
+ assert stake > Balance (0 ). set_unit ( netuid ) , f"netuid={ netuid } stake={ stake } "
259
258
260
259
alice_balance -= len (netuids ) * Balance .from_tao (10_000 )
261
260
@@ -308,7 +307,7 @@ def test_batch_operations(subtensor, alice_wallet, bob_wallet):
308
307
assert balances == expected_balances
309
308
310
309
assert balances [alice_wallet .coldkey .ss58_address ] > alice_balance
311
- logging .console .success (f "✅ Test [green]test_batch_operations[/green] passed" )
310
+ logging .console .success ("✅ Test [green]test_batch_operations[/green] passed" )
312
311
313
312
314
313
def test_safe_staking_scenarios (subtensor , alice_wallet , bob_wallet ):
@@ -349,7 +348,7 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
349
348
bob_wallet .hotkey .ss58_address ,
350
349
netuid = alice_subnet_netuid ,
351
350
)
352
- assert initial_stake == Balance (0 )
351
+ assert initial_stake == Balance (0 ). set_unit ( alice_subnet_netuid )
353
352
354
353
# Test Staking Scenarios
355
354
stake_amount = Balance .from_tao (100 )
@@ -373,7 +372,9 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
373
372
bob_wallet .hotkey .ss58_address ,
374
373
netuid = alice_subnet_netuid ,
375
374
)
376
- assert current_stake == Balance (0 ), "Stake should not change after failed attempt"
375
+ assert current_stake == Balance (0 ).set_unit (alice_subnet_netuid ), (
376
+ "Stake should not change after failed attempt"
377
+ )
377
378
378
379
# 2. Partial allowed - should succeed partially
379
380
success = subtensor .add_stake (
@@ -394,7 +395,9 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
394
395
bob_wallet .hotkey .ss58_address ,
395
396
netuid = alice_subnet_netuid ,
396
397
)
397
- assert partial_stake > Balance (0 ), "Partial stake should be added"
398
+ assert partial_stake > Balance (0 ).set_unit (alice_subnet_netuid ), (
399
+ "Partial stake should be added"
400
+ )
398
401
assert partial_stake < stake_amount , (
399
402
"Partial stake should be less than requested amount"
400
403
)
@@ -468,7 +471,9 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
468
471
netuid = alice_subnet_netuid ,
469
472
)
470
473
logging .console .info (f"[orange]Partial unstake: { partial_unstake } [orange]" )
471
- assert partial_unstake > Balance (0 ), "Some stake should remain"
474
+ assert partial_unstake > Balance (0 ).set_unit (alice_subnet_netuid ), (
475
+ "Some stake should remain"
476
+ )
472
477
473
478
# 3. Higher threshold - should succeed fully
474
479
success = subtensor .unstake (
@@ -483,9 +488,7 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
483
488
allow_partial_stake = False ,
484
489
)
485
490
assert success is True , "Unstake should succeed"
486
- logging .console .success (
487
- f"✅ Test [green]test_safe_staking_scenarios[/green] passed"
488
- )
491
+ logging .console .success ("✅ Test [green]test_safe_staking_scenarios[/green] passed" )
489
492
490
493
491
494
def test_safe_swap_stake_scenarios (subtensor , alice_wallet , bob_wallet ):
@@ -539,7 +542,9 @@ def test_safe_swap_stake_scenarios(subtensor, alice_wallet, bob_wallet):
539
542
alice_wallet .hotkey .ss58_address ,
540
543
netuid = origin_netuid ,
541
544
)
542
- assert origin_stake > Balance (0 ), "Origin stake should be non-zero"
545
+ assert origin_stake > Balance (0 ).set_unit (origin_netuid ), (
546
+ "Origin stake should be non-zero"
547
+ )
543
548
544
549
stake_swap_amount = Balance .from_tao (10_000 )
545
550
# 1. Try swap with strict threshold and big amount- should fail
@@ -563,7 +568,7 @@ def test_safe_swap_stake_scenarios(subtensor, alice_wallet, bob_wallet):
563
568
alice_wallet .hotkey .ss58_address ,
564
569
netuid = dest_netuid ,
565
570
)
566
- assert dest_stake == Balance (0 ), (
571
+ assert dest_stake == Balance (0 ). set_unit ( dest_netuid ) , (
567
572
"Destination stake should remain 0 after failed swap"
568
573
)
569
574
@@ -584,7 +589,7 @@ def test_safe_swap_stake_scenarios(subtensor, alice_wallet, bob_wallet):
584
589
assert success is True
585
590
586
591
# Verify stake was moved
587
- origin_stake = subtensor .get_stake (
592
+ origin_stake = subtensor .get_stake ( # TODO this seems unused
588
593
alice_wallet .coldkey .ss58_address ,
589
594
alice_wallet .hotkey .ss58_address ,
590
595
netuid = origin_netuid ,
@@ -594,11 +599,11 @@ def test_safe_swap_stake_scenarios(subtensor, alice_wallet, bob_wallet):
594
599
alice_wallet .hotkey .ss58_address ,
595
600
netuid = dest_netuid ,
596
601
)
597
- assert dest_stake > Balance (0 ), (
602
+ assert dest_stake > Balance (0 ). set_unit ( dest_netuid ) , (
598
603
"Destination stake should be non-zero after successful swap"
599
604
)
600
605
logging .console .success (
601
- f "✅ Test [green]test_safe_swap_stake_scenarios[/green] passed"
606
+ "✅ Test [green]test_safe_swap_stake_scenarios[/green] passed"
602
607
)
603
608
604
609
@@ -641,7 +646,7 @@ def test_move_stake(subtensor, alice_wallet, bob_wallet):
641
646
coldkey_ss58 = alice_wallet .coldkey .ss58_address ,
642
647
netuid = alice_subnet_netuid ,
643
648
stake = get_dynamic_balance (stakes [0 ].stake .rao , alice_subnet_netuid ),
644
- locked = Balance (0 ),
649
+ locked = Balance (0 ). set_unit ( alice_subnet_netuid ) ,
645
650
emission = get_dynamic_balance (stakes [0 ].emission .rao , alice_subnet_netuid ),
646
651
drain = 0 ,
647
652
is_registered = True ,
@@ -704,7 +709,7 @@ def test_move_stake(subtensor, alice_wallet, bob_wallet):
704
709
expected_stakes += fast_block_stake
705
710
706
711
assert stakes == expected_stakes
707
- logging .console .success (f "✅ Test [green]test_move_stake[/green] passed" )
712
+ logging .console .success ("✅ Test [green]test_move_stake[/green] passed" )
708
713
709
714
710
715
def test_transfer_stake (subtensor , alice_wallet , bob_wallet , dave_wallet ):
@@ -746,7 +751,7 @@ def test_transfer_stake(subtensor, alice_wallet, bob_wallet, dave_wallet):
746
751
coldkey_ss58 = alice_wallet .coldkey .ss58_address ,
747
752
netuid = alice_subnet_netuid ,
748
753
stake = get_dynamic_balance (alice_stakes [0 ].stake .rao , alice_subnet_netuid ),
749
- locked = Balance (0 ),
754
+ locked = Balance (0 ). set_unit ( alice_subnet_netuid ) ,
750
755
emission = get_dynamic_balance (
751
756
alice_stakes [0 ].emission .rao , alice_subnet_netuid
752
757
),
@@ -815,7 +820,7 @@ def test_transfer_stake(subtensor, alice_wallet, bob_wallet, dave_wallet):
815
820
coldkey_ss58 = bob_wallet .coldkey .ss58_address ,
816
821
netuid = dave_subnet_netuid ,
817
822
stake = get_dynamic_balance (bob_stakes [0 ].stake .rao , dave_subnet_netuid ),
818
- locked = Balance (0 ),
823
+ locked = Balance (0 ). set_unit ( dave_subnet_netuid ) ,
819
824
emission = get_dynamic_balance (
820
825
bob_stakes [0 ].emission .rao , dave_subnet_netuid
821
826
),
@@ -824,4 +829,4 @@ def test_transfer_stake(subtensor, alice_wallet, bob_wallet, dave_wallet):
824
829
),
825
830
]
826
831
assert bob_stakes == expected_bob_stake
827
- logging .console .success (f "✅ Test [green]test_transfer_stake[/green] passed" )
832
+ logging .console .success ("✅ Test [green]test_transfer_stake[/green] passed" )
0 commit comments