mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-29 12:41:44 +00:00
fix tests for state and mempool
This commit is contained in:
@ -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")
|
||||||
|
@ -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(cc, nil)
|
||||||
proxyApp := proxy.NewAppConns(config, 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
|
||||||
|
@ -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"))
|
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir)
|
||||||
state := GetState(config, stateDB)
|
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"))
|
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir)
|
||||||
state := GetState(config, stateDB)
|
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_")
|
config := ResetConfig("state_")
|
||||||
stateDB := dbm.NewDB("state", config.GetString("db_backend"), config.GetString("db_dir"))
|
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir)
|
||||||
state := GetState(config, stateDB)
|
state := GetState(stateDB, config.GenesisFile)
|
||||||
|
|
||||||
state.LastBlockHeight += 1
|
state.LastBlockHeight += 1
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user