From a4c026aec029b02338aa1c84b0e5ffa8cca14b73 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 25 Nov 2024 11:23:55 +0100 Subject: [PATCH] fixes --- .../integration/slashing/keeper/keeper_test.go | 7 ++----- testutil/integration/router.go | 17 ++++++++++++++++- types/module/module.go | 8 ++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index d2d2205c1a6..74ccf5da61f 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -67,7 +67,6 @@ func initFixture(tb testing.TB) *fixture { encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) cdc := encodingCfg.Codec - logger := log.NewTestLogger(tb) authority := authtypes.NewModuleAddress("gov") maccPerms := map[string][]string{ @@ -124,7 +123,7 @@ func initFixture(tb testing.TB) *fixture { slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry(), cometInfoService) consensusModule := consensus.NewAppModule(cdc, consensusParamsKeeper) - integrationApp := integration.NewIntegrationApp(logger, keys, cdc, + integrationApp := integration.NewIntegrationApp(log.NewNopLogger(), keys, cdc, encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), map[string]appmodule.AppModule{ @@ -144,10 +143,8 @@ func initFixture(tb testing.TB) *fixture { slashingtypes.RegisterQueryServer(integrationApp.QueryHelper(), slashingkeeper.NewQuerier(slashingKeeper)) // set default staking params - err := stakingKeeper.Params.Set(sdkCtx, stakingtypes.DefaultParams()) - assert.NilError(tb, err) // TestParams set the SignedBlocksWindow to 1000 and MaxMissedBlocksPerWindow to 500 - err = slashingKeeper.Params.Set(sdkCtx, testutil.TestParams()) + err := slashingKeeper.Params.Set(sdkCtx, testutil.TestParams()) assert.NilError(tb, err) addrDels := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, sdkCtx, 6, stakingKeeper.TokensFromConsensusPower(sdkCtx, 200)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels) diff --git a/testutil/integration/router.go b/testutil/integration/router.go index 9b85d313a60..a65766847f2 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -156,7 +156,7 @@ func (app *App) RunMsg(msg sdk.Msg, option ...Option) (*codectypes.Any, error) { if cfg.AutomaticFinalizeBlock { height := app.LastBlockHeight() + 1 - if _, err := app.FinalizeBlock(&cmtabcitypes.FinalizeBlockRequest{Height: height, DecidedLastCommit: cmtabcitypes.CommitInfo{Votes: []cmtabcitypes.VoteInfo{{}}}}); err != nil { + if _, err := app.FinalizeBlock(&cmtabcitypes.FinalizeBlockRequest{Height: height, DecidedLastCommit: cmtabcitypes.CommitInfo{Votes: []cmtabcitypes.VoteInfo{}}}); err != nil { return nil, fmt.Errorf("failed to run finalize block: %w", err) } } @@ -186,6 +186,21 @@ func (app *App) RunMsg(msg sdk.Msg, option ...Option) (*codectypes.Any, error) { return response, nil } +// NextBlock advances the chain height and returns the new height. +func (app *App) NextBlock(txsblob ...[]byte) (int64, error) { + height := app.LastBlockHeight() + 1 + if _, err := app.FinalizeBlock(&cmtabcitypes.FinalizeBlockRequest{ + Txs: txsblob, // txsBlob are raw txs to be executed in the block + Height: height, + DecidedLastCommit: cmtabcitypes.CommitInfo{Votes: []cmtabcitypes.VoteInfo{}}, + }); err != nil { + return 0, fmt.Errorf("failed to run finalize block: %w", err) + } + + _, err := app.Commit() + return height, err +} + // Context returns the application context. It can be unwrapped to a sdk.Context, // with the sdk.UnwrapSDKContext function. func (app *App) Context() context.Context { diff --git a/types/module/module.go b/types/module/module.go index 7d865930b26..354fddc81c6 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -727,7 +727,7 @@ func (m *Manager) PreBlock(ctx sdk.Context) error { for _, moduleName := range m.OrderPreBlockers { if module, ok := m.Modules[moduleName].(appmodule.HasPreBlocker); ok { if err := module.PreBlock(ctx); err != nil { - return err + return fmt.Errorf("module %s PreBlock failed: %w", moduleName, err) } } } @@ -742,7 +742,7 @@ func (m *Manager) BeginBlock(ctx sdk.Context) (sdk.BeginBlock, error) { for _, moduleName := range m.OrderBeginBlockers { if module, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok { if err := module.BeginBlock(ctx); err != nil { - return sdk.BeginBlock{}, err + return sdk.BeginBlock{}, fmt.Errorf("module %s BeginBlock failed: %w", moduleName, err) } } } @@ -763,12 +763,12 @@ func (m *Manager) EndBlock(ctx sdk.Context) (sdk.EndBlock, error) { if module, ok := m.Modules[moduleName].(appmodule.HasEndBlocker); ok { err := module.EndBlock(ctx) if err != nil { - return sdk.EndBlock{}, err + return sdk.EndBlock{}, fmt.Errorf("module %s EndBlock failed: %w", moduleName, err) } } else if module, ok := m.Modules[moduleName].(HasABCIEndBlock); ok { moduleValUpdates, err := module.EndBlock(ctx) if err != nil { - return sdk.EndBlock{}, err + return sdk.EndBlock{}, fmt.Errorf("module %s EndBlock failed: %w", moduleName, err) } // use these validator updates if provided, the module manager assumes // only one module will update the validator set