Skip to content

Commit

Permalink
Add tests for Commiter change
Browse files Browse the repository at this point in the history
  • Loading branch information
prettymuchbryce committed Feb 3, 2023
1 parent 0514dfa commit bd28a85
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 0 deletions.
21 changes: 21 additions & 0 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ func TestGetBlockRentionHeight(t *testing.T) {
}
}

// Verifies that the Commiter is called with the checkState.
func TestCommiterCalledWithCheckState(t *testing.T) {
t.Parallel()

logger := defaultLogger()
db := dbm.NewMemDB()
name := t.Name()
app := NewBaseApp(name, logger, db, nil)

wasCommiterCalled := false
app.commiter = func(ctx sdk.Context) {
require.Equal(t, app.checkState.ctx, ctx)
wasCommiterCalled = true
}

app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
app.Commit()

require.Equal(t, true, wasCommiterCalled)
}

// Test and ensure that invalid block heights always cause errors.
// See issues:
// - https://github.com/cosmos/cosmos-sdk/issues/11220
Expand Down
30 changes: 30 additions & 0 deletions baseapp/deliver_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ func TestBaseAppOptionSeal(t *testing.T) {
require.Panics(t, func() {
app.SetEndBlocker(nil)
})
require.Panics(t, func() {
app.SetCommiter(nil)
})
require.Panics(t, func() {
app.SetAnteHandler(nil)
})
Expand Down Expand Up @@ -1002,6 +1005,33 @@ func TestBaseApp_EndBlock(t *testing.T) {
require.Equal(t, cp.Block.MaxGas, res.ConsensusParamUpdates.Block.MaxGas)
}

func TestBaseApp_Commit(t *testing.T) {
db := dbm.NewMemDB()
name := t.Name()
logger := defaultLogger()

cp := &tmproto.ConsensusParams{
Block: &tmproto.BlockParams{
MaxGas: 5000000,
},
}

app := baseapp.NewBaseApp(name, logger, db, nil)
app.SetParamStore(&paramStore{db: dbm.NewMemDB()})
app.InitChain(abci.RequestInitChain{
ConsensusParams: cp,
})

wasCommiterCalled := false
app.SetCommiter(func(ctx sdk.Context) {
wasCommiterCalled = true
})
app.Seal()

app.Commit()
require.Equal(t, true, wasCommiterCalled)
}

// Test that txs can be unmarshalled and read and that
// correct error codes are returned when not
func TestTxDecoder(t *testing.T) {
Expand Down
141 changes: 141 additions & 0 deletions testutil/mock/types_module_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions types/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func TestManagerOrderSetters(t *testing.T) {
require.Equal(t, []string{"module1", "module2"}, mm.OrderEndBlockers)
mm.SetOrderEndBlockers("module2", "module1")
require.Equal(t, []string{"module2", "module1"}, mm.OrderEndBlockers)

require.Equal(t, []string{"module1", "module2"}, mm.OrderCommiters)
mm.SetOrderCommiters("module2", "module1")
require.Equal(t, []string{"module2", "module1"}, mm.OrderCommiters)
}

func TestManager_RegisterInvariants(t *testing.T) {
Expand Down Expand Up @@ -249,3 +253,20 @@ func TestManager_EndBlock(t *testing.T) {
mockAppModule2.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1).Return([]abci.ValidatorUpdate{{}})
require.Panics(t, func() { mm.EndBlock(sdk.Context{}, req) })
}

func TestManager_Commit(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)

mockAppModule1 := mock.NewMockCommitAppModule(mockCtrl)
mockAppModule2 := mock.NewMockCommitAppModule(mockCtrl)
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
mm := module.NewManager(mockAppModule1, mockAppModule2)
require.NotNil(t, mm)
require.Equal(t, 2, len(mm.Modules))

mockAppModule1.EXPECT().Commit(gomock.Any()).Times(1)
mockAppModule2.EXPECT().Commit(gomock.Any()).Times(1)
mm.Commit(sdk.Context{})
}

0 comments on commit bd28a85

Please sign in to comment.