From a0ed43794207a54f9c5b3d075a3868b6130d9832 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 22 Sep 2022 12:42:25 +0200 Subject: [PATCH] config: cleaner separation of tests (#9421) --- blocksync/reactor_test.go | 7 +- cmd/tendermint/commands/reindex_event.go | 12 +- cmd/tendermint/commands/reindex_event_test.go | 3 +- config/config.go | 53 ++++----- config/config_test.go | 66 +++++------ config/toml.go | 104 +----------------- config/toml_test.go | 23 ++-- consensus/common_test.go | 9 +- consensus/reactor_test.go | 2 +- consensus/replay_test.go | 8 +- consensus/state_test.go | 6 +- consensus/types/height_vote_set_test.go | 8 +- consensus/wal_generator.go | 3 +- internal/test/config.go | 96 ++++++++++++++++ internal/test/genesis.go | 5 +- light/client_test.go | 3 +- light/example_test.go | 10 +- mempool/v0/clist_mempool_test.go | 9 +- mempool/v1/mempool_test.go | 4 +- mempool/v1/reactor_test.go | 3 +- node/node_test.go | 23 ++-- rpc/client/evidence_test.go | 3 +- rpc/test/helpers.go | 3 +- state/state_test.go | 4 +- state/store_test.go | 4 +- store/store_test.go | 9 +- 26 files changed, 240 insertions(+), 240 deletions(-) create mode 100644 internal/test/config.go diff --git a/blocksync/reactor_test.go b/blocksync/reactor_test.go index f15ca0afc..202fe2832 100644 --- a/blocksync/reactor_test.go +++ b/blocksync/reactor_test.go @@ -15,6 +15,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" cfg "github.com/tendermint/tendermint/config" + "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" mpmocks "github.com/tendermint/tendermint/mempool/mocks" "github.com/tendermint/tendermint/p2p" @@ -42,7 +43,7 @@ func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.G return &types.GenesisDoc{ GenesisTime: tmtime.Now(), - ChainID: config.ChainID(), + ChainID: test.DefaultTestChainID, Validators: validators, }, privValidators } @@ -151,7 +152,7 @@ func newReactor( } func TestNoBlockResponse(t *testing.T) { - config = cfg.ResetTestRoot("blockchain_reactor_test") + config = test.ResetTestRoot("blockchain_reactor_test") defer os.RemoveAll(config.RootDir) genDoc, privVals := randGenesisDoc(1, false, 30) @@ -213,7 +214,7 @@ func TestNoBlockResponse(t *testing.T) { // Alternatively we could actually dial a TCP conn but // that seems extreme. func TestBadBlockStopsPeer(t *testing.T) { - config = cfg.ResetTestRoot("blockchain_reactor_test") + config = test.ResetTestRoot("blockchain_reactor_test") defer os.RemoveAll(config.RootDir) genDoc, privVals := randGenesisDoc(1, false, 30) diff --git a/cmd/tendermint/commands/reindex_event.go b/cmd/tendermint/commands/reindex_event.go index f91a49ad7..976224f96 100644 --- a/cmd/tendermint/commands/reindex_event.go +++ b/cmd/tendermint/commands/reindex_event.go @@ -57,12 +57,18 @@ want to use this command. return } + state, err := ss.Load() + if err != nil { + fmt.Println(reindexFailed, err) + return + } + if err := checkValidHeight(bs); err != nil { fmt.Println(reindexFailed, err) return } - bi, ti, err := loadEventSinks(config) + bi, ti, err := loadEventSinks(config, state.ChainID) if err != nil { fmt.Println(reindexFailed, err) return @@ -94,7 +100,7 @@ func init() { ReIndexEventCmd.Flags().Int64Var(&endHeight, "end-height", 0, "the block height would like to finish for re-index") } -func loadEventSinks(cfg *tmcfg.Config) (indexer.BlockIndexer, txindex.TxIndexer, error) { +func loadEventSinks(cfg *tmcfg.Config, chainID string) (indexer.BlockIndexer, txindex.TxIndexer, error) { switch strings.ToLower(cfg.TxIndex.Indexer) { case "null": return nil, nil, errors.New("found null event sink, please check the tx-index section in the config.toml") @@ -103,7 +109,7 @@ func loadEventSinks(cfg *tmcfg.Config) (indexer.BlockIndexer, txindex.TxIndexer, if conn == "" { return nil, nil, errors.New("the psql connection settings cannot be empty") } - es, err := psql.NewEventSink(conn, cfg.ChainID()) + es, err := psql.NewEventSink(conn, chainID) if err != nil { return nil, nil, err } diff --git a/cmd/tendermint/commands/reindex_event_test.go b/cmd/tendermint/commands/reindex_event_test.go index 87ff80ddc..336f61a61 100644 --- a/cmd/tendermint/commands/reindex_event_test.go +++ b/cmd/tendermint/commands/reindex_event_test.go @@ -13,6 +13,7 @@ import ( abcitypes "github.com/tendermint/tendermint/abci/types" tmcfg "github.com/tendermint/tendermint/config" + "github.com/tendermint/tendermint/internal/test" prototmstate "github.com/tendermint/tendermint/proto/tendermint/state" blockmocks "github.com/tendermint/tendermint/state/indexer/mocks" "github.com/tendermint/tendermint/state/mocks" @@ -98,7 +99,7 @@ func TestLoadEventSink(t *testing.T) { cfg := tmcfg.TestConfig() cfg.TxIndex.Indexer = tc.sinks cfg.TxIndex.PsqlConn = tc.connURL - _, _, err := loadEventSinks(cfg) + _, _, err := loadEventSinks(cfg, test.DefaultTestChainID) if tc.loadErr { require.Error(t, err, idx) } else { diff --git a/config/config.go b/config/config.go index 01cf2c268..6ec62c004 100644 --- a/config/config.go +++ b/config/config.go @@ -31,6 +31,19 @@ const ( // Default is v0. MempoolV0 = "v0" MempoolV1 = "v1" + + DefaultTendermintDir = ".tendermint" + DefaultConfigDir = "config" + DefaultDataDir = "data" + + DefaultConfigFileName = "config.toml" + DefaultGenesisJSONName = "genesis.json" + + DefaultPrivValKeyName = "priv_validator_key.json" + DefaultPrivValStateName = "priv_validator_state.json" + + DefaultNodeKeyName = "node_key.json" + DefaultAddrBookName = "addrbook.json" ) // NOTE: Most of the structs & relevant comments + the @@ -40,26 +53,13 @@ const ( // config/toml.go // NOTE: libs/cli must know to look in the config dir! var ( - DefaultTendermintDir = ".tendermint" - defaultConfigDir = "config" - defaultDataDir = "data" + defaultConfigFilePath = filepath.Join(DefaultConfigDir, DefaultConfigFileName) + defaultGenesisJSONPath = filepath.Join(DefaultConfigDir, DefaultGenesisJSONName) + defaultPrivValKeyPath = filepath.Join(DefaultConfigDir, DefaultPrivValKeyName) + defaultPrivValStatePath = filepath.Join(DefaultDataDir, DefaultPrivValStateName) - defaultConfigFileName = "config.toml" - defaultGenesisJSONName = "genesis.json" - - defaultPrivValKeyName = "priv_validator_key.json" - defaultPrivValStateName = "priv_validator_state.json" - - defaultNodeKeyName = "node_key.json" - defaultAddrBookName = "addrbook.json" - - defaultConfigFilePath = filepath.Join(defaultConfigDir, defaultConfigFileName) - defaultGenesisJSONPath = filepath.Join(defaultConfigDir, defaultGenesisJSONName) - defaultPrivValKeyPath = filepath.Join(defaultConfigDir, defaultPrivValKeyName) - defaultPrivValStatePath = filepath.Join(defaultDataDir, defaultPrivValStateName) - - defaultNodeKeyPath = filepath.Join(defaultConfigDir, defaultNodeKeyName) - defaultAddrBookPath = filepath.Join(defaultConfigDir, defaultAddrBookName) + defaultNodeKeyPath = filepath.Join(DefaultConfigDir, DefaultNodeKeyName) + defaultAddrBookPath = filepath.Join(DefaultConfigDir, DefaultAddrBookName) minSubscriptionBufferSize = 100 defaultSubscriptionBufferSize = 200 @@ -168,8 +168,6 @@ func (cfg *Config) CheckDeprecated() []string { // BaseConfig defines the base configuration for a Tendermint node type BaseConfig struct { //nolint: maligned - // chainID is unexposed and immutable but here for convenience - chainID string // The version of the Tendermint binary that created // or last modified the config file @@ -261,24 +259,19 @@ func DefaultBaseConfig() BaseConfig { BlockSyncMode: true, FilterPeers: false, DBBackend: "goleveldb", - DBPath: defaultDataDir, + DBPath: DefaultDataDir, } } // TestBaseConfig returns a base configuration for testing a Tendermint node func TestBaseConfig() BaseConfig { cfg := DefaultBaseConfig() - cfg.chainID = "tendermint_test" cfg.ProxyApp = "kvstore" cfg.BlockSyncMode = false cfg.DBBackend = "memdb" return cfg } -func (cfg BaseConfig) ChainID() string { - return cfg.chainID -} - // GenesisFile returns the full path to the genesis.json file func (cfg BaseConfig) GenesisFile() string { return rootify(cfg.Genesis, cfg.RootDir) @@ -518,7 +511,7 @@ func (cfg RPCConfig) KeyFile() string { if filepath.IsAbs(path) { return path } - return rootify(filepath.Join(defaultConfigDir, path), cfg.RootDir) + return rootify(filepath.Join(DefaultConfigDir, path), cfg.RootDir) } func (cfg RPCConfig) CertFile() string { @@ -526,7 +519,7 @@ func (cfg RPCConfig) CertFile() string { if filepath.IsAbs(path) { return path } - return rootify(filepath.Join(defaultConfigDir, path), cfg.RootDir) + return rootify(filepath.Join(DefaultConfigDir, path), cfg.RootDir) } func (cfg RPCConfig) IsTLSEnabled() bool { @@ -975,7 +968,7 @@ type ConsensusConfig struct { // DefaultConsensusConfig returns a default configuration for the consensus service func DefaultConsensusConfig() *ConsensusConfig { return &ConsensusConfig{ - WalPath: filepath.Join(defaultDataDir, "cs.wal", "wal"), + WalPath: filepath.Join(DefaultDataDir, "cs.wal", "wal"), TimeoutPropose: 3000 * time.Millisecond, TimeoutProposeDelta: 500 * time.Millisecond, TimeoutPrevote: 1000 * time.Millisecond, diff --git a/config/config_test.go b/config/config_test.go index 86b32c768..cd241e5aa 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1,4 +1,4 @@ -package config +package config_test import ( "reflect" @@ -7,13 +7,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/tendermint/tendermint/config" ) func TestDefaultConfig(t *testing.T) { assert := assert.New(t) // set up some defaults - cfg := DefaultConfig() + cfg := config.DefaultConfig() assert.NotNil(cfg.P2P) assert.NotNil(cfg.Mempool) assert.NotNil(cfg.Consensus) @@ -31,7 +33,7 @@ func TestDefaultConfig(t *testing.T) { } func TestConfigValidateBasic(t *testing.T) { - cfg := DefaultConfig() + cfg := config.DefaultConfig() assert.NoError(t, cfg.ValidateBasic()) // tamper with timeout_propose @@ -41,7 +43,7 @@ func TestConfigValidateBasic(t *testing.T) { func TestTLSConfiguration(t *testing.T) { assert := assert.New(t) - cfg := DefaultConfig() + cfg := config.DefaultConfig() cfg.SetRoot("/home/user") cfg.RPC.TLSCertFile = "file.crt" @@ -56,7 +58,7 @@ func TestTLSConfiguration(t *testing.T) { } func TestBaseConfigValidateBasic(t *testing.T) { - cfg := TestBaseConfig() + cfg := config.TestBaseConfig() assert.NoError(t, cfg.ValidateBasic()) // tamper with log format @@ -65,7 +67,7 @@ func TestBaseConfigValidateBasic(t *testing.T) { } func TestRPCConfigValidateBasic(t *testing.T) { - cfg := TestRPCConfig() + cfg := config.TestRPCConfig() assert.NoError(t, cfg.ValidateBasic()) fieldsToTest := []string{ @@ -86,7 +88,7 @@ func TestRPCConfigValidateBasic(t *testing.T) { } func TestP2PConfigValidateBasic(t *testing.T) { - cfg := TestP2PConfig() + cfg := config.TestP2PConfig() assert.NoError(t, cfg.ValidateBasic()) fieldsToTest := []string{ @@ -106,7 +108,7 @@ func TestP2PConfigValidateBasic(t *testing.T) { } func TestMempoolConfigValidateBasic(t *testing.T) { - cfg := TestMempoolConfig() + cfg := config.TestMempoolConfig() assert.NoError(t, cfg.ValidateBasic()) fieldsToTest := []string{ @@ -124,12 +126,12 @@ func TestMempoolConfigValidateBasic(t *testing.T) { } func TestStateSyncConfigValidateBasic(t *testing.T) { - cfg := TestStateSyncConfig() + cfg := config.TestStateSyncConfig() require.NoError(t, cfg.ValidateBasic()) } func TestBlockSyncConfigValidateBasic(t *testing.T) { - cfg := TestBlockSyncConfig() + cfg := config.TestBlockSyncConfig() assert.NoError(t, cfg.ValidateBasic()) // tamper with version @@ -143,33 +145,33 @@ func TestBlockSyncConfigValidateBasic(t *testing.T) { func TestConsensusConfig_ValidateBasic(t *testing.T) { //nolint: lll testcases := map[string]struct { - modify func(*ConsensusConfig) + modify func(*config.ConsensusConfig) expectErr bool }{ - "TimeoutPropose": {func(c *ConsensusConfig) { c.TimeoutPropose = time.Second }, false}, - "TimeoutPropose negative": {func(c *ConsensusConfig) { c.TimeoutPropose = -1 }, true}, - "TimeoutProposeDelta": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = time.Second }, false}, - "TimeoutProposeDelta negative": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = -1 }, true}, - "TimeoutPrevote": {func(c *ConsensusConfig) { c.TimeoutPrevote = time.Second }, false}, - "TimeoutPrevote negative": {func(c *ConsensusConfig) { c.TimeoutPrevote = -1 }, true}, - "TimeoutPrevoteDelta": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = time.Second }, false}, - "TimeoutPrevoteDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = -1 }, true}, - "TimeoutPrecommit": {func(c *ConsensusConfig) { c.TimeoutPrecommit = time.Second }, false}, - "TimeoutPrecommit negative": {func(c *ConsensusConfig) { c.TimeoutPrecommit = -1 }, true}, - "TimeoutPrecommitDelta": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = time.Second }, false}, - "TimeoutPrecommitDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = -1 }, true}, - "TimeoutCommit": {func(c *ConsensusConfig) { c.TimeoutCommit = time.Second }, false}, - "TimeoutCommit negative": {func(c *ConsensusConfig) { c.TimeoutCommit = -1 }, true}, - "PeerGossipSleepDuration": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = time.Second }, false}, - "PeerGossipSleepDuration negative": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = -1 }, true}, - "PeerQueryMaj23SleepDuration": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = time.Second }, false}, - "PeerQueryMaj23SleepDuration negative": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = -1 }, true}, - "DoubleSignCheckHeight negative": {func(c *ConsensusConfig) { c.DoubleSignCheckHeight = -1 }, true}, + "TimeoutPropose": {func(c *config.ConsensusConfig) { c.TimeoutPropose = time.Second }, false}, + "TimeoutPropose negative": {func(c *config.ConsensusConfig) { c.TimeoutPropose = -1 }, true}, + "TimeoutProposeDelta": {func(c *config.ConsensusConfig) { c.TimeoutProposeDelta = time.Second }, false}, + "TimeoutProposeDelta negative": {func(c *config.ConsensusConfig) { c.TimeoutProposeDelta = -1 }, true}, + "TimeoutPrevote": {func(c *config.ConsensusConfig) { c.TimeoutPrevote = time.Second }, false}, + "TimeoutPrevote negative": {func(c *config.ConsensusConfig) { c.TimeoutPrevote = -1 }, true}, + "TimeoutPrevoteDelta": {func(c *config.ConsensusConfig) { c.TimeoutPrevoteDelta = time.Second }, false}, + "TimeoutPrevoteDelta negative": {func(c *config.ConsensusConfig) { c.TimeoutPrevoteDelta = -1 }, true}, + "TimeoutPrecommit": {func(c *config.ConsensusConfig) { c.TimeoutPrecommit = time.Second }, false}, + "TimeoutPrecommit negative": {func(c *config.ConsensusConfig) { c.TimeoutPrecommit = -1 }, true}, + "TimeoutPrecommitDelta": {func(c *config.ConsensusConfig) { c.TimeoutPrecommitDelta = time.Second }, false}, + "TimeoutPrecommitDelta negative": {func(c *config.ConsensusConfig) { c.TimeoutPrecommitDelta = -1 }, true}, + "TimeoutCommit": {func(c *config.ConsensusConfig) { c.TimeoutCommit = time.Second }, false}, + "TimeoutCommit negative": {func(c *config.ConsensusConfig) { c.TimeoutCommit = -1 }, true}, + "PeerGossipSleepDuration": {func(c *config.ConsensusConfig) { c.PeerGossipSleepDuration = time.Second }, false}, + "PeerGossipSleepDuration negative": {func(c *config.ConsensusConfig) { c.PeerGossipSleepDuration = -1 }, true}, + "PeerQueryMaj23SleepDuration": {func(c *config.ConsensusConfig) { c.PeerQueryMaj23SleepDuration = time.Second }, false}, + "PeerQueryMaj23SleepDuration negative": {func(c *config.ConsensusConfig) { c.PeerQueryMaj23SleepDuration = -1 }, true}, + "DoubleSignCheckHeight negative": {func(c *config.ConsensusConfig) { c.DoubleSignCheckHeight = -1 }, true}, } for desc, tc := range testcases { tc := tc // appease linter t.Run(desc, func(t *testing.T) { - cfg := DefaultConsensusConfig() + cfg := config.DefaultConsensusConfig() tc.modify(cfg) err := cfg.ValidateBasic() @@ -183,7 +185,7 @@ func TestConsensusConfig_ValidateBasic(t *testing.T) { } func TestInstrumentationConfigValidateBasic(t *testing.T) { - cfg := TestInstrumentationConfig() + cfg := config.TestInstrumentationConfig() assert.NoError(t, cfg.ValidateBasic()) // tamper with maximum open connections diff --git a/config/toml.go b/config/toml.go index f88611cc9..ce7c35d7f 100644 --- a/config/toml.go +++ b/config/toml.go @@ -2,8 +2,6 @@ package config import ( "bytes" - "fmt" - "os" "path/filepath" "strings" "text/template" @@ -34,10 +32,10 @@ func EnsureRoot(rootDir string) { if err := tmos.EnsureDir(rootDir, DefaultDirPerm); err != nil { panic(err.Error()) } - if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil { + if err := tmos.EnsureDir(filepath.Join(rootDir, DefaultConfigDir), DefaultDirPerm); err != nil { panic(err.Error()) } - if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil { + if err := tmos.EnsureDir(filepath.Join(rootDir, DefaultDataDir), DefaultDirPerm); err != nil { panic(err.Error()) } @@ -540,101 +538,3 @@ max_open_connections = {{ .Instrumentation.MaxOpenConnections }} # Instrumentation namespace namespace = "{{ .Instrumentation.Namespace }}" ` - -/****** these are for test settings ***********/ - -func ResetTestRoot(testName string) *Config { - return ResetTestRootWithChainID(testName, "") -} - -func ResetTestRootWithChainID(testName string, chainID string) *Config { - // create a unique, concurrency-safe test directory under os.TempDir() - rootDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s_", chainID, testName)) - if err != nil { - panic(err) - } - // ensure config and data subdirs are created - if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil { - panic(err) - } - if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil { - panic(err) - } - - baseConfig := DefaultBaseConfig() - configFilePath := filepath.Join(rootDir, defaultConfigFilePath) - genesisFilePath := filepath.Join(rootDir, baseConfig.Genesis) - privKeyFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorKey) - privStateFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorState) - - // Write default config file if missing. - if !tmos.FileExists(configFilePath) { - writeDefaultConfigFile(configFilePath) - } - if !tmos.FileExists(genesisFilePath) { - if chainID == "" { - chainID = "tendermint_test" - } - testGenesis := fmt.Sprintf(testGenesisFmt, chainID) - tmos.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644) - } - // we always overwrite the priv val - tmos.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644) - tmos.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644) - - config := TestConfig().SetRoot(rootDir) - return config -} - -var testGenesisFmt = `{ - "genesis_time": "2018-10-10T08:20:13.695936996Z", - "chain_id": "%s", - "initial_height": "1", - "consensus_params": { - "block": { - "max_bytes": "22020096", - "max_gas": "-1", - "time_iota_ms": "10" - }, - "evidence": { - "max_age_num_blocks": "100000", - "max_age_duration": "172800000000000", - "max_bytes": "1048576" - }, - "validator": { - "pub_key_types": [ - "ed25519" - ] - }, - "version": {} - }, - "validators": [ - { - "pub_key": { - "type": "tendermint/PubKeyEd25519", - "value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE=" - }, - "power": "10", - "name": "" - } - ], - "app_hash": "" -}` - -var testPrivValidatorKey = `{ - "address": "A3258DCBF45DCA0DF052981870F2D1441A36D145", - "pub_key": { - "type": "tendermint/PubKeyEd25519", - "value": "AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE=" - }, - "priv_key": { - "type": "tendermint/PrivKeyEd25519", - "value": "EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ==" - } -}` - -var testPrivValidatorState = `{ - "height": "0", - "round": 0, - "step": 0 -}` diff --git a/config/toml_test.go b/config/toml_test.go index d78f7eb9d..12b7f9c49 100644 --- a/config/toml_test.go +++ b/config/toml_test.go @@ -1,4 +1,4 @@ -package config +package config_test import ( "os" @@ -7,13 +7,16 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/tendermint/tendermint/config" + "github.com/tendermint/tendermint/internal/test" ) func ensureFiles(t *testing.T, rootDir string, files ...string) { for _, f := range files { - p := rootify(rootDir, f) + p := filepath.Join(rootDir, f) _, err := os.Stat(p) - assert.Nil(t, err, p) + assert.NoError(t, err, p) } } @@ -26,10 +29,10 @@ func TestEnsureRoot(t *testing.T) { defer os.RemoveAll(tmpDir) // create root dir - EnsureRoot(tmpDir) + config.EnsureRoot(tmpDir) // make sure config is set properly - data, err := os.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath)) + data, err := os.ReadFile(filepath.Join(tmpDir, config.DefaultConfigDir, config.DefaultConfigFileName)) require.Nil(err) assertValidConfig(t, string(data)) @@ -40,22 +43,20 @@ func TestEnsureRoot(t *testing.T) { func TestEnsureTestRoot(t *testing.T) { require := require.New(t) - testName := "ensureTestRoot" - // create root dir - cfg := ResetTestRoot(testName) + cfg := test.ResetTestRoot("ensureTestRoot") defer os.RemoveAll(cfg.RootDir) rootDir := cfg.RootDir // make sure config is set properly - data, err := os.ReadFile(filepath.Join(rootDir, defaultConfigFilePath)) + data, err := os.ReadFile(filepath.Join(rootDir, config.DefaultConfigDir, config.DefaultConfigFileName)) require.Nil(err) assertValidConfig(t, string(data)) // TODO: make sure the cfg returned and testconfig are the same! - baseConfig := DefaultBaseConfig() - ensureFiles(t, rootDir, defaultDataDir, baseConfig.Genesis, baseConfig.PrivValidatorKey, baseConfig.PrivValidatorState) + baseConfig := config.DefaultBaseConfig() + ensureFiles(t, rootDir, config.DefaultDataDir, baseConfig.Genesis, baseConfig.PrivValidatorKey, baseConfig.PrivValidatorState) } func assertValidConfig(t *testing.T, configFile string) { diff --git a/consensus/common_test.go b/consensus/common_test.go index 876563c07..fee218198 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -24,6 +24,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" cfg "github.com/tendermint/tendermint/config" cstypes "github.com/tendermint/tendermint/consensus/types" + "github.com/tendermint/tendermint/internal/test" tmbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" @@ -63,7 +64,7 @@ func ensureDir(dir string, mode os.FileMode) { } func ResetConfig(name string) *cfg.Config { - return cfg.ResetTestRoot(name) + return test.ResetTestRoot(name) } //------------------------------------------------------------------------------- @@ -108,7 +109,7 @@ func (vs *validatorStub) signVote( BlockID: types.BlockID{Hash: hash, PartSetHeader: header}, } v := vote.ToProto() - if err := vs.PrivValidator.SignVote(config.ChainID(), v); err != nil { + if err := vs.PrivValidator.SignVote(test.DefaultTestChainID, v); err != nil { return nil, fmt.Errorf("sign vote failed: %w", err) } @@ -369,7 +370,7 @@ func subscribeToVoter(cs *State, addr []byte) <-chan tmpubsub.Message { // consensus states func newState(state sm.State, pv types.PrivValidator, app abci.Application) *State { - config := cfg.ResetTestRoot("consensus_state_test") + config := test.ResetTestRoot("consensus_state_test") return newStateWithConfig(config, state, pv, app) } @@ -868,7 +869,7 @@ func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.G return &types.GenesisDoc{ GenesisTime: tmtime.Now(), InitialHeight: 1, - ChainID: config.ChainID(), + ChainID: test.DefaultTestChainID, Validators: validators, }, privValidators } diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index c60409539..303f5e6e2 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -190,7 +190,7 @@ func TestReactorWithEvidence(t *testing.T) { // mock the evidence pool // everyone includes evidence of another double signing vIdx := (i + 1) % nValidators - ev, err := types.NewMockDuplicateVoteEvidenceWithValidator(1, defaultTestTime, privVals[vIdx], config.ChainID()) + ev, err := types.NewMockDuplicateVoteEvidenceWithValidator(1, defaultTestTime, privVals[vIdx], genDoc.ChainID) require.NoError(t, err) evpool := &statemocks.EvidencePool{} evpool.On("CheckEvidence", mock.AnythingOfType("types.EvidenceList")).Return(nil) diff --git a/consensus/replay_test.go b/consensus/replay_test.go index ecc63b3f7..65b5968d4 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -373,7 +373,7 @@ func TestSimulateValidatorsChange(t *testing.T) { proposal := types.NewProposal(vss[1].Height, round, -1, blockID) p := proposal.ToProto() - if err := vss[1].SignProposal(config.ChainID(), p); err != nil { + if err := vss[1].SignProposal(genDoc.ChainID, p); err != nil { t.Fatal("failed to sign bad proposal", err) } proposal.Signature = p.Signature @@ -405,7 +405,7 @@ func TestSimulateValidatorsChange(t *testing.T) { proposal = types.NewProposal(vss[2].Height, round, -1, blockID) p = proposal.ToProto() - if err := vss[2].SignProposal(config.ChainID(), p); err != nil { + if err := vss[2].SignProposal(genDoc.ChainID, p); err != nil { t.Fatal("failed to sign bad proposal", err) } proposal.Signature = p.Signature @@ -464,7 +464,7 @@ func TestSimulateValidatorsChange(t *testing.T) { proposal = types.NewProposal(vss[3].Height, round, -1, blockID) p = proposal.ToProto() - if err := vss[3].SignProposal(config.ChainID(), p); err != nil { + if err := vss[3].SignProposal(genDoc.ChainID, p); err != nil { t.Fatal("failed to sign bad proposal", err) } proposal.Signature = p.Signature @@ -525,7 +525,7 @@ func TestSimulateValidatorsChange(t *testing.T) { selfIndex = valIndexFn(0) proposal = types.NewProposal(vss[1].Height, round, -1, blockID) p = proposal.ToProto() - if err := vss[1].SignProposal(config.ChainID(), p); err != nil { + if err := vss[1].SignProposal(genDoc.ChainID, p); err != nil { t.Fatal("failed to sign bad proposal", err) } proposal.Signature = p.Signature diff --git a/consensus/state_test.go b/consensus/state_test.go index 3f795d708..e80015135 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -214,7 +214,7 @@ func TestStateBadProposal(t *testing.T) { blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()} proposal := types.NewProposal(vs2.Height, round, -1, blockID) p := proposal.ToProto() - if err := vs2.SignProposal(config.ChainID(), p); err != nil { + if err := vs2.SignProposal(cs1.state.ChainID, p); err != nil { t.Fatal("failed to sign bad proposal", err) } @@ -276,7 +276,7 @@ func TestStateOversizedBlock(t *testing.T) { blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()} proposal := types.NewProposal(height, round, -1, blockID) p := proposal.ToProto() - if err := vs2.SignProposal(config.ChainID(), p); err != nil { + if err := vs2.SignProposal(cs1.state.ChainID, p); err != nil { t.Fatal("failed to sign bad proposal", err) } proposal.Signature = p.Signature @@ -1132,7 +1132,7 @@ func TestStateLockPOLSafety2(t *testing.T) { // in round 2 we see the polkad block from round 0 newProp := types.NewProposal(height, round, 0, propBlockID0) p := newProp.ToProto() - if err := vs3.SignProposal(config.ChainID(), p); err != nil { + if err := vs3.SignProposal(cs1.state.ChainID, p); err != nil { t.Fatal(err) } diff --git a/consensus/types/height_vote_set_test.go b/consensus/types/height_vote_set_test.go index 68c4d98c0..ccbdbed9d 100644 --- a/consensus/types/height_vote_set_test.go +++ b/consensus/types/height_vote_set_test.go @@ -7,6 +7,7 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto/tmhash" + "github.com/tendermint/tendermint/internal/test" tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" @@ -16,7 +17,7 @@ import ( var config *cfg.Config // NOTE: must be reset for each _test.go file func TestMain(m *testing.M) { - config = cfg.ResetTestRoot("consensus_height_vote_set_test") + config = test.ResetTestRoot("consensus_height_vote_set_test") code := m.Run() os.RemoveAll(config.RootDir) os.Exit(code) @@ -25,7 +26,7 @@ func TestMain(m *testing.M) { func TestPeerCatchupRounds(t *testing.T) { valSet, privVals := types.RandValidatorSet(10, 1) - hvs := NewHeightVoteSet(config.ChainID(), 1, valSet) + hvs := NewHeightVoteSet(test.DefaultTestChainID, 1, valSet) vote999_0 := makeVoteHR(t, 1, 0, 999, privVals) added, err := hvs.AddVote(vote999_0, "peer1") @@ -73,10 +74,9 @@ func makeVoteHR(t *testing.T, height int64, valIndex, round int32, privVals []ty Type: tmproto.PrecommitType, BlockID: types.BlockID{Hash: randBytes, PartSetHeader: types.PartSetHeader{}}, } - chainID := config.ChainID() v := vote.ToProto() - err = privVal.SignVote(chainID, v) + err = privVal.SignVote(test.DefaultTestChainID, v) if err != nil { panic(fmt.Sprintf("Error signing vote: %v", err)) } diff --git a/consensus/wal_generator.go b/consensus/wal_generator.go index 9035f504a..96a0d485c 100644 --- a/consensus/wal_generator.go +++ b/consensus/wal_generator.go @@ -13,6 +13,7 @@ import ( "github.com/tendermint/tendermint/abci/example/kvstore" cfg "github.com/tendermint/tendermint/config" + "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/privval" @@ -149,7 +150,7 @@ func makeAddrs() (string, string, string) { // getConfig returns a config for test cases func getConfig(t *testing.T) *cfg.Config { - c := cfg.ResetTestRoot(t.Name()) + c := test.ResetTestRoot(t.Name()) // and we use random ports to run in parallel tm, rpc, grpc := makeAddrs() diff --git a/internal/test/config.go b/internal/test/config.go new file mode 100644 index 000000000..85a84cec2 --- /dev/null +++ b/internal/test/config.go @@ -0,0 +1,96 @@ +package test + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/tendermint/tendermint/config" + tmos "github.com/tendermint/tendermint/libs/os" +) + +func ResetTestRoot(testName string) *config.Config { + return ResetTestRootWithChainID(testName, "") +} + +func ResetTestRootWithChainID(testName string, chainID string) *config.Config { + // create a unique, concurrency-safe test directory under os.TempDir() + rootDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s_", chainID, testName)) + if err != nil { + panic(err) + } + + config.EnsureRoot(rootDir) + + baseConfig := config.DefaultBaseConfig() + genesisFilePath := filepath.Join(rootDir, baseConfig.Genesis) + privKeyFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorKey) + privStateFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorState) + + if !tmos.FileExists(genesisFilePath) { + if chainID == "" { + chainID = DefaultTestChainID + } + testGenesis := fmt.Sprintf(testGenesisFmt, chainID) + tmos.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644) + } + // we always overwrite the priv val + tmos.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644) + tmos.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644) + + config := config.TestConfig().SetRoot(rootDir) + return config +} + +var testGenesisFmt = `{ + "genesis_time": "2018-10-10T08:20:13.695936996Z", + "chain_id": "%s", + "initial_height": "1", + "consensus_params": { + "block": { + "max_bytes": "22020096", + "max_gas": "-1", + "time_iota_ms": "10" + }, + "evidence": { + "max_age_num_blocks": "100000", + "max_age_duration": "172800000000000", + "max_bytes": "1048576" + }, + "validator": { + "pub_key_types": [ + "ed25519" + ] + }, + "version": {} + }, + "validators": [ + { + "pub_key": { + "type": "tendermint/PubKeyEd25519", + "value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE=" + }, + "power": "10", + "name": "" + } + ], + "app_hash": "" +}` + +var testPrivValidatorKey = `{ + "address": "A3258DCBF45DCA0DF052981870F2D1441A36D145", + "pub_key": { + "type": "tendermint/PubKeyEd25519", + "value": "AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE=" + }, + "priv_key": { + "type": "tendermint/PrivKeyEd25519", + "value": "EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ==" + } +}` + +var testPrivValidatorState = `{ + "height": "0", + "round": 0, + "step": 0 +}` diff --git a/internal/test/genesis.go b/internal/test/genesis.go index 732adf5a3..d8047ba96 100644 --- a/internal/test/genesis.go +++ b/internal/test/genesis.go @@ -3,15 +3,14 @@ package test import ( "time" - cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/types" ) func GenesisDoc( - config *cfg.Config, time time.Time, validators []*types.Validator, consensusParams *types.ConsensusParams, + chainID string, ) *types.GenesisDoc { genesisValidators := make([]types.GenesisValidator, len(validators)) @@ -26,7 +25,7 @@ func GenesisDoc( return &types.GenesisDoc{ GenesisTime: time, InitialHeight: 1, - ChainID: config.ChainID(), + ChainID: chainID, Validators: genesisValidators, ConsensusParams: consensusParams, } diff --git a/light/client_test.go b/light/client_test.go index 4a7503d7d..09067c9d9 100644 --- a/light/client_test.go +++ b/light/client_test.go @@ -12,6 +12,7 @@ import ( dbm "github.com/tendermint/tm-db" + "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/light/provider" @@ -21,7 +22,7 @@ import ( ) const ( - chainID = "test" + chainID = test.DefaultTestChainID ) var ( diff --git a/light/example_test.go b/light/example_test.go index f49b34a5d..756a9d551 100644 --- a/light/example_test.go +++ b/light/example_test.go @@ -30,10 +30,7 @@ func ExampleClient_Update() { } defer os.RemoveAll(dbDir) - var ( - config = rpctest.GetConfig() - chainID = config.ChainID() - ) + var config = rpctest.GetConfig() primary, err := httpp.New(chainID, config.RPC.ListenAddress) if err != nil { @@ -98,10 +95,7 @@ func ExampleClient_VerifyLightBlockAtHeight() { } defer os.RemoveAll(dbDir) - var ( - config = rpctest.GetConfig() - chainID = config.ChainID() - ) + var config = rpctest.GetConfig() primary, err := httpp.New(chainID, config.RPC.ListenAddress) if err != nil { diff --git a/mempool/v0/clist_mempool_test.go b/mempool/v0/clist_mempool_test.go index 5a6150d34..8cb2aa7ad 100644 --- a/mempool/v0/clist_mempool_test.go +++ b/mempool/v0/clist_mempool_test.go @@ -21,6 +21,7 @@ import ( abciserver "github.com/tendermint/tendermint/abci/server" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/config" + "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/libs/service" @@ -34,7 +35,7 @@ import ( type cleanupFunc func() func newMempoolWithAppMock(cc proxy.ClientCreator, client abciclient.Client) (*CListMempool, cleanupFunc, error) { - conf := config.ResetTestRoot("mempool_test") + conf := test.ResetTestRoot("mempool_test") mp, cu := newMempoolWithAppAndConfigMock(cc, conf, client) return mp, cu, nil @@ -57,7 +58,7 @@ func newMempoolWithAppAndConfigMock(cc proxy.ClientCreator, } func newMempoolWithApp(cc proxy.ClientCreator) (*CListMempool, cleanupFunc) { - conf := config.ResetTestRoot("mempool_test") + conf := test.ResetTestRoot("mempool_test") mp, cu := newMempoolWithAppAndConfig(cc, conf) return mp, cu @@ -550,7 +551,7 @@ func TestMempoolTxsBytes(t *testing.T) { app := kvstore.NewApplication() cc := proxy.NewLocalClientCreator(app) - cfg := config.ResetTestRoot("mempool_test") + cfg := test.ResetTestRoot("mempool_test") cfg.Mempool.MaxTxsBytes = 10 mp, cleanup := newMempoolWithAppAndConfig(cc, cfg) @@ -652,7 +653,7 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) { } }) - cfg := config.ResetTestRoot("mempool_test") + cfg := test.ResetTestRoot("mempool_test") mp, cleanup := newMempoolWithAppAndConfig(proxy.NewRemoteClientCreator(sockPath, "socket", true), cfg) defer cleanup() diff --git a/mempool/v1/mempool_test.go b/mempool/v1/mempool_test.go index 7e62b9100..f05e993a2 100644 --- a/mempool/v1/mempool_test.go +++ b/mempool/v1/mempool_test.go @@ -18,7 +18,7 @@ import ( "github.com/tendermint/tendermint/abci/example/code" "github.com/tendermint/tendermint/abci/example/kvstore" abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/config" + "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/proxy" @@ -78,7 +78,7 @@ func setup(t testing.TB, cacheSize int, options ...TxMempoolOption) *TxMempool { app := &application{kvstore.NewApplication()} cc := proxy.NewLocalClientCreator(app) - cfg := config.ResetTestRoot(strings.ReplaceAll(t.Name(), "/", "|")) + cfg := test.ResetTestRoot(strings.ReplaceAll(t.Name(), "/", "|")) cfg.Mempool.CacheSize = cacheSize appConnMem, err := cc.NewABCIClient() diff --git a/mempool/v1/reactor_test.go b/mempool/v1/reactor_test.go index a91122016..9dc56839f 100644 --- a/mempool/v1/reactor_test.go +++ b/mempool/v1/reactor_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/abci/example/kvstore" + "github.com/tendermint/tendermint/internal/test" cfg "github.com/tendermint/tendermint/config" @@ -128,7 +129,7 @@ func mempoolLogger() log.Logger { } func newMempoolWithApp(cc proxy.ClientCreator) (*TxMempool, func()) { - conf := cfg.ResetTestRoot("mempool_test") + conf := test.ResetTestRoot("mempool_test") mp, cu := newMempoolWithAppAndConfig(cc, conf) return mp, cu diff --git a/node/node_test.go b/node/node_test.go index fc3f3f298..84baf9c56 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -18,6 +18,7 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/evidence" + "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" tmrand "github.com/tendermint/tendermint/libs/rand" mempl "github.com/tendermint/tendermint/mempool" @@ -35,7 +36,7 @@ import ( ) func TestNodeStartStop(t *testing.T) { - config := cfg.ResetTestRoot("node_node_test") + config := test.ResetTestRoot("node_node_test") defer os.RemoveAll(config.RootDir) // create & start node @@ -97,7 +98,7 @@ func TestSplitAndTrimEmpty(t *testing.T) { } func TestNodeDelayedStart(t *testing.T) { - config := cfg.ResetTestRoot("node_delayed_start_test") + config := test.ResetTestRoot("node_delayed_start_test") defer os.RemoveAll(config.RootDir) now := tmtime.Now() @@ -115,7 +116,7 @@ func TestNodeDelayedStart(t *testing.T) { } func TestNodeSetAppVersion(t *testing.T) { - config := cfg.ResetTestRoot("node_app_version_test") + config := test.ResetTestRoot("node_app_version_test") defer os.RemoveAll(config.RootDir) // create & start node @@ -137,7 +138,7 @@ func TestNodeSetAppVersion(t *testing.T) { func TestNodeSetPrivValTCP(t *testing.T) { addr := "tcp://" + testFreeAddr(t) - config := cfg.ResetTestRoot("node_priv_val_tcp_test") + config := test.ResetTestRoot("node_priv_val_tcp_test") defer os.RemoveAll(config.RootDir) config.BaseConfig.PrivValidatorListenAddr = addr @@ -150,7 +151,7 @@ func TestNodeSetPrivValTCP(t *testing.T) { signerServer := privval.NewSignerServer( dialerEndpoint, - config.ChainID(), + test.DefaultTestChainID, types.NewMockPV(), ) @@ -171,7 +172,7 @@ func TestNodeSetPrivValTCP(t *testing.T) { func TestPrivValidatorListenAddrNoProtocol(t *testing.T) { addrNoPrefix := testFreeAddr(t) - config := cfg.ResetTestRoot("node_priv_val_tcp_test") + config := test.ResetTestRoot("node_priv_val_tcp_test") defer os.RemoveAll(config.RootDir) config.BaseConfig.PrivValidatorListenAddr = addrNoPrefix @@ -183,7 +184,7 @@ func TestNodeSetPrivValIPC(t *testing.T) { tmpfile := "/tmp/kms." + tmrand.Str(6) + ".sock" defer os.Remove(tmpfile) // clean up - config := cfg.ResetTestRoot("node_priv_val_tcp_test") + config := test.ResetTestRoot("node_priv_val_tcp_test") defer os.RemoveAll(config.RootDir) config.BaseConfig.PrivValidatorListenAddr = "unix://" + tmpfile @@ -196,7 +197,7 @@ func TestNodeSetPrivValIPC(t *testing.T) { pvsc := privval.NewSignerServer( dialerEndpoint, - config.ChainID(), + test.DefaultTestChainID, types.NewMockPV(), ) @@ -223,7 +224,7 @@ func testFreeAddr(t *testing.T) string { // create a proposal block using real and full // mempool and evidence pool and validate it. func TestCreateProposalBlock(t *testing.T) { - config := cfg.ResetTestRoot("node_create_proposal") + config := test.ResetTestRoot("node_create_proposal") defer os.RemoveAll(config.RootDir) cc := proxy.NewLocalClientCreator(kvstore.NewApplication()) proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) @@ -335,7 +336,7 @@ func TestCreateProposalBlock(t *testing.T) { } func TestMaxProposalBlockSize(t *testing.T) { - config := cfg.ResetTestRoot("node_create_proposal") + config := test.ResetTestRoot("node_create_proposal") defer os.RemoveAll(config.RootDir) cc := proxy.NewLocalClientCreator(kvstore.NewApplication()) proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) @@ -414,7 +415,7 @@ func TestMaxProposalBlockSize(t *testing.T) { } func TestNodeNewNodeCustomReactors(t *testing.T) { - config := cfg.ResetTestRoot("node_new_node_custom_reactors_test") + config := test.ResetTestRoot("node_new_node_custom_reactors_test") defer os.RemoveAll(config.RootDir) cr := p2pmock.NewReactor() diff --git a/rpc/client/evidence_test.go b/rpc/client/evidence_test.go index a813d3912..ca4e0567e 100644 --- a/rpc/client/evidence_test.go +++ b/rpc/client/evidence_test.go @@ -13,6 +13,7 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" cryptoenc "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/crypto/tmhash" + "github.com/tendermint/tendermint/internal/test" tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/privval" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -117,7 +118,7 @@ func makeEvidences( func TestBroadcastEvidence_DuplicateVoteEvidence(t *testing.T) { var ( config = rpctest.GetConfig() - chainID = config.ChainID() + chainID = test.DefaultTestChainID pv = privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile()) ) diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index ebf2e14d5..1b88dec51 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -9,6 +9,7 @@ import ( "time" abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" cfg "github.com/tendermint/tendermint/config" @@ -91,7 +92,7 @@ func makeAddrs() (string, string, string) { func createConfig() *cfg.Config { pathname := makePathname() - c := cfg.ResetTestRoot(pathname) + c := test.ResetTestRoot(pathname) // and we use random ports to run in parallel tm, rpc, grpc := makeAddrs() diff --git a/state/state_test.go b/state/state_test.go index 6577e02c5..f88affa56 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -14,9 +14,9 @@ import ( dbm "github.com/tendermint/tm-db" abci "github.com/tendermint/tendermint/abci/types" - cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto/ed25519" cryptoenc "github.com/tendermint/tendermint/crypto/encoding" + "github.com/tendermint/tendermint/internal/test" tmrand "github.com/tendermint/tendermint/libs/rand" tmstate "github.com/tendermint/tendermint/proto/tendermint/state" sm "github.com/tendermint/tendermint/state" @@ -25,7 +25,7 @@ import ( // setupTestCase does setup common to all test cases. func setupTestCase(t *testing.T) (func(t *testing.T), dbm.DB, sm.State) { - config := cfg.ResetTestRoot("state_") + config := test.ResetTestRoot("state_") dbType := dbm.BackendType(config.DBBackend) stateDB, err := dbm.NewDB("state", dbType, config.DBDir()) stateStore := sm.NewStore(stateDB, sm.StoreOptions{ diff --git a/state/store_test.go b/state/store_test.go index 8b3a6c4bd..e2ecbe4fa 100644 --- a/state/store_test.go +++ b/state/store_test.go @@ -11,9 +11,9 @@ import ( dbm "github.com/tendermint/tm-db" abci "github.com/tendermint/tendermint/abci/types" - cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/internal/test" tmrand "github.com/tendermint/tendermint/libs/rand" tmstate "github.com/tendermint/tendermint/proto/tendermint/state" sm "github.com/tendermint/tendermint/state" @@ -50,7 +50,7 @@ func TestStoreLoadValidators(t *testing.T) { func BenchmarkLoadValidators(b *testing.B) { const valSetSize = 100 - config := cfg.ResetTestRoot("state_") + config := test.ResetTestRoot("state_") defer os.RemoveAll(config.RootDir) dbType := dbm.BackendType(config.DBBackend) stateDB, err := dbm.NewDB("state", dbType, config.DBDir()) diff --git a/store/store_test.go b/store/store_test.go index 1d92824b0..9fff81511 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -15,7 +15,6 @@ import ( "github.com/stretchr/testify/require" dbm "github.com/tendermint/tm-db" - cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" @@ -45,7 +44,7 @@ func makeTestCommit(height int64, timestamp time.Time) *types.Commit { } func makeStateAndBlockStore(logger log.Logger) (sm.State, *BlockStore, cleanupFunc) { - config := cfg.ResetTestRoot("blockchain_reactor_test") + config := test.ResetTestRoot("blockchain_reactor_test") // blockDB := dbm.NewDebugDB("blockDB", dbm.NewMemDB()) // stateDB := dbm.NewDebugDB("stateDB", dbm.NewMemDB()) blockDB := dbm.NewMemDB() @@ -365,7 +364,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { } func TestLoadBaseMeta(t *testing.T) { - config := cfg.ResetTestRoot("blockchain_reactor_test") + config := test.ResetTestRoot("blockchain_reactor_test") defer os.RemoveAll(config.RootDir) stateStore := sm.NewStore(dbm.NewMemDB(), sm.StoreOptions{ DiscardABCIResponses: false, @@ -427,7 +426,7 @@ func TestLoadBlockPart(t *testing.T) { } func TestPruneBlocks(t *testing.T) { - config := cfg.ResetTestRoot("blockchain_reactor_test") + config := test.ResetTestRoot("blockchain_reactor_test") defer os.RemoveAll(config.RootDir) stateStore := sm.NewStore(dbm.NewMemDB(), sm.StoreOptions{ DiscardABCIResponses: false, @@ -557,7 +556,7 @@ func TestLoadBlockMeta(t *testing.T) { } func TestLoadBlockMetaByHash(t *testing.T) { - config := cfg.ResetTestRoot("blockchain_reactor_test") + config := test.ResetTestRoot("blockchain_reactor_test") defer os.RemoveAll(config.RootDir) stateStore := sm.NewStore(dbm.NewMemDB(), sm.StoreOptions{ DiscardABCIResponses: false,