Skip to content

Commit

Permalink
Add tests for Commiter change (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
prettymuchbryce committed Feb 28, 2023
1 parent 0e7ab87 commit 5d6053c
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 0 deletions.
49 changes: 49 additions & 0 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,33 @@ func TestABCI_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)
}

func TestABCI_CheckTx(t *testing.T) {
// This ante handler reads the key and checks that the value matches the
// current counter. This ensures changes to the KVStore persist across
Expand Down Expand Up @@ -1315,6 +1342,28 @@ func TestABCI_GetBlockRetentionHeight(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 := baseapp.NewBaseApp(name, logger, db, nil)

wasCommiterCalled := false
app.SetCommiter(func(ctx sdk.Context) {
// Make sure context is for next block
require.Equal(t, true, ctx.IsCheckTx())
wasCommiterCalled = true
})

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

require.Equal(t, true, wasCommiterCalled)
}

func TestABCI_Proposal_HappyPath(t *testing.T) {
anteKey := []byte("ante-key")
pool := mempool.NewSenderNonceMempool()
Expand Down
3 changes: 3 additions & 0 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ func TestBaseAppOptionSeal(t *testing.T) {
require.Panics(t, func() {
suite.baseApp.SetEndBlocker(nil)
})
require.Panics(t, func() {
suite.baseApp.SetCommiter(nil)
})
require.Panics(t, func() {
suite.baseApp.SetAnteHandler(nil)
})
Expand Down
113 changes: 113 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 @@ -251,3 +255,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 5d6053c

Please sign in to comment.