Browse Source

fix tests for state and mempool

pull/484/head
Ethan Buchman 8 years ago
parent
commit
4982cb4d1f
3 changed files with 41 additions and 19 deletions
  1. +16
    -2
      mempool/mempool_test.go
  2. +3
    -7
      state/execution_test.go
  3. +22
    -10
      state/state_test.go

+ 16
- 2
mempool/mempool_test.go View File

@ -4,14 +4,28 @@ import (
"encoding/binary" "encoding/binary"
"testing" "testing"
"github.com/tendermint/abci/example/counter"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/config/tendermint_test" "github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/abci/example/counter"
) )
func ResetConfig(name string) *Config {
viperConfig := tendermint_test.ResetConfig(name)
config := new(struct {
cfg.Config `mapstructure:",squash"`
Mempool *Config `mapstructure:"mempool"`
})
if err := viperConfig.Unmarshal(config); err != nil {
panic(err)
}
return config.Mempool
}
func TestSerialReap(t *testing.T) { func TestSerialReap(t *testing.T) {
config := tendermint_test.ResetConfig("mempool_mempool_test")
config := ResetConfig("mempool_test")
app := counter.NewCounterApplication(true) app := counter.NewCounterApplication(true)
app.SetOption("serial", "on") app.SetOption("serial", "on")


+ 3
- 7
state/execution_test.go View File

@ -7,12 +7,10 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/tendermint/abci/example/dummy" "github.com/tendermint/abci/example/dummy"
crypto "github.com/tendermint/go-crypto" crypto "github.com/tendermint/go-crypto"
dbm "github.com/tendermint/tmlibs/db"
cfg "github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/state/txindex" "github.com/tendermint/tendermint/state/txindex"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tmlibs/db"
) )
var ( var (
@ -24,12 +22,10 @@ var (
func TestApplyBlock(t *testing.T) { func TestApplyBlock(t *testing.T) {
cc := proxy.NewLocalClientCreator(dummy.NewDummyApplication()) cc := proxy.NewLocalClientCreator(dummy.NewDummyApplication())
config := cfg.ResetConfig("execution_test_")
proxyApp := proxy.NewAppConns(config, cc, nil)
proxyApp := proxy.NewAppConns(cc, nil)
_, err := proxyApp.Start() _, err := proxyApp.Start()
require.Nil(t, err) require.Nil(t, err)
defer proxyApp.Stop() defer proxyApp.Stop()
mempool := mempool.NewMempool(config, proxyApp.Mempool())
state := state() state := state()
indexer := &dummyIndexer{0} indexer := &dummyIndexer{0}
@ -38,7 +34,7 @@ func TestApplyBlock(t *testing.T) {
// make block // make block
block := makeBlock(1, state) block := makeBlock(1, state)
err = state.ApplyBlock(nil, proxyApp.Consensus(), block, block.MakePartSet(testPartSize).Header(), mempool)
err = state.ApplyBlock(nil, proxyApp.Consensus(), block, block.MakePartSet(testPartSize).Header(), types.MockMempool{})
require.Nil(t, err) require.Nil(t, err)
assert.Equal(t, nTxsPerBlock, indexer.Indexed) // test indexing works assert.Equal(t, nTxsPerBlock, indexer.Indexed) // test indexing works


+ 22
- 10
state/state_test.go View File

@ -7,15 +7,27 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-crypto" "github.com/tendermint/go-crypto"
dbm "github.com/tendermint/tmlibs/db"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/config/tendermint_test" "github.com/tendermint/tendermint/config/tendermint_test"
dbm "github.com/tendermint/tmlibs/db"
) )
func ResetConfig(name string) *cfg.Config {
viperConfig := tendermint_test.ResetConfig(name)
config := new(struct {
cfg.Config `mapstructure:",squash"`
})
if err := viperConfig.Unmarshal(config); err != nil {
panic(err)
}
return &config.Config
}
func TestStateCopyEquals(t *testing.T) { func TestStateCopyEquals(t *testing.T) {
config := tendermint_test.ResetConfig("state_")
config := ResetConfig("state_")
// Get State db // Get State db
stateDB := dbm.NewDB("state", config.GetString("db_backend"), config.GetString("db_dir"))
state := GetState(config, stateDB)
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir)
state := GetState(stateDB, config.GenesisFile)
stateCopy := state.Copy() stateCopy := state.Copy()
@ -31,10 +43,10 @@ func TestStateCopyEquals(t *testing.T) {
} }
func TestStateSaveLoad(t *testing.T) { func TestStateSaveLoad(t *testing.T) {
config := tendermint_test.ResetConfig("state_")
config := ResetConfig("state_")
// Get State db // Get State db
stateDB := dbm.NewDB("state", config.GetString("db_backend"), config.GetString("db_dir"))
state := GetState(config, stateDB)
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir)
state := GetState(stateDB, config.GenesisFile)
state.LastBlockHeight += 1 state.LastBlockHeight += 1
state.Save() state.Save()
@ -48,9 +60,9 @@ func TestStateSaveLoad(t *testing.T) {
func TestABCIResponsesSaveLoad(t *testing.T) { func TestABCIResponsesSaveLoad(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
config := tendermint_test.ResetConfig("state_")
stateDB := dbm.NewDB("state", config.GetString("db_backend"), config.GetString("db_dir"))
state := GetState(config, stateDB)
config := ResetConfig("state_")
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir)
state := GetState(stateDB, config.GenesisFile)
state.LastBlockHeight += 1 state.LastBlockHeight += 1


Loading…
Cancel
Save