1- use frame_support:: { assert_ok, assert_err, dispatch:: { DispatchClass , GetDispatchInfo , Pays } } ;
21use frame_support:: sp_runtime:: DispatchError ;
2+ use frame_support:: {
3+ assert_err, assert_ok,
4+ dispatch:: { DispatchClass , GetDispatchInfo , Pays } ,
5+ } ;
36use frame_system:: Config ;
47use pallet_admin_utils:: Error ;
58use pallet_subtensor:: Error as SubtensorError ;
@@ -1225,39 +1228,37 @@ fn test_sudo_get_set_alpha() {
12251228
12261229 let hotkey: U256 = U256 :: from ( 1 ) ;
12271230 let coldkey: U256 = U256 :: from ( 1 + 456 ) ;
1228- let signer = <<Test as Config >:: RuntimeOrigin >:: signed ( coldkey. clone ( ) ) ;
1231+ let signer = <<Test as Config >:: RuntimeOrigin >:: signed ( coldkey) ;
12291232
12301233 // Enable Liquid Alpha and setup
12311234 SubtensorModule :: set_liquid_alpha_enabled ( netuid, true ) ;
12321235 migration:: migrate_create_root_network :: < Test > ( ) ;
1233- SubtensorModule :: add_balance_to_coldkey_account (
1234- & coldkey,
1235- 1_000_000_000_000_000 ,
1236- ) ;
1237- assert_ok ! ( SubtensorModule :: root_register(
1238- signer. clone( ) ,
1239- hotkey,
1240- ) ) ;
1241- assert_ok ! ( SubtensorModule :: add_stake(
1242- signer. clone( ) ,
1243- hotkey,
1244- 1000
1245- ) ) ;
1236+ SubtensorModule :: add_balance_to_coldkey_account ( & coldkey, 1_000_000_000_000_000 ) ;
1237+ assert_ok ! ( SubtensorModule :: root_register( signer. clone( ) , hotkey, ) ) ;
1238+ assert_ok ! ( SubtensorModule :: add_stake( signer. clone( ) , hotkey, 1000 ) ) ;
12461239
12471240 // Should fail as signer does not own the subnet
12481241 assert_err ! (
12491242 AdminUtils :: sudo_set_alpha_values( signer. clone( ) , netuid, alpha_low, alpha_high) ,
12501243 DispatchError :: BadOrigin
12511244 ) ;
12521245
1253- assert_ok ! ( SubtensorModule :: register_network(
1254- signer. clone( )
1255- ) ) ;
1246+ assert_ok ! ( SubtensorModule :: register_network( signer. clone( ) ) ) ;
12561247
1257- assert_ok ! ( AdminUtils :: sudo_set_alpha_values( signer. clone( ) , netuid, alpha_low, alpha_high) ) ;
1258- let ( grabbed_alpha_low, grabbed_alpha_high) : ( u16 , u16 ) = SubtensorModule :: get_alpha_values ( netuid) ;
1248+ assert_ok ! ( AdminUtils :: sudo_set_alpha_values(
1249+ signer. clone( ) ,
1250+ netuid,
1251+ alpha_low,
1252+ alpha_high
1253+ ) ) ;
1254+ let ( grabbed_alpha_low, grabbed_alpha_high) : ( u16 , u16 ) =
1255+ SubtensorModule :: get_alpha_values ( netuid) ;
12591256
1260- log:: info!( "alpha_low: {:?} alpha_high: {:?}" , grabbed_alpha_low, grabbed_alpha_high) ;
1257+ log:: info!(
1258+ "alpha_low: {:?} alpha_high: {:?}" ,
1259+ grabbed_alpha_low,
1260+ grabbed_alpha_high
1261+ ) ;
12611262 assert_eq ! ( grabbed_alpha_low, alpha_low) ;
12621263 assert_eq ! ( grabbed_alpha_high, alpha_high) ;
12631264
@@ -1275,8 +1276,18 @@ fn test_sudo_get_set_alpha() {
12751276 let tolerance: f32 = 1e-6 ; // 0.000001
12761277
12771278 // Check if the values are equal to the sixth decimal
1278- assert ! ( ( alpha_low_32. to_num:: <f32 >( ) - alpha_low_decimal) . abs( ) < tolerance, "alpha_low mismatch: {} != {}" , alpha_low_32. to_num:: <f32 >( ) , alpha_low_decimal) ;
1279- assert ! ( ( alpha_high_32. to_num:: <f32 >( ) - alpha_high_decimal) . abs( ) < tolerance, "alpha_high mismatch: {} != {}" , alpha_high_32. to_num:: <f32 >( ) , alpha_high_decimal) ;
1279+ assert ! (
1280+ ( alpha_low_32. to_num:: <f32 >( ) - alpha_low_decimal) . abs( ) < tolerance,
1281+ "alpha_low mismatch: {} != {}" ,
1282+ alpha_low_32. to_num:: <f32 >( ) ,
1283+ alpha_low_decimal
1284+ ) ;
1285+ assert ! (
1286+ ( alpha_high_32. to_num:: <f32 >( ) - alpha_high_decimal) . abs( ) < tolerance,
1287+ "alpha_high mismatch: {} != {}" ,
1288+ alpha_high_32. to_num:: <f32 >( ) ,
1289+ alpha_high_decimal
1290+ ) ;
12801291
12811292 // 1. Liquid alpha disabled
12821293 SubtensorModule :: set_liquid_alpha_enabled ( netuid, false ) ;
@@ -1286,32 +1297,67 @@ fn test_sudo_get_set_alpha() {
12861297 ) ;
12871298 // Correct scenario after error
12881299 SubtensorModule :: set_liquid_alpha_enabled ( netuid, true ) ; // Re-enable for further tests
1289- assert_ok ! ( AdminUtils :: sudo_set_alpha_values( signer. clone( ) , netuid, alpha_low, alpha_high) ) ;
1300+ assert_ok ! ( AdminUtils :: sudo_set_alpha_values(
1301+ signer. clone( ) ,
1302+ netuid,
1303+ alpha_low,
1304+ alpha_high
1305+ ) ) ;
12901306
12911307 // 2. Alpha high too low
12921308 let alpha_high_too_low = ( u16:: MAX as u32 * 4 / 5 ) as u16 - 1 ; // One less than the minimum acceptable value
12931309 assert_err ! (
1294- AdminUtils :: sudo_set_alpha_values( signer. clone( ) , netuid, alpha_low, alpha_high_too_low) ,
1310+ AdminUtils :: sudo_set_alpha_values(
1311+ signer. clone( ) ,
1312+ netuid,
1313+ alpha_low,
1314+ alpha_high_too_low
1315+ ) ,
12951316 SubtensorError :: <Test >:: AlphaHighTooLow
12961317 ) ;
12971318 // Correct scenario after error
1298- assert_ok ! ( AdminUtils :: sudo_set_alpha_values( signer. clone( ) , netuid, alpha_low, alpha_high) ) ;
1319+ assert_ok ! ( AdminUtils :: sudo_set_alpha_values(
1320+ signer. clone( ) ,
1321+ netuid,
1322+ alpha_low,
1323+ alpha_high
1324+ ) ) ;
12991325
13001326 // 3. Alpha low too low or too high
13011327 let alpha_low_too_low = 0_u16 ;
13021328 assert_err ! (
1303- AdminUtils :: sudo_set_alpha_values( signer. clone( ) , netuid, alpha_low_too_low, alpha_high) ,
1329+ AdminUtils :: sudo_set_alpha_values(
1330+ signer. clone( ) ,
1331+ netuid,
1332+ alpha_low_too_low,
1333+ alpha_high
1334+ ) ,
13041335 SubtensorError :: <Test >:: AlphaLowOutOfRange
13051336 ) ;
13061337 // Correct scenario after error
1307- assert_ok ! ( AdminUtils :: sudo_set_alpha_values( signer. clone( ) , netuid, alpha_low, alpha_high) ) ;
1338+ assert_ok ! ( AdminUtils :: sudo_set_alpha_values(
1339+ signer. clone( ) ,
1340+ netuid,
1341+ alpha_low,
1342+ alpha_high
1343+ ) ) ;
13081344
13091345 let alpha_low_too_high = ( u16:: MAX as u32 * 4 / 5 ) as u16 + 1 ; // One more than the maximum acceptable value
13101346 assert_err ! (
1311- AdminUtils :: sudo_set_alpha_values( signer. clone( ) , netuid, alpha_low_too_high, alpha_high) ,
1347+ AdminUtils :: sudo_set_alpha_values(
1348+ signer. clone( ) ,
1349+ netuid,
1350+ alpha_low_too_high,
1351+ alpha_high
1352+ ) ,
13121353 SubtensorError :: <Test >:: AlphaLowOutOfRange
13131354 ) ;
13141355 // Correct scenario after error
1315- assert_ok ! ( AdminUtils :: sudo_set_alpha_values( signer. clone( ) , netuid, alpha_low, alpha_high) ) ;
1356+ assert_ok ! ( AdminUtils :: sudo_set_alpha_values(
1357+ signer. clone( ) ,
1358+ netuid,
1359+ alpha_low,
1360+ alpha_high
1361+ ) ) ;
13161362 } ) ;
13171363}
0 commit comments