Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Nov 25, 2024
1 parent 6bcb81a commit a4c026a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
7 changes: 2 additions & 5 deletions tests/integration/slashing/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion testutil/integration/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand All @@ -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
Expand Down

0 comments on commit a4c026a

Please sign in to comment.