blockchain: less fragile and involved tests for blockstore

With feedback from @ebuchman, to make the tests nicer
and less fragile.
This commit is contained in:
Emmanuel Odeke
2017-10-14 19:21:13 -06:00
committed by Ethan Buchman
parent 83b40b25d6
commit 2da5299924
4 changed files with 258 additions and 39 deletions

View File

@ -14,10 +14,8 @@ import (
"github.com/tendermint/tendermint/types"
)
func newBlockchainReactor(maxBlockHeight int64) *BlockchainReactor {
logger := log.TestingLogger()
func makeStateAndBlockStore(logger log.Logger) (*sm.State, *BlockStore) {
config := cfg.ResetTestRoot("blockchain_reactor_test")
blockStore := NewBlockStore(dbm.NewMemDB())
// Get State
@ -25,6 +23,13 @@ func newBlockchainReactor(maxBlockHeight int64) *BlockchainReactor {
state.SetLogger(logger.With("module", "state"))
state.Save()
return state, blockStore
}
func newBlockchainReactor(logger log.Logger, maxBlockHeight int) *BlockchainReactor {
logger := log.TestingLogger()
state, blockStore := makeStateAndBlockStore(logger)
// Make the blockchainReactor itself
fastSync := true
bcReactor := NewBlockchainReactor(state.Copy(), nil, blockStore, fastSync)
@ -47,7 +52,7 @@ func newBlockchainReactor(maxBlockHeight int64) *BlockchainReactor {
func TestNoBlockMessageResponse(t *testing.T) {
maxBlockHeight := int64(20)
bcr := newBlockchainReactor(maxBlockHeight)
bcr := newBlockchainReactor(log.NewNopLogger(), maxBlockHeight)
bcr.Start()
defer bcr.Stop()