@@ -3167,8 +3167,11 @@ fn test_arbitrated_coldkey_swap_success() {
31673167 let ( current_coldkey, hotkey, new_coldkey) = setup_test_environment ( ) ;
31683168
31693169 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3170- let ( work, nonce) =
3171- generate_valid_pow ( & current_coldkey, current_block, U256 :: from ( 10_000_000u64 ) ) ;
3170+ let ( work, nonce) = generate_valid_pow (
3171+ & current_coldkey,
3172+ current_block,
3173+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
3174+ ) ;
31723175 SubtensorModule :: add_balance_to_coldkey_account (
31733176 & current_coldkey,
31743177 MIN_BALANCE_TO_PERFORM_COLDKEY_SWAP ,
@@ -3239,8 +3242,11 @@ fn test_arbitrated_coldkey_swap_same_coldkey() {
32393242 let ( current_coldkey, _hotkey, _) = setup_test_environment ( ) ;
32403243
32413244 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3242- let ( work, nonce) =
3243- generate_valid_pow ( & current_coldkey, current_block, U256 :: from ( 10_000_000u64 ) ) ;
3245+ let ( work, nonce) = generate_valid_pow (
3246+ & current_coldkey,
3247+ current_block,
3248+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
3249+ ) ;
32443250
32453251 assert_noop ! (
32463252 SubtensorModule :: do_schedule_coldkey_swap(
@@ -3290,8 +3296,11 @@ fn test_arbitrated_coldkey_swap_no_balance() {
32903296
32913297 // Generate valid PoW
32923298 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3293- let ( work, nonce) =
3294- generate_valid_pow ( & current_coldkey, current_block, U256 :: from ( 10_000_000u64 ) ) ;
3299+ let ( work, nonce) = generate_valid_pow (
3300+ & current_coldkey,
3301+ current_block,
3302+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
3303+ ) ;
32953304
32963305 // Try to schedule coldkey swap
32973306 let result = SubtensorModule :: do_schedule_coldkey_swap (
@@ -3373,8 +3382,11 @@ fn test_arbitrated_coldkey_swap_with_no_stake() {
33733382 assert_eq ! ( Balances :: total_balance( & new_coldkey) , 0 ) ;
33743383
33753384 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3376- let ( work, nonce) =
3377- generate_valid_pow ( & current_coldkey, current_block, U256 :: from ( 10_000_000u64 ) ) ;
3385+ let ( work, nonce) = generate_valid_pow (
3386+ & current_coldkey,
3387+ current_block,
3388+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
3389+ ) ;
33783390
33793391 // Schedule coldkey swap
33803392 assert_ok ! ( SubtensorModule :: do_schedule_coldkey_swap(
@@ -3435,8 +3447,11 @@ fn test_arbitrated_coldkey_swap_with_multiple_stakes() {
34353447 ) ) ;
34363448
34373449 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3438- let ( work, nonce) =
3439- generate_valid_pow ( & current_coldkey, current_block, U256 :: from ( 10_000_000u64 ) ) ;
3450+ let ( work, nonce) = generate_valid_pow (
3451+ & current_coldkey,
3452+ current_block,
3453+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
3454+ ) ;
34403455
34413456 assert_ok ! ( SubtensorModule :: do_schedule_coldkey_swap(
34423457 & current_coldkey. clone( ) ,
@@ -3476,6 +3491,9 @@ fn test_arbitrated_coldkey_swap_with_multiple_stakes() {
34763491#[ test]
34773492fn test_arbitrated_coldkey_swap_multiple_arbitrations ( ) {
34783493 new_test_ext ( 1 ) . execute_with ( || {
3494+ // Set a very low base difficulty for testing
3495+ BaseDifficulty :: < Test > :: put ( 1 ) ;
3496+
34793497 // Create coldkey with three choices.
34803498 let coldkey: AccountId = U256 :: from ( 1 ) ;
34813499 let new_coldkey1: AccountId = U256 :: from ( 2 ) ;
@@ -3493,12 +3511,11 @@ fn test_arbitrated_coldkey_swap_multiple_arbitrations() {
34933511 register_ok_neuron ( 1 , hotkey, coldkey, 0 ) ;
34943512
34953513 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3496- let ( work1, nonce1) =
3497- generate_valid_pow ( & coldkey, current_block, U256 :: from ( 10_000_000u64 ) ) ;
3498- let ( work2, nonce2) =
3499- generate_valid_pow ( & coldkey, current_block, U256 :: from ( 20_000_000u64 ) ) ;
3500- let ( work3, nonce3) =
3501- generate_valid_pow ( & coldkey, current_block, U256 :: from ( 30_000_000u64 ) ) ;
3514+
3515+ // Generate valid PoW for each swap attempt
3516+ let ( work1, nonce1) = generate_valid_pow ( & coldkey, current_block, U256 :: from ( 1 ) ) ;
3517+ let ( work2, nonce2) = generate_valid_pow ( & coldkey, current_block, U256 :: from ( 2 ) ) ;
3518+ let ( work3, nonce3) = generate_valid_pow ( & coldkey, current_block, U256 :: from ( 4 ) ) ;
35023519
35033520 // Schedule three swaps
35043521 assert_ok ! ( SubtensorModule :: do_schedule_coldkey_swap(
@@ -3531,7 +3548,6 @@ fn test_arbitrated_coldkey_swap_multiple_arbitrations() {
35313548
35323549 // Simulate the passage of blocks and on_idle calls
35333550 for i in 0 ..( 5400 + 1 ) {
3534- // Simulate 10 blocks
35353551 next_block ( ) ;
35363552 SubtensorModule :: on_idle ( System :: block_number ( ) , Weight :: MAX ) ;
35373553
@@ -3655,8 +3671,11 @@ fn test_arbitration_period_extension() {
36553671 let another_coldkey = U256 :: from ( 4 ) ;
36563672
36573673 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3658- let ( work1, nonce1) =
3659- generate_valid_pow ( & current_coldkey, current_block, U256 :: from ( 10_000_000u64 ) ) ;
3674+ let ( work1, nonce1) = generate_valid_pow (
3675+ & current_coldkey,
3676+ current_block,
3677+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
3678+ ) ;
36603679 let ( work2, nonce2) =
36613680 generate_valid_pow ( & current_coldkey, current_block, U256 :: from ( 20_000_000u64 ) ) ;
36623681 SubtensorModule :: add_balance_to_coldkey_account (
@@ -3725,10 +3744,16 @@ fn test_concurrent_arbitrated_coldkey_swaps() {
37253744 ) ;
37263745
37273746 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3728- let ( work1, nonce1) =
3729- generate_valid_pow ( & coldkey1, current_block, U256 :: from ( 10_000_000u64 ) ) ;
3730- let ( work2, nonce2) =
3731- generate_valid_pow ( & coldkey2, current_block, U256 :: from ( 10_000_000u64 ) ) ;
3747+ let ( work1, nonce1) = generate_valid_pow (
3748+ & coldkey1,
3749+ current_block,
3750+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
3751+ ) ;
3752+ let ( work2, nonce2) = generate_valid_pow (
3753+ & coldkey2,
3754+ current_block,
3755+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
3756+ ) ;
37323757 // Schedule swaps for both coldkeys
37333758 assert_ok ! ( SubtensorModule :: do_schedule_coldkey_swap(
37343759 & coldkey1. clone( ) ,
@@ -3773,7 +3798,7 @@ fn test_get_remaining_arbitration_period() {
37733798 let ( work, nonce) = generate_valid_pow (
37743799 & coldkey_account_id,
37753800 current_block,
3776- U256 :: from ( 10_000_000u64 ) ,
3801+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
37773802 ) ;
37783803
37793804 SubtensorModule :: add_balance_to_coldkey_account (
@@ -3833,7 +3858,7 @@ fn test_transfer_coldkey_in_arbitration() {
38333858 let ( work, nonce) = generate_valid_pow (
38343859 & coldkey_account_id,
38353860 current_block,
3836- U256 :: from ( 10_000_000u64 ) ,
3861+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
38373862 ) ;
38383863
38393864 // Schedule a coldkey swap to put the coldkey in arbitration
@@ -3876,8 +3901,11 @@ fn test_add_stake_coldkey_in_arbitration() {
38763901 ) ;
38773902
38783903 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3879- let ( work, nonce) =
3880- generate_valid_pow ( & coldkey_account_id, current_block, U256 :: from ( 1_000_000u64 ) ) ;
3904+ let ( work, nonce) = generate_valid_pow (
3905+ & coldkey_account_id,
3906+ current_block,
3907+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
3908+ ) ;
38813909
38823910 // Schedule a coldkey swap to put the coldkey in arbitration
38833911 assert_ok ! ( SubtensorModule :: do_schedule_coldkey_swap(
@@ -3916,8 +3944,11 @@ fn test_remove_stake_coldkey_in_arbitration() {
39163944 SubtensorModule :: increase_stake_on_hotkey_account ( & hotkey_account_id, 1000 ) ;
39173945
39183946 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3919- let ( work, nonce) =
3920- generate_valid_pow ( & coldkey_account_id, current_block, U256 :: from ( 1_000_000u64 ) ) ;
3947+ let ( work, nonce) = generate_valid_pow (
3948+ & coldkey_account_id,
3949+ current_block,
3950+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
3951+ ) ;
39213952
39223953 // Schedule a coldkey swap to put the coldkey in arbitration
39233954 assert_ok ! ( SubtensorModule :: do_schedule_coldkey_swap(
@@ -3992,8 +4023,11 @@ fn test_coldkey_meets_enough() {
39924023 add_network ( netuid, 13 , 0 ) ;
39934024 register_ok_neuron ( netuid, hotkey, coldkey, 0 ) ;
39944025 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
3995- let ( work1, nonce1) =
3996- generate_valid_pow ( & coldkey, current_block, U256 :: from ( 10_000_000u64 ) ) ;
4026+ let ( work1, nonce1) = generate_valid_pow (
4027+ & coldkey,
4028+ current_block,
4029+ U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
4030+ ) ;
39974031 assert_err ! (
39984032 SubtensorModule :: do_schedule_coldkey_swap(
39994033 & coldkey. clone( ) ,
@@ -4039,21 +4073,29 @@ fn test_comprehensive_coldkey_swap_scenarios() {
40394073 SubnetOwner :: < Test > :: insert ( netuid1, subnet_owner1) ;
40404074 SubnetOwner :: < Test > :: insert ( netuid2, subnet_owner2) ;
40414075
4042- // Add balance to regular user
4076+ // Add balance to subnet owners and regular user
4077+ SubtensorModule :: add_balance_to_coldkey_account (
4078+ & subnet_owner1,
4079+ MIN_BALANCE_TO_PERFORM_COLDKEY_SWAP ,
4080+ ) ;
4081+ SubtensorModule :: add_balance_to_coldkey_account (
4082+ & subnet_owner2,
4083+ MIN_BALANCE_TO_PERFORM_COLDKEY_SWAP ,
4084+ ) ;
40434085 SubtensorModule :: add_balance_to_coldkey_account (
40444086 & regular_user,
40454087 MIN_BALANCE_TO_PERFORM_COLDKEY_SWAP * 2 ,
40464088 ) ;
40474089
4090+ // Set a very low base difficulty for testing
4091+ BaseDifficulty :: < Test > :: put ( 1 ) ;
4092+
40484093 let current_block = SubtensorModule :: get_current_block_as_u64 ( ) ;
40494094
40504095 // Schedule swaps for subnet owners and regular user
4051- let ( work1, nonce1) =
4052- generate_valid_pow ( & subnet_owner1, current_block, U256 :: from ( 10_000_000u64 ) ) ;
4053- let ( work2, nonce2) =
4054- generate_valid_pow ( & subnet_owner2, current_block, U256 :: from ( 20_000_000u64 ) ) ;
4055- let ( work3, nonce3) =
4056- generate_valid_pow ( & regular_user, current_block, U256 :: from ( 30_000_000u64 ) ) ;
4096+ let ( work1, nonce1) = generate_valid_pow ( & subnet_owner1, current_block, U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ) ;
4097+ let ( work2, nonce2) = generate_valid_pow ( & subnet_owner2, current_block, U256 :: from ( 2 ) * U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ) ;
4098+ let ( work3, nonce3) = generate_valid_pow ( & regular_user, current_block, U256 :: from ( 3 ) * U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) , ) ;
40574099
40584100 assert_ok ! ( SubtensorModule :: do_schedule_coldkey_swap(
40594101 & subnet_owner1,
@@ -4110,7 +4152,7 @@ fn test_comprehensive_coldkey_swap_scenarios() {
41104152 let ( work4, nonce4) = generate_valid_pow (
41114153 & subnet_owner1,
41124154 current_block + i as u64 ,
4113- U256 :: from ( 40_000_000u64 ) ,
4155+ U256 :: from ( 4 ) * U256 :: from ( BaseDifficulty :: < Test > :: get ( ) ) ,
41144156 ) ;
41154157 assert_ok ! ( SubtensorModule :: do_schedule_coldkey_swap(
41164158 & subnet_owner1,
@@ -4151,54 +4193,5 @@ fn test_comprehensive_coldkey_swap_scenarios() {
41514193 MIN_BALANCE_TO_PERFORM_COLDKEY_SWAP * 2
41524194 ) ;
41534195 assert_eq ! ( SubtensorModule :: get_coldkey_balance( & regular_user) , 0 ) ;
4154-
4155- // Test multiple calls for the same subnet owner
4156- let ( work5, nonce5) =
4157- generate_valid_pow ( & new_coldkey1, current_block + 7 , U256 :: from ( 50_000_000u64 ) ) ;
4158- let ( work6, nonce6) =
4159- generate_valid_pow ( & new_coldkey1, current_block + 7 , U256 :: from ( 60_000_000u64 ) ) ;
4160-
4161- assert_ok ! ( SubtensorModule :: do_schedule_coldkey_swap(
4162- & new_coldkey1,
4163- & subnet_owner1,
4164- work5. to_fixed_bytes( ) . to_vec( ) ,
4165- current_block + 7 ,
4166- nonce5
4167- ) ) ;
4168-
4169- assert_ok ! ( SubtensorModule :: do_schedule_coldkey_swap(
4170- & new_coldkey1,
4171- & subnet_owner2,
4172- work6. to_fixed_bytes( ) . to_vec( ) ,
4173- current_block + 7 ,
4174- nonce6
4175- ) ) ;
4176-
4177- assert_eq ! (
4178- ColdkeySwapDestinations :: <Test >:: get( new_coldkey1) ,
4179- vec![ subnet_owner1, subnet_owner2]
4180- ) ;
4181-
4182- // Run through another arbitration period plus one block
4183- for i in 0 ..6 {
4184- next_block ( ) ;
4185- SubtensorModule :: on_idle ( System :: block_number ( ) , Weight :: MAX ) ;
4186-
4187- log:: info!(
4188- "Block {}: Coldkey in arbitration: {}, Swap destinations: {:?}" ,
4189- i + 7 ,
4190- SubtensorModule :: coldkey_in_arbitration( & new_coldkey1) ,
4191- ColdkeySwapDestinations :: <Test >:: get( new_coldkey1)
4192- ) ;
4193- }
4194-
4195- // Check final state
4196- log:: info!(
4197- "Final state - Swap destinations for new_coldkey1: {:?}" ,
4198- ColdkeySwapDestinations :: <Test >:: get( new_coldkey1)
4199- ) ;
4200- assert ! ( ColdkeySwapDestinations :: <Test >:: get( new_coldkey1) . is_empty( ) ) ;
4201- assert_eq ! ( SubnetOwner :: <Test >:: get( netuid1) , subnet_owner1) ;
4202- assert_eq ! ( SubnetOwner :: <Test >:: get( netuid2) , subnet_owner2) ;
42034196 } ) ;
42044197}
0 commit comments