From 73aa070f65fe657bd2555a48083fbd5da701f6dd Mon Sep 17 00:00:00 2001 From: Sergio Mena Date: Tue, 29 Nov 2022 21:41:35 +0100 Subject: [PATCH] fixed_more_UTs --- consensus/byzantine_test.go | 2 +- consensus/common_test.go | 48 +++++++++++++++++++++++++++++-------- consensus/mempool_test.go | 10 ++++---- consensus/reactor_test.go | 2 +- consensus/state_test.go | 16 +++++-------- test/e2e/tests/app_test.go | 1 - 6 files changed, 51 insertions(+), 28 deletions(-) diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index 52e97bdf7..7dd7e6479 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -46,7 +46,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { tickerFunc := newMockTickerFunc(true) appFunc := newKVStore - genDoc, privVals := randGenesisDoc(nValidators, false, 30) + genDoc, privVals := randGenesisDoc(nValidators, false, 30, nil) css := make([]*State, nValidators) for i := 0; i < nValidators; i++ { diff --git a/consensus/common_test.go b/consensus/common_test.go index ebdc60f9b..bf707b8d2 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -463,9 +463,27 @@ func randState(nValidators int) (*State, []*validatorStub) { return randStateWithApp(nValidators, kvstore.NewInMemoryApplication()) } +func randStateWithAppWithHeight( + nValidators int, + app abci.Application, + height int64, +) (*State, []*validatorStub) { + c := test.ConsensusParams() + c.ABCI.VoteExtensionsEnableHeight = height + return randStateWithAppImpl(nValidators, app, c) +} func randStateWithApp(nValidators int, app abci.Application) (*State, []*validatorStub) { + c := test.ConsensusParams() + return randStateWithAppImpl(nValidators, app, c) +} + +func randStateWithAppImpl( + nValidators int, + app abci.Application, + consensusParams *types.ConsensusParams, +) (*State, []*validatorStub) { // Get State - state, privVals := randGenesisState(nValidators, false, 10) + state, privVals := randGenesisState(nValidators, false, 10, consensusParams) vss := make([]*validatorStub, nValidators) @@ -751,7 +769,7 @@ func consensusLogger() log.Logger { func randConsensusNet(t *testing.T, nValidators int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application, configOpts ...func(*cfg.Config)) ([]*State, cleanupFunc) { t.Helper() - genDoc, privVals := randGenesisDoc(nValidators, false, 30) + genDoc, privVals := randGenesisDoc(nValidators, false, 30, nil) css := make([]*State, nValidators) logger := consensusLogger() configRootDirs := make([]string, 0, nValidators) @@ -792,7 +810,7 @@ func randConsensusNetWithPeers( tickerFunc func() TimeoutTicker, appFunc func(string) abci.Application, ) ([]*State, *types.GenesisDoc, *cfg.Config, cleanupFunc) { - genDoc, privVals := randGenesisDoc(nValidators, false, testMinPower) + genDoc, privVals := randGenesisDoc(nValidators, false, testMinPower, nil) css := make([]*State, nPeers) logger := consensusLogger() var peer0Config *cfg.Config @@ -858,7 +876,11 @@ func getSwitchIndex(switches []*p2p.Switch, peer p2p.Peer) int { //------------------------------------------------------------------------------- // genesis -func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.GenesisDoc, []types.PrivValidator) { +func randGenesisDoc(numValidators int, + randPower bool, + minPower int64, + consensusParams *types.ConsensusParams, +) (*types.GenesisDoc, []types.PrivValidator) { validators := make([]types.GenesisValidator, numValidators) privValidators := make([]types.PrivValidator, numValidators) for i := 0; i < numValidators; i++ { @@ -872,15 +894,21 @@ func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.G sort.Sort(types.PrivValidatorsByAddress(privValidators)) return &types.GenesisDoc{ - GenesisTime: tmtime.Now(), - InitialHeight: 1, - ChainID: test.DefaultTestChainID, - Validators: validators, + GenesisTime: tmtime.Now(), + InitialHeight: 1, + ChainID: test.DefaultTestChainID, + Validators: validators, + ConsensusParams: consensusParams, }, privValidators } -func randGenesisState(numValidators int, randPower bool, minPower int64) (sm.State, []types.PrivValidator) { - genDoc, privValidators := randGenesisDoc(numValidators, randPower, minPower) +func randGenesisState( + numValidators int, + randPower bool, + minPower int64, + consensusParams *types.ConsensusParams, +) (sm.State, []types.PrivValidator) { + genDoc, privValidators := randGenesisDoc(numValidators, randPower, minPower, consensusParams) s0, _ := sm.MakeGenesisState(genDoc) return s0, privValidators } diff --git a/consensus/mempool_test.go b/consensus/mempool_test.go index a729e5b2d..c810a4527 100644 --- a/consensus/mempool_test.go +++ b/consensus/mempool_test.go @@ -29,7 +29,7 @@ func TestMempoolNoProgressUntilTxsAvailable(t *testing.T) { config := ResetConfig("consensus_mempool_txs_available_test") defer os.RemoveAll(config.RootDir) config.Consensus.CreateEmptyBlocks = false - state, privVals := randGenesisState(1, false, 10) + state, privVals := randGenesisState(1, false, 10, nil) app := kvstore.NewInMemoryApplication() resp, err := app.Info(context.Background(), proxy.RequestInfo) require.NoError(t, err) @@ -53,7 +53,7 @@ func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) { defer os.RemoveAll(config.RootDir) config.Consensus.CreateEmptyBlocksInterval = ensureTimeout - state, privVals := randGenesisState(1, false, 10) + state, privVals := randGenesisState(1, false, 10, nil) app := kvstore.NewInMemoryApplication() resp, err := app.Info(context.Background(), proxy.RequestInfo) require.NoError(t, err) @@ -74,7 +74,7 @@ func TestMempoolProgressInHigherRound(t *testing.T) { config := ResetConfig("consensus_mempool_txs_available_test") defer os.RemoveAll(config.RootDir) config.Consensus.CreateEmptyBlocks = false - state, privVals := randGenesisState(1, false, 10) + state, privVals := randGenesisState(1, false, 10, nil) cs := newStateWithConfig(config, state, privVals[0], kvstore.NewInMemoryApplication()) assertMempool(cs.txNotifier).EnableTxsAvailable() height, round := cs.Height, cs.Round @@ -116,7 +116,7 @@ func deliverTxsRange(t *testing.T, cs *State, start, end int) { } func TestMempoolTxConcurrentWithCommit(t *testing.T) { - state, privVals := randGenesisState(1, false, 10) + state, privVals := randGenesisState(1, false, 10, nil) blockDB := dbm.NewMemDB() stateStore := sm.NewStore(blockDB, sm.StoreOptions{DiscardABCIResponses: false}) cs := newStateWithConfigAndBlockStore(config, state, privVals[0], kvstore.NewInMemoryApplication(), blockDB) @@ -140,7 +140,7 @@ func TestMempoolTxConcurrentWithCommit(t *testing.T) { } func TestMempoolRmBadTx(t *testing.T) { - state, privVals := randGenesisState(1, false, 10) + state, privVals := randGenesisState(1, false, 10, nil) app := kvstore.NewInMemoryApplication() blockDB := dbm.NewMemDB() stateStore := sm.NewStore(blockDB, sm.StoreOptions{DiscardABCIResponses: false}) diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index 114015b9c..5f1a346eb 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -133,7 +133,7 @@ func TestReactorWithEvidence(t *testing.T) { // to unroll unwieldy abstractions. Here we duplicate the code from: // css := randConsensusNet(N, "consensus_reactor_test", newMockTickerFunc(true), newKVStore) - genDoc, privVals := randGenesisDoc(nValidators, false, 30) + genDoc, privVals := randGenesisDoc(nValidators, false, 30, nil) css := make([]*State, nValidators) logger := consensusLogger() for i := 0; i < nValidators; i++ { diff --git a/consensus/state_test.go b/consensus/state_test.go index 032ca0af0..6a837cbba 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -16,7 +16,6 @@ import ( abcimocks "github.com/tendermint/tendermint/abci/types/mocks" cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/crypto/tmhash" - "github.com/tendermint/tendermint/internal/test" tmbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" tmpubsub "github.com/tendermint/tendermint/libs/pubsub" @@ -1449,11 +1448,11 @@ func TestExtendVoteCalledWhenEnabled(t *testing.T) { } m.On("Commit", mock.Anything, mock.Anything).Return(&abci.ResponseCommit{}, nil).Maybe() m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(&abci.ResponseFinalizeBlock{}, nil).Maybe() - c := test.ConsensusParams() + height := int64(1) if !testCase.enabled { - c.ABCI.VoteExtensionsEnableHeight = 0 + height = 0 } - cs1, vss := randStateWithApp(4, m) + cs1, vss := randStateWithAppWithHeight(4, m, height) height, round := cs1.Height, cs1.Round @@ -1810,12 +1809,9 @@ func TestVoteExtensionEnableHeight(t *testing.T) { Status: abci.ResponseVerifyVoteExtension_ACCEPT, }, nil).Times(numValidators - 1) } - //m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(&abci.ResponseFinalizeBlock{}, nil).Maybe() - m.On("Commit", mock.Anything).Return(&abci.ResponseCommit{}, nil).Maybe() - c := test.ConsensusParams() - c.ABCI.VoteExtensionsEnableHeight = testCase.enableHeight - //consensusParams: c}) - cs1, vss := randStateWithApp(numValidators, m) + m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(&abci.ResponseFinalizeBlock{}, nil).Maybe() + m.On("Commit", mock.Anything, mock.Anything).Return(&abci.ResponseCommit{}, nil).Maybe() + cs1, vss := randStateWithAppWithHeight(numValidators, m, testCase.enableHeight) cs1.state.ConsensusParams.ABCI.VoteExtensionsEnableHeight = testCase.enableHeight height, round := cs1.Height, cs1.Round diff --git a/test/e2e/tests/app_test.go b/test/e2e/tests/app_test.go index 34ab5e14f..7b700da5e 100644 --- a/test/e2e/tests/app_test.go +++ b/test/e2e/tests/app_test.go @@ -107,7 +107,6 @@ func TestApp_Tx(t *testing.T) { func TestApp_VoteExtensions(t *testing.T) { testNode(t, func(t *testing.T, node e2e.Node) { - t.Skip() client, err := node.Client() require.NoError(t, err)