Browse Source

config: WriteConfigFile should return error (#7169)

pull/7173/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
93eb940dcd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 320 additions and 156 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +3
    -1
      cmd/tendermint/commands/init.go
  3. +3
    -1
      cmd/tendermint/commands/testnet.go
  4. +28
    -17
      config/toml.go
  5. +5
    -4
      config/toml_test.go
  6. +9
    -4
      internal/blocksync/reactor_test.go
  7. +3
    -1
      internal/consensus/byzantine_test.go
  8. +41
    -23
      internal/consensus/common_test.go
  9. +6
    -3
      internal/consensus/mempool_test.go
  10. +2
    -1
      internal/consensus/reactor_test.go
  11. +10
    -5
      internal/consensus/replay_test.go
  12. +71
    -34
      internal/consensus/state_test.go
  13. +5
    -1
      internal/consensus/types/height_vote_set_test.go
  14. +2
    -1
      internal/consensus/wal_generator.go
  15. +5
    -2
      internal/inspect/inspect_test.go
  16. +10
    -4
      internal/mempool/v0/bench_test.go
  17. +2
    -1
      internal/mempool/v0/cache_test.go
  18. +34
    -16
      internal/mempool/v0/clist_mempool_test.go
  19. +2
    -1
      internal/mempool/v0/reactor_test.go
  20. +2
    -1
      internal/mempool/v1/mempool_test.go
  21. +3
    -4
      internal/mempool/v1/reactor_test.go
  22. +3
    -1
      internal/state/state_test.go
  23. +3
    -1
      internal/state/store_test.go
  24. +11
    -3
      internal/store/store_test.go
  25. +5
    -1
      light/example_test.go
  26. +4
    -2
      light/light_test.go
  27. +2
    -1
      light/provider/http/http_test.go
  28. +30
    -15
      node/node_test.go
  29. +4
    -2
      rpc/client/examples_test.go
  30. +2
    -1
      rpc/client/main_test.go
  31. +6
    -3
      rpc/test/helpers.go
  32. +3
    -1
      test/e2e/runner/setup.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -27,6 +27,7 @@ Special thanks to external contributors on this release:
- [blocksync] \#7046 Remove v2 implementation of the blocksync service and recactor, which was disabled in the previous release. (@tychoish)
- [p2p] \#7064 Remove WDRR queue implementation. (@tychoish)
- [config] \#7169 `WriteConfigFile` now returns an error. (@tychoish)
- Blockchain Protocol


+ 3
- 1
cmd/tendermint/commands/init.go View File

@ -121,7 +121,9 @@ func initFilesWithConfig(config *cfg.Config) error {
}
// write config file
cfg.WriteConfigFile(config.RootDir, config)
if err := cfg.WriteConfigFile(config.RootDir, config); err != nil {
return err
}
logger.Info("Generated config", "mode", config.Mode)
return nil


+ 3
- 1
cmd/tendermint/commands/testnet.go View File

@ -239,7 +239,9 @@ func testnetFiles(cmd *cobra.Command, args []string) error {
}
config.Moniker = moniker(i)
cfg.WriteConfigFile(nodeDir, config)
if err := cfg.WriteConfigFile(nodeDir, config); err != nil {
return err
}
}
fmt.Printf("Successfully initialized %v node directories\n", nValidators+nNonValidators)


+ 28
- 17
config/toml.go View File

@ -45,23 +45,24 @@ func EnsureRoot(rootDir string) {
// WriteConfigFile renders config using the template and writes it to configFilePath.
// This function is called by cmd/tendermint/commands/init.go
func WriteConfigFile(rootDir string, config *Config) {
func WriteConfigFile(rootDir string, config *Config) error {
var buffer bytes.Buffer
if err := configTemplate.Execute(&buffer, config); err != nil {
panic(err)
return err
}
configFilePath := filepath.Join(rootDir, defaultConfigFilePath)
mustWriteFile(configFilePath, buffer.Bytes(), 0644)
return writeFile(configFilePath, buffer.Bytes(), 0644)
}
func writeDefaultConfigFileIfNone(rootDir string) {
func writeDefaultConfigFileIfNone(rootDir string) error {
configFilePath := filepath.Join(rootDir, defaultConfigFilePath)
if !tmos.FileExists(configFilePath) {
WriteConfigFile(rootDir, DefaultConfig())
return WriteConfigFile(rootDir, DefaultConfig())
}
return nil
}
// Note: any changes to the comments/variables/mapstructure
@ -503,22 +504,22 @@ namespace = "{{ .Instrumentation.Namespace }}"
/****** these are for test settings ***********/
func ResetTestRoot(testName string) *Config {
func ResetTestRoot(testName string) (*Config, error) {
return ResetTestRootWithChainID(testName, "")
}
func ResetTestRootWithChainID(testName string, chainID string) *Config {
func ResetTestRootWithChainID(testName string, chainID string) (*Config, error) {
// create a unique, concurrency-safe test directory under os.TempDir()
rootDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s_", chainID, testName))
if err != nil {
panic(err)
return nil, err
}
// ensure config and data subdirs are created
if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil {
panic(err)
return nil, err
}
if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil {
panic(err)
return nil, err
}
conf := DefaultConfig()
@ -527,26 +528,36 @@ func ResetTestRootWithChainID(testName string, chainID string) *Config {
privStateFilePath := filepath.Join(rootDir, conf.PrivValidator.State)
// Write default config file if missing.
writeDefaultConfigFileIfNone(rootDir)
if err := writeDefaultConfigFileIfNone(rootDir); err != nil {
return nil, err
}
if !tmos.FileExists(genesisFilePath) {
if chainID == "" {
chainID = "tendermint_test"
}
testGenesis := fmt.Sprintf(testGenesisFmt, chainID)
mustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
if err := writeFile(genesisFilePath, []byte(testGenesis), 0644); err != nil {
return nil, err
}
}
// we always overwrite the priv val
mustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644)
mustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644)
if err := writeFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644); err != nil {
return nil, err
}
if err := writeFile(privStateFilePath, []byte(testPrivValidatorState), 0644); err != nil {
return nil, err
}
config := TestConfig().SetRoot(rootDir)
return config
return config, nil
}
func mustWriteFile(filePath string, contents []byte, mode os.FileMode) {
func writeFile(filePath string, contents []byte, mode os.FileMode) error {
if err := ioutil.WriteFile(filePath, contents, mode); err != nil {
tmos.Exit(fmt.Sprintf("failed to write file: %v", err))
return fmt.Errorf("failed to write file: %w", err)
}
return nil
}
var testGenesisFmt = `{


+ 5
- 4
config/toml_test.go View File

@ -24,17 +24,17 @@ func TestEnsureRoot(t *testing.T) {
// setup temp dir for test
tmpDir, err := ioutil.TempDir("", "config-test")
require.Nil(err)
require.NoError(err)
defer os.RemoveAll(tmpDir)
// create root dir
EnsureRoot(tmpDir)
WriteConfigFile(tmpDir, DefaultConfig())
require.NoError(WriteConfigFile(tmpDir, DefaultConfig()))
// make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath))
require.Nil(err)
require.NoError(err)
checkConfig(t, string(data))
@ -47,7 +47,8 @@ func TestEnsureTestRoot(t *testing.T) {
testName := "ensureTestRoot"
// create root dir
cfg := ResetTestRoot(testName)
cfg, err := ResetTestRoot(testName)
require.NoError(err)
defer os.RemoveAll(cfg.RootDir)
rootDir := cfg.RootDir


+ 9
- 4
internal/blocksync/reactor_test.go View File

@ -182,7 +182,8 @@ func (rts *reactorTestSuite) start(t *testing.T) {
}
func TestReactor_AbruptDisconnect(t *testing.T) {
cfg := config.ResetTestRoot("block_sync_reactor_test")
cfg, err := config.ResetTestRoot("block_sync_reactor_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
genDoc, privVals := factory.RandGenesisDoc(cfg, 1, false, 30)
@ -217,7 +218,8 @@ func TestReactor_AbruptDisconnect(t *testing.T) {
}
func TestReactor_SyncTime(t *testing.T) {
cfg := config.ResetTestRoot("block_sync_reactor_test")
cfg, err := config.ResetTestRoot("block_sync_reactor_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
genDoc, privVals := factory.RandGenesisDoc(cfg, 1, false, 30)
@ -240,7 +242,9 @@ func TestReactor_SyncTime(t *testing.T) {
}
func TestReactor_NoBlockResponse(t *testing.T) {
cfg := config.ResetTestRoot("block_sync_reactor_test")
cfg, err := config.ResetTestRoot("block_sync_reactor_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
genDoc, privVals := factory.RandGenesisDoc(cfg, 1, false, 30)
@ -287,7 +291,8 @@ func TestReactor_BadBlockStopsPeer(t *testing.T) {
// See: https://github.com/tendermint/tendermint/issues/6005
t.SkipNow()
cfg := config.ResetTestRoot("block_sync_reactor_test")
cfg, err := config.ResetTestRoot("block_sync_reactor_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
maxBlockHeight := int64(48)


+ 3
- 1
internal/consensus/byzantine_test.go View File

@ -50,7 +50,9 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
require.NoError(t, err)
require.NoError(t, stateStore.Save(state))
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
thisConfig, err := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
require.NoError(t, err)
defer os.RemoveAll(thisConfig.RootDir)
ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal


+ 41
- 23
internal/consensus/common_test.go View File

@ -50,20 +50,26 @@ type cleanupFunc func()
func configSetup(t *testing.T) *config.Config {
t.Helper()
cfg := ResetConfig("consensus_reactor_test")
consensusReplayConfig := ResetConfig("consensus_replay_test")
configStateTest := ResetConfig("consensus_state_test")
configMempoolTest := ResetConfig("consensus_mempool_test")
configByzantineTest := ResetConfig("consensus_byzantine_test")
t.Cleanup(func() {
os.RemoveAll(cfg.RootDir)
os.RemoveAll(consensusReplayConfig.RootDir)
os.RemoveAll(configStateTest.RootDir)
os.RemoveAll(configMempoolTest.RootDir)
os.RemoveAll(configByzantineTest.RootDir)
})
cfg, err := ResetConfig("consensus_reactor_test")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(cfg.RootDir) })
consensusReplayConfig, err := ResetConfig("consensus_replay_test")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(consensusReplayConfig.RootDir) })
configStateTest, err := ResetConfig("consensus_state_test")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(configStateTest.RootDir) })
configMempoolTest, err := ResetConfig("consensus_mempool_test")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(configMempoolTest.RootDir) })
configByzantineTest, err := ResetConfig("consensus_byzantine_test")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(configByzantineTest.RootDir) })
return cfg
}
@ -73,7 +79,7 @@ func ensureDir(dir string, mode os.FileMode) {
}
}
func ResetConfig(name string) *config.Config {
func ResetConfig(name string) (*config.Config, error) {
return config.ResetTestRoot(name)
}
@ -384,9 +390,12 @@ func subscribeToVoter(cs *State, addr []byte) <-chan tmpubsub.Message {
//-------------------------------------------------------------------------------
// consensus states
func newState(state sm.State, pv types.PrivValidator, app abci.Application) *State {
cfg := config.ResetTestRoot("consensus_state_test")
return newStateWithConfig(cfg, state, pv, app)
func newState(state sm.State, pv types.PrivValidator, app abci.Application) (*State, error) {
cfg, err := config.ResetTestRoot("consensus_state_test")
if err != nil {
return nil, err
}
return newStateWithConfig(cfg, state, pv, app), nil
}
func newStateWithConfig(
@ -454,13 +463,16 @@ func loadPrivValidator(cfg *config.Config) *privval.FilePV {
return privValidator
}
func randState(cfg *config.Config, nValidators int) (*State, []*validatorStub) {
func randState(cfg *config.Config, nValidators int) (*State, []*validatorStub, error) {
// Get State
state, privVals := randGenesisState(cfg, nValidators, false, 10)
vss := make([]*validatorStub, nValidators)
cs := newState(state, privVals[0], kvstore.NewApplication())
cs, err := newState(state, privVals[0], kvstore.NewApplication())
if err != nil {
return nil, nil, err
}
for i := 0; i < nValidators; i++ {
vss[i] = newValidatorStub(privVals[i], int32(i))
@ -468,7 +480,7 @@ func randState(cfg *config.Config, nValidators int) (*State, []*validatorStub) {
// since cs1 starts at 1
incrementHeight(vss[1:]...)
return cs, vss
return cs, vss, nil
}
//-------------------------------------------------------------------------------
@ -722,7 +734,9 @@ func randConsensusState(
blockStore := store.NewBlockStore(dbm.NewMemDB()) // each state needs its own db
state, err := sm.MakeGenesisState(genDoc)
require.NoError(t, err)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
thisConfig, err := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
require.NoError(t, err)
configRootDirs = append(configRootDirs, thisConfig.RootDir)
for _, opt := range configOpts {
@ -772,7 +786,11 @@ func randConsensusNetWithPeers(
configRootDirs := make([]string, 0, nPeers)
for i := 0; i < nPeers; i++ {
state, _ := sm.MakeGenesisState(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
thisConfig, err := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
if err != nil {
panic(err)
}
configRootDirs = append(configRootDirs, thisConfig.RootDir)
ensureDir(filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
if i == 0 {


+ 6
- 3
internal/consensus/mempool_test.go View File

@ -28,7 +28,8 @@ func assertMempool(txn txNotifier) mempool.Mempool {
func TestMempoolNoProgressUntilTxsAvailable(t *testing.T) {
baseConfig := configSetup(t)
config := ResetConfig("consensus_mempool_txs_available_test")
config, err := ResetConfig("consensus_mempool_txs_available_test")
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(config.RootDir) })
config.Consensus.CreateEmptyBlocks = false
@ -50,7 +51,8 @@ func TestMempoolNoProgressUntilTxsAvailable(t *testing.T) {
func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) {
baseConfig := configSetup(t)
config := ResetConfig("consensus_mempool_txs_available_test")
config, err := ResetConfig("consensus_mempool_txs_available_test")
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(config.RootDir) })
config.Consensus.CreateEmptyBlocksInterval = ensureTimeout
@ -70,7 +72,8 @@ func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) {
func TestMempoolProgressInHigherRound(t *testing.T) {
baseConfig := configSetup(t)
config := ResetConfig("consensus_mempool_txs_available_test")
config, err := ResetConfig("consensus_mempool_txs_available_test")
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(config.RootDir) })
config.Consensus.CreateEmptyBlocks = false


+ 2
- 1
internal/consensus/reactor_test.go View File

@ -334,7 +334,8 @@ func TestReactorWithEvidence(t *testing.T) {
stateStore := sm.NewStore(stateDB)
state, err := sm.MakeGenesisState(genDoc)
require.NoError(t, err)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
thisConfig, err := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
require.NoError(t, err)
defer os.RemoveAll(thisConfig.RootDir)


+ 10
- 5
internal/consensus/replay_test.go View File

@ -131,7 +131,8 @@ func TestWALCrash(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
consensusReplayConfig := ResetConfig(tc.name)
consensusReplayConfig, err := ResetConfig(tc.name)
require.NoError(t, err)
crashWALandCheckLiveness(t, consensusReplayConfig, tc.initFn, tc.heightToStop)
})
}
@ -690,7 +691,8 @@ func testHandshakeReplay(t *testing.T, sim *simulatorTestSuite, nBlocks int, mod
cfg := sim.Config
if testValidatorsChange {
testConfig := ResetConfig(fmt.Sprintf("%s_%v_m", t.Name(), mode))
testConfig, err := ResetConfig(fmt.Sprintf("%s_%v_m", t.Name(), mode))
require.NoError(t, err)
defer func() { _ = os.RemoveAll(testConfig.RootDir) }()
stateDB = dbm.NewMemDB()
@ -700,7 +702,8 @@ func testHandshakeReplay(t *testing.T, sim *simulatorTestSuite, nBlocks int, mod
commits = sim.Commits
store = newMockBlockStore(cfg, genesisState.ConsensusParams)
} else { // test single node
testConfig := ResetConfig(fmt.Sprintf("%s_%v_s", t.Name(), mode))
testConfig, err := ResetConfig(fmt.Sprintf("%s_%v_s", t.Name(), mode))
require.NoError(t, err)
defer func() { _ = os.RemoveAll(testConfig.RootDir) }()
walBody, err := WALWithNBlocks(t, numBlocks)
require.NoError(t, err)
@ -938,7 +941,8 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) {
// - 0x01
// - 0x02
// - 0x03
cfg := ResetConfig("handshake_test_")
cfg, err := ResetConfig("handshake_test_")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(cfg.RootDir) })
privVal, err := privval.LoadFilePV(cfg.PrivValidator.KeyFile(), cfg.PrivValidator.StateFile())
require.NoError(t, err)
@ -1228,7 +1232,8 @@ func TestHandshakeUpdatesValidators(t *testing.T) {
app := &initChainApp{vals: types.TM2PB.ValidatorUpdates(vals)}
clientCreator := abciclient.NewLocalCreator(app)
cfg := ResetConfig("handshake_test_")
cfg, err := ResetConfig("handshake_test_")
require.NoError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(cfg.RootDir) })
privVal, err := privval.LoadFilePV(cfg.PrivValidator.KeyFile(), cfg.PrivValidator.StateFile())


+ 71
- 34
internal/consensus/state_test.go View File

@ -57,7 +57,9 @@ x * TestHalt1 - if we see +2/3 precommits after timing out into new round, we sh
func TestStateProposerSelection0(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
height, round := cs1.Height, cs1.Round
newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
@ -99,7 +101,9 @@ func TestStateProposerSelection0(t *testing.T) {
func TestStateProposerSelection2(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4) // test needs more work for more than 3 validators
cs1, vss, err := randState(config, 4) // test needs more work for more than 3 validators
require.NoError(t, err)
height := cs1.Height
newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
@ -138,7 +142,8 @@ func TestStateProposerSelection2(t *testing.T) {
func TestStateEnterProposeNoPrivValidator(t *testing.T) {
config := configSetup(t)
cs, _ := randState(config, 1)
cs, _, err := randState(config, 1)
require.NoError(t, err)
cs.SetPrivValidator(nil)
height, round := cs.Height, cs.Round
@ -159,7 +164,8 @@ func TestStateEnterProposeNoPrivValidator(t *testing.T) {
func TestStateEnterProposeYesPrivValidator(t *testing.T) {
config := configSetup(t)
cs, _ := randState(config, 1)
cs, _, err := randState(config, 1)
require.NoError(t, err)
height, round := cs.Height, cs.Round
// Listen for propose timeout event
@ -191,7 +197,8 @@ func TestStateEnterProposeYesPrivValidator(t *testing.T) {
func TestStateBadProposal(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 2)
cs1, vss, err := randState(config, 2)
require.NoError(t, err)
height, round := cs1.Height, cs1.Round
vs2 := vss[1]
@ -251,7 +258,8 @@ func TestStateBadProposal(t *testing.T) {
func TestStateOversizedBlock(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 2)
cs1, vss, err := randState(config, 2)
require.NoError(t, err)
cs1.state.ConsensusParams.Block.MaxBytes = 2000
height, round := cs1.Height, cs1.Round
vs2 := vss[1]
@ -315,7 +323,8 @@ func TestStateOversizedBlock(t *testing.T) {
func TestStateFullRound1(t *testing.T) {
config := configSetup(t)
cs, vss := randState(config, 1)
cs, vss, err := randState(config, 1)
require.NoError(t, err)
height, round := cs.Height, cs.Round
// NOTE: buffer capacity of 0 ensures we can validate prevote and last commit
@ -357,7 +366,8 @@ func TestStateFullRound1(t *testing.T) {
func TestStateFullRoundNil(t *testing.T) {
config := configSetup(t)
cs, vss := randState(config, 1)
cs, vss, err := randState(config, 1)
require.NoError(t, err)
height, round := cs.Height, cs.Round
voteCh := subscribe(cs.eventBus, types.EventQueryVote)
@ -377,7 +387,8 @@ func TestStateFullRoundNil(t *testing.T) {
func TestStateFullRound2(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 2)
cs1, vss, err := randState(config, 2)
require.NoError(t, err)
vs2 := vss[1]
height, round := cs1.Height, cs1.Round
@ -419,7 +430,8 @@ func TestStateFullRound2(t *testing.T) {
func TestStateLockNoPOL(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 2)
cs1, vss, err := randState(config, 2)
require.NoError(t, err)
vs2 := vss[1]
height, round := cs1.Height, cs1.Round
@ -557,7 +569,8 @@ func TestStateLockNoPOL(t *testing.T) {
ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds())
cs2, _ := randState(config, 2) // needed so generated block is different than locked block
cs2, _, err := randState(config, 2) // needed so generated block is different than locked block
require.NoError(t, err)
// before we time out into new round, set next proposal block
prop, propBlock := decideProposal(cs2, vs2, vs2.Height, vs2.Round+1)
if prop == nil || propBlock == nil {
@ -609,7 +622,8 @@ func TestStateLockNoPOL(t *testing.T) {
func TestStateLockPOLRelock(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -653,7 +667,9 @@ func TestStateLockPOLRelock(t *testing.T) {
signAddVotes(config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
// before we timeout to the new round set the new proposal
cs2 := newState(cs1.state, vs2, kvstore.NewApplication())
cs2, err := newState(cs1.state, vs2, kvstore.NewApplication())
require.NoError(t, err)
prop, propBlock := decideProposal(cs2, vs2, vs2.Height, vs2.Round+1)
if prop == nil || propBlock == nil {
t.Fatal("Failed to create proposal block with vs2")
@ -708,7 +724,8 @@ func TestStateLockPOLRelock(t *testing.T) {
func TestStateLockPOLUnlock(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -802,7 +819,8 @@ func TestStateLockPOLUnlock(t *testing.T) {
func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -842,7 +860,8 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) {
signAddVotes(config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
// before we timeout to the new round set the new proposal
cs2 := newState(cs1.state, vs2, kvstore.NewApplication())
cs2, err := newState(cs1.state, vs2, kvstore.NewApplication())
require.NoError(t, err)
prop, propBlock := decideProposal(cs2, vs2, vs2.Height, vs2.Round+1)
if prop == nil || propBlock == nil {
t.Fatal("Failed to create proposal block with vs2")
@ -886,7 +905,8 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) {
signAddVotes(config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
// before we timeout to the new round set the new proposal
cs3 := newState(cs1.state, vs3, kvstore.NewApplication())
cs3, err := newState(cs1.state, vs3, kvstore.NewApplication())
require.NoError(t, err)
prop, propBlock = decideProposal(cs3, vs3, vs3.Height, vs3.Round+1)
if prop == nil || propBlock == nil {
t.Fatal("Failed to create proposal block with vs2")
@ -930,7 +950,8 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) {
func TestStateLockPOLSafety1(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -1053,7 +1074,8 @@ func TestStateLockPOLSafety1(t *testing.T) {
func TestStateLockPOLSafety2(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -1152,7 +1174,8 @@ func TestStateLockPOLSafety2(t *testing.T) {
func TestProposeValidBlock(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -1244,7 +1267,8 @@ func TestProposeValidBlock(t *testing.T) {
func TestSetValidBlockOnDelayedPrevote(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -1308,7 +1332,8 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) {
func TestSetValidBlockOnDelayedProposal(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -1366,7 +1391,8 @@ func TestSetValidBlockOnDelayedProposal(t *testing.T) {
func TestWaitingTimeoutOnNilPolka(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -1389,7 +1415,8 @@ func TestWaitingTimeoutOnNilPolka(t *testing.T) {
func TestWaitingTimeoutProposeOnNewRound(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -1427,7 +1454,8 @@ func TestWaitingTimeoutProposeOnNewRound(t *testing.T) {
func TestRoundSkipOnNilPolkaFromHigherRound(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -1465,7 +1493,8 @@ func TestRoundSkipOnNilPolkaFromHigherRound(t *testing.T) {
func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, int32(1)
@ -1494,7 +1523,8 @@ func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) {
func TestEmitNewValidBlockEventOnCommitWithoutBlock(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, int32(1)
@ -1530,7 +1560,8 @@ func TestEmitNewValidBlockEventOnCommitWithoutBlock(t *testing.T) {
func TestCommitFromPreviousRound(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, int32(1)
@ -1586,7 +1617,8 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) {
config := configSetup(t)
config.Consensus.SkipTimeoutCommit = false
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
cs1.txNotifier = &fakeTxNotifier{ch: make(chan struct{})}
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
@ -1649,7 +1681,8 @@ func TestResetTimeoutPrecommitUponNewHeight(t *testing.T) {
config := configSetup(t)
config.Consensus.SkipTimeoutCommit = false
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
@ -1792,7 +1825,8 @@ func TestStateSlashingPrecommits(t *testing.T) {
func TestStateHalt1(t *testing.T) {
config := configSetup(t)
cs1, vss := randState(config, 4)
cs1, vss, err := randState(config, 4)
require.NoError(t, err)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
height, round := cs1.Height, cs1.Round
partSize := types.BlockPartSizeBytes
@ -1862,7 +1896,8 @@ func TestStateOutputsBlockPartsStats(t *testing.T) {
config := configSetup(t)
// create dummy peer
cs, _ := randState(config, 1)
cs, _, err := randState(config, 1)
require.NoError(t, err)
peerID, err := types.NewNodeID("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
require.NoError(t, err)
@ -1907,7 +1942,8 @@ func TestStateOutputsBlockPartsStats(t *testing.T) {
func TestStateOutputVoteStats(t *testing.T) {
config := configSetup(t)
cs, vss := randState(config, 2)
cs, vss, err := randState(config, 2)
require.NoError(t, err)
// create dummy peer
peerID, err := types.NewNodeID("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
require.NoError(t, err)
@ -1943,7 +1979,8 @@ func TestStateOutputVoteStats(t *testing.T) {
func TestSignSameVoteTwice(t *testing.T) {
config := configSetup(t)
_, vss := randState(config, 2)
_, vss, err := randState(config, 2)
require.NoError(t, err)
randBytes := tmrand.Bytes(tmhash.Size)


+ 5
- 1
internal/consensus/types/height_vote_set_test.go View File

@ -18,7 +18,11 @@ import (
var cfg *config.Config // NOTE: must be reset for each _test.go file
func TestMain(m *testing.M) {
cfg = config.ResetTestRoot("consensus_height_vote_set_test")
var err error
cfg, err = config.ResetTestRoot("consensus_height_vote_set_test")
if err != nil {
panic(err)
}
code := m.Run()
os.RemoveAll(cfg.RootDir)
os.Exit(code)


+ 2
- 1
internal/consensus/wal_generator.go View File

@ -156,7 +156,8 @@ func makeAddrs() (p2pAddr, rpcAddr string) {
// getConfig returns a config for test cases
func getConfig(t *testing.T) *config.Config {
c := config.ResetTestRoot(t.Name())
c, err := config.ResetTestRoot(t.Name())
require.NoError(t, err)
p2pAddr, rpcAddr := makeAddrs()
c.P2P.ListenAddress = p2pAddr


+ 5
- 2
internal/inspect/inspect_test.go View File

@ -27,7 +27,8 @@ import (
)
func TestInspectConstructor(t *testing.T) {
cfg := config.ResetTestRoot("test")
cfg, err := config.ResetTestRoot("test")
require.NoError(t, err)
testLogger := log.TestingLogger()
t.Cleanup(leaktest.Check(t))
defer func() { _ = os.RemoveAll(cfg.RootDir) }()
@ -41,7 +42,9 @@ func TestInspectConstructor(t *testing.T) {
}
func TestInspectRun(t *testing.T) {
cfg := config.ResetTestRoot("test")
cfg, err := config.ResetTestRoot("test")
require.NoError(t, err)
testLogger := log.TestingLogger()
t.Cleanup(leaktest.Check(t))
defer func() { _ = os.RemoveAll(cfg.RootDir) }()


+ 10
- 4
internal/mempool/v0/bench_test.go View File

@ -6,6 +6,7 @@ import (
"sync/atomic"
"testing"
"github.com/stretchr/testify/require"
abciclient "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/kvstore"
"github.com/tendermint/tendermint/internal/mempool"
@ -14,8 +15,10 @@ import (
func BenchmarkReap(b *testing.B) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(b, err)
defer cleanup()
mp.config.Size = 100000
size := 10000
@ -35,7 +38,8 @@ func BenchmarkReap(b *testing.B) {
func BenchmarkCheckTx(b *testing.B) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(b, err)
defer cleanup()
mp.config.Size = 1000000
@ -57,7 +61,8 @@ func BenchmarkCheckTx(b *testing.B) {
func BenchmarkParallelCheckTx(b *testing.B) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(b, err)
defer cleanup()
mp.config.Size = 100000000
@ -82,7 +87,8 @@ func BenchmarkParallelCheckTx(b *testing.B) {
func BenchmarkCheckDuplicateTx(b *testing.B) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(b, err)
defer cleanup()
mp.config.Size = 1000000


+ 2
- 1
internal/mempool/v0/cache_test.go View File

@ -17,7 +17,8 @@ import (
func TestCacheAfterUpdate(t *testing.T) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(t, err)
defer cleanup()
// reAddIndices & txsInCache can have elements > numTxsToCreate


+ 34
- 16
internal/mempool/v0/clist_mempool_test.go View File

@ -33,8 +33,14 @@ import (
// test.
type cleanupFunc func()
func newMempoolWithApp(cc abciclient.Creator) (*CListMempool, cleanupFunc) {
return newMempoolWithAppAndConfig(cc, config.ResetTestRoot("mempool_test"))
func newMempoolWithApp(cc abciclient.Creator) (*CListMempool, cleanupFunc, error) {
conf, err := config.ResetTestRoot("mempool_test")
if err != nil {
return nil, func() {}, err
}
mp, cu := newMempoolWithAppAndConfig(cc, conf)
return mp, cu, nil
}
func newMempoolWithAppAndConfig(cc abciclient.Creator, cfg *config.Config) (*CListMempool, cleanupFunc) {
@ -95,7 +101,8 @@ func checkTxs(t *testing.T, mp mempool.Mempool, count int, peerID uint16) types.
func TestReapMaxBytesMaxGas(t *testing.T) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(t, err)
defer cleanup()
// Ensure gas calculation behaves as expected
@ -144,7 +151,8 @@ func TestReapMaxBytesMaxGas(t *testing.T) {
func TestMempoolFilters(t *testing.T) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(t, err)
defer cleanup()
emptyTxArr := []types.Tx{[]byte{}}
@ -183,7 +191,8 @@ func TestMempoolFilters(t *testing.T) {
func TestMempoolUpdate(t *testing.T) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(t, err)
defer cleanup()
// 1. Adds valid txs to the cache
@ -230,7 +239,8 @@ func TestMempoolUpdateDoesNotPanicWhenApplicationMissedTx(t *testing.T) {
return mockClient, nil
}
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(t, err)
defer cleanup()
// Add 4 transactions to the mempool by calling the mempool's `CheckTx` on each of them.
@ -249,7 +259,7 @@ func TestMempoolUpdateDoesNotPanicWhenApplicationMissedTx(t *testing.T) {
// Calling update to remove the first transaction from the mempool.
// This call also triggers the mempool to recheck its remaining transactions.
err := mp.Update(0, []types.Tx{txs[0]}, abciResponses(1, abci.CodeTypeOK), nil, nil)
err = mp.Update(0, []types.Tx{txs[0]}, abciResponses(1, abci.CodeTypeOK), nil, nil)
require.Nil(t, err)
// The mempool has now sent its requests off to the client to be rechecked
@ -318,7 +328,8 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) {
func TestTxsAvailable(t *testing.T) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(t, err)
defer cleanup()
mp.EnableTxsAvailable()
@ -363,12 +374,13 @@ func TestSerialReap(t *testing.T) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mp, cleanup := newMempoolWithApp(cc)
mp, cleanup, err := newMempoolWithApp(cc)
require.NoError(t, err)
defer cleanup()
appConnCon, _ := cc()
appConnCon.SetLogger(log.TestingLogger().With("module", "abci-client", "connection", "consensus"))
err := appConnCon.Start()
err = appConnCon.Start()
require.Nil(t, err)
cacheMap := make(map[string]struct{})
@ -473,7 +485,8 @@ func TestSerialReap(t *testing.T) {
func TestMempool_CheckTxChecksTxSize(t *testing.T) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
mempl, cleanup := newMempoolWithApp(cc)
mempl, cleanup, err := newMempoolWithApp(cc)
require.NoError(t, err)
defer cleanup()
maxTxSize := mempl.config.MaxTxBytes
@ -518,7 +531,9 @@ func TestMempool_CheckTxChecksTxSize(t *testing.T) {
func TestMempoolTxsBytes(t *testing.T) {
app := kvstore.NewApplication()
cc := abciclient.NewLocalCreator(app)
cfg := config.ResetTestRoot("mempool_test")
cfg, err := config.ResetTestRoot("mempool_test")
require.NoError(t, err)
cfg.Mempool.MaxTxsBytes = 10
mp, cleanup := newMempoolWithAppAndConfig(cc, cfg)
defer cleanup()
@ -527,7 +542,7 @@ func TestMempoolTxsBytes(t *testing.T) {
assert.EqualValues(t, 0, mp.SizeBytes())
// 2. len(tx) after CheckTx
err := mp.CheckTx(context.Background(), []byte{0x01}, nil, mempool.TxInfo{})
err = mp.CheckTx(context.Background(), []byte{0x01}, nil, mempool.TxInfo{})
require.NoError(t, err)
assert.EqualValues(t, 1, mp.SizeBytes())
@ -561,7 +576,8 @@ func TestMempoolTxsBytes(t *testing.T) {
// 6. zero after tx is rechecked and removed due to not being valid anymore
app2 := kvstore.NewApplication()
cc = abciclient.NewLocalCreator(app2)
mp, cleanup = newMempoolWithApp(cc)
mp, cleanup, err = newMempoolWithApp(cc)
require.NoError(t, err)
defer cleanup()
txBytes := make([]byte, 8)
@ -617,7 +633,9 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) {
t.Error(err)
}
})
cfg := config.ResetTestRoot("mempool_test")
cfg, err := config.ResetTestRoot("mempool_test")
require.NoError(t, err)
mp, cleanup := newMempoolWithAppAndConfig(cc, cfg)
defer cleanup()
@ -640,7 +658,7 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) {
// this will err with ErrTxInCache many times ...
mp.CheckTx(context.Background(), tx, nil, mempool.TxInfo{SenderID: uint16(peerID)}) //nolint: errcheck // will error
}
err := mp.FlushAppConn()
err = mp.FlushAppConn()
require.NoError(t, err)
}


+ 2
- 1
internal/mempool/v0/reactor_test.go View File

@ -58,7 +58,8 @@ func setup(t *testing.T, config *config.MempoolConfig, numNodes int, chBuf uint)
rts.kvstores[nodeID] = kvstore.NewApplication()
cc := abciclient.NewLocalCreator(rts.kvstores[nodeID])
mempool, memCleanup := newMempoolWithApp(cc)
mempool, memCleanup, err := newMempoolWithApp(cc)
require.NoError(t, err)
t.Cleanup(memCleanup)
mempool.SetLogger(rts.logger)
rts.mempools[nodeID] = mempool


+ 2
- 1
internal/mempool/v1/mempool_test.go View File

@ -79,7 +79,8 @@ func setup(t testing.TB, cacheSize int, options ...TxMempoolOption) *TxMempool {
app := &application{kvstore.NewApplication()}
cc := abciclient.NewLocalCreator(app)
cfg := config.ResetTestRoot(strings.ReplaceAll(t.Name(), "/", "|"))
cfg, err := config.ResetTestRoot(strings.ReplaceAll(t.Name(), "/", "|"))
require.NoError(t, err)
cfg.Mempool.CacheSize = cacheSize
appConnMem, err := cc()


+ 3
- 4
internal/mempool/v1/reactor_test.go View File

@ -34,10 +34,9 @@ type reactorTestSuite struct {
func setupReactors(t *testing.T, numNodes int, chBuf uint) *reactorTestSuite {
t.Helper()
cfg := config.ResetTestRoot(strings.ReplaceAll(t.Name(), "/", "|"))
t.Cleanup(func() {
os.RemoveAll(cfg.RootDir)
})
cfg, err := config.ResetTestRoot(strings.ReplaceAll(t.Name(), "/", "|"))
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(cfg.RootDir) })
rts := &reactorTestSuite{
logger: log.TestingLogger().With("testCase", t.Name()),


+ 3
- 1
internal/state/state_test.go View File

@ -26,7 +26,9 @@ import (
// setupTestCase does setup common to all test cases.
func setupTestCase(t *testing.T) (func(t *testing.T), dbm.DB, sm.State) {
cfg := config.ResetTestRoot("state_")
cfg, err := config.ResetTestRoot("state_")
require.NoError(t, err)
dbType := dbm.BackendType(cfg.DBBackend)
stateDB, err := dbm.NewDB("state", dbType, cfg.DBDir())
require.NoError(t, err)


+ 3
- 1
internal/state/store_test.go View File

@ -101,7 +101,9 @@ func TestStoreLoadValidators(t *testing.T) {
func BenchmarkLoadValidators(b *testing.B) {
const valSetSize = 100
cfg := config.ResetTestRoot("state_")
cfg, err := config.ResetTestRoot("state_")
require.NoError(b, err)
defer os.RemoveAll(cfg.RootDir)
dbType := dbm.BackendType(cfg.DBBackend)
stateDB, err := dbm.NewDB("state", dbType, cfg.DBDir())


+ 11
- 3
internal/store/store_test.go View File

@ -46,7 +46,11 @@ func makeTestCommit(height int64, timestamp time.Time) *types.Commit {
}
func makeStateAndBlockStore(logger log.Logger) (sm.State, *BlockStore, cleanupFunc) {
cfg := config.ResetTestRoot("blockchain_reactor_test")
cfg, err := config.ResetTestRoot("blockchain_reactor_test")
if err != nil {
panic(err)
}
blockDB := dbm.NewMemDB()
state, err := sm.MakeGenesisStateFromFile(cfg.GenesisFile())
if err != nil {
@ -292,7 +296,9 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
}
func TestLoadBaseMeta(t *testing.T) {
cfg := config.ResetTestRoot("blockchain_reactor_test")
cfg, err := config.ResetTestRoot("blockchain_reactor_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
state, err := sm.MakeGenesisStateFromFile(cfg.GenesisFile())
require.NoError(t, err)
@ -348,7 +354,9 @@ func TestLoadBlockPart(t *testing.T) {
}
func TestPruneBlocks(t *testing.T) {
cfg := config.ResetTestRoot("blockchain_reactor_test")
cfg, err := config.ResetTestRoot("blockchain_reactor_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
state, err := sm.MakeGenesisStateFromFile(cfg.GenesisFile())
require.NoError(t, err)


+ 5
- 1
light/example_test.go View File

@ -22,7 +22,11 @@ import (
func ExampleClient() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf := rpctest.CreateConfig("ExampleClient_VerifyLightBlockAtHeight")
conf, err := rpctest.CreateConfig("ExampleClient_VerifyLightBlockAtHeight")
if err != nil {
stdlog.Fatal(err)
}
logger := log.TestingLogger()
// Start a test application


+ 4
- 2
light/light_test.go View File

@ -29,7 +29,8 @@ func TestClientIntegration_Update(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf := rpctest.CreateConfig(t.Name())
conf, err := rpctest.CreateConfig(t.Name())
require.NoError(t, err)
// Start a test application
app := kvstore.NewApplication()
@ -89,7 +90,8 @@ func TestClientIntegration_VerifyLightBlockAtHeight(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf := rpctest.CreateConfig(t.Name())
conf, err := rpctest.CreateConfig(t.Name())
require.NoError(t, err)
// Start a test application
app := kvstore.NewApplication()


+ 2
- 1
light/provider/http/http_test.go View File

@ -35,7 +35,8 @@ func TestNewProvider(t *testing.T) {
func TestProvider(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := rpctest.CreateConfig(t.Name())
cfg, err := rpctest.CreateConfig(t.Name())
require.NoError(t, err)
// start a tendermint node in the background to test against
app := kvstore.NewApplication()


+ 30
- 15
node/node_test.go View File

@ -38,7 +38,8 @@ import (
)
func TestNodeStartStop(t *testing.T) {
cfg := config.ResetTestRoot("node_node_test")
cfg, err := config.ResetTestRoot("node_node_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
@ -110,7 +111,9 @@ func getTestNode(t *testing.T, conf *config.Config, logger log.Logger) *nodeImpl
}
func TestNodeDelayedStart(t *testing.T) {
cfg := config.ResetTestRoot("node_delayed_start_test")
cfg, err := config.ResetTestRoot("node_delayed_start_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
now := tmtime.Now()
@ -125,7 +128,8 @@ func TestNodeDelayedStart(t *testing.T) {
}
func TestNodeSetAppVersion(t *testing.T) {
cfg := config.ResetTestRoot("node_app_version_test")
cfg, err := config.ResetTestRoot("node_app_version_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
// create node
@ -146,7 +150,8 @@ func TestNodeSetAppVersion(t *testing.T) {
func TestNodeSetPrivValTCP(t *testing.T) {
addr := "tcp://" + testFreeAddr(t)
cfg := config.ResetTestRoot("node_priv_val_tcp_test")
cfg, err := config.ResetTestRoot("node_priv_val_tcp_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
cfg.PrivValidator.ListenAddr = addr
@ -179,7 +184,8 @@ func TestNodeSetPrivValTCP(t *testing.T) {
func TestPrivValidatorListenAddrNoProtocol(t *testing.T) {
addrNoPrefix := testFreeAddr(t)
cfg := config.ResetTestRoot("node_priv_val_tcp_test")
cfg, err := config.ResetTestRoot("node_priv_val_tcp_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
cfg.PrivValidator.ListenAddr = addrNoPrefix
@ -196,7 +202,8 @@ func TestNodeSetPrivValIPC(t *testing.T) {
tmpfile := "/tmp/kms." + tmrand.Str(6) + ".sock"
defer os.Remove(tmpfile) // clean up
cfg := config.ResetTestRoot("node_priv_val_tcp_test")
cfg, err := config.ResetTestRoot("node_priv_val_tcp_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
cfg.PrivValidator.ListenAddr = "unix://" + tmpfile
@ -237,11 +244,12 @@ func TestCreateProposalBlock(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := config.ResetTestRoot("node_create_proposal")
cfg, err := config.ResetTestRoot("node_create_proposal")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
cc := abciclient.NewLocalCreator(kvstore.NewApplication())
proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics())
err := proxyApp.Start()
err = proxyApp.Start()
require.Nil(t, err)
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
@ -332,11 +340,13 @@ func TestMaxTxsProposalBlockSize(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := config.ResetTestRoot("node_create_proposal")
cfg, err := config.ResetTestRoot("node_create_proposal")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
cc := abciclient.NewLocalCreator(kvstore.NewApplication())
proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics())
err := proxyApp.Start()
err = proxyApp.Start()
require.Nil(t, err)
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
@ -397,11 +407,12 @@ func TestMaxProposalBlockSize(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := config.ResetTestRoot("node_create_proposal")
cfg, err := config.ResetTestRoot("node_create_proposal")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
cc := abciclient.NewLocalCreator(kvstore.NewApplication())
proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics())
err := proxyApp.Start()
err = proxyApp.Start()
require.Nil(t, err)
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
@ -512,7 +523,8 @@ func TestMaxProposalBlockSize(t *testing.T) {
}
func TestNodeNewSeedNode(t *testing.T) {
cfg := config.ResetTestRoot("node_new_node_custom_reactors_test")
cfg, err := config.ResetTestRoot("node_new_node_custom_reactors_test")
require.NoError(t, err)
cfg.Mode = config.ModeSeed
defer os.RemoveAll(cfg.RootDir)
@ -539,7 +551,9 @@ func TestNodeNewSeedNode(t *testing.T) {
}
func TestNodeSetEventSink(t *testing.T) {
cfg := config.ResetTestRoot("node_app_version_test")
cfg, err := config.ResetTestRoot("node_app_version_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
logger := log.TestingLogger()
@ -701,7 +715,8 @@ func loadStatefromGenesis(t *testing.T) sm.State {
stateDB := dbm.NewMemDB()
stateStore := sm.NewStore(stateDB)
cfg := config.ResetTestRoot("load_state_from_genesis")
cfg, err := config.ResetTestRoot("load_state_from_genesis")
require.NoError(t, err)
loadedState, err := stateStore.Load()
require.NoError(t, err)


+ 4
- 2
rpc/client/examples_test.go View File

@ -22,7 +22,8 @@ func TestHTTPSimple(t *testing.T) {
// Start a tendermint node (and kvstore) in the background to test against
app := kvstore.NewApplication()
conf := rpctest.CreateConfig("ExampleHTTP_simple")
conf, err := rpctest.CreateConfig("ExampleHTTP_simple")
require.NoError(t, err)
_, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout)
if err != nil {
@ -71,7 +72,8 @@ func TestHTTPBatching(t *testing.T) {
// Start a tendermint node (and kvstore) in the background to test against
app := kvstore.NewApplication()
conf := rpctest.CreateConfig("ExampleHTTP_batching")
conf, err := rpctest.CreateConfig("ExampleHTTP_batching")
require.NoError(t, err)
_, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout)
if err != nil {


+ 2
- 1
rpc/client/main_test.go View File

@ -20,7 +20,8 @@ func NodeSuite(t *testing.T) (service.Service, *config.Config) {
ctx, cancel := context.WithCancel(context.Background())
conf := rpctest.CreateConfig(t.Name())
conf, err := rpctest.CreateConfig(t.Name())
require.NoError(t, err)
// start a tendermint node in the background to test against
dir, err := ioutil.TempDir("/tmp", fmt.Sprint("rpc-client-test-", t.Name()))


+ 6
- 3
rpc/test/helpers.go View File

@ -57,15 +57,18 @@ func makeAddrs() (p2pAddr, rpcAddr string) {
return fmt.Sprintf(addrTemplate, randPort()), fmt.Sprintf(addrTemplate, randPort())
}
func CreateConfig(testName string) *config.Config {
c := config.ResetTestRoot(testName)
func CreateConfig(testName string) (*config.Config, error) {
c, err := config.ResetTestRoot(testName)
if err != nil {
return nil, err
}
p2pAddr, rpcAddr := makeAddrs()
c.P2P.ListenAddress = p2pAddr
c.RPC.ListenAddress = rpcAddr
c.Consensus.WalPath = "rpc-test"
c.RPC.CORSAllowedOrigins = []string{"https://tendermint.com/"}
return c
return c, nil
}
type ServiceCloser func(context.Context) error


+ 3
- 1
test/e2e/runner/setup.go View File

@ -84,7 +84,9 @@ func Setup(testnet *e2e.Testnet) error {
if err != nil {
return err
}
config.WriteConfigFile(nodeDir, cfg) // panics
if err := config.WriteConfigFile(nodeDir, cfg); err != nil {
return err
}
appCfg, err := MakeAppConfig(node)
if err != nil {


Loading…
Cancel
Save