Skip to content

Commit e4b9cc9

Browse files
e2e tests for move_stake and transfer_stake
1 parent 5ba1401 commit e4b9cc9

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

tests/e2e_tests/test_staking.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,151 @@ def test_safe_swap_stake_scenarios(subtensor, alice_wallet, bob_wallet):
516516
assert dest_stake > Balance(
517517
0
518518
), "Destination stake should be non-zero after successful swap"
519+
520+
521+
def test_move_stake(subtensor, alice_wallet, bob_wallet):
522+
"""
523+
Tests:
524+
- Adding stake
525+
- Moving stake from one hotkey-subnet pair to another
526+
"""
527+
528+
subtensor.burned_register(
529+
alice_wallet,
530+
netuid=1,
531+
wait_for_inclusion=True,
532+
wait_for_finalization=True,
533+
)
534+
535+
assert subtensor.add_stake(
536+
alice_wallet,
537+
alice_wallet.hotkey.ss58_address,
538+
netuid=1,
539+
amount=Balance.from_tao(1_000),
540+
wait_for_inclusion=True,
541+
wait_for_finalization=True,
542+
)
543+
544+
stakes = subtensor.get_stake_for_coldkey(alice_wallet.coldkey.ss58_address)
545+
546+
assert stakes == [
547+
StakeInfo(
548+
hotkey_ss58=alice_wallet.hotkey.ss58_address,
549+
coldkey_ss58=alice_wallet.coldkey.ss58_address,
550+
netuid=1,
551+
stake=ANY_BALANCE,
552+
locked=Balance(0),
553+
emission=ANY_BALANCE,
554+
drain=0,
555+
is_registered=True,
556+
),
557+
]
558+
559+
subtensor.register_subnet(bob_wallet)
560+
561+
assert subtensor.move_stake(
562+
alice_wallet,
563+
origin_hotkey=alice_wallet.hotkey.ss58_address,
564+
origin_netuid=1,
565+
destination_hotkey=bob_wallet.hotkey.ss58_address,
566+
destination_netuid=2,
567+
amount=stakes[0].stake,
568+
wait_for_finalization=True,
569+
wait_for_inclusion=True,
570+
)
571+
572+
stakes = subtensor.get_stake_for_coldkey(alice_wallet.coldkey.ss58_address)
573+
574+
assert stakes == [
575+
StakeInfo(
576+
hotkey_ss58=bob_wallet.hotkey.ss58_address,
577+
coldkey_ss58=alice_wallet.coldkey.ss58_address,
578+
netuid=2,
579+
stake=ANY_BALANCE,
580+
locked=Balance(0),
581+
emission=ANY_BALANCE,
582+
drain=0,
583+
is_registered=True,
584+
),
585+
]
586+
587+
588+
def test_transfer_stake(subtensor, alice_wallet, bob_wallet, dave_wallet):
589+
"""
590+
Tests:
591+
- Adding stake
592+
- Transfering stake from one coldkey-subnet pair to another
593+
"""
594+
595+
subtensor.burned_register(
596+
alice_wallet,
597+
netuid=1,
598+
wait_for_inclusion=True,
599+
wait_for_finalization=True,
600+
)
601+
602+
assert subtensor.add_stake(
603+
alice_wallet,
604+
alice_wallet.hotkey.ss58_address,
605+
netuid=1,
606+
amount=Balance.from_tao(1_000),
607+
wait_for_inclusion=True,
608+
wait_for_finalization=True,
609+
)
610+
611+
alice_stakes = subtensor.get_stake_for_coldkey(alice_wallet.coldkey.ss58_address)
612+
613+
assert alice_stakes == [
614+
StakeInfo(
615+
hotkey_ss58=alice_wallet.hotkey.ss58_address,
616+
coldkey_ss58=alice_wallet.coldkey.ss58_address,
617+
netuid=1,
618+
stake=ANY_BALANCE,
619+
locked=Balance(0),
620+
emission=ANY_BALANCE,
621+
drain=0,
622+
is_registered=True,
623+
),
624+
]
625+
626+
bob_stakes = subtensor.get_stake_for_coldkey(bob_wallet.coldkey.ss58_address)
627+
628+
assert bob_stakes == []
629+
630+
subtensor.register_subnet(dave_wallet)
631+
subtensor.burned_register(
632+
bob_wallet,
633+
netuid=2,
634+
wait_for_inclusion=True,
635+
wait_for_finalization=True,
636+
)
637+
638+
assert subtensor.transfer_stake(
639+
alice_wallet,
640+
destination_coldkey_ss58=bob_wallet.coldkey.ss58_address,
641+
hotkey_ss58=alice_wallet.hotkey.ss58_address,
642+
origin_netuid=1,
643+
destination_netuid=2,
644+
amount=alice_stakes[0].stake,
645+
wait_for_inclusion=True,
646+
wait_for_finalization=True,
647+
)
648+
649+
alice_stakes = subtensor.get_stake_for_coldkey(alice_wallet.coldkey.ss58_address)
650+
651+
assert alice_stakes == []
652+
653+
bob_stakes = subtensor.get_stake_for_coldkey(bob_wallet.coldkey.ss58_address)
654+
655+
assert bob_stakes == [
656+
StakeInfo(
657+
hotkey_ss58=alice_wallet.hotkey.ss58_address,
658+
coldkey_ss58=bob_wallet.coldkey.ss58_address,
659+
netuid=2,
660+
stake=ANY_BALANCE,
661+
locked=Balance(0),
662+
emission=ANY_BALANCE,
663+
drain=0,
664+
is_registered=False,
665+
),
666+
]

0 commit comments

Comments
 (0)