@@ -490,6 +490,49 @@ fn test_burn_registration_without_neuron_slot() {
490
490
} ) ;
491
491
}
492
492
493
+ #[ test]
494
+ fn test_burn_registration_doesnt_write_on_failure ( ) {
495
+ new_test_ext ( 1 ) . execute_with ( || {
496
+ let netuid: u16 = 1 ;
497
+ let tempo: u16 = 13 ;
498
+ let hotkey_account_id = U256 :: from ( 1 ) ;
499
+ let burn_cost = 1000 ;
500
+ let initial_balance = burn_cost * 10 ;
501
+ let coldkey_account_id = U256 :: from ( 987 ) ;
502
+
503
+ // Add network and set burn cost
504
+ add_network ( netuid, tempo, 0 ) ;
505
+ SubtensorModule :: set_burn ( netuid, burn_cost) ;
506
+ // Give coldkey balance to pay for registration
507
+ SubtensorModule :: add_balance_to_coldkey_account ( & coldkey_account_id, initial_balance) ;
508
+ // Set max allowed uids to 0 so registration will fail, but only on last check.
509
+ SubtensorModule :: set_max_allowed_uids ( netuid, 0 ) ;
510
+
511
+ // We expect this to fail at the last ensure check.
512
+ assert_err ! (
513
+ SubtensorModule :: burned_register(
514
+ <<Test as Config >:: RuntimeOrigin >:: signed( coldkey_account_id) ,
515
+ netuid,
516
+ hotkey_account_id
517
+ ) ,
518
+ Error :: <Test >:: NoNeuronIdAvailable
519
+ ) ;
520
+
521
+ // Make sure the coldkey balance is unchanged.
522
+ assert_eq ! (
523
+ SubtensorModule :: get_coldkey_balance( & coldkey_account_id) ,
524
+ initial_balance
525
+ ) ;
526
+ // Make sure the neuron is not registered.
527
+ assert_eq ! ( SubtensorModule :: get_subnetwork_n( netuid) , 0 ) ;
528
+ // Make sure the hotkey is not registered.
529
+ assert_eq ! (
530
+ SubtensorModule :: get_uid_for_net_and_hotkey( netuid, & hotkey_account_id) . is_err( ) ,
531
+ true
532
+ ) ;
533
+ } ) ;
534
+ }
535
+
493
536
#[ test]
494
537
fn test_burn_adjustment ( ) {
495
538
new_test_ext ( 1 ) . execute_with ( || {
0 commit comments