@@ -4,14 +4,17 @@ use crate::tests::mock::{
44 RuntimeOrigin , SubtensorModule , Test , add_dynamic_network, new_test_ext, run_to_block,
55} ;
66use crate :: {
7- Error , MAX_NUM_ROOT_CLAIMS , NetworksAdded , NumRootClaim , NumStakingColdkeys ,
8- PendingRootAlphaDivs , RootClaimable , StakingColdkeys , StakingColdkeysByIndex , SubnetAlphaIn ,
9- SubnetMechanism , SubnetTAO , SubtokenEnabled , Tempo , pallet,
7+ DefaultMinRootClaimAmount , Error , MAX_NUM_ROOT_CLAIMS , MAX_ROOT_CLAIM_THRESHOLD , NetworksAdded ,
8+ NumRootClaim , NumStakingColdkeys , PendingRootAlphaDivs , RootClaimable , RootClaimableThreshold ,
9+ StakingColdkeys , StakingColdkeysByIndex , SubnetAlphaIn , SubnetMechanism , SubnetTAO ,
10+ SubtokenEnabled , Tempo , pallet,
1011} ;
1112use crate :: { RootClaimType , RootClaimTypeEnum , RootClaimed } ;
1213use approx:: assert_abs_diff_eq;
14+ use frame_support:: dispatch:: RawOrigin ;
1315use frame_support:: pallet_prelude:: Weight ;
14- use frame_support:: { assert_noop, assert_ok} ;
16+ use frame_support:: traits:: Get ;
17+ use frame_support:: { assert_err, assert_noop, assert_ok} ;
1518use sp_core:: { H256 , U256 } ;
1619use sp_runtime:: DispatchError ;
1720use substrate_fixed:: types:: { I96F32 , U96F32 } ;
@@ -1297,6 +1300,61 @@ fn test_claim_root_on_network_deregistration() {
12971300 assert ! ( !RootClaimed :: <Test >:: contains_key( (
12981301 & hotkey, & coldkey, netuid
12991302 ) ) ) ;
1300- assert ! ( !RootClaimable :: <Test >:: get( & hotkey) . contains_key( & netuid) ) ;
1303+ assert ! ( !RootClaimable :: <Test >:: get( hotkey) . contains_key( & netuid) ) ;
1304+ } ) ;
1305+ }
1306+
1307+ #[ test]
1308+ fn test_claim_root_threshold ( ) {
1309+ new_test_ext ( 1 ) . execute_with ( || {
1310+ let owner_coldkey = U256 :: from ( 1001 ) ;
1311+ let hotkey = U256 :: from ( 1002 ) ;
1312+ let netuid = add_dynamic_network ( & hotkey, & owner_coldkey) ;
1313+
1314+ assert_eq ! (
1315+ RootClaimableThreshold :: <Test >:: get( netuid) ,
1316+ DefaultMinRootClaimAmount :: <Test >:: get( )
1317+ ) ;
1318+
1319+ let threshold = 1000u64 ;
1320+ assert_ok ! ( SubtensorModule :: sudo_set_root_claim_threshold(
1321+ RawOrigin :: Root . into( ) ,
1322+ netuid,
1323+ threshold
1324+ ) ) ;
1325+ assert_eq ! (
1326+ RootClaimableThreshold :: <Test >:: get( netuid) ,
1327+ I96F32 :: from( threshold)
1328+ ) ;
1329+
1330+ let threshold = 2000u64 ;
1331+ assert_ok ! ( SubtensorModule :: sudo_set_root_claim_threshold(
1332+ RawOrigin :: Signed ( owner_coldkey) . into( ) ,
1333+ netuid,
1334+ threshold
1335+ ) ) ;
1336+ assert_eq ! (
1337+ RootClaimableThreshold :: <Test >:: get( netuid) ,
1338+ I96F32 :: from( threshold)
1339+ ) ;
1340+
1341+ // Errors
1342+ assert_err ! (
1343+ SubtensorModule :: sudo_set_root_claim_threshold(
1344+ RawOrigin :: Signed ( hotkey) . into( ) ,
1345+ netuid,
1346+ threshold
1347+ ) ,
1348+ DispatchError :: BadOrigin ,
1349+ ) ;
1350+
1351+ assert_err ! (
1352+ SubtensorModule :: sudo_set_root_claim_threshold(
1353+ RawOrigin :: Signed ( owner_coldkey) . into( ) ,
1354+ netuid,
1355+ MAX_ROOT_CLAIM_THRESHOLD + 1
1356+ ) ,
1357+ Error :: <Test >:: InvalidRootClaimThreshold ,
1358+ ) ;
13011359 } ) ;
13021360}
0 commit comments