From 687b3eda31cfcc5c3f8d12973253fceca5008d89 Mon Sep 17 00:00:00 2001 From: Sergio Mena Date: Wed, 30 Nov 2022 00:22:26 +0100 Subject: [PATCH] Fix all unit tests --- state/execution_test.go | 2 +- types/block_test.go | 10 ++++------ types/vote_set_test.go | 10 +++------- types/vote_test.go | 5 +---- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/state/execution_test.go b/state/execution_test.go index f87ce60c8..46207ea2b 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -139,7 +139,7 @@ func TestFinalizeBlockDecidedLastCommit(t *testing.T) { } // block for height 2 - block := makeBlock(state, 2, lastCommit.StripExtensions()) + block := makeBlock(state, 2, lastCommit.ToCommit()) bps, err := block.MakePartSet(testPartSize) require.NoError(t, err) blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} diff --git a/types/block_test.go b/types/block_test.go index dee6d639d..b72ea083d 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -3,7 +3,7 @@ package types import ( // it is ok to use math/rand here: we do not need a cryptographically secure random // number generator here and we can run the tests a bit faster - "context" + "crypto/rand" "encoding/hex" "math" @@ -537,10 +537,8 @@ func TestVoteSetToExtendedCommit(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { blockID := makeBlockIDRandom() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - valSet, vals := randValidatorPrivValSet(ctx, t, 10, 1) + valSet, vals := RandValidatorSet(10, 1) var voteSet *VoteSet if testCase.includeExtension { voteSet = NewExtendedVoteSet("test_chain_id", 3, 1, tmproto.PrecommitType, valSet) @@ -548,7 +546,7 @@ func TestVoteSetToExtendedCommit(t *testing.T) { voteSet = NewVoteSet("test_chain_id", 3, 1, tmproto.PrecommitType, valSet) } for i := 0; i < len(vals); i++ { - pubKey, err := vals[i].GetPubKey(ctx) + pubKey, err := vals[i].GetPubKey() require.NoError(t, err) vote := &Vote{ ValidatorAddress: pubKey.Address(), @@ -560,7 +558,7 @@ func TestVoteSetToExtendedCommit(t *testing.T) { Timestamp: time.Now(), } v := vote.ToProto() - err = vals[i].SignVote(ctx, voteSet.ChainID(), v) + err = vals[i].SignVote(voteSet.ChainID(), v) require.NoError(t, err) vote.Signature = v.Signature if testCase.includeExtension { diff --git a/types/vote_set_test.go b/types/vote_set_test.go index 45a82ae49..d6862883d 100644 --- a/types/vote_set_test.go +++ b/types/vote_set_test.go @@ -2,7 +2,6 @@ package types import ( "bytes" - "context" "testing" "github.com/stretchr/testify/assert" @@ -511,11 +510,8 @@ func TestVoteSet_VoteExtensionsEnabled(t *testing.T) { }, } { t.Run(tc.name, func(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - height, round := int64(1), int32(0) - valSet, privValidators := randValidatorPrivValSet(ctx, t, 5, 10) + valSet, privValidators := RandValidatorSet(5, 10) var voteSet *VoteSet if tc.requireExtensions { voteSet = NewExtendedVoteSet("test_chain_id", height, round, tmproto.PrecommitType, valSet) @@ -525,7 +521,7 @@ func TestVoteSet_VoteExtensionsEnabled(t *testing.T) { val0 := privValidators[0] - val0p, err := val0.GetPubKey(ctx) + val0p, err := val0.GetPubKey() require.NoError(t, err) val0Addr := val0p.Address() blockHash := crypto.CRandBytes(32) @@ -542,7 +538,7 @@ func TestVoteSet_VoteExtensionsEnabled(t *testing.T) { BlockID: BlockID{blockHash, blockPartSetHeader}, } v := vote.ToProto() - err = val0.SignVote(ctx, voteSet.ChainID(), v) + err = val0.SignVote(voteSet.ChainID(), v) require.NoError(t, err) vote.Signature = v.Signature diff --git a/types/vote_test.go b/types/vote_test.go index af3c86f1d..b28ffa955 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -240,9 +240,6 @@ func TestVoteExtension(t *testing.T) { privVal := NewMockPV() pk, err := privVal.GetPubKey() require.NoError(t, err) - blk := Block{} - ps, err := blk.MakePartSet(BlockPartSizeBytes) - require.NoError(t, err) vote := &Vote{ ValidatorAddress: pk.Address(), ValidatorIndex: 0, @@ -250,7 +247,7 @@ func TestVoteExtension(t *testing.T) { Round: round, Timestamp: tmtime.Now(), Type: tmproto.PrecommitType, - BlockID: BlockID{blk.Hash(), ps.Header()}, + BlockID: makeBlockIDRandom(), } v := vote.ToProto()