@@ -2044,3 +2044,115 @@ fn test_migrate_restore_subnet_locked_65_128() {
20442044 ) ;
20452045 } ) ;
20462046}
2047+
2048+ #[ test]
2049+ fn test_migrate_network_lock_cost_2500_sets_price_and_decay ( ) {
2050+ new_test_ext ( 0 ) . execute_with ( || {
2051+ // ── constants ───────────────────────────────────────────────────────
2052+ const RAO_PER_TAO : u64 = 1_000_000_000 ;
2053+ const TARGET_COST_TAO : u64 = 2_500 ;
2054+ const TARGET_COST_RAO : u64 = TARGET_COST_TAO * RAO_PER_TAO ;
2055+ const NEW_LAST_LOCK_RAO : u64 = ( TARGET_COST_TAO / 2 ) * RAO_PER_TAO ;
2056+
2057+ let migration_key = b"migrate_network_lock_cost_2500" . to_vec ( ) ;
2058+
2059+ // ── pre ──────────────────────────────────────────────────────────────
2060+ assert ! (
2061+ !HasMigrationRun :: <Test >:: get( migration_key. clone( ) ) ,
2062+ "HasMigrationRun should be false before migration"
2063+ ) ;
2064+
2065+ // Ensure current_block > 0 so mult == 2 in get_network_lock_cost()
2066+ step_block ( 1 ) ;
2067+ let current_block_before = Pallet :: < Test > :: get_current_block_as_u64 ( ) ;
2068+
2069+ // Snapshot interval to ensure migration doesn't change it
2070+ let interval_before = NetworkLockReductionInterval :: < Test > :: get ( ) ;
2071+
2072+ // ── run migration ────────────────────────────────────────────────────
2073+ let weight = crate :: migrations:: migrate_network_lock_cost_2500:: migrate_network_lock_cost_2500 :: < Test > ( ) ;
2074+ assert ! ( !weight. is_zero( ) , "migration weight should be > 0" ) ;
2075+
2076+ // ── asserts: params & flags ─────────────────────────────────────────
2077+ assert_eq ! (
2078+ Pallet :: <Test >:: get_network_last_lock( ) ,
2079+ NEW_LAST_LOCK_RAO . into( ) ,
2080+ "last_lock should be set to 1,250 TAO (in rao)"
2081+ ) ;
2082+ assert_eq ! (
2083+ Pallet :: <Test >:: get_network_last_lock_block( ) ,
2084+ current_block_before,
2085+ "last_lock_block should be set to the current block"
2086+ ) ;
2087+
2088+ // Lock cost should be exactly 2,500 TAO immediately after migration
2089+ let lock_cost_now = Pallet :: < Test > :: get_network_lock_cost ( ) ;
2090+ assert_eq ! (
2091+ lock_cost_now,
2092+ TARGET_COST_RAO . into( ) ,
2093+ "lock cost should be 2,500 TAO right after migration"
2094+ ) ;
2095+
2096+ // Interval should be unchanged by this migration
2097+ assert_eq ! (
2098+ NetworkLockReductionInterval :: <Test >:: get( ) ,
2099+ interval_before,
2100+ "lock reduction interval should not be modified by this migration"
2101+ ) ;
2102+
2103+ assert ! (
2104+ HasMigrationRun :: <Test >:: get( migration_key. clone( ) ) ,
2105+ "HasMigrationRun should be true after migration"
2106+ ) ;
2107+
2108+ // ── decay check (1 block later) ─────────────────────────────────────
2109+ // Expected: cost = max(min_lock, 2*L - floor(L / eff_interval) * delta_blocks)
2110+ let eff_interval = Pallet :: < Test > :: get_lock_reduction_interval ( ) ;
2111+ let per_block_decrement: u64 = if eff_interval == 0 {
2112+ 0
2113+ } else {
2114+ NEW_LAST_LOCK_RAO / eff_interval
2115+ } ;
2116+
2117+ let min_lock_rao: u64 = Pallet :: < Test > :: get_network_min_lock ( ) . to_u64 ( ) ;
2118+
2119+ step_block ( 1 ) ;
2120+ let expected_after_1: u64 = core:: cmp:: max (
2121+ min_lock_rao,
2122+ TARGET_COST_RAO . saturating_sub ( per_block_decrement) ,
2123+ ) ;
2124+ let lock_cost_after_1 = Pallet :: < Test > :: get_network_lock_cost ( ) ;
2125+ assert_eq ! (
2126+ lock_cost_after_1,
2127+ expected_after_1. into( ) ,
2128+ "lock cost should decay by one per-block step after 1 block"
2129+ ) ;
2130+
2131+ // ── idempotency: running the migration again should do nothing ──────
2132+ let last_lock_before_rerun = Pallet :: < Test > :: get_network_last_lock ( ) ;
2133+ let last_lock_block_before_rerun = Pallet :: < Test > :: get_network_last_lock_block ( ) ;
2134+ let cost_before_rerun = Pallet :: < Test > :: get_network_lock_cost ( ) ;
2135+
2136+ let _weight2 = crate :: migrations:: migrate_network_lock_cost_2500:: migrate_network_lock_cost_2500 :: < Test > ( ) ;
2137+
2138+ assert ! (
2139+ HasMigrationRun :: <Test >:: get( migration_key. clone( ) ) ,
2140+ "HasMigrationRun remains true on second run"
2141+ ) ;
2142+ assert_eq ! (
2143+ Pallet :: <Test >:: get_network_last_lock( ) ,
2144+ last_lock_before_rerun,
2145+ "second run should not modify last_lock"
2146+ ) ;
2147+ assert_eq ! (
2148+ Pallet :: <Test >:: get_network_last_lock_block( ) ,
2149+ last_lock_block_before_rerun,
2150+ "second run should not modify last_lock_block"
2151+ ) ;
2152+ assert_eq ! (
2153+ Pallet :: <Test >:: get_network_lock_cost( ) ,
2154+ cost_before_rerun,
2155+ "second run should not change current lock cost"
2156+ ) ;
2157+ } ) ;
2158+ }
0 commit comments