@@ -4,6 +4,7 @@ use frame_system::Config;
44use pallet_subtensor:: * ;
55use rand:: { distributions:: Uniform , rngs:: StdRng , seq:: SliceRandom , thread_rng, Rng , SeedableRng } ;
66use sp_core:: U256 ;
7+ use sp_runtime:: DispatchError ;
78use std:: time:: Instant ;
89use substrate_fixed:: types:: I32F32 ;
910mod mock;
@@ -1481,9 +1482,30 @@ fn test_bonds_with_liquid_alpha() {
14811482fn test_set_alpha_disabled ( ) {
14821483 new_test_ext ( 1 ) . execute_with ( || {
14831484 let netuid: u16 = 1 ;
1484- let tempo: u16 = u16:: MAX - 1 ;
1485- let signer: RuntimeOrigin = RuntimeOrigin :: signed ( U256 :: from ( 1 ) ) ;
1486- add_network ( netuid, tempo, 0 ) ;
1485+ let hotkey: U256 = U256 :: from ( 1 ) ;
1486+ let coldkey: U256 = U256 :: from ( 1 + 456 ) ;
1487+ let signer = <<Test as Config >:: RuntimeOrigin >:: signed ( coldkey. clone ( ) ) ;
1488+
1489+ // Enable Liquid Alpha and setup
1490+ SubtensorModule :: set_liquid_alpha_enabled ( netuid, true ) ;
1491+ migration:: migrate_create_root_network :: < Test > ( ) ;
1492+ SubtensorModule :: add_balance_to_coldkey_account (
1493+ & coldkey,
1494+ 1_000_000_000_000_000 ,
1495+ ) ;
1496+ assert_ok ! ( SubtensorModule :: root_register(
1497+ signer. clone( ) ,
1498+ hotkey,
1499+ ) ) ;
1500+ assert_ok ! ( SubtensorModule :: add_stake(
1501+ signer. clone( ) ,
1502+ hotkey,
1503+ 1000
1504+ ) ) ;
1505+ // Only owner can set alpha values
1506+ assert_ok ! ( SubtensorModule :: register_network(
1507+ signer. clone( )
1508+ ) ) ;
14871509
14881510 // Explicitly set to false
14891511 SubtensorModule :: set_liquid_alpha_enabled ( netuid, false ) ;
@@ -2509,10 +2531,38 @@ fn test_get_set_alpha() {
25092531 let netuid: u16 = 1 ;
25102532 let alpha_low: u16 = 12_u16 ;
25112533 let alpha_high: u16 = u16:: MAX - 10 ;
2512- let signer: RuntimeOrigin = RuntimeOrigin :: signed ( U256 :: from ( 1 ) ) ;
25132534
2514- // Enable liquid alpha and set alpha values
2535+ let hotkey: U256 = U256 :: from ( 1 ) ;
2536+ let coldkey: U256 = U256 :: from ( 1 + 456 ) ;
2537+ let signer = <<Test as Config >:: RuntimeOrigin >:: signed ( coldkey. clone ( ) ) ;
2538+
2539+ // Enable Liquid Alpha and setup
25152540 SubtensorModule :: set_liquid_alpha_enabled ( netuid, true ) ;
2541+ migration:: migrate_create_root_network :: < Test > ( ) ;
2542+ SubtensorModule :: add_balance_to_coldkey_account (
2543+ & coldkey,
2544+ 1_000_000_000_000_000 ,
2545+ ) ;
2546+ assert_ok ! ( SubtensorModule :: root_register(
2547+ signer. clone( ) ,
2548+ hotkey,
2549+ ) ) ;
2550+ assert_ok ! ( SubtensorModule :: add_stake(
2551+ signer. clone( ) ,
2552+ hotkey,
2553+ 1000
2554+ ) ) ;
2555+
2556+ // Should fail as signer does not own the subnet
2557+ assert_err ! (
2558+ SubtensorModule :: set_alpha_values( signer. clone( ) , netuid, alpha_low, alpha_high) ,
2559+ DispatchError :: BadOrigin
2560+ ) ;
2561+
2562+ assert_ok ! ( SubtensorModule :: register_network(
2563+ signer. clone( )
2564+ ) ) ;
2565+
25162566 assert_ok ! ( SubtensorModule :: set_alpha_values( signer. clone( ) , netuid, alpha_low, alpha_high) ) ;
25172567 let ( grabbed_alpha_low, grabbed_alpha_high) : ( u16 , u16 ) = SubtensorModule :: get_alpha_values ( netuid) ;
25182568
@@ -2537,8 +2587,6 @@ fn test_get_set_alpha() {
25372587 assert ! ( ( alpha_low_32. to_num:: <f32 >( ) - alpha_low_decimal) . abs( ) < tolerance, "alpha_low mismatch: {} != {}" , alpha_low_32. to_num:: <f32 >( ) , alpha_low_decimal) ;
25382588 assert ! ( ( alpha_high_32. to_num:: <f32 >( ) - alpha_high_decimal) . abs( ) < tolerance, "alpha_high mismatch: {} != {}" , alpha_high_32. to_num:: <f32 >( ) , alpha_high_decimal) ;
25392589
2540- // Test error cases
2541-
25422590 // 1. Liquid alpha disabled
25432591 SubtensorModule :: set_liquid_alpha_enabled ( netuid, false ) ;
25442592 assert_err ! (
0 commit comments