44from bittensor .core .chain_data .stake_info import StakeInfo
55from bittensor .core .errors import ChainError
66from bittensor .utils .balance import Balance
7- from tests .e2e_tests .utils .chain_interactions import get_dynamic_balance
7+ from tests .e2e_tests .utils .chain_interactions import (
8+ get_dynamic_balance ,
9+ sudo_set_admin_utils ,
10+ )
811from tests .e2e_tests .utils .e2e_test_utils import wait_to_start_call
912from tests .helpers .helpers import CLOSE_IN_VALUE
1013
@@ -328,7 +331,9 @@ def test_batch_operations(subtensor, alice_wallet, bob_wallet):
328331 logging .console .success ("✅ Test [green]test_batch_operations[/green] passed" )
329332
330333
331- def test_safe_staking_scenarios (subtensor , alice_wallet , bob_wallet ):
334+ def test_safe_staking_scenarios (
335+ local_chain , subtensor , alice_wallet , bob_wallet , eve_wallet
336+ ):
332337 """
333338 Tests safe staking scenarios with different parameters.
334339
@@ -337,44 +342,56 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
337342 2. Succeeds with strict threshold (0.5%) and partial staking allowed
338343 3. Succeeds with lenient threshold (10% and 30%) and no partial staking
339344 """
340- alice_subnet_netuid = subtensor .get_total_subnets () # 2
345+ alice_subnet_netuid = subtensor .subnets . get_total_subnets () # 2
341346 # Register root as Alice - the subnet owner and validator
342- assert subtensor .register_subnet (alice_wallet , True , True )
347+ assert subtensor .extrinsics . register_subnet (alice_wallet , True , True )
343348
344349 # Verify subnet created successfully
345- assert subtensor .subnet_exists (alice_subnet_netuid ), (
350+ assert subtensor .subnets . subnet_exists (alice_subnet_netuid ), (
346351 "Subnet wasn't created successfully"
347352 )
348353
354+ # Change the tempo of the subnet
355+ TEMPO_TO_SET = 100 if subtensor .chain .is_fast_blocks () else 20
356+ assert (
357+ sudo_set_admin_utils (
358+ local_chain ,
359+ alice_wallet ,
360+ call_function = "sudo_set_tempo" ,
361+ call_params = {"netuid" : alice_subnet_netuid , "tempo" : TEMPO_TO_SET },
362+ )[0 ]
363+ is True
364+ )
365+ tempo = subtensor .subnets .get_subnet_hyperparameters (
366+ netuid = alice_subnet_netuid
367+ ).tempo
368+ assert tempo == TEMPO_TO_SET , "SN tempos has not been changed."
369+ logging .console .success (f"SN #{ alice_subnet_netuid } tempo set to { TEMPO_TO_SET } " )
370+
349371 assert wait_to_start_call (subtensor , alice_wallet , alice_subnet_netuid )
350372
351- subtensor .burned_register (
352- alice_wallet ,
353- netuid = alice_subnet_netuid ,
354- wait_for_inclusion = True ,
355- wait_for_finalization = True ,
356- )
357- subtensor .burned_register (
358- bob_wallet ,
373+ subtensor .extrinsics .burned_register (
374+ wallet = bob_wallet ,
359375 netuid = alice_subnet_netuid ,
360376 wait_for_inclusion = True ,
361377 wait_for_finalization = True ,
362378 )
363379
364- initial_stake = subtensor .get_stake (
365- alice_wallet .coldkey .ss58_address ,
366- bob_wallet .hotkey .ss58_address ,
380+ initial_stake = subtensor .staking . get_stake (
381+ coldkey_ss58 = alice_wallet .coldkey .ss58_address ,
382+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
367383 netuid = alice_subnet_netuid ,
368384 )
369385 assert initial_stake == Balance (0 ).set_unit (alice_subnet_netuid )
386+ logging .console .info (f"[orange]Initial stake: { initial_stake } [orange]" )
370387
371388 # Test Staking Scenarios
372389 stake_amount = Balance .from_tao (100 )
373390
374391 # 1. Strict params - should fail
375- success = subtensor .add_stake (
376- alice_wallet ,
377- bob_wallet .hotkey .ss58_address ,
392+ success = subtensor .staking . add_stake (
393+ wallet = alice_wallet ,
394+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
378395 netuid = alice_subnet_netuid ,
379396 amount = stake_amount ,
380397 wait_for_inclusion = True ,
@@ -385,19 +402,20 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
385402 )
386403 assert success is False
387404
388- current_stake = subtensor .get_stake (
389- alice_wallet .coldkey .ss58_address ,
390- bob_wallet .hotkey .ss58_address ,
405+ current_stake = subtensor .staking . get_stake (
406+ coldkey_ss58 = alice_wallet .coldkey .ss58_address ,
407+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
391408 netuid = alice_subnet_netuid ,
392409 )
393410 assert current_stake == Balance (0 ).set_unit (alice_subnet_netuid ), (
394411 "Stake should not change after failed attempt"
395412 )
413+ logging .console .info (f"[orange]Current stake: { current_stake } [orange]" )
396414
397415 # 2. Partial allowed - should succeed partially
398- success = subtensor .add_stake (
399- alice_wallet ,
400- bob_wallet .hotkey .ss58_address ,
416+ success = subtensor .staking . add_stake (
417+ wallet = alice_wallet ,
418+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
401419 netuid = alice_subnet_netuid ,
402420 amount = stake_amount ,
403421 wait_for_inclusion = True ,
@@ -408,9 +426,9 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
408426 )
409427 assert success is True
410428
411- partial_stake = subtensor .get_stake (
412- alice_wallet .coldkey .ss58_address ,
413- bob_wallet .hotkey .ss58_address ,
429+ partial_stake = subtensor .staking . get_stake (
430+ coldkey_ss58 = alice_wallet .coldkey .ss58_address ,
431+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
414432 netuid = alice_subnet_netuid ,
415433 )
416434 assert partial_stake > Balance (0 ).set_unit (alice_subnet_netuid ), (
@@ -422,9 +440,9 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
422440
423441 # 3. Higher threshold - should succeed fully
424442 amount = Balance .from_tao (100 )
425- success = subtensor .add_stake (
426- alice_wallet ,
427- bob_wallet .hotkey .ss58_address ,
443+ success = subtensor .staking . add_stake (
444+ wallet = alice_wallet ,
445+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
428446 netuid = alice_subnet_netuid ,
429447 amount = amount ,
430448 wait_for_inclusion = True ,
@@ -435,17 +453,17 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
435453 )
436454 assert success is True
437455
438- full_stake = subtensor .get_stake (
439- alice_wallet .coldkey .ss58_address ,
440- bob_wallet .hotkey .ss58_address ,
456+ full_stake = subtensor .staking . get_stake (
457+ coldkey_ss58 = alice_wallet .coldkey .ss58_address ,
458+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
441459 netuid = alice_subnet_netuid ,
442460 )
443461
444462 # Test Unstaking Scenarios
445463 # 1. Strict params - should fail
446- success = subtensor .unstake (
447- alice_wallet ,
448- bob_wallet .hotkey .ss58_address ,
464+ success = subtensor .staking . unstake (
465+ wallet = alice_wallet ,
466+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
449467 netuid = alice_subnet_netuid ,
450468 amount = full_stake ,
451469 wait_for_inclusion = True ,
@@ -456,9 +474,9 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
456474 )
457475 assert success is False , "Unstake should fail."
458476
459- current_stake = subtensor .get_stake (
460- alice_wallet .coldkey .ss58_address ,
461- bob_wallet .hotkey .ss58_address ,
477+ current_stake = subtensor .staking . get_stake (
478+ coldkey_ss58 = alice_wallet .coldkey .ss58_address ,
479+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
462480 netuid = alice_subnet_netuid ,
463481 )
464482
@@ -470,9 +488,9 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
470488 )
471489
472490 # 2. Partial allowed - should succeed partially
473- success = subtensor .unstake (
474- alice_wallet ,
475- bob_wallet .hotkey .ss58_address ,
491+ success = subtensor .staking . unstake (
492+ wallet = alice_wallet ,
493+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
476494 netuid = alice_subnet_netuid ,
477495 amount = current_stake ,
478496 wait_for_inclusion = True ,
@@ -484,8 +502,8 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
484502 assert success is True
485503
486504 partial_unstake = subtensor .get_stake (
487- alice_wallet .coldkey .ss58_address ,
488- bob_wallet .hotkey .ss58_address ,
505+ coldkey_ss58 = alice_wallet .coldkey .ss58_address ,
506+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
489507 netuid = alice_subnet_netuid ,
490508 )
491509 logging .console .info (f"[orange]Partial unstake: { partial_unstake } [orange]" )
@@ -495,8 +513,8 @@ def test_safe_staking_scenarios(subtensor, alice_wallet, bob_wallet):
495513
496514 # 3. Higher threshold - should succeed fully
497515 success = subtensor .unstake (
498- alice_wallet ,
499- bob_wallet .hotkey .ss58_address ,
516+ wallet = alice_wallet ,
517+ hotkey_ss58 = bob_wallet .hotkey .ss58_address ,
500518 netuid = alice_subnet_netuid ,
501519 amount = partial_unstake ,
502520 wait_for_inclusion = True ,
0 commit comments