@@ -249,9 +249,10 @@ fn test_registration_rate_limit_exceeded() {
249249 let coldkey_account_id = U256 :: from ( 667 ) ;
250250 let who: <Test as frame_system:: Config >:: AccountId = hotkey_account_id;
251251
252- let max_registrants = 1 ;
253- SubtensorModule :: set_target_registrations_per_interval ( netuid, max_registrants) ;
254- SubtensorModule :: set_registrations_this_interval ( netuid, 1 ) ;
252+ let target_registrants = 1 ;
253+ let max_registrants = target_registrants * 3 ;
254+ SubtensorModule :: set_target_registrations_per_interval ( netuid, target_registrants) ;
255+ SubtensorModule :: set_registrations_this_interval ( netuid, max_registrants) ;
255256
256257 let ( nonce, work) = SubtensorModule :: create_work_for_block_number (
257258 netuid,
@@ -290,18 +291,18 @@ fn test_burned_registration_under_limit() {
290291 let netuid: u16 = 1 ;
291292 let hotkey_account_id: U256 = U256 :: from ( 1 ) ;
292293 let coldkey_account_id = U256 :: from ( 667 ) ;
293- let who: <Test as frame_system:: Config >:: AccountId = hotkey_account_id;
294- let block_number: u64 = 0 ;
294+ let who: <Test as frame_system:: Config >:: AccountId = coldkey_account_id;
295+ let burn_cost = 1000 ;
296+ // Set the burn cost
297+ SubtensorModule :: set_burn ( netuid, burn_cost) ;
295298
296- let ( nonce, work) = SubtensorModule :: create_work_for_block_number (
297- netuid,
298- block_number,
299- 129123813 ,
300- & hotkey_account_id,
301- ) ;
299+ add_network ( netuid, 13 , 0 ) ; // Add the network
300+ // Give it some TAO to the coldkey balance; more than the burn cost
301+ SubtensorModule :: add_balance_to_coldkey_account ( & coldkey_account_id, burn_cost + 10_000 ) ;
302302
303- let max_registrants = 2 ;
304- SubtensorModule :: set_target_registrations_per_interval ( netuid, max_registrants) ;
303+ let target_registrants = 2 ;
304+ let max_registrants = target_registrants * 3 ; // Maximum is 3 times the target
305+ SubtensorModule :: set_target_registrations_per_interval ( netuid, target_registrants) ;
305306
306307 let call_burned_register: pallet_subtensor:: Call < Test > =
307308 pallet_subtensor:: Call :: burned_register {
@@ -317,21 +318,15 @@ fn test_burned_registration_under_limit() {
317318 extension. validate ( & who, & call_burned_register. into ( ) , & info, 10 ) ;
318319 assert_ok ! ( burned_register_result) ;
319320
320- add_network ( netuid, 13 , 0 ) ;
321321 //actually call register
322- assert_ok ! ( SubtensorModule :: register (
323- <<Test as Config >:: RuntimeOrigin >:: signed( hotkey_account_id ) ,
322+ assert_ok ! ( SubtensorModule :: burned_register (
323+ <<Test as Config >:: RuntimeOrigin >:: signed( coldkey_account_id ) ,
324324 netuid,
325- block_number,
326- nonce,
327- work,
328325 hotkey_account_id,
329- coldkey_account_id
330326 ) ) ;
331327
332328 let current_registrants = SubtensorModule :: get_registrations_this_interval ( netuid) ;
333- let target_registrants = SubtensorModule :: get_target_registrations_per_interval ( netuid) ;
334- assert ! ( current_registrants <= target_registrants) ;
329+ assert ! ( current_registrants <= max_registrants) ;
335330 } ) ;
336331}
337332
@@ -340,11 +335,15 @@ fn test_burned_registration_rate_limit_exceeded() {
340335 new_test_ext ( 1 ) . execute_with ( || {
341336 let netuid: u16 = 1 ;
342337 let hotkey_account_id: U256 = U256 :: from ( 1 ) ;
343- let who : < Test as frame_system :: Config > :: AccountId = hotkey_account_id ;
344- let max_registrants = 1 ;
338+ let coldkey_account_id = U256 :: from ( 667 ) ;
339+ let who : < Test as frame_system :: Config > :: AccountId = coldkey_account_id ;
345340
346- SubtensorModule :: set_target_registrations_per_interval ( netuid, max_registrants) ;
347- SubtensorModule :: set_registrations_this_interval ( netuid, 1 ) ;
341+ let target_registrants = 1 ;
342+ let max_registrants = target_registrants * 3 ; // Maximum is 3 times the target
343+
344+ SubtensorModule :: set_target_registrations_per_interval ( netuid, target_registrants) ;
345+ // Set the current registrations to the maximum; should not be able to register more
346+ SubtensorModule :: set_registrations_this_interval ( netuid, max_registrants) ;
348347
349348 let call_burned_register: pallet_subtensor:: Call < Test > =
350349 pallet_subtensor:: Call :: burned_register {
@@ -369,6 +368,55 @@ fn test_burned_registration_rate_limit_exceeded() {
369368 } ) ;
370369}
371370
371+ #[ test]
372+ fn test_burned_registration_rate_allows_burn_adjustment ( ) {
373+ // We need to be able to register more than the *target* registrations per interval
374+ new_test_ext ( 1 ) . execute_with ( || {
375+ let netuid: u16 = 1 ;
376+ let hotkey_account_id: U256 = U256 :: from ( 1 ) ;
377+ let coldkey_account_id = U256 :: from ( 667 ) ;
378+ let who: <Test as frame_system:: Config >:: AccountId = coldkey_account_id;
379+
380+ let burn_cost = 1000 ;
381+ // Set the burn cost
382+ SubtensorModule :: set_burn ( netuid, burn_cost) ;
383+
384+ add_network ( netuid, 13 , 0 ) ; // Add the network
385+ // Give it some TAO to the coldkey balance; more than the burn cost
386+ SubtensorModule :: add_balance_to_coldkey_account ( & coldkey_account_id, burn_cost + 10_000 ) ;
387+
388+ let target_registrants = 1 ; // Target is 1, but we can register more than that, up to some maximum.
389+ SubtensorModule :: set_target_registrations_per_interval ( netuid, target_registrants) ;
390+ // Set the current registrations to above the target; we should be able to register at least 1 more
391+ SubtensorModule :: set_registrations_this_interval ( netuid, target_registrants) ;
392+
393+ // Register one more, so the current registrations are above the target
394+ let call_burned_register: pallet_subtensor:: Call < Test > =
395+ pallet_subtensor:: Call :: burned_register {
396+ netuid,
397+ hotkey : hotkey_account_id,
398+ } ;
399+
400+ let info: DispatchInfo =
401+ DispatchInfoOf :: < <Test as frame_system:: Config >:: RuntimeCall > :: default ( ) ;
402+ let extension = SubtensorSignedExtension :: < Test > :: new ( ) ;
403+ //does not actually call register
404+ let burned_register_result =
405+ extension. validate ( & who, & call_burned_register. into ( ) , & info, 10 ) ;
406+ assert_ok ! ( burned_register_result) ;
407+
408+ //actually call register
409+ assert_ok ! ( SubtensorModule :: burned_register(
410+ <<Test as Config >:: RuntimeOrigin >:: signed( coldkey_account_id) ,
411+ netuid,
412+ hotkey_account_id
413+ ) ) ;
414+
415+ let current_registrants = SubtensorModule :: get_registrations_this_interval ( netuid) ;
416+ assert ! ( current_registrants > target_registrants) ; // Should be able to register more than the target
417+ } ) ;
418+ }
419+
372420#[ test]
373421fn test_burned_registration_ok ( ) {
374422 new_test_ext ( 1 ) . execute_with ( || {
0 commit comments