Browse Source

add test

pull/8151/head
jay tseng 3 years ago
parent
commit
7fc68a27ce
No known key found for this signature in database GPG Key ID: 5A9D3063305E6427
1 changed files with 45 additions and 0 deletions
  1. +45
    -0
      internal/consensus/replay_test.go

+ 45
- 0
internal/consensus/replay_test.go View File

@ -1281,3 +1281,48 @@ func (ica *initChainApp) InitChain(req abci.RequestInitChain) abci.ResponseInitC
Validators: ica.vals,
}
}
func TestReplayUpdateAppVerion(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewNopLogger()
app := kvstore.NewApplication()
client := abciclient.NewLocalClient(logger, app)
cfg, err := ResetConfig(t.TempDir(), "replay_test_")
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(cfg.RootDir) })
privVal, err := privval.LoadFilePV(cfg.PrivValidator.KeyFile(), cfg.PrivValidator.StateFile())
require.NoError(t, err)
pubKey, err := privVal.GetPubKey(ctx)
require.NoError(t, err)
stateDB, state, store := stateAndStore(t, cfg, pubKey, 0x0)
stateStore := sm.NewStore(stateDB)
// we modify the app version to the initial state for simulating the appversion update in the genesis file.
testGenesusAppVer := kvstore.ProtocolVersion + 1
state.Version.Consensus.App = testGenesusAppVer
state.ConsensusParams.Version.AppVersion = testGenesusAppVer
stateStore.Save(state)
// the genDoc has the default genesis app version which it's fine because it's be used in the app InitChain request.
genDoc, err := sm.MakeGenesisDocFromFile(cfg.GenesisFile())
require.NoError(t, err)
handshaker := NewHandshaker(logger, stateStore, state, store, nil, genDoc)
proxyApp := proxy.New(client, logger, proxy.NopMetrics())
require.NoError(t, proxyApp.Start(ctx), "Error starting proxy app connections")
require.NoError(t, handshaker.Handshake(ctx, proxyApp), "error on abci handshake")
// reload the state, check the app version was updated.
state, err = stateStore.Load()
require.NoError(t, err)
require.Equal(t, kvstore.ProtocolVersion, state.Version.Consensus.App)
require.Equal(t, kvstore.ProtocolVersion, state.ConsensusParams.Version.AppVersion)
}

Loading…
Cancel
Save