From 2c31b39030904f4a3c68a82b21c38775d2e48220 Mon Sep 17 00:00:00 2001 From: Sam Ricotta Date: Wed, 3 Aug 2022 13:31:04 +0200 Subject: [PATCH] mocks --- evidence/mocks/block_store.go | 4 ++-- light/rpc/mocks/light_client.go | 4 ++-- node/node.go | 4 +++- p2p/mocks/peer.go | 4 ++-- proxy/mocks/app_conn_consensus.go | 4 ++-- proxy/mocks/app_conn_mempool.go | 4 ++-- proxy/mocks/app_conn_query.go | 4 ++-- proxy/mocks/app_conn_snapshot.go | 4 ++-- proxy/mocks/client_creator.go | 4 ++-- state/indexer/mocks/block_indexer.go | 4 ++-- state/mocks/block_store.go | 4 ++-- state/mocks/evidence_pool.go | 4 ++-- state/mocks/store.go | 28 +++++++++++++++++++++++++--- state/rollback_test.go | 3 +-- state/state.go | 5 +---- state/state_test.go | 4 +++- state/store.go | 2 +- state/txindex/mocks/tx_indexer.go | 4 ++-- statesync/mocks/state_provider.go | 4 ++-- store/store_test.go | 2 +- 20 files changed, 61 insertions(+), 39 deletions(-) diff --git a/evidence/mocks/block_store.go b/evidence/mocks/block_store.go index b0c67ff87..e61c4e0ae 100644 --- a/evidence/mocks/block_store.go +++ b/evidence/mocks/block_store.go @@ -58,13 +58,13 @@ func (_m *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta { return r0 } -type NewBlockStoreT interface { +type mockConstructorTestingTNewBlockStore interface { mock.TestingT Cleanup(func()) } // NewBlockStore creates a new instance of BlockStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewBlockStore(t NewBlockStoreT) *BlockStore { +func NewBlockStore(t mockConstructorTestingTNewBlockStore) *BlockStore { mock := &BlockStore{} mock.Mock.Test(t) diff --git a/light/rpc/mocks/light_client.go b/light/rpc/mocks/light_client.go index 25e101c86..fabf73b01 100644 --- a/light/rpc/mocks/light_client.go +++ b/light/rpc/mocks/light_client.go @@ -100,13 +100,13 @@ func (_m *LightClient) VerifyLightBlockAtHeight(ctx context.Context, height int6 return r0, r1 } -type NewLightClientT interface { +type mockConstructorTestingTNewLightClient interface { mock.TestingT Cleanup(func()) } // NewLightClient creates a new instance of LightClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewLightClient(t NewLightClientT) *LightClient { +func NewLightClient(t mockConstructorTestingTNewLightClient) *LightClient { mock := &LightClient{} mock.Mock.Test(t) diff --git a/node/node.go b/node/node.go index 4c29bca9e..810e8bda7 100644 --- a/node/node.go +++ b/node/node.go @@ -429,7 +429,9 @@ func createEvidenceReactor(config *cfg.Config, dbProvider DBProvider, return nil, nil, err } evidenceLogger := logger.With("module", "evidence") - evidencePool, err := evidence.NewPool(evidenceDB, sm.NewStore(stateDB), blockStore) + evidencePool, err := evidence.NewPool(evidenceDB, sm.NewStore(stateDB, sm.StoreOptions{ + DiscardABCIResponses: false, + }), blockStore) if err != nil { return nil, nil, err } diff --git a/p2p/mocks/peer.go b/p2p/mocks/peer.go index f739a0b21..e195c78bb 100644 --- a/p2p/mocks/peer.go +++ b/p2p/mocks/peer.go @@ -330,13 +330,13 @@ func (_m *Peer) TrySend(_a0 byte, _a1 []byte) bool { return r0 } -type NewPeerT interface { +type mockConstructorTestingTNewPeer interface { mock.TestingT Cleanup(func()) } // NewPeer creates a new instance of Peer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewPeer(t NewPeerT) *Peer { +func NewPeer(t mockConstructorTestingTNewPeer) *Peer { mock := &Peer{} mock.Mock.Test(t) diff --git a/proxy/mocks/app_conn_consensus.go b/proxy/mocks/app_conn_consensus.go index 5acd8cac9..d70cd7cc1 100644 --- a/proxy/mocks/app_conn_consensus.go +++ b/proxy/mocks/app_conn_consensus.go @@ -141,13 +141,13 @@ func (_m *AppConnConsensus) SetResponseCallback(_a0 abcicli.Callback) { _m.Called(_a0) } -type NewAppConnConsensusT interface { +type mockConstructorTestingTNewAppConnConsensus interface { mock.TestingT Cleanup(func()) } // NewAppConnConsensus creates a new instance of AppConnConsensus. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAppConnConsensus(t NewAppConnConsensusT) *AppConnConsensus { +func NewAppConnConsensus(t mockConstructorTestingTNewAppConnConsensus) *AppConnConsensus { mock := &AppConnConsensus{} mock.Mock.Test(t) diff --git a/proxy/mocks/app_conn_mempool.go b/proxy/mocks/app_conn_mempool.go index 87128ce85..05e23dd43 100644 --- a/proxy/mocks/app_conn_mempool.go +++ b/proxy/mocks/app_conn_mempool.go @@ -102,13 +102,13 @@ func (_m *AppConnMempool) SetResponseCallback(_a0 abcicli.Callback) { _m.Called(_a0) } -type NewAppConnMempoolT interface { +type mockConstructorTestingTNewAppConnMempool interface { mock.TestingT Cleanup(func()) } // NewAppConnMempool creates a new instance of AppConnMempool. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAppConnMempool(t NewAppConnMempoolT) *AppConnMempool { +func NewAppConnMempool(t mockConstructorTestingTNewAppConnMempool) *AppConnMempool { mock := &AppConnMempool{} mock.Mock.Test(t) diff --git a/proxy/mocks/app_conn_query.go b/proxy/mocks/app_conn_query.go index 6560ca0b5..544ab765e 100644 --- a/proxy/mocks/app_conn_query.go +++ b/proxy/mocks/app_conn_query.go @@ -96,13 +96,13 @@ func (_m *AppConnQuery) QuerySync(_a0 types.RequestQuery) (*types.ResponseQuery, return r0, r1 } -type NewAppConnQueryT interface { +type mockConstructorTestingTNewAppConnQuery interface { mock.TestingT Cleanup(func()) } // NewAppConnQuery creates a new instance of AppConnQuery. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAppConnQuery(t NewAppConnQueryT) *AppConnQuery { +func NewAppConnQuery(t mockConstructorTestingTNewAppConnQuery) *AppConnQuery { mock := &AppConnQuery{} mock.Mock.Test(t) diff --git a/proxy/mocks/app_conn_snapshot.go b/proxy/mocks/app_conn_snapshot.go index a90cd798a..e3d5cb6cd 100644 --- a/proxy/mocks/app_conn_snapshot.go +++ b/proxy/mocks/app_conn_snapshot.go @@ -119,13 +119,13 @@ func (_m *AppConnSnapshot) OfferSnapshotSync(_a0 types.RequestOfferSnapshot) (*t return r0, r1 } -type NewAppConnSnapshotT interface { +type mockConstructorTestingTNewAppConnSnapshot interface { mock.TestingT Cleanup(func()) } // NewAppConnSnapshot creates a new instance of AppConnSnapshot. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAppConnSnapshot(t NewAppConnSnapshotT) *AppConnSnapshot { +func NewAppConnSnapshot(t mockConstructorTestingTNewAppConnSnapshot) *AppConnSnapshot { mock := &AppConnSnapshot{} mock.Mock.Test(t) diff --git a/proxy/mocks/client_creator.go b/proxy/mocks/client_creator.go index 759b17957..eced0aeff 100644 --- a/proxy/mocks/client_creator.go +++ b/proxy/mocks/client_creator.go @@ -35,13 +35,13 @@ func (_m *ClientCreator) NewABCIClient() (abcicli.Client, error) { return r0, r1 } -type NewClientCreatorT interface { +type mockConstructorTestingTNewClientCreator interface { mock.TestingT Cleanup(func()) } // NewClientCreator creates a new instance of ClientCreator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewClientCreator(t NewClientCreatorT) *ClientCreator { +func NewClientCreator(t mockConstructorTestingTNewClientCreator) *ClientCreator { mock := &ClientCreator{} mock.Mock.Test(t) diff --git a/state/indexer/mocks/block_indexer.go b/state/indexer/mocks/block_indexer.go index 583e64d3a..2c0f0ecb0 100644 --- a/state/indexer/mocks/block_indexer.go +++ b/state/indexer/mocks/block_indexer.go @@ -75,13 +75,13 @@ func (_m *BlockIndexer) Search(ctx context.Context, q *query.Query) ([]int64, er return r0, r1 } -type NewBlockIndexerT interface { +type mockConstructorTestingTNewBlockIndexer interface { mock.TestingT Cleanup(func()) } // NewBlockIndexer creates a new instance of BlockIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewBlockIndexer(t NewBlockIndexerT) *BlockIndexer { +func NewBlockIndexer(t mockConstructorTestingTNewBlockIndexer) *BlockIndexer { mock := &BlockIndexer{} mock.Mock.Test(t) diff --git a/state/mocks/block_store.go b/state/mocks/block_store.go index 20e6a9b16..4493a6e3f 100644 --- a/state/mocks/block_store.go +++ b/state/mocks/block_store.go @@ -193,13 +193,13 @@ func (_m *BlockStore) Size() int64 { return r0 } -type NewBlockStoreT interface { +type mockConstructorTestingTNewBlockStore interface { mock.TestingT Cleanup(func()) } // NewBlockStore creates a new instance of BlockStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewBlockStore(t NewBlockStoreT) *BlockStore { +func NewBlockStore(t mockConstructorTestingTNewBlockStore) *BlockStore { mock := &BlockStore{} mock.Mock.Test(t) diff --git a/state/mocks/evidence_pool.go b/state/mocks/evidence_pool.go index b4d57d04d..7279d36f7 100644 --- a/state/mocks/evidence_pool.go +++ b/state/mocks/evidence_pool.go @@ -70,13 +70,13 @@ func (_m *EvidencePool) Update(_a0 state.State, _a1 types.EvidenceList) { _m.Called(_a0, _a1) } -type NewEvidencePoolT interface { +type mockConstructorTestingTNewEvidencePool interface { mock.TestingT Cleanup(func()) } // NewEvidencePool creates a new instance of EvidencePool. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewEvidencePool(t NewEvidencePoolT) *EvidencePool { +func NewEvidencePool(t mockConstructorTestingTNewEvidencePool) *EvidencePool { mock := &EvidencePool{} mock.Mock.Test(t) diff --git a/state/mocks/store.go b/state/mocks/store.go index ab68bcc1d..8cbe49080 100644 --- a/state/mocks/store.go +++ b/state/mocks/store.go @@ -67,7 +67,6 @@ func (_m *Store) Load() (state.State, error) { return r0, r1 } - // LoadABCIResponses provides a mock function with given fields: _a0 func (_m *Store) LoadABCIResponses(_a0 int64) (*tendermintstate.ABCIResponses, error) { ret := _m.Called(_a0) @@ -154,6 +153,29 @@ func (_m *Store) LoadFromDBOrGenesisFile(_a0 string) (state.State, error) { return r0, r1 } +// LoadLastABCIResponse provides a mock function with given fields: _a0 +func (_m *Store) LoadLastABCIResponse(_a0 int64) (*tendermintstate.ABCIResponses, error) { + ret := _m.Called(_a0) + + var r0 *tendermintstate.ABCIResponses + if rf, ok := ret.Get(0).(func(int64) *tendermintstate.ABCIResponses); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*tendermintstate.ABCIResponses) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(int64) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // LoadValidators provides a mock function with given fields: _a0 func (_m *Store) LoadValidators(_a0 int64) (*tenderminttypes.ValidatorSet, error) { ret := _m.Called(_a0) @@ -219,13 +241,13 @@ func (_m *Store) SaveABCIResponses(_a0 int64, _a1 *tendermintstate.ABCIResponses return r0 } -type NewStoreT interface { +type mockConstructorTestingTNewStore interface { mock.TestingT Cleanup(func()) } // NewStore creates a new instance of Store. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewStore(t NewStoreT) *Store { +func NewStore(t mockConstructorTestingTNewStore) *Store { mock := &Store{} mock.Mock.Test(t) diff --git a/state/rollback_test.go b/state/rollback_test.go index 73fc2254b..4cd203810 100644 --- a/state/rollback_test.go +++ b/state/rollback_test.go @@ -85,8 +85,7 @@ func TestRollbackNoState(t *testing.T) { stateStore := state.NewStore(dbm.NewMemDB(), state.StoreOptions{ DiscardABCIResponses: false, - } - ) + }) blockStore := &mocks.BlockStore{} _, _, err := state.Rollback(blockStore, stateStore) diff --git a/state/state.go b/state/state.go index a1df48d45..37f950d9f 100644 --- a/state/state.go +++ b/state/state.go @@ -17,10 +17,7 @@ import ( "github.com/tendermint/tendermint/version" ) -// database keys -var ( - stateKey = []byte("stateKey") -) +// database key //----------------------------------------------------------------------------- diff --git a/state/state_test.go b/state/state_test.go index eeec9fffb..cec4dfd9a 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -224,7 +224,9 @@ func TestValidatorSimpleSaveLoad(t *testing.T) { defer tearDown(t) assert := assert.New(t) - statestore := sm.NewStore(stateDB) + statestore := sm.NewStore(stateDB, sm.StoreOptions{ + DiscardABCIResponses: false, + }) // Can't load anything for height 0. _, err := statestore.LoadValidators(0) diff --git a/state/store.go b/state/store.go index d537f977e..8bff08936 100644 --- a/state/store.go +++ b/state/store.go @@ -485,7 +485,7 @@ func (store dbStore) SaveABCIResponses(height int64, abciResponses *tmstate.ABCI if err != nil { return err } - if err := store.db.Set(ResponsesKey(height), bz); err != nil { + if err := store.db.Set(ABCIResponsesKey(height), bz); err != nil { return err } } diff --git a/state/txindex/mocks/tx_indexer.go b/state/txindex/mocks/tx_indexer.go index 210942e2e..93d0eb9c2 100644 --- a/state/txindex/mocks/tx_indexer.go +++ b/state/txindex/mocks/tx_indexer.go @@ -92,13 +92,13 @@ func (_m *TxIndexer) Search(ctx context.Context, q *query.Query) ([]*types.TxRes return r0, r1 } -type NewTxIndexerT interface { +type mockConstructorTestingTNewTxIndexer interface { mock.TestingT Cleanup(func()) } // NewTxIndexer creates a new instance of TxIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewTxIndexer(t NewTxIndexerT) *TxIndexer { +func NewTxIndexer(t mockConstructorTestingTNewTxIndexer) *TxIndexer { mock := &TxIndexer{} mock.Mock.Test(t) diff --git a/statesync/mocks/state_provider.go b/statesync/mocks/state_provider.go index 5029f615e..f52b9e33d 100644 --- a/statesync/mocks/state_provider.go +++ b/statesync/mocks/state_provider.go @@ -83,13 +83,13 @@ func (_m *StateProvider) State(ctx context.Context, height uint64) (state.State, return r0, r1 } -type NewStateProviderT interface { +type mockConstructorTestingTNewStateProvider interface { mock.TestingT Cleanup(func()) } // NewStateProvider creates a new instance of StateProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewStateProvider(t NewStateProviderT) *StateProvider { +func NewStateProvider(t mockConstructorTestingTNewStateProvider) *StateProvider { mock := &StateProvider{} mock.Mock.Test(t) diff --git a/store/store_test.go b/store/store_test.go index 8bb758d41..0f17180ea 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -431,7 +431,7 @@ func TestPruneBlocks(t *testing.T) { defer os.RemoveAll(config.RootDir) stateStore := sm.NewStore(dbm.NewMemDB(), sm.StoreOptions{ DiscardABCIResponses: false, - )} + }) state, err := stateStore.LoadFromDBOrGenesisFile(config.GenesisFile()) require.NoError(t, err) db := dbm.NewMemDB()