|
8 | 8 | "time" |
9 | 9 |
|
10 | 10 | "github.com/sei-protocol/sei-chain/app/migration" |
| 11 | + "github.com/sei-protocol/sei-chain/app/upgrades/migrationpause" |
| 12 | + sctypes "github.com/sei-protocol/sei-chain/sei-db/state_db/sc/types" |
11 | 13 | abci "github.com/sei-protocol/sei-chain/sei-tendermint/abci/types" |
12 | 14 | tmproto "github.com/sei-protocol/sei-chain/sei-tendermint/proto/tendermint/types" |
13 | 15 | "github.com/stretchr/testify/require" |
@@ -71,6 +73,40 @@ func TestApplyMigrationBatchSize(t *testing.T) { |
71 | 73 | require.Equal(t, int(migration.MaxNumKeysToMigratePerBlock), got) |
72 | 74 | } |
73 | 75 |
|
| 76 | +func TestMigrationPauseHardForkPreservesInFlightMode(t *testing.T) { |
| 77 | + a := Setup(t, false, false, false) |
| 78 | + ctx := a.NewContext(false, tmproto.Header{Height: 1, ChainID: "sei-test", Time: time.Now()}) |
| 79 | + |
| 80 | + subspace, ok := a.ParamsKeeper.GetSubspace(migration.SubspaceName) |
| 81 | + require.True(t, ok) |
| 82 | + subspace.Set(ctx, migration.KeyNumKeysToMigratePerBlock, uint64(500)) |
| 83 | + a.applyMigrationBatchSize(ctx) |
| 84 | + |
| 85 | + modeBeforePause, ok := a.rootStore.GetWriteMode() |
| 86 | + require.True(t, ok) |
| 87 | + require.Equal(t, sctypes.MigrateEVM, modeBeforePause) |
| 88 | + |
| 89 | + const recoveryHeight = int64(2) |
| 90 | + a.HardForkManager.RegisterHandler( |
| 91 | + migrationpause.NewHardForkHandler(recoveryHeight, ctx.ChainID(), a.ParamsKeeper), |
| 92 | + ) |
| 93 | + ctx = ctx.WithBlockHeight(recoveryHeight) |
| 94 | + require.NotPanics(t, func() { |
| 95 | + a.BeginBlock(ctx, recoveryHeight, nil, nil, false) |
| 96 | + }) |
| 97 | + |
| 98 | + var storedRate uint64 |
| 99 | + subspace.Get(ctx, migration.KeyNumKeysToMigratePerBlock, &storedRate) |
| 100 | + require.Zero(t, storedRate) |
| 101 | + effectiveRate, ok := a.rootStore.GetMigrationBatchSize() |
| 102 | + require.True(t, ok) |
| 103 | + require.Zero(t, effectiveRate) |
| 104 | + |
| 105 | + modeAfterPause, ok := a.rootStore.GetWriteMode() |
| 106 | + require.True(t, ok) |
| 107 | + require.Equal(t, modeBeforePause, modeAfterPause) |
| 108 | +} |
| 109 | + |
74 | 110 | // TestBeginBlockAppliesMigrationBatchSize exercises the full BeginBlock path |
75 | 111 | // (not the helper in isolation): it mimics a governance ParameterChangeProposal |
76 | 112 | // having set NumKeysToMigratePerBlock, then runs app.BeginBlock and asserts the |
|
0 commit comments