Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): fix long tests for abci 2.0 #16198

Merged
merged 16 commits into from
May 18, 2023
15 changes: 8 additions & 7 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ func SetupWithGenesisValSet(t *testing.T, valSet *cmttypes.ValidatorSet, genAccs
)

// commit genesis changes
app.Commit(context.TODO(), &abci.RequestCommit{})
// app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{
// Height: app.LastBlockHeight() + 1,
// AppHash: app.LastCommitID().Hash,
// ValidatorsHash: valSet.Hash(),
// NextValidatorsHash: valSet.Hash(),
// }})
_, err = app.Commit(context.TODO(), nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be removed. This will be causing consensus key nil issues

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit sets the finalizeBlockState to nil, so this makes sense.

require.NoError(t, err)
_, err = app.FinalizeBlock(context.TODO(), &abci.RequestFinalizeBlock{
Height: app.LastBlockHeight() + 1,
Hash: app.LastCommitID().Hash,
NextValidatorsHash: valSet.Hash(),
})
require.NoError(t, err)

return app
}
Expand Down
10 changes: 4 additions & 6 deletions tests/integration/store/rootmulti/rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestRollback(t *testing.T) {
AppOpts: simtestutil.NewAppOptionsWithFlagHome(t.TempDir()),
}
app := simapp.NewSimappWithCustomOptions(t, false, options)
app.Commit(context.TODO(), &abci.RequestCommit{})
app.Commit(context.TODO(), nil)
ver0 := app.LastBlockHeight()
// commit 10 blocks
for i := int64(1); i <= 10; i++ {
Expand All @@ -38,7 +38,7 @@ func TestRollback(t *testing.T) {
ctx := app.NewContext(false, header)
store := ctx.KVStore(app.GetKey("bank"))
store.Set([]byte("key"), []byte(fmt.Sprintf("value%d", i)))
app.Commit(context.TODO(), &abci.RequestCommit{})
app.Commit(context.TODO(), nil)
}

assert.Equal(t, ver0+10, app.LastBlockHeight())
Expand All @@ -61,13 +61,11 @@ func TestRollback(t *testing.T) {
Height: ver0 + i,
AppHash: app.LastCommitID().Hash,
}
app.FinalizeBlock(context.TODO(), &abci.RequestFinalizeBlock{
Height: ver0 + i,
})
app.FinalizeBlock(context.TODO(), &abci.RequestFinalizeBlock{Height: ver0 + i})
ctx := app.NewContext(false, header)
store := ctx.KVStore(app.GetKey("bank"))
store.Set([]byte("key"), []byte(fmt.Sprintf("VALUE%d", i)))
app.Commit(context.TODO(), &abci.RequestCommit{})
app.Commit(context.TODO(), nil)
}

assert.Equal(t, ver0+10, app.LastBlockHeight())
Expand Down
2 changes: 1 addition & 1 deletion testutil/integration/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Config struct {
// Option is a function that can be used to configure the integration app.
type Option func(*Config)

// WithAutomaticBlockCreation enables begin/end block calls.
// WithAutomaticFinalizeBlock calls ABCI finalize block.
func WithAutomaticFinalizeBlock() Option {
return func(cfg *Config) {
cfg.AutomaticFinalizeBlock = true
Expand Down
28 changes: 12 additions & 16 deletions testutil/integration/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,28 @@ func NewIntegrationApp(
bApp.SetMsgServiceRouter(router)

if keys[consensusparamtypes.StoreKey] != nil {

// set baseApp param store
consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress("gov").String(), runtime.EventService{})
bApp.SetParamStore(consensusParamsKeeper.ParamsStore)

if err := bApp.LoadLatestVersion(); err != nil {
panic(fmt.Errorf("failed to load application version from store: %w", err))
}
bApp.InitChain(context.TODO(), &cmtabcitypes.RequestInitChain{ChainId: appName, ConsensusParams: simtestutil.DefaultConsensusParams})

if _, err := bApp.InitChain(context.TODO(), &cmtabcitypes.RequestInitChain{ChainId: appName, ConsensusParams: simtestutil.DefaultConsensusParams}); err != nil {
panic(fmt.Errorf("failed to initialize application: %w", err))
}
} else {
if err := bApp.LoadLatestVersion(); err != nil {
panic(fmt.Errorf("failed to load application version from store: %w", err))
}
bApp.InitChain(context.TODO(), &cmtabcitypes.RequestInitChain{ChainId: appName})

if _, err := bApp.InitChain(context.TODO(), &cmtabcitypes.RequestInitChain{ChainId: appName}); err != nil {
panic(fmt.Errorf("failed to initialize application: %w", err))
}
}

bApp.InitChain(context.Background(), &cmtabcitypes.RequestInitChain{ChainId: appName})
bApp.Commit(context.TODO(), &cmtabcitypes.RequestCommit{})
bApp.Commit(context.TODO(), nil)

Check warning

Code scanning / gosec

Errors unhandled.

Errors unhandled.

ctx := sdkCtx.WithBlockHeader(cmtproto.Header{ChainID: appName}).WithIsCheckTx(true)

Expand All @@ -125,22 +128,15 @@ func (app *App) RunMsg(msg sdk.Msg, option ...Option) (*codectypes.Any, error) {
}

if cfg.AutomaticCommit {
defer app.Commit(context.TODO(), &cmtabcitypes.RequestCommit{})
defer app.Commit(context.TODO(), nil)
}

if cfg.AutomaticFinalizeBlock {
height := app.LastBlockHeight() + 1
ctx := app.ctx.WithBlockHeight(height).WithChainID(appName)

app.FinalizeBlock(context.TODO(), &cmtabcitypes.RequestFinalizeBlock{Height: height})

app.logger.Info("Running BeginBlock", "height", height)
app.moduleManager.BeginBlock(ctx)

defer func() {
app.logger.Info("Running EndBlock", "height", height)
app.moduleManager.EndBlock(ctx)
}()
if _, err := app.FinalizeBlock(ctx, &cmtabcitypes.RequestFinalizeBlock{Height: height}); err != nil {
return nil, fmt.Errorf("failed to run finalize block: %w", err)
}
}

app.logger.Info("Running msg", "msg", msg.String())
Expand Down
5 changes: 5 additions & 0 deletions testutil/sims/app_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon

// commit genesis changes
if !startupConfig.AtGenesis {
_, err = app.Commit(context.TODO(), nil)
if err != nil {
return nil, fmt.Errorf("failed to commit genesis changes: %w", err)
}

_, err = app.FinalizeBlock(context.TODO(), &abci.RequestFinalizeBlock{
Height: app.LastBlockHeight() + 1,
NextValidatorsHash: valSet.Hash(),
Expand Down