mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-15 19:56:11 +00:00
config: backport file writing changes (#7182)
This commit is contained in:
+2
-2
@@ -13,12 +13,12 @@ linters:
|
||||
# - gochecknoinits
|
||||
# - gocognit
|
||||
- goconst
|
||||
- gocritic
|
||||
# - gocritic
|
||||
# - gocyclo
|
||||
# - godox
|
||||
- gofmt
|
||||
- goimports
|
||||
- golint
|
||||
# - golint
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
|
||||
@@ -165,7 +165,7 @@ func TestValUpdates(t *testing.T) {
|
||||
|
||||
makeApplyBlock(t, kvstore, 2, diff, tx1, tx2, tx3)
|
||||
|
||||
vals1 = append(vals[:nInit-2], vals[nInit+1]) // nolint: gocritic
|
||||
vals1 = append(vals[:nInit-2], vals[nInit+1])
|
||||
vals2 = kvstore.Validators()
|
||||
valsEqual(t, vals1, vals2)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -240,7 +240,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)
|
||||
|
||||
+40
-24
@@ -45,23 +45,29 @@ 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) {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
if err := configTemplate.Execute(&buffer, config); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
configFilePath := filepath.Join(rootDir, defaultConfigFilePath)
|
||||
|
||||
mustWriteFile(configFilePath, buffer.Bytes(), 0644)
|
||||
func WriteConfigFile(rootDir string, config *Config) error {
|
||||
return config.WriteToTemplate(filepath.Join(rootDir, defaultConfigFilePath))
|
||||
}
|
||||
|
||||
func writeDefaultConfigFileIfNone(rootDir string) {
|
||||
// WriteToTemplate writes the config to the exact file specified by
|
||||
// the path, in the default toml template and does not mangle the path
|
||||
// or filename at all.
|
||||
func (cfg *Config) WriteToTemplate(path string) error {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
if err := configTemplate.Execute(&buffer, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return writeFile(path, buffer.Bytes(), 0644)
|
||||
}
|
||||
|
||||
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
|
||||
@@ -570,22 +576,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()
|
||||
@@ -594,26 +600,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
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -365,7 +365,8 @@ func TestReactorHelperMode(t *testing.T) {
|
||||
channelID = byte(0x40)
|
||||
)
|
||||
|
||||
cfg := config.ResetTestRoot("blockchain_reactor_v2_test")
|
||||
cfg, err := config.ResetTestRoot("blockchain_reactor_v2_test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(cfg.RootDir)
|
||||
genDoc, privVals := factory.RandGenesisDoc(cfg, 1, false, 30)
|
||||
|
||||
@@ -455,7 +456,8 @@ func TestReactorHelperMode(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReactorSetSwitchNil(t *testing.T) {
|
||||
cfg := config.ResetTestRoot("blockchain_reactor_v2_test")
|
||||
cfg, err := config.ResetTestRoot("blockchain_reactor_v2_test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(cfg.RootDir)
|
||||
genDoc, privVals := factory.RandGenesisDoc(cfg, 1, false, 30)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -50,20 +50,26 @@ type cleanupFunc func()
|
||||
func configSetup(t *testing.T) *config.Config {
|
||||
t.Helper()
|
||||
|
||||
cfg := ResetConfig("consensus_reactor_test")
|
||||
cfg, err := ResetConfig("consensus_reactor_test")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { os.RemoveAll(cfg.RootDir) })
|
||||
|
||||
consensusReplayConfig := ResetConfig("consensus_replay_test")
|
||||
configStateTest := ResetConfig("consensus_state_test")
|
||||
configMempoolTest := ResetConfig("consensus_mempool_test")
|
||||
configByzantineTest := ResetConfig("consensus_byzantine_test")
|
||||
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) })
|
||||
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(cfg.RootDir)
|
||||
os.RemoveAll(consensusReplayConfig.RootDir)
|
||||
os.RemoveAll(configStateTest.RootDir)
|
||||
os.RemoveAll(configMempoolTest.RootDir)
|
||||
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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -77,7 +77,7 @@ func (m *NewRoundStepMessage) ValidateHeight(initialHeight int64) error {
|
||||
m.LastCommitRound, initialHeight)
|
||||
}
|
||||
if m.Height > initialHeight && m.LastCommitRound < 0 {
|
||||
return fmt.Errorf("LastCommitRound can only be negative for initial height %v", // nolint
|
||||
return fmt.Errorf("LastCommitRound can only be negative for initial height %v",
|
||||
initialHeight)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -332,7 +332,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)
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -1968,7 +1968,6 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID types.NodeID) (bool, error)
|
||||
// If the vote height is off, we'll just ignore it,
|
||||
// But if it's a conflicting sig, add it to the cs.evpool.
|
||||
// If it's otherwise invalid, punish peer.
|
||||
// nolint: gocritic
|
||||
if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok {
|
||||
if cs.privValidatorPubKey == nil {
|
||||
return false, errPubKeyIsNotSet
|
||||
|
||||
@@ -58,7 +58,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)
|
||||
@@ -100,7 +102,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)
|
||||
|
||||
@@ -139,7 +143,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
|
||||
|
||||
@@ -160,7 +165,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
|
||||
@@ -192,7 +198,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]
|
||||
|
||||
@@ -252,7 +259,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]
|
||||
@@ -316,7 +324,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
|
||||
@@ -358,7 +367,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)
|
||||
@@ -378,7 +388,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
|
||||
|
||||
@@ -420,7 +431,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
|
||||
|
||||
@@ -558,7 +570,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 {
|
||||
@@ -610,7 +623,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
|
||||
|
||||
@@ -654,7 +668,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")
|
||||
@@ -709,7 +725,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
|
||||
|
||||
@@ -803,7 +820,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
|
||||
|
||||
@@ -843,7 +861,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")
|
||||
@@ -887,7 +906,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")
|
||||
@@ -931,7 +951,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
|
||||
|
||||
@@ -1054,7 +1075,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
|
||||
|
||||
@@ -1153,7 +1175,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
|
||||
|
||||
@@ -1245,7 +1268,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
|
||||
|
||||
@@ -1309,7 +1333,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
|
||||
|
||||
@@ -1367,7 +1392,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
|
||||
|
||||
@@ -1390,7 +1416,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
|
||||
|
||||
@@ -1428,7 +1455,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
|
||||
|
||||
@@ -1466,7 +1494,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)
|
||||
|
||||
@@ -1495,7 +1524,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)
|
||||
|
||||
@@ -1531,7 +1561,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)
|
||||
|
||||
@@ -1587,7 +1618,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]
|
||||
@@ -1650,7 +1682,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
|
||||
@@ -1793,7 +1826,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
|
||||
@@ -1863,7 +1897,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)
|
||||
peer := p2pmock.NewPeer(nil)
|
||||
|
||||
// 1) new block part
|
||||
@@ -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
|
||||
peer := p2pmock.NewPeer(nil)
|
||||
|
||||
@@ -1942,7 +1978,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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -154,7 +154,8 @@ func makeAddrs() (string, string, 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)
|
||||
|
||||
// and we use random ports to run in parallel
|
||||
tm, rpc, grpc := makeAddrs()
|
||||
|
||||
@@ -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) }()
|
||||
|
||||
@@ -71,7 +71,7 @@ func iotest(writer protoio.WriteCloser, reader protoio.ReadCloser) error {
|
||||
return err
|
||||
}
|
||||
if n != len(bz)+visize {
|
||||
return fmt.Errorf("WriteMsg() wrote %v bytes, expected %v", n, len(bz)+visize) // nolint
|
||||
return fmt.Errorf("WriteMsg() wrote %v bytes, expected %v", n, len(bz)+visize)
|
||||
}
|
||||
lens[i] = n
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -347,7 +358,7 @@ func TestTxsAvailable(t *testing.T) {
|
||||
ensureNoFire(t, mp.TxsAvailable(), timeoutMS)
|
||||
|
||||
// now call update with all the txs. it should not fire as there are no txs left
|
||||
committedTxs = append(txs, moreTxs...) //nolint: gocritic
|
||||
committedTxs = append(txs, moreTxs...)
|
||||
if err := mp.Update(2, committedTxs, abciResponses(len(committedTxs), abci.CodeTypeOK), nil, nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -36,10 +36,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()),
|
||||
|
||||
@@ -195,7 +195,8 @@ func TestSecretConnectionReadWrite(t *testing.T) {
|
||||
compareWritesReads := func(writes []string, reads []string) {
|
||||
for {
|
||||
// Pop next write & corresponding reads
|
||||
var read, write string = "", writes[0]
|
||||
var read string
|
||||
var write = writes[0]
|
||||
var readCount = 0
|
||||
for _, readChunk := range reads {
|
||||
read += readChunk
|
||||
|
||||
@@ -180,7 +180,8 @@ func (o *PeerManagerOptions) Validate() error {
|
||||
|
||||
if o.MaxPeers > 0 {
|
||||
if o.MaxConnected == 0 || o.MaxConnected+o.MaxConnectedUpgrade > o.MaxPeers {
|
||||
return fmt.Errorf("MaxConnected %v and MaxConnectedUpgrade %v can't exceed MaxPeers %v", // nolint
|
||||
return fmt.Errorf(
|
||||
"MaxConnected %v and MaxConnectedUpgrade %v can't exceed MaxPeers %v",
|
||||
o.MaxConnected, o.MaxConnectedUpgrade, o.MaxPeers)
|
||||
}
|
||||
}
|
||||
@@ -190,7 +191,7 @@ func (o *PeerManagerOptions) Validate() error {
|
||||
return errors.New("can't set MaxRetryTime without MinRetryTime")
|
||||
}
|
||||
if o.MinRetryTime > o.MaxRetryTime {
|
||||
return fmt.Errorf("MinRetryTime %v is greater than MaxRetryTime %v", // nolint
|
||||
return fmt.Errorf("MinRetryTime %v is greater than MaxRetryTime %v",
|
||||
o.MinRetryTime, o.MaxRetryTime)
|
||||
}
|
||||
}
|
||||
@@ -200,7 +201,8 @@ func (o *PeerManagerOptions) Validate() error {
|
||||
return errors.New("can't set MaxRetryTimePersistent without MinRetryTime")
|
||||
}
|
||||
if o.MinRetryTime > o.MaxRetryTimePersistent {
|
||||
return fmt.Errorf("MinRetryTime %v is greater than MaxRetryTimePersistent %v", // nolint
|
||||
return fmt.Errorf(
|
||||
"MinRetryTime %v is greater than MaxRetryTimePersistent %v",
|
||||
o.MinRetryTime, o.MaxRetryTimePersistent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -61,7 +61,6 @@ func (c CustomValue) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (c CustomValue) UnmarshalJSON(bz []byte) error {
|
||||
c.Value = "custom"
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -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
@@ -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()
|
||||
|
||||
@@ -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
-16
@@ -37,7 +37,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)
|
||||
|
||||
@@ -91,7 +92,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()
|
||||
|
||||
@@ -107,7 +110,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
|
||||
@@ -128,7 +132,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
|
||||
|
||||
@@ -161,11 +166,12 @@ 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
|
||||
|
||||
_, err := newDefaultNode(cfg, log.TestingLogger())
|
||||
_, err = newDefaultNode(cfg, log.TestingLogger())
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
@@ -173,7 +179,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
|
||||
|
||||
@@ -211,11 +218,12 @@ 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) {
|
||||
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)
|
||||
err := proxyApp.Start()
|
||||
err = proxyApp.Start()
|
||||
require.Nil(t, err)
|
||||
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
|
||||
|
||||
@@ -303,11 +311,12 @@ func TestCreateProposalBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxTxsProposalBlockSize(t *testing.T) {
|
||||
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)
|
||||
err := proxyApp.Start()
|
||||
err = proxyApp.Start()
|
||||
require.Nil(t, err)
|
||||
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
|
||||
|
||||
@@ -365,11 +374,12 @@ func TestMaxTxsProposalBlockSize(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxProposalBlockSize(t *testing.T) {
|
||||
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)
|
||||
err := proxyApp.Start()
|
||||
err = proxyApp.Start()
|
||||
require.Nil(t, err)
|
||||
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
|
||||
|
||||
@@ -480,7 +490,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)
|
||||
|
||||
@@ -504,7 +515,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()
|
||||
@@ -647,7 +660,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)
|
||||
|
||||
@@ -18,11 +18,14 @@ func ExampleHTTP_simple() {
|
||||
|
||||
// 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")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout)
|
||||
if err != nil {
|
||||
log.Fatal(err) //nolint:gocritic
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer func() { _ = closer(ctx) }()
|
||||
|
||||
@@ -79,11 +82,14 @@ func ExampleHTTP_batching() {
|
||||
|
||||
// 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")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout)
|
||||
if err != nil {
|
||||
log.Fatal(err) //nolint:gocritic
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer func() { _ = closer(ctx) }()
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ func WaitForOneEvent(c EventsClient, eventValue string, timeout time.Duration) (
|
||||
|
||||
select {
|
||||
case event := <-eventCh:
|
||||
return event.Data.(types.TMEventData), nil
|
||||
return event.Data, nil
|
||||
case <-ctx.Done():
|
||||
return nil, errors.New("timed out waiting for event")
|
||||
}
|
||||
|
||||
@@ -19,7 +19,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()))
|
||||
|
||||
@@ -18,7 +18,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
|
||||
app := kvstore.NewApplication()
|
||||
|
||||
+6
-3
@@ -66,8 +66,11 @@ func makeAddrs() (string, string, string) {
|
||||
fmt.Sprintf("tcp://127.0.0.1:%d", 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
|
||||
}
|
||||
|
||||
// and we use random ports to run in parallel
|
||||
tm, rpc, grpc := makeAddrs()
|
||||
@@ -75,7 +78,7 @@ func CreateConfig(testName string) *config.Config {
|
||||
c.RPC.ListenAddress = rpc
|
||||
c.RPC.CORSAllowedOrigins = []string{"https://tendermint.com/"}
|
||||
c.RPC.GRPCListenAddress = grpc
|
||||
return c
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func GetGRPCClient(conf *config.Config) coregrpc.BroadcastAPIClient {
|
||||
|
||||
@@ -55,7 +55,7 @@ func main() {
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Failed to write message", err)
|
||||
os.Exit(1) //nolint:gocritic
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestNodeInfoValidate(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
"Too Many Channels",
|
||||
func(ni *NodeInfo) { ni.Channels = append(channels, byte(maxNumChannels)) }, // nolint: gocritic
|
||||
func(ni *NodeInfo) { ni.Channels = append(channels, byte(maxNumChannels)) },
|
||||
true,
|
||||
},
|
||||
{"Duplicate Channel", func(ni *NodeInfo) { ni.Channels = dupChannels }, true},
|
||||
|
||||
@@ -500,7 +500,9 @@ func TestAveragingInIncrementProposerPriority(t *testing.T) {
|
||||
{Address: []byte("a"), ProposerPriority: 1},
|
||||
{Address: []byte("b"), ProposerPriority: 2},
|
||||
{Address: []byte("c"), ProposerPriority: 3}}},
|
||||
1, 2},
|
||||
1,
|
||||
2,
|
||||
},
|
||||
1: {ValidatorSet{
|
||||
Validators: []*Validator{
|
||||
{Address: []byte("a"), ProposerPriority: 10},
|
||||
@@ -508,13 +510,17 @@ func TestAveragingInIncrementProposerPriority(t *testing.T) {
|
||||
{Address: []byte("c"), ProposerPriority: 1}}},
|
||||
// this should average twice but the average should be 0 after the first iteration
|
||||
// (voting power is 0 -> no changes)
|
||||
11, 1 / 3},
|
||||
11,
|
||||
0, // 1 / 3,
|
||||
},
|
||||
2: {ValidatorSet{
|
||||
Validators: []*Validator{
|
||||
{Address: []byte("a"), ProposerPriority: 100},
|
||||
{Address: []byte("b"), ProposerPriority: -10},
|
||||
{Address: []byte("c"), ProposerPriority: 1}}},
|
||||
1, 91 / 3},
|
||||
1,
|
||||
91 / 3,
|
||||
},
|
||||
}
|
||||
for i, tc := range tcs {
|
||||
// work on copy to have the old ProposerPriorities:
|
||||
|
||||
Reference in New Issue
Block a user