@@ -4,6 +4,7 @@ mod mock;
44use frame_support:: assert_ok;
55use frame_system:: Config ;
66use mock:: * ;
7+ use pallet_subtensor:: * ;
78use sp_core:: U256 ;
89
910#[ test]
@@ -276,3 +277,73 @@ fn test_migration_delete_subnet_21() {
276277 assert ! ( !SubtensorModule :: if_subnet_exist( 21 ) ) ;
277278 } )
278279}
280+
281+ // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake --exact --nocapture
282+ #[ test]
283+ fn test_migrate_fix_total_coldkey_stake ( ) {
284+ new_test_ext ( 1 ) . execute_with ( || {
285+ let coldkey = U256 :: from ( 0 ) ;
286+ TotalColdkeyStake :: < Test > :: insert ( coldkey, 0 ) ;
287+ StakingHotkeys :: < Test > :: insert ( coldkey, vec ! [ U256 :: from( 1 ) , U256 :: from( 2 ) , U256 :: from( 3 ) ] ) ;
288+ Stake :: < Test > :: insert ( U256 :: from ( 1 ) , U256 :: from ( 0 ) , 10000 ) ;
289+ Stake :: < Test > :: insert ( U256 :: from ( 2 ) , U256 :: from ( 0 ) , 10000 ) ;
290+ Stake :: < Test > :: insert ( U256 :: from ( 3 ) , U256 :: from ( 0 ) , 10000 ) ;
291+ pallet_subtensor:: migration:: do_migrate_fix_total_coldkey_stake :: < Test > ( ) ;
292+ assert_eq ! ( TotalColdkeyStake :: <Test >:: get( coldkey) , 30000 ) ;
293+ } )
294+ }
295+
296+ // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake_value_already_in_total --exact --nocapture
297+ #[ test]
298+ fn test_migrate_fix_total_coldkey_stake_value_already_in_total ( ) {
299+ new_test_ext ( 1 ) . execute_with ( || {
300+ let coldkey = U256 :: from ( 0 ) ;
301+ TotalColdkeyStake :: < Test > :: insert ( coldkey, 100000000 ) ;
302+ StakingHotkeys :: < Test > :: insert ( coldkey, vec ! [ U256 :: from( 1 ) , U256 :: from( 2 ) , U256 :: from( 3 ) ] ) ;
303+ Stake :: < Test > :: insert ( U256 :: from ( 1 ) , U256 :: from ( 0 ) , 10000 ) ;
304+ Stake :: < Test > :: insert ( U256 :: from ( 2 ) , U256 :: from ( 0 ) , 10000 ) ;
305+ Stake :: < Test > :: insert ( U256 :: from ( 3 ) , U256 :: from ( 0 ) , 10000 ) ;
306+ pallet_subtensor:: migration:: do_migrate_fix_total_coldkey_stake :: < Test > ( ) ;
307+ assert_eq ! ( TotalColdkeyStake :: <Test >:: get( coldkey) , 30000 ) ;
308+ } )
309+ }
310+
311+ // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake_no_entry --exact --nocapture
312+ #[ test]
313+ fn test_migrate_fix_total_coldkey_stake_no_entry ( ) {
314+ new_test_ext ( 1 ) . execute_with ( || {
315+ let coldkey = U256 :: from ( 0 ) ;
316+ StakingHotkeys :: < Test > :: insert ( coldkey, vec ! [ U256 :: from( 1 ) , U256 :: from( 2 ) , U256 :: from( 3 ) ] ) ;
317+ Stake :: < Test > :: insert ( U256 :: from ( 1 ) , U256 :: from ( 0 ) , 10000 ) ;
318+ Stake :: < Test > :: insert ( U256 :: from ( 2 ) , U256 :: from ( 0 ) , 10000 ) ;
319+ Stake :: < Test > :: insert ( U256 :: from ( 3 ) , U256 :: from ( 0 ) , 10000 ) ;
320+ pallet_subtensor:: migration:: do_migrate_fix_total_coldkey_stake :: < Test > ( ) ;
321+ assert_eq ! ( TotalColdkeyStake :: <Test >:: get( coldkey) , 30000 ) ;
322+ } )
323+ }
324+
325+ // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake_no_entry_in_hotkeys --exact --nocapture
326+ #[ test]
327+ fn test_migrate_fix_total_coldkey_stake_no_entry_in_hotkeys ( ) {
328+ new_test_ext ( 1 ) . execute_with ( || {
329+ let coldkey = U256 :: from ( 0 ) ;
330+ TotalColdkeyStake :: < Test > :: insert ( coldkey, 100000000 ) ;
331+ StakingHotkeys :: < Test > :: insert ( coldkey, vec ! [ U256 :: from( 1 ) , U256 :: from( 2 ) , U256 :: from( 3 ) ] ) ;
332+ pallet_subtensor:: migration:: do_migrate_fix_total_coldkey_stake :: < Test > ( ) ;
333+ assert_eq ! ( TotalColdkeyStake :: <Test >:: get( coldkey) , 0 ) ;
334+ } )
335+ }
336+
337+ // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake_one_hotkey_stake_missing --exact --nocapture
338+ #[ test]
339+ fn test_migrate_fix_total_coldkey_stake_one_hotkey_stake_missing ( ) {
340+ new_test_ext ( 1 ) . execute_with ( || {
341+ let coldkey = U256 :: from ( 0 ) ;
342+ TotalColdkeyStake :: < Test > :: insert ( coldkey, 100000000 ) ;
343+ StakingHotkeys :: < Test > :: insert ( coldkey, vec ! [ U256 :: from( 1 ) , U256 :: from( 2 ) , U256 :: from( 3 ) ] ) ;
344+ Stake :: < Test > :: insert ( U256 :: from ( 1 ) , U256 :: from ( 0 ) , 10000 ) ;
345+ Stake :: < Test > :: insert ( U256 :: from ( 2 ) , U256 :: from ( 0 ) , 10000 ) ;
346+ pallet_subtensor:: migration:: do_migrate_fix_total_coldkey_stake :: < Test > ( ) ;
347+ assert_eq ! ( TotalColdkeyStake :: <Test >:: get( coldkey) , 20000 ) ;
348+ } )
349+ }
0 commit comments