@@ -3747,3 +3747,112 @@ fn test_do_set_child_cooldown_period() {
3747
3747
assert_eq ! ( children_after, vec![ ( proportion, child) ] ) ;
3748
3748
} ) ;
3749
3749
}
3750
+
3751
+ // Test that setting childkeys requires minimum stake
3752
+ #[ test]
3753
+ fn test_do_set_child_min_stake_check ( ) {
3754
+ new_test_ext ( 1 ) . execute_with ( || {
3755
+ let coldkey = U256 :: from ( 1 ) ;
3756
+ let parent = U256 :: from ( 2 ) ;
3757
+ let child = U256 :: from ( 3 ) ;
3758
+ let netuid: u16 = 1 ;
3759
+ let proportion: u64 = 1000 ;
3760
+
3761
+ // Add network and register hotkey
3762
+ add_network ( netuid, 13 , 0 ) ;
3763
+ register_ok_neuron ( netuid, parent, coldkey, 0 ) ;
3764
+
3765
+ // Set below minimum stake for setting children
3766
+ let parent_total_stake_original = TotalHotkeyStake :: < Test > :: get ( parent) ;
3767
+ StakeThreshold :: < Test > :: put ( 1_000_000_000_000 ) ;
3768
+ TotalHotkeyStake :: < Test > :: insert ( parent, StakeThreshold :: < Test > :: get ( ) - 1 ) ;
3769
+
3770
+ // Schedule parent-child relationship
3771
+ assert_err ! (
3772
+ SubtensorModule :: do_schedule_children(
3773
+ RuntimeOrigin :: signed( coldkey) ,
3774
+ parent,
3775
+ netuid,
3776
+ vec![ ( proportion, child) ] ,
3777
+ ) ,
3778
+ Error :: <Test >:: NotEnoughStakeToSetChildkeys
3779
+ ) ;
3780
+
3781
+ // Ensure the childkeys are not yet applied
3782
+ let children_before = SubtensorModule :: get_children ( & parent, netuid) ;
3783
+ assert_eq ! ( children_before, vec![ ] ) ;
3784
+
3785
+ wait_and_set_pending_children ( netuid) ;
3786
+ TotalHotkeyStake :: < Test > :: insert ( parent, parent_total_stake_original) ;
3787
+
3788
+ // Ensure the childkeys are still not applied
3789
+ let children_after = SubtensorModule :: get_children ( & parent, netuid) ;
3790
+ assert_eq ! ( children_after, vec![ ] ) ;
3791
+ } ) ;
3792
+ }
3793
+
3794
+ // Test that revoking childkeys does not require minimum stake
3795
+ #[ test]
3796
+ fn test_revoke_child_no_min_stake_check ( ) {
3797
+ new_test_ext ( 1 ) . execute_with ( || {
3798
+ let coldkey = U256 :: from ( 1 ) ;
3799
+ let parent = U256 :: from ( 2 ) ;
3800
+ let child = U256 :: from ( 3 ) ;
3801
+ let netuid: u16 = 1 ;
3802
+ let proportion: u64 = 1000 ;
3803
+
3804
+ // Add network and register hotkey
3805
+ add_network ( netuid, 13 , 0 ) ;
3806
+ register_ok_neuron ( netuid, parent, coldkey, 0 ) ;
3807
+
3808
+ // Set below minimum stake for setting children
3809
+ let parent_total_stake_original = TotalHotkeyStake :: < Test > :: get ( parent) ;
3810
+ StakeThreshold :: < Test > :: put ( 1_000_000_000_000 ) ;
3811
+ TotalHotkeyStake :: < Test > :: insert ( parent, StakeThreshold :: < Test > :: get ( ) ) ;
3812
+
3813
+ // Schedule parent-child relationship
3814
+ assert_ok ! ( SubtensorModule :: do_schedule_children(
3815
+ RuntimeOrigin :: signed( coldkey) ,
3816
+ parent,
3817
+ netuid,
3818
+ vec![ ( proportion, child) ] ,
3819
+ ) ) ;
3820
+
3821
+ // Ensure the childkeys are not yet applied
3822
+ let children_before = SubtensorModule :: get_children ( & parent, netuid) ;
3823
+ assert_eq ! ( children_before, vec![ ] ) ;
3824
+
3825
+ wait_and_set_pending_children ( netuid) ;
3826
+ TotalHotkeyStake :: < Test > :: insert ( parent, parent_total_stake_original) ;
3827
+
3828
+ // Ensure the childkeys are applied
3829
+ let children_after = SubtensorModule :: get_children ( & parent, netuid) ;
3830
+ assert_eq ! ( children_after, vec![ ( proportion, child) ] ) ;
3831
+
3832
+ // Reduce the stake below required threshold
3833
+ TotalHotkeyStake :: < Test > :: insert ( parent, StakeThreshold :: < Test > :: get ( ) - 1 ) ;
3834
+
3835
+ // Bypass tx rate limit
3836
+ SubtensorModule :: set_last_transaction_block_on_subnet (
3837
+ & parent,
3838
+ netuid,
3839
+ & TransactionType :: SetChildren ,
3840
+ 0 ,
3841
+ ) ;
3842
+
3843
+ // Schedule parent-child relationship revokation
3844
+ assert_ok ! ( SubtensorModule :: do_schedule_children(
3845
+ RuntimeOrigin :: signed( coldkey) ,
3846
+ parent,
3847
+ netuid,
3848
+ vec![ ] ,
3849
+ ) ) ;
3850
+
3851
+ wait_and_set_pending_children ( netuid) ;
3852
+ TotalHotkeyStake :: < Test > :: insert ( parent, parent_total_stake_original) ;
3853
+
3854
+ // Ensure the childkeys are revoked
3855
+ let children_after = SubtensorModule :: get_children ( & parent, netuid) ;
3856
+ assert_eq ! ( children_after, vec![ ] ) ;
3857
+ } ) ;
3858
+ }
0 commit comments