@@ -3988,3 +3988,109 @@ fn test_pending_cooldown_one_day() {
39883988 assert_eq ! ( pending_children. 1 , curr_block + expected_cooldown) ;
39893989 } ) ;
39903990}
3991+
3992+ #[ test]
3993+ fn test_do_set_childkey_take_success ( ) {
3994+ new_test_ext ( 1 ) . execute_with ( || {
3995+ // Setup
3996+ let coldkey = U256 :: from ( 1 ) ;
3997+ let hotkey = U256 :: from ( 2 ) ;
3998+ let netuid: u16 = 1 ;
3999+ let take = 5000 ;
4000+
4001+ // Add network and register hotkey
4002+ add_network ( netuid, 13 , 0 ) ;
4003+ register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
4004+
4005+ // Set childkey take
4006+ assert_ok ! ( SubtensorModule :: do_set_childkey_take(
4007+ coldkey, hotkey, netuid, take
4008+ ) ) ;
4009+
4010+ // Verify the take was set correctly
4011+ assert_eq ! ( SubtensorModule :: get_childkey_take( & hotkey, netuid) , take) ;
4012+ let tx_type: u16 = TransactionType :: SetChildkeyTake . into ( ) ;
4013+ assert_eq ! (
4014+ TransactionKeyLastBlock :: <Test >:: get( ( hotkey, netuid, tx_type, ) ) ,
4015+ System :: block_number( )
4016+ ) ;
4017+ } ) ;
4018+ }
4019+
4020+ #[ test]
4021+ fn test_do_set_childkey_take_non_associated_coldkey ( ) {
4022+ new_test_ext ( 1 ) . execute_with ( || {
4023+ // Setup
4024+ let coldkey = U256 :: from ( 1 ) ;
4025+ let hotkey = U256 :: from ( 2 ) ;
4026+ let hotkey2 = U256 :: from ( 3 ) ;
4027+ let netuid: u16 = 1 ;
4028+ let take = 5000 ;
4029+
4030+ // Add network and register hotkey
4031+ add_network ( netuid, 13 , 0 ) ;
4032+ register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
4033+
4034+ // Set childkey take
4035+ assert_noop ! (
4036+ SubtensorModule :: do_set_childkey_take( coldkey, hotkey2, netuid, take) ,
4037+ Error :: <Test >:: NonAssociatedColdKey
4038+ ) ;
4039+ } ) ;
4040+ }
4041+
4042+ #[ test]
4043+ fn test_do_set_childkey_take_invalid_take_value ( ) {
4044+ new_test_ext ( 1 ) . execute_with ( || {
4045+ // Setup
4046+ let coldkey = U256 :: from ( 1 ) ;
4047+ let hotkey = U256 :: from ( 2 ) ;
4048+ let netuid: u16 = 1 ;
4049+ let take = SubtensorModule :: get_max_childkey_take ( ) + 1 ;
4050+
4051+ // Add network and register hotkey
4052+ add_network ( netuid, 13 , 0 ) ;
4053+ register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
4054+
4055+ // Set childkey take
4056+ assert_noop ! (
4057+ SubtensorModule :: do_set_childkey_take( coldkey, hotkey, netuid, take) ,
4058+ Error :: <Test >:: InvalidChildkeyTake
4059+ ) ;
4060+ } ) ;
4061+ }
4062+
4063+ #[ test]
4064+ fn test_do_set_childkey_take_rate_limit_exceeded ( ) {
4065+ new_test_ext ( 1 ) . execute_with ( || {
4066+ // Setup
4067+ let coldkey = U256 :: from ( 1 ) ;
4068+ let hotkey = U256 :: from ( 2 ) ;
4069+ let netuid: u16 = 1 ;
4070+ let initial_take = 3000 ;
4071+ let higher_take = 5000 ;
4072+ let lower_take = 1000 ;
4073+
4074+ add_network ( netuid, 13 , 0 ) ;
4075+ register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
4076+
4077+ // Set initial childkey take
4078+ assert_ok ! ( SubtensorModule :: do_set_childkey_take(
4079+ coldkey,
4080+ hotkey,
4081+ netuid,
4082+ initial_take
4083+ ) ) ;
4084+
4085+ // Try to increase the take value, should hit rate limit
4086+ assert_noop ! (
4087+ SubtensorModule :: do_set_childkey_take( coldkey, hotkey, netuid, higher_take) ,
4088+ Error :: <Test >:: TxChildkeyTakeRateLimitExceeded
4089+ ) ;
4090+
4091+ // lower take value should be ok
4092+ assert_ok ! ( SubtensorModule :: do_set_childkey_take(
4093+ coldkey, hotkey, netuid, lower_take
4094+ ) ) ;
4095+ } ) ;
4096+ }
0 commit comments