@@ -2,10 +2,9 @@ use frame_support::assert_ok;
22use frame_support:: sp_runtime:: DispatchError ;
33use frame_system:: Config ;
44use pallet_admin_utils:: Error ;
5+ use pallet_subtensor:: Error as SubtensorError ;
56use pallet_subtensor:: Event ;
67use sp_core:: U256 ;
7- use pallet_subtensor:: Error as SubtensorError ;
8-
98
109mod mock;
1110use mock:: * ;
@@ -1181,156 +1180,153 @@ fn test_sudo_set_target_stakes_per_interval() {
11811180 } ) ;
11821181}
11831182
1183+ #[ test]
1184+ fn alpha_low_can_only_be_called_by_admin ( ) {
1185+ new_test_ext ( ) . execute_with ( || {
1186+ let netuid: u16 = 1 ;
1187+ let to_be_set: u16 = 52428 ; // 0.8 i.e. 0.8 x u16::MAX
1188+ assert_eq ! (
1189+ AdminUtils :: sudo_set_alpha_low(
1190+ <<Test as Config >:: RuntimeOrigin >:: signed( U256 :: from( 1 ) ) ,
1191+ netuid,
1192+ to_be_set
1193+ ) ,
1194+ Err ( DispatchError :: BadOrigin )
1195+ ) ;
1196+ } ) ;
1197+ }
11841198
1185- #[ test]
1186- fn alpha_low_can_only_be_called_by_admin ( ) {
1187- new_test_ext ( ) . execute_with ( || {
1188- let netuid: u16 = 1 ;
1189- let to_be_set: u16 = 52428 ; // 0.8 i.e. 0.8 x u16::MAX
1190- assert_eq ! (
1191- AdminUtils :: sudo_set_alpha_low(
1192- <<Test as Config >:: RuntimeOrigin >:: signed( U256 :: from( 1 ) ) ,
1193- netuid,
1194- to_be_set
1195- ) ,
1196- Err ( DispatchError :: BadOrigin )
1197- ) ;
1198- } ) ;
1199- }
1199+ #[ test]
1200+ fn sets_alpha_low_valid_value ( ) {
1201+ new_test_ext ( ) . execute_with ( || {
1202+ let netuid: u16 = 1 ;
1203+ let to_be_set: u16 = 52428 ; // 0.8 i.e. 0.8 x u16::MAX
1204+ let init_value = SubtensorModule :: get_alpha_low ( netuid) ;
1205+ assert_eq ! ( SubtensorModule :: get_alpha_low( netuid) , init_value) ;
1206+ assert_ok ! ( AdminUtils :: sudo_set_liquid_alpha_enabled(
1207+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1208+ netuid,
1209+ true ,
1210+ ) ) ;
1211+ assert_ok ! ( AdminUtils :: sudo_set_alpha_low(
1212+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1213+ netuid,
1214+ to_be_set
1215+ ) ) ;
1216+ assert_eq ! ( SubtensorModule :: get_alpha_low( netuid) , to_be_set) ;
1217+ } ) ;
1218+ }
12001219
1201- #[ test]
1202- fn sets_alpha_low_valid_value ( ) {
1203- new_test_ext ( ) . execute_with ( || {
1204- let netuid: u16 = 1 ;
1205- let to_be_set: u16 = 52428 ; // 0.8 i.e. 0.8 x u16::MAX
1206- let init_value = SubtensorModule :: get_alpha_low ( netuid) ;
1207- assert_eq ! ( SubtensorModule :: get_alpha_low( netuid) , init_value) ;
1208- assert_ok ! ( AdminUtils :: sudo_set_liquid_alpha_enabled(
1220+ #[ test]
1221+ fn alpha_low_fails_if_liquid_alpha_disabled ( ) {
1222+ new_test_ext ( ) . execute_with ( || {
1223+ let netuid: u16 = 1 ;
1224+ let to_be_set: u16 = 52428 ; // 0.8 i.e. 0.8 x u16::MAX
1225+ assert_eq ! (
1226+ AdminUtils :: sudo_set_alpha_low(
12091227 <<Test as Config >:: RuntimeOrigin >:: root( ) ,
12101228 netuid,
1211- true ,
1212- ) ) ;
1213- assert_ok ! ( AdminUtils :: sudo_set_alpha_low(
1229+ to_be_set
1230+ ) ,
1231+ Err ( SubtensorError :: <Test >:: LiquidAlphaDisabled . into( ) )
1232+ ) ;
1233+ } ) ;
1234+ }
1235+
1236+ #[ test]
1237+ fn alpha_low_fails_if_alpha_low_too_low ( ) {
1238+ new_test_ext ( ) . execute_with ( || {
1239+ let netuid: u16 = 1 ;
1240+ let to_be_set: u16 = 0 ; // Invalid value
1241+ assert_ok ! ( AdminUtils :: sudo_set_liquid_alpha_enabled(
1242+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1243+ netuid,
1244+ true ,
1245+ ) ) ;
1246+ assert_eq ! (
1247+ AdminUtils :: sudo_set_alpha_low(
12141248 <<Test as Config >:: RuntimeOrigin >:: root( ) ,
12151249 netuid,
12161250 to_be_set
1217- ) ) ;
1218- assert_eq ! ( SubtensorModule :: get_alpha_low( netuid) , to_be_set) ;
1219- } ) ;
1220- }
1251+ ) ,
1252+ Err ( SubtensorError :: <Test >:: AlphaLowTooLow . into( ) )
1253+ ) ;
1254+ } ) ;
1255+ }
12211256
1222- #[ test]
1223- fn alpha_low_fails_if_liquid_alpha_disabled ( ) {
1224- new_test_ext ( ) . execute_with ( || {
1225- let netuid: u16 = 1 ;
1226- let to_be_set: u16 = 52428 ; // 0.8 i.e. 0.8 x u16::MAX
1227- assert_eq ! (
1228- AdminUtils :: sudo_set_alpha_low (
1229- <<Test as Config >:: RuntimeOrigin >:: root ( ) ,
1230- netuid,
1231- to_be_set
1232- ) ,
1233- Err ( SubtensorError :: < Test > :: LiquidAlphaDisabled . into ( ) )
1234- ) ;
1235- } ) ;
1236- }
1257+ #[ test]
1258+ fn alpha_high_can_only_be_called_by_admin ( ) {
1259+ new_test_ext ( ) . execute_with ( || {
1260+ let netuid: u16 = 1 ;
1261+ let to_be_set: u16 = 60000 ; // Valid value
1262+ assert_eq ! (
1263+ AdminUtils :: sudo_set_alpha_high (
1264+ <<Test as Config >:: RuntimeOrigin >:: signed ( U256 :: from ( 1 ) ) ,
1265+ netuid,
1266+ to_be_set
1267+ ) ,
1268+ Err ( DispatchError :: BadOrigin )
1269+ ) ;
1270+ } ) ;
1271+ }
12371272
1238- #[ test]
1239- fn alpha_low_fails_if_alpha_low_too_low ( ) {
1240- new_test_ext ( ) . execute_with ( || {
1241- let netuid: u16 = 1 ;
1242- let to_be_set: u16 = 0 ; // Invalid value
1243- assert_ok ! ( AdminUtils :: sudo_set_liquid_alpha_enabled(
1273+ #[ test]
1274+ fn sets_a_valid_value ( ) {
1275+ new_test_ext ( ) . execute_with ( || {
1276+ let netuid: u16 = 1 ;
1277+ let to_be_set: u16 = 60000 ; // Valid value
1278+ let init_value = SubtensorModule :: get_alpha_high ( netuid) ;
1279+ assert_eq ! ( SubtensorModule :: get_alpha_high( netuid) , init_value) ;
1280+ assert_ok ! ( AdminUtils :: sudo_set_liquid_alpha_enabled(
1281+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1282+ netuid,
1283+ true ,
1284+ ) ) ;
1285+ assert_ok ! ( AdminUtils :: sudo_set_alpha_high(
1286+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1287+ netuid,
1288+ to_be_set
1289+ ) ) ;
1290+ assert_eq ! ( SubtensorModule :: get_alpha_high( netuid) , to_be_set) ;
1291+ } ) ;
1292+ }
1293+
1294+ #[ test]
1295+ fn alpha_high_fails_if_liquid_alpha_disabled ( ) {
1296+ new_test_ext ( ) . execute_with ( || {
1297+ let netuid: u16 = 1 ;
1298+ let to_be_set: u16 = 60000 ; // Valid value
1299+ assert_eq ! (
1300+ AdminUtils :: sudo_set_alpha_high(
12441301 <<Test as Config >:: RuntimeOrigin >:: root( ) ,
12451302 netuid,
1246- true ,
1247- ) ) ;
1248- assert_eq ! (
1249- AdminUtils :: sudo_set_alpha_low(
1250- <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1251- netuid,
1252- to_be_set
1253- ) ,
1254- Err ( SubtensorError :: <Test >:: AlphaLowTooLow . into( ) )
1255- ) ;
1256- } ) ;
1257- }
1303+ to_be_set
1304+ ) ,
1305+ Err ( SubtensorError :: <Test >:: LiquidAlphaDisabled . into( ) )
1306+ ) ;
1307+ } ) ;
1308+ }
12581309
1259-
1260- #[ test]
1261- fn alpha_high_can_only_be_called_by_admin ( ) {
1262- new_test_ext ( ) . execute_with ( || {
1263- let netuid: u16 = 1 ;
1264- let to_be_set: u16 = 60000 ; // Valid value
1265- assert_eq ! (
1266- AdminUtils :: sudo_set_alpha_high(
1267- <<Test as Config >:: RuntimeOrigin >:: signed( U256 :: from( 1 ) ) ,
1268- netuid,
1269- to_be_set
1270- ) ,
1271- Err ( DispatchError :: BadOrigin )
1272- ) ;
1273- } ) ;
1274- }
1275-
1276- #[ test]
1277- fn sets_a_valid_value ( ) {
1278- new_test_ext ( ) . execute_with ( || {
1279- let netuid: u16 = 1 ;
1280- let to_be_set: u16 = 60000 ; // Valid value
1281- let init_value = SubtensorModule :: get_alpha_high ( netuid) ;
1282- assert_eq ! ( SubtensorModule :: get_alpha_high( netuid) , init_value) ;
1283- assert_ok ! ( AdminUtils :: sudo_set_liquid_alpha_enabled(
1284- <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1285- netuid,
1286- true ,
1287- ) ) ;
1288- assert_ok ! ( AdminUtils :: sudo_set_alpha_high(
1289- <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1290- netuid,
1291- to_be_set
1292- ) ) ;
1293- assert_eq ! ( SubtensorModule :: get_alpha_high( netuid) , to_be_set) ;
1294- } ) ;
1295- }
1296-
1297- #[ test]
1298- fn alpha_high_fails_if_liquid_alpha_disabled ( ) {
1299- new_test_ext ( ) . execute_with ( || {
1300- let netuid: u16 = 1 ;
1301- let to_be_set: u16 = 60000 ; // Valid value
1302- assert_eq ! (
1303- AdminUtils :: sudo_set_alpha_high(
1304- <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1305- netuid,
1306- to_be_set
1307- ) ,
1308- Err ( SubtensorError :: <Test >:: LiquidAlphaDisabled . into( ) )
1309- ) ;
1310- } ) ;
1311- }
1312-
1313- #[ test]
1314- fn fails_if_alpha_high_too_low ( ) {
1315- new_test_ext ( ) . execute_with ( || {
1316- let netuid: u16 = 1 ;
1317- let to_be_set: u16 = 50000 ; // Invalid value, less than 52428
1318- assert_ok ! ( AdminUtils :: sudo_set_liquid_alpha_enabled(
1319- <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1320- netuid,
1321- true ,
1322- ) ) ;
1323- assert_eq ! (
1324- AdminUtils :: sudo_set_alpha_high(
1325- <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1326- netuid,
1327- to_be_set
1328- ) ,
1329- Err ( SubtensorError :: <Test >:: AlphaHighTooLow . into( ) )
1330- ) ;
1331- } ) ;
1332- }
1333-
1310+ #[ test]
1311+ fn fails_if_alpha_high_too_low ( ) {
1312+ new_test_ext ( ) . execute_with ( || {
1313+ let netuid: u16 = 1 ;
1314+ let to_be_set: u16 = 50000 ; // Invalid value, less than 52428
1315+ assert_ok ! ( AdminUtils :: sudo_set_liquid_alpha_enabled(
1316+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1317+ netuid,
1318+ true ,
1319+ ) ) ;
1320+ assert_eq ! (
1321+ AdminUtils :: sudo_set_alpha_high(
1322+ <<Test as Config >:: RuntimeOrigin >:: root( ) ,
1323+ netuid,
1324+ to_be_set
1325+ ) ,
1326+ Err ( SubtensorError :: <Test >:: AlphaHighTooLow . into( ) )
1327+ ) ;
1328+ } ) ;
1329+ }
13341330
13351331#[ test]
13361332fn test_sudo_set_liquid_alpha_enabled ( ) {
0 commit comments