Skip to content

Commit 34c384f

Browse files
committed
test swap stake
1 parent 8ff6266 commit 34c384f

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

tests/e2e_tests/test_stake_movement.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,112 @@ def test_stake_movement(local_chain, wallet_setup):
398398
for stake in stakes:
399399
if stake["netuid"] == 0:
400400
pytest.fail("Stake found in root netuid after transfer")
401+
402+
################################
403+
# TEST 3: Swap stake command
404+
# Swap stake between subnets while keeping the same coldkey-hotkey pair
405+
################################
406+
407+
swap_seed_stake_result = exec_command_alice(
408+
command="stake",
409+
sub_command="add",
410+
extra_args=[
411+
"--netuid",
412+
"4",
413+
"--wallet-path",
414+
wallet_path_alice,
415+
"--wallet-name",
416+
wallet_alice.name,
417+
"--hotkey",
418+
wallet_alice.hotkey_str,
419+
"--chain",
420+
"ws://127.0.0.1:9945",
421+
"--amount",
422+
"25",
423+
"--no-prompt",
424+
"--era",
425+
"144",
426+
"--unsafe",
427+
"--no-mev-protection",
428+
],
429+
)
430+
assert "✅ Finalized" in swap_seed_stake_result.stdout, (
431+
swap_seed_stake_result.stderr
432+
)
433+
434+
# Ensure stake was added to Alice's hotkey on netuid 4
435+
alice_stake_list_before_swap_cmd = exec_command_alice(
436+
command="stake",
437+
sub_command="list",
438+
extra_args=[
439+
"--wallet-path",
440+
wallet_path_alice,
441+
"--wallet-name",
442+
wallet_alice.name,
443+
"--chain",
444+
"ws://127.0.0.1:9945",
445+
"--no-prompt",
446+
"--verbose",
447+
"--json-output",
448+
],
449+
)
450+
451+
alice_stake_list_before_swap = json.loads(alice_stake_list_before_swap_cmd.stdout)
452+
alice_stakes_before_swap = alice_stake_list_before_swap.get("stake_info", {})
453+
found_stake_in_netuid_4 = False
454+
for hotkey_ss58, stakes in alice_stakes_before_swap.items():
455+
for stake in stakes:
456+
if stake["netuid"] == 4:
457+
found_stake_in_netuid_4 = True
458+
break
459+
if not found_stake_in_netuid_4:
460+
pytest.fail("Stake not found in netuid 4 before swap")
461+
462+
# Swap stake from Alice's hotkey on netuid 4 -> Bob's hotkey on netuid 0
463+
swap_result = exec_command_alice(
464+
command="stake",
465+
sub_command="swap",
466+
extra_args=[
467+
"--origin-netuid",
468+
"4",
469+
"--wallet-path",
470+
wallet_path_alice,
471+
"--wallet-name",
472+
wallet_alice.name,
473+
"--wallet-hotkey",
474+
wallet_alice.hotkey_str,
475+
"--dest-netuid",
476+
"0",
477+
"--all",
478+
"--chain",
479+
"ws://127.0.0.1:9945",
480+
"--no-prompt",
481+
],
482+
)
483+
assert "✅ Sent" in swap_result.stdout, swap_result.stderr
484+
485+
# Check Alice's stakes after swap
486+
alice_stake_list_after_swap_cmd = exec_command_alice(
487+
command="stake",
488+
sub_command="list",
489+
extra_args=[
490+
"--wallet-path",
491+
wallet_path_alice,
492+
"--wallet-name",
493+
wallet_alice.name,
494+
"--chain",
495+
"ws://127.0.0.1:9945",
496+
"--no-prompt",
497+
"--verbose",
498+
"--json-output",
499+
],
500+
)
501+
502+
alice_stake_list_after_swap = json.loads(alice_stake_list_after_swap_cmd.stdout)
503+
alice_stakes_after_swap = alice_stake_list_after_swap.get("stake_info", {})
504+
for hotkey_ss58, stakes in alice_stakes_after_swap.items():
505+
for stake in stakes:
506+
if stake["netuid"] == 4:
507+
pytest.fail("Stake found in netuid 4 after swap")
508+
509+
print("Passed stake movement commands")

0 commit comments

Comments
 (0)