abci: application type should take contexts (#8388)

This commit is contained in:
Sam Kleinman
2022-04-22 10:58:01 -04:00
committed by GitHub
parent 6970c9177b
commit 8345dc4f7c
38 changed files with 543 additions and 357 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
ensureDir(t, path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
app := kvstore.NewApplication()
vals := types.TM2PB.ValidatorUpdates(state.Validators)
app.InitChain(abci.RequestInitChain{Validators: vals})
app.InitChain(ctx, abci.RequestInitChain{Validators: vals})
blockDB := dbm.NewMemDB()
blockStore := store.NewBlockStore(blockDB)
+6 -5
View File
@@ -12,6 +12,7 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
@@ -730,9 +731,9 @@ func ensureVoteMatch(t *testing.T, voteCh <-chan tmpubsub.Message, height int64,
msg.Data())
vote := voteEvent.Vote
require.Equal(t, height, vote.Height, "expected height %d, but got %d", height, vote.Height)
require.Equal(t, round, vote.Round, "expected round %d, but got %d", round, vote.Round)
require.Equal(t, voteType, vote.Type, "expected type %s, but got %s", voteType, vote.Type)
assert.Equal(t, height, vote.Height, "expected height %d, but got %d", height, vote.Height)
assert.Equal(t, round, vote.Round, "expected round %d, but got %d", round, vote.Round)
assert.Equal(t, voteType, vote.Type, "expected type %s, but got %s", voteType, vote.Type)
if hash == nil {
require.Nil(t, vote.BlockID.Hash, "Expected prevote to be for nil, got %X", vote.BlockID.Hash)
} else {
@@ -820,7 +821,7 @@ func makeConsensusState(
closeFuncs = append(closeFuncs, app.Close)
vals := types.TM2PB.ValidatorUpdates(state.Validators)
app.InitChain(abci.RequestInitChain{Validators: vals})
app.InitChain(ctx, abci.RequestInitChain{Validators: vals})
l := logger.With("validator", i, "module", "consensus")
css[i] = newStateWithConfigAndBlockStore(ctx, t, l, thisConfig, state, privVals[i], app, blockStore)
@@ -891,7 +892,7 @@ func randConsensusNetWithPeers(
case *kvstore.Application:
state.Version.Consensus.App = kvstore.ProtocolVersion
}
app.InitChain(abci.RequestInitChain{Validators: vals})
app.InitChain(ctx, abci.RequestInitChain{Validators: vals})
// sm.SaveState(stateDB,state) //height 1's validatorsInfo already saved in LoadStateFromDBOrGenesisDoc above
css[i] = newStateWithConfig(ctx, t, logger.With("validator", i, "module", "consensus"), thisConfig, state, privVal, app)
+8 -10
View File
@@ -199,10 +199,10 @@ func TestMempoolRmBadTx(t *testing.T) {
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(0))
resFinalize := app.FinalizeBlock(abci.RequestFinalizeBlock{Txs: [][]byte{txBytes}})
resFinalize := app.FinalizeBlock(ctx, abci.RequestFinalizeBlock{Txs: [][]byte{txBytes}})
assert.False(t, resFinalize.TxResults[0].IsErr(), fmt.Sprintf("expected no error. got %v", resFinalize))
resCommit := app.Commit()
resCommit := app.Commit(ctx)
assert.True(t, len(resCommit.Data) > 0)
emptyMempoolCh := make(chan struct{})
@@ -267,11 +267,11 @@ func NewCounterApplication() *CounterApplication {
return &CounterApplication{}
}
func (app *CounterApplication) Info(req abci.RequestInfo) abci.ResponseInfo {
func (app *CounterApplication) Info(_ context.Context, req abci.RequestInfo) abci.ResponseInfo {
return abci.ResponseInfo{Data: fmt.Sprintf("txs:%v", app.txCount)}
}
func (app *CounterApplication) FinalizeBlock(req abci.RequestFinalizeBlock) abci.ResponseFinalizeBlock {
func (app *CounterApplication) FinalizeBlock(_ context.Context, req abci.RequestFinalizeBlock) abci.ResponseFinalizeBlock {
respTxs := make([]*abci.ExecTxResult, len(req.Txs))
for i, tx := range req.Txs {
txValue := txAsUint64(tx)
@@ -288,7 +288,7 @@ func (app *CounterApplication) FinalizeBlock(req abci.RequestFinalizeBlock) abci
return abci.ResponseFinalizeBlock{TxResults: respTxs}
}
func (app *CounterApplication) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
func (app *CounterApplication) CheckTx(_ context.Context, req abci.RequestCheckTx) abci.ResponseCheckTx {
txValue := txAsUint64(req.Tx)
if txValue != uint64(app.mempoolTxCount) {
return abci.ResponseCheckTx{
@@ -305,7 +305,7 @@ func txAsUint64(tx []byte) uint64 {
return binary.BigEndian.Uint64(tx8)
}
func (app *CounterApplication) Commit() abci.ResponseCommit {
func (app *CounterApplication) Commit(context.Context) abci.ResponseCommit {
app.mempoolTxCount = app.txCount
if app.txCount == 0 {
return abci.ResponseCommit{}
@@ -315,8 +315,7 @@ func (app *CounterApplication) Commit() abci.ResponseCommit {
return abci.ResponseCommit{Data: hash}
}
func (app *CounterApplication) PrepareProposal(
req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
func (app *CounterApplication) PrepareProposal(_ context.Context, req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
trs := make([]*abci.TxRecord, 0, len(req.Txs))
var totalBytes int64
@@ -333,7 +332,6 @@ func (app *CounterApplication) PrepareProposal(
return abci.ResponsePrepareProposal{TxRecords: trs}
}
func (app *CounterApplication) ProcessProposal(
req abci.RequestProcessProposal) abci.ResponseProcessProposal {
func (app *CounterApplication) ProcessProposal(_ context.Context, req abci.RequestProcessProposal) abci.ResponseProcessProposal {
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}
}
@@ -3,6 +3,8 @@
package mocks
import (
testing "testing"
mock "github.com/stretchr/testify/mock"
state "github.com/tendermint/tendermint/internal/state"
)
@@ -26,3 +28,12 @@ func (_m *ConsSyncReactor) SetStateSyncingMetrics(_a0 float64) {
func (_m *ConsSyncReactor) SwitchToConsensus(_a0 state.State, _a1 bool) {
_m.Called(_a0, _a1)
}
// NewConsSyncReactor creates a new instance of ConsSyncReactor. It also registers a cleanup function to assert the mocks expectations.
func NewConsSyncReactor(t testing.TB) *ConsSyncReactor {
mock := &ConsSyncReactor{}
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
+1 -1
View File
@@ -466,7 +466,7 @@ func TestReactorWithEvidence(t *testing.T) {
app := kvstore.NewApplication()
vals := types.TM2PB.ValidatorUpdates(state.Validators)
app.InitChain(abci.RequestInitChain{Validators: vals})
app.InitChain(ctx, abci.RequestInitChain{Validators: vals})
pv := privVals[i]
blockDB := dbm.NewMemDB()
+2 -2
View File
@@ -75,7 +75,7 @@ type mockProxyApp struct {
abciResponses *tmstate.ABCIResponses
}
func (mock *mockProxyApp) FinalizeBlock(req abci.RequestFinalizeBlock) abci.ResponseFinalizeBlock {
func (mock *mockProxyApp) FinalizeBlock(_ context.Context, req abci.RequestFinalizeBlock) abci.ResponseFinalizeBlock {
r := mock.abciResponses.FinalizeBlock
mock.txCount++
if r == nil {
@@ -84,6 +84,6 @@ func (mock *mockProxyApp) FinalizeBlock(req abci.RequestFinalizeBlock) abci.Resp
return *r
}
func (mock *mockProxyApp) Commit() abci.ResponseCommit {
func (mock *mockProxyApp) Commit(context.Context) abci.ResponseCommit {
return abci.ResponseCommit{Data: mock.appHash}
}
+5 -5
View File
@@ -118,9 +118,6 @@ func sendTxs(ctx context.Context, t *testing.T, cs *State) {
// TestWALCrash uses crashing WAL to test we can recover from any WAL failure.
func TestWALCrash(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
testCases := []struct {
name string
initFn func(dbm.DB, *State, context.Context)
@@ -139,6 +136,9 @@ func TestWALCrash(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
consensusReplayConfig, err := ResetConfig(t.TempDir(), tc.name)
require.NoError(t, err)
crashWALandCheckLiveness(ctx, t, consensusReplayConfig, tc.initFn, tc.heightToStop)
@@ -1017,7 +1017,7 @@ type badApp struct {
onlyLastHashIsWrong bool
}
func (app *badApp) Commit() abci.ResponseCommit {
func (app *badApp) Commit(context.Context) abci.ResponseCommit {
app.height++
if app.onlyLastHashIsWrong {
if app.height == app.numBlocks {
@@ -1275,7 +1275,7 @@ type initChainApp struct {
vals []abci.ValidatorUpdate
}
func (ica *initChainApp) InitChain(req abci.RequestInitChain) abci.ResponseInitChain {
func (ica *initChainApp) InitChain(_ context.Context, req abci.RequestInitChain) abci.ResponseInitChain {
return abci.ResponseInitChain{
Validators: ica.vals,
}
+34 -25
View File
@@ -1917,7 +1917,8 @@ func TestProcessProposalAccept(t *testing.T) {
if testCase.accept {
status = abci.ResponseProcessProposal_ACCEPT
}
m.On("ProcessProposal", mock.Anything).Return(abci.ResponseProcessProposal{Status: status})
m.On("ProcessProposal", mock.Anything, mock.Anything).Return(abci.ResponseProcessProposal{Status: status})
m.On("PrepareProposal", mock.Anything, mock.Anything).Return(abci.ResponsePrepareProposal{})
cs1, _ := makeState(ctx, t, makeStateArgs{config: config, application: m})
height, round := cs1.Height, cs1.Round
@@ -1965,11 +1966,14 @@ func TestFinalizeBlockCalled(t *testing.T) {
defer cancel()
m := abcimocks.NewBaseMock()
m.On("ProcessProposal", mock.Anything).Return(abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT})
m.On("VerifyVoteExtension", mock.Anything).Return(abci.ResponseVerifyVoteExtension{
m.On("ProcessProposal", mock.Anything, mock.Anything).Return(abci.ResponseProcessProposal{
Status: abci.ResponseProcessProposal_ACCEPT,
})
m.On("PrepareProposal", mock.Anything, mock.Anything).Return(abci.ResponsePrepareProposal{})
m.On("VerifyVoteExtension", mock.Anything, mock.Anything).Return(abci.ResponseVerifyVoteExtension{
Status: abci.ResponseVerifyVoteExtension_ACCEPT,
})
m.On("FinalizeBlock", mock.Anything).Return(abci.ResponseFinalizeBlock{}).Maybe()
m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(abci.ResponseFinalizeBlock{}).Maybe()
cs1, vss := makeState(ctx, t, makeStateArgs{config: config, application: m})
height, round := cs1.Height, cs1.Round
@@ -2007,9 +2011,9 @@ func TestFinalizeBlockCalled(t *testing.T) {
m.AssertExpectations(t)
if !testCase.expectCalled {
m.AssertNotCalled(t, "FinalizeBlock", mock.Anything)
m.AssertNotCalled(t, "FinalizeBlock", ctx, mock.Anything)
} else {
m.AssertCalled(t, "FinalizeBlock", mock.Anything)
m.AssertCalled(t, "FinalizeBlock", ctx, mock.Anything)
}
})
}
@@ -2023,14 +2027,15 @@ func TestExtendVoteCalled(t *testing.T) {
defer cancel()
m := abcimocks.NewBaseMock()
m.On("ProcessProposal", mock.Anything).Return(abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT})
m.On("ExtendVote", mock.Anything).Return(abci.ResponseExtendVote{
m.On("ProcessProposal", mock.Anything, mock.Anything).Return(abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT})
m.On("PrepareProposal", mock.Anything, mock.Anything).Return(abci.ResponsePrepareProposal{})
m.On("ExtendVote", mock.Anything, mock.Anything).Return(abci.ResponseExtendVote{
VoteExtension: []byte("extension"),
})
m.On("VerifyVoteExtension", mock.Anything).Return(abci.ResponseVerifyVoteExtension{
m.On("VerifyVoteExtension", mock.Anything, mock.Anything).Return(abci.ResponseVerifyVoteExtension{
Status: abci.ResponseVerifyVoteExtension_ACCEPT,
})
m.On("FinalizeBlock", mock.Anything).Return(abci.ResponseFinalizeBlock{}).Maybe()
m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(abci.ResponseFinalizeBlock{}).Maybe()
cs1, vss := makeState(ctx, t, makeStateArgs{config: config, application: m})
height, round := cs1.Height, cs1.Round
@@ -2045,7 +2050,7 @@ func TestExtendVoteCalled(t *testing.T) {
ensureNewRound(t, newRoundCh, height, round)
ensureNewProposal(t, proposalCh, height, round)
m.AssertNotCalled(t, "ExtendVote", mock.Anything)
m.AssertNotCalled(t, "ExtendVote", mock.Anything, mock.Anything)
rs := cs1.GetRoundState()
@@ -2058,12 +2063,12 @@ func TestExtendVoteCalled(t *testing.T) {
ensurePrecommit(t, voteCh, height, round)
m.AssertCalled(t, "ExtendVote", abci.RequestExtendVote{
m.AssertCalled(t, "ExtendVote", ctx, abci.RequestExtendVote{
Height: height,
Hash: blockID.Hash,
})
m.AssertCalled(t, "VerifyVoteExtension", abci.RequestVerifyVoteExtension{
m.AssertCalled(t, "VerifyVoteExtension", ctx, abci.RequestVerifyVoteExtension{
Hash: blockID.Hash,
ValidatorAddress: addr,
Height: height,
@@ -2080,7 +2085,7 @@ func TestExtendVoteCalled(t *testing.T) {
pv, err := pv.GetPubKey(ctx)
require.NoError(t, err)
addr := pv.Address()
m.AssertCalled(t, "VerifyVoteExtension", abci.RequestVerifyVoteExtension{
m.AssertCalled(t, "VerifyVoteExtension", ctx, abci.RequestVerifyVoteExtension{
Hash: blockID.Hash,
ValidatorAddress: addr,
Height: height,
@@ -2098,14 +2103,15 @@ func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) {
defer cancel()
m := abcimocks.NewBaseMock()
m.On("ProcessProposal", mock.Anything).Return(abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT})
m.On("ExtendVote", mock.Anything).Return(abci.ResponseExtendVote{
m.On("ProcessProposal", mock.Anything, mock.Anything).Return(abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT})
m.On("PrepareProposal", mock.Anything, mock.Anything).Return(abci.ResponsePrepareProposal{})
m.On("ExtendVote", mock.Anything, mock.Anything).Return(abci.ResponseExtendVote{
VoteExtension: []byte("extension"),
})
m.On("VerifyVoteExtension", mock.Anything).Return(abci.ResponseVerifyVoteExtension{
m.On("VerifyVoteExtension", mock.Anything, mock.Anything).Return(abci.ResponseVerifyVoteExtension{
Status: abci.ResponseVerifyVoteExtension_ACCEPT,
})
m.On("FinalizeBlock", mock.Anything).Return(abci.ResponseFinalizeBlock{}).Maybe()
m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(abci.ResponseFinalizeBlock{}).Maybe()
cs1, vss := makeState(ctx, t, makeStateArgs{config: config, application: m})
height, round := cs1.Height, cs1.Round
@@ -2130,12 +2136,12 @@ func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) {
ensurePrecommit(t, voteCh, height, round)
m.AssertCalled(t, "ExtendVote", abci.RequestExtendVote{
m.AssertCalled(t, "ExtendVote", mock.Anything, abci.RequestExtendVote{
Height: height,
Hash: blockID.Hash,
})
m.AssertCalled(t, "VerifyVoteExtension", abci.RequestVerifyVoteExtension{
m.AssertCalled(t, "VerifyVoteExtension", mock.Anything, abci.RequestVerifyVoteExtension{
Hash: blockID.Hash,
ValidatorAddress: addr,
Height: height,
@@ -2152,7 +2158,7 @@ func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) {
require.NoError(t, err)
addr = pv.Address()
m.AssertNotCalled(t, "VerifyVoteExtension", abci.RequestVerifyVoteExtension{
m.AssertNotCalled(t, "VerifyVoteExtension", ctx, abci.RequestVerifyVoteExtension{
Hash: blockID.Hash,
ValidatorAddress: addr,
Height: height,
@@ -2168,10 +2174,11 @@ func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) {
// is the proposer again and ensures that the mock application receives the set of
// vote extensions from the previous consensus instance.
func TestPrepareProposalReceivesVoteExtensions(t *testing.T) {
config := configSetup(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
config := configSetup(t)
// create a list of vote extensions, one for each validator.
voteExtensions := [][]byte{
[]byte("extension 0"),
@@ -2181,10 +2188,12 @@ func TestPrepareProposalReceivesVoteExtensions(t *testing.T) {
}
m := abcimocks.NewBaseMock()
m.On("ExtendVote", mock.Anything).Return(abci.ResponseExtendVote{
m.On("ExtendVote", mock.Anything, mock.Anything).Return(abci.ResponseExtendVote{
VoteExtension: voteExtensions[0],
})
m.On("PrepareProposal", mock.Anything).Return(abci.ResponsePrepareProposal{}).Once()
m.On("PrepareProposal", mock.Anything, mock.Anything).Return(abci.ResponsePrepareProposal{}).Once()
m.On("ProcessProposal", mock.Anything, mock.Anything).Return(abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}).Once()
m.On("VerifyVoteExtension", mock.Anything, mock.Anything).Return(abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT})
cs1, vss := makeState(ctx, t, makeStateArgs{config: config, application: m})
height, round := cs1.Height, cs1.Round
@@ -2228,7 +2237,7 @@ func TestPrepareProposalReceivesVoteExtensions(t *testing.T) {
// capture the prepare proposal request.
rpp := abci.RequestPrepareProposal{}
m.On("PrepareProposal", mock.MatchedBy(func(r abci.RequestPrepareProposal) bool {
m.On("PrepareProposal", mock.Anything, mock.MatchedBy(func(r abci.RequestPrepareProposal) bool {
rpp = r
return true
})).Return(abci.ResponsePrepareProposal{})
+12
View File
@@ -3,7 +3,10 @@
package mocks
import (
testing "testing"
mock "github.com/stretchr/testify/mock"
types "github.com/tendermint/tendermint/types"
)
@@ -57,3 +60,12 @@ func (_m *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
return r0
}
// NewBlockStore creates a new instance of BlockStore. It also registers a cleanup function to assert the mocks expectations.
func NewBlockStore(t testing.TB) *BlockStore {
mock := &BlockStore{}
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
+1 -1
View File
@@ -36,7 +36,7 @@ type testTx struct {
priority int64
}
func (app *application) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
func (app *application) CheckTx(_ context.Context, req abci.RequestCheckTx) abci.ResponseCheckTx {
var (
priority int64
sender string
+11
View File
@@ -11,6 +11,8 @@ import (
mock "github.com/stretchr/testify/mock"
testing "testing"
types "github.com/tendermint/tendermint/types"
)
@@ -170,3 +172,12 @@ func (_m *Mempool) Update(ctx context.Context, blockHeight int64, blockTxs types
return r0
}
// NewMempool creates a new instance of Mempool. It also registers a cleanup function to assert the mocks expectations.
func NewMempool(t testing.TB) *Mempool {
mock := &Mempool{}
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
+11
View File
@@ -13,6 +13,8 @@ import (
p2p "github.com/tendermint/tendermint/internal/p2p"
testing "testing"
types "github.com/tendermint/tendermint/types"
)
@@ -150,3 +152,12 @@ func (_m *Connection) String() string {
return r0
}
// NewConnection creates a new instance of Connection. It also registers a cleanup function to assert the mocks expectations.
func NewConnection(t testing.TB) *Connection {
mock := &Connection{}
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
+11
View File
@@ -10,6 +10,8 @@ import (
mock "github.com/stretchr/testify/mock"
p2p "github.com/tendermint/tendermint/internal/p2p"
testing "testing"
)
// Transport is an autogenerated mock type for the Transport type
@@ -141,3 +143,12 @@ func (_m *Transport) String() string {
return r0
}
// NewTransport creates a new instance of Transport. It also registers a cleanup function to assert the mocks expectations.
func NewTransport(t testing.TB) *Transport {
mock := &Transport{}
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
+7 -7
View File
@@ -343,12 +343,12 @@ func TestProcessProposal(t *testing.T) {
ProposerAddress: block1.ProposerAddress,
}
app.On("ProcessProposal", mock.Anything).Return(abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT})
app.On("ProcessProposal", mock.Anything, mock.Anything).Return(abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT})
acceptBlock, err := blockExec.ProcessProposal(ctx, block1, state)
require.NoError(t, err)
require.True(t, acceptBlock)
app.AssertExpectations(t)
app.AssertCalled(t, "ProcessProposal", expectedRpp)
app.AssertCalled(t, "ProcessProposal", ctx, expectedRpp)
}
func TestValidateValidatorUpdates(t *testing.T) {
@@ -691,7 +691,7 @@ func TestPrepareProposalErrorOnNonExistingRemoved(t *testing.T) {
},
},
}
app.On("PrepareProposal", mock.Anything).Return(rpp)
app.On("PrepareProposal", mock.Anything, mock.Anything).Return(rpp)
cc := abciclient.NewLocalClient(logger, app)
proxyApp := proxy.New(cc, logger, proxy.NopMetrics())
@@ -745,7 +745,7 @@ func TestPrepareProposalRemoveTxs(t *testing.T) {
mp.On("RemoveTxByKey", mock.Anything).Return(nil).Twice()
app := abcimocks.NewBaseMock()
app.On("PrepareProposal", mock.Anything).Return(abci.ResponsePrepareProposal{
app.On("PrepareProposal", mock.Anything, mock.Anything).Return(abci.ResponsePrepareProposal{
TxRecords: trs,
})
@@ -804,7 +804,7 @@ func TestPrepareProposalAddedTxsIncluded(t *testing.T) {
trs[1].Action = abci.TxRecord_ADDED
app := abcimocks.NewBaseMock()
app.On("PrepareProposal", mock.Anything).Return(abci.ResponsePrepareProposal{
app.On("PrepareProposal", mock.Anything, mock.Anything).Return(abci.ResponsePrepareProposal{
TxRecords: trs,
})
@@ -860,7 +860,7 @@ func TestPrepareProposalReorderTxs(t *testing.T) {
trs = append(trs[len(trs)/2:], trs[:len(trs)/2]...)
app := abcimocks.NewBaseMock()
app.On("PrepareProposal", mock.Anything).Return(abci.ResponsePrepareProposal{
app.On("PrepareProposal", mock.Anything, mock.Anything).Return(abci.ResponsePrepareProposal{
TxRecords: trs,
})
@@ -920,7 +920,7 @@ func TestPrepareProposalErrorOnTooManyTxs(t *testing.T) {
trs := txsToTxRecords(types.Txs(txs))
app := abcimocks.NewBaseMock()
app.On("PrepareProposal", mock.Anything).Return(abci.ResponsePrepareProposal{
app.On("PrepareProposal", mock.Anything, mock.Anything).Return(abci.ResponsePrepareProposal{
TxRecords: trs,
})
+6 -6
View File
@@ -278,11 +278,11 @@ type testApp struct {
var _ abci.Application = (*testApp)(nil)
func (app *testApp) Info(req abci.RequestInfo) (resInfo abci.ResponseInfo) {
func (app *testApp) Info(_ context.Context, req abci.RequestInfo) (resInfo abci.ResponseInfo) {
return abci.ResponseInfo{}
}
func (app *testApp) FinalizeBlock(req abci.RequestFinalizeBlock) abci.ResponseFinalizeBlock {
func (app *testApp) FinalizeBlock(_ context.Context, req abci.RequestFinalizeBlock) abci.ResponseFinalizeBlock {
app.CommitVotes = req.DecidedLastCommit.Votes
app.ByzantineValidators = req.ByzantineValidators
@@ -307,19 +307,19 @@ func (app *testApp) FinalizeBlock(req abci.RequestFinalizeBlock) abci.ResponseFi
}
}
func (app *testApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
func (app *testApp) CheckTx(_ context.Context, req abci.RequestCheckTx) abci.ResponseCheckTx {
return abci.ResponseCheckTx{}
}
func (app *testApp) Commit() abci.ResponseCommit {
func (app *testApp) Commit(context.Context) abci.ResponseCommit {
return abci.ResponseCommit{RetainHeight: 1}
}
func (app *testApp) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQuery) {
func (app *testApp) Query(_ context.Context, req abci.RequestQuery) (resQuery abci.ResponseQuery) {
return
}
func (app *testApp) ProcessProposal(req abci.RequestProcessProposal) abci.ResponseProcessProposal {
func (app *testApp) ProcessProposal(_ context.Context, req abci.RequestProcessProposal) abci.ResponseProcessProposal {
for _, tx := range req.Txs {
if len(tx) == 0 {
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
@@ -12,6 +12,8 @@ import (
tenderminttypes "github.com/tendermint/tendermint/types"
testing "testing"
types "github.com/tendermint/tendermint/abci/types"
)
@@ -165,3 +167,12 @@ func (_m *EventSink) Type() indexer.EventSinkType {
return r0
}
// NewEventSink creates a new instance of EventSink. It also registers a cleanup function to assert the mocks expectations.
func NewEventSink(t testing.TB) *EventSink {
mock := &EventSink{}
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
+11
View File
@@ -5,6 +5,8 @@ package mocks
import (
mock "github.com/stretchr/testify/mock"
testing "testing"
types "github.com/tendermint/tendermint/types"
)
@@ -208,3 +210,12 @@ func (_m *BlockStore) Size() int64 {
return r0
}
// NewBlockStore creates a new instance of BlockStore. It also registers a cleanup function to assert the mocks expectations.
func NewBlockStore(t testing.TB) *BlockStore {
mock := &BlockStore{}
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
+11
View File
@@ -8,6 +8,8 @@ import (
mock "github.com/stretchr/testify/mock"
state "github.com/tendermint/tendermint/internal/state"
testing "testing"
types "github.com/tendermint/tendermint/types"
)
@@ -71,3 +73,12 @@ func (_m *EvidencePool) PendingEvidence(maxBytes int64) ([]types.Evidence, int64
func (_m *EvidencePool) Update(_a0 context.Context, _a1 state.State, _a2 types.EvidenceList) {
_m.Called(_a0, _a1, _a2)
}
// NewEvidencePool creates a new instance of EvidencePool. It also registers a cleanup function to assert the mocks expectations.
func NewEvidencePool(t testing.TB) *EvidencePool {
mock := &EvidencePool{}
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
+11
View File
@@ -7,6 +7,8 @@ import (
state "github.com/tendermint/tendermint/internal/state"
tendermintstate "github.com/tendermint/tendermint/proto/tendermint/state"
testing "testing"
types "github.com/tendermint/tendermint/types"
)
@@ -186,3 +188,12 @@ func (_m *Store) SaveValidatorSets(_a0 int64, _a1 int64, _a2 *types.ValidatorSet
return r0
}
// NewStore creates a new instance of Store. It also registers a cleanup function to assert the mocks expectations.
func NewStore(t testing.TB) *Store {
mock := &Store{}
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
@@ -8,6 +8,8 @@ import (
mock "github.com/stretchr/testify/mock"
state "github.com/tendermint/tendermint/internal/state"
testing "testing"
types "github.com/tendermint/tendermint/types"
)
@@ -82,3 +84,12 @@ func (_m *StateProvider) State(ctx context.Context, height uint64) (state.State,
return r0, r1
}
// NewStateProvider creates a new instance of StateProvider. It also registers a cleanup function to assert the mocks expectations.
func NewStateProvider(t testing.TB) *StateProvider {
mock := &StateProvider{}
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}