@@ -1628,3 +1628,49 @@ fn test_coldkey_swap_no_identity_no_changes_newcoldkey_exists() {
16281628 assert ! ( Identities :: <Test >:: get( new_coldkey) . is_some( ) ) ;
16291629 } ) ;
16301630}
1631+
1632+ // SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test swap_coldkey -- test_coldkey_swap_last_add_stake_increase --exact --nocapture
1633+ #[ test]
1634+ fn test_coldkey_swap_last_add_stake_increase ( ) {
1635+ new_test_ext ( 1 ) . execute_with ( || {
1636+ let old_coldkey = U256 :: from ( 3 ) ;
1637+ let new_coldkey = U256 :: from ( 4 ) ;
1638+ let hotkey = U256 :: from ( 5 ) ;
1639+
1640+ let netuid = 1 ;
1641+ let burn_cost = 10 ;
1642+ let tempo = 1 ;
1643+
1644+ SubtensorModule :: set_burn ( netuid, burn_cost) ;
1645+ add_network ( netuid, tempo, 0 ) ;
1646+ SubtensorModule :: add_balance_to_coldkey_account ( & old_coldkey, 100_000_000_000 ) ;
1647+
1648+ assert_ok ! ( SubtensorModule :: burned_register(
1649+ <<Test as Config >:: RuntimeOrigin >:: signed( old_coldkey) ,
1650+ netuid,
1651+ hotkey
1652+ ) ) ;
1653+
1654+ // Step some blocks
1655+ run_to_block ( 10 ) ;
1656+ // Add stake to the old coldkey
1657+ assert_ok ! ( SubtensorModule :: add_stake(
1658+ <<Test as Config >:: RuntimeOrigin >:: signed( old_coldkey) ,
1659+ hotkey,
1660+ 100_000
1661+ ) ) ;
1662+ // Check LastAddStakeIncrease
1663+ assert_eq ! ( LastAddStakeIncrease :: <Test >:: get( & hotkey, & old_coldkey) , 10 ) ; // Just added stake
1664+
1665+ // Check the same for the new coldkey
1666+ assert_eq ! ( LastAddStakeIncrease :: <Test >:: get( & hotkey, & new_coldkey) , 0 ) ; // No stake added ever
1667+
1668+ // Perform the coldkey swap
1669+ assert_ok ! ( SubtensorModule :: do_swap_coldkey( & old_coldkey, & new_coldkey) ) ;
1670+
1671+ // Check the LastAddStakeIncrease for the hotkey
1672+ assert_eq ! ( LastAddStakeIncrease :: <Test >:: get( & hotkey, & new_coldkey) , 10 ) ; // Matches the old coldkey
1673+ assert_eq ! ( LastAddStakeIncrease :: <Test >:: get( & hotkey, & old_coldkey) , 0 ) ;
1674+ // Should be reset to 0 (empty)
1675+ } ) ;
1676+ }
0 commit comments