diff --git a/consensus/common_test.go b/consensus/common_test.go index 36d9e08b1..d5bc92c62 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -337,23 +337,6 @@ func validatePrecommit( } } -func validatePrevoteAndPrecommit( - t *testing.T, - cs *State, - thisRound, - lockRound int32, - privVal *validatorStub, - votedBlockHash, - lockedBlockHash []byte, -) { - // verify the prevote - validatePrevote(t, cs, thisRound, privVal, votedBlockHash) - // verify precommit - cs.mtx.Lock() - validatePrecommit(t, cs, thisRound, lockRound, privVal, votedBlockHash, lockedBlockHash) - cs.mtx.Unlock() -} - func subscribeToVoter(cs *State, addr []byte) <-chan tmpubsub.Message { votesSub, err := cs.eventBus.SubscribeUnbuffered(context.Background(), testSubscriber, types.EventQueryVote) if err != nil { @@ -700,6 +683,11 @@ func ensurePrevoteMatch(t *testing.T, voteCh <-chan tmpubsub.Message, height int ensureVoteMatch(t, voteCh, height, round, hash, tmproto.PrevoteType) } +func ensurePrecommitMatch(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32, hash []byte) { + t.Helper() + ensureVoteMatch(t, voteCh, height, round, hash, tmproto.PrecommitType) +} + func ensureVoteMatch(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32, hash []byte, voteType tmproto.SignedMsgType) { t.Helper() select { diff --git a/consensus/state_test.go b/consensus/state_test.go index 4f0c92ba2..969adda68 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -363,7 +363,7 @@ func TestStateFullRound1(t *testing.T) { // nil is proposed, so prevote and precommit nil func TestStateFullRoundNil(t *testing.T) { - cs, vss := randState(1) + cs, _ := randState(1) height, round := cs.Height, cs.Round voteCh := subscribeUnBuffered(cs.eventBus, types.EventQueryVote) @@ -371,11 +371,8 @@ func TestStateFullRoundNil(t *testing.T) { cs.enterPrevote(height, round) cs.startRoutines(4) - ensurePrevote(voteCh, height, round) // prevote - ensurePrecommit(voteCh, height, round) // precommit - - // should prevote and precommit nil - validatePrevoteAndPrecommit(t, cs, round, -1, vss[0], nil, nil) + ensurePrevoteMatch(t, voteCh, height, round, nil) // prevote + ensurePrecommitMatch(t, voteCh, height, round, nil) // precommit } // run through propose, prevote, precommit commit with two validators @@ -1424,32 +1421,30 @@ func TestProcessProposalAccept(t *testing.T) { // TestExtendVoteCalled tests that the vote extension methods are called at the // correct point in the consensus algorithm. func TestExtendVoteCalled(t *testing.T) { - config := configSetup(t) - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - m := abcimocks.NewBaseMock() - m.On("ProcessProposal", mock.Anything).Return(abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}) - m.On("ExtendVote", mock.Anything).Return(abci.ResponseExtendVote{ + m := abcimocks.NewApplication(t) + m.On("PrepareProposal", mock.Anything, mock.Anything).Return(&abci.ResponsePrepareProposal{}, nil) + m.On("ProcessProposal", mock.Anything, mock.Anything).Return(&abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil) + m.On("ExtendVote", mock.Anything, mock.Anything).Return(&abci.ResponseExtendVote{ VoteExtension: []byte("extension"), - }) - m.On("VerifyVoteExtension", mock.Anything).Return(abci.ResponseVerifyVoteExtension{ + }, nil) + m.On("VerifyVoteExtension", mock.Anything, mock.Anything).Return(&abci.ResponseVerifyVoteExtension{ Status: abci.ResponseVerifyVoteExtension_ACCEPT, - }) - m.On("FinalizeBlock", mock.Anything).Return(abci.ResponseFinalizeBlock{}).Maybe() - cs1, vss := makeState(ctx, t, makeStateArgs{config: config, application: m}) + }, nil) + m.On("Commit", mock.Anything, mock.Anything).Return(&abci.ResponseCommit{}, nil).Maybe() + m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(&abci.ResponseFinalizeBlock{}, nil).Maybe() + cs1, vss := randStateWithApp(4, m) height, round := cs1.Height, cs1.Round - proposalCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryCompleteProposal) - newRoundCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryNewRound) - pv1, err := cs1.privValidator.GetPubKey(ctx) + proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal) + newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound) + pv1, err := cs1.privValidator.GetPubKey() require.NoError(t, err) addr := pv1.Address() - voteCh := subscribeToVoter(ctx, t, cs1, addr) + voteCh := subscribeToVoter(cs1, addr) - startTestRound(ctx, cs1, cs1.Height, round) - ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(t, proposalCh, height, round) + startTestRound(cs1, cs1.Height, round) + ensureNewRound(newRoundCh, height, round) + ensureNewProposal(proposalCh, height, round) m.AssertNotCalled(t, "ExtendVote", mock.Anything) @@ -1459,34 +1454,34 @@ func TestExtendVoteCalled(t *testing.T) { Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header(), } - signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vss[1:]...) + signAddVotes(cs1, tmproto.PrevoteType, blockID.Hash, blockID.PartSetHeader, vss[1:]...) ensurePrevoteMatch(t, voteCh, height, round, blockID.Hash) - ensurePrecommit(t, voteCh, height, round) + ensurePrecommit(voteCh, height, round) - m.AssertCalled(t, "ExtendVote", abci.RequestExtendVote{ + m.AssertCalled(t, "ExtendVote", context.TODO(), &abci.RequestExtendVote{ Height: height, Hash: blockID.Hash, }) - m.AssertCalled(t, "VerifyVoteExtension", abci.RequestVerifyVoteExtension{ + m.AssertCalled(t, "VerifyVoteExtension", context.TODO(), &abci.RequestVerifyVoteExtension{ Hash: blockID.Hash, ValidatorAddress: addr, Height: height, VoteExtension: []byte("extension"), }) - signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vss[1:]...) - ensureNewRound(t, newRoundCh, height+1, 0) + signAddVotes(cs1, tmproto.PrecommitType, blockID.Hash, blockID.PartSetHeader, vss[1:]...) + ensureNewRound(newRoundCh, height+1, 0) m.AssertExpectations(t) // Only 3 of the vote extensions are seen, as consensus proceeds as soon as the +2/3 threshold // is observed by the consensus engine. for _, pv := range vss[:3] { - pv, err := pv.GetPubKey(ctx) + pv, err := pv.GetPubKey() require.NoError(t, err) addr := pv.Address() - m.AssertCalled(t, "VerifyVoteExtension", abci.RequestVerifyVoteExtension{ + m.AssertCalled(t, "VerifyVoteExtension", context.TODO(), &abci.RequestVerifyVoteExtension{ Hash: blockID.Hash, ValidatorAddress: addr, Height: height, @@ -1499,66 +1494,64 @@ func TestExtendVoteCalled(t *testing.T) { // TestVerifyVoteExtensionNotCalledOnAbsentPrecommit tests that the VerifyVoteExtension // method is not called for a validator's vote that is never delivered. func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) { - config := configSetup(t) - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - m := abcimocks.NewBaseMock() - m.On("ProcessProposal", mock.Anything).Return(abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}) - m.On("ExtendVote", mock.Anything).Return(abci.ResponseExtendVote{ + m := abcimocks.NewApplication(t) + m.On("PrepareProposal", mock.Anything, mock.Anything).Return(&abci.ResponsePrepareProposal{}, nil) + m.On("ProcessProposal", mock.Anything, mock.Anything).Return(&abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil) + m.On("ExtendVote", mock.Anything, mock.Anything).Return(&abci.ResponseExtendVote{ VoteExtension: []byte("extension"), - }) - m.On("VerifyVoteExtension", mock.Anything).Return(abci.ResponseVerifyVoteExtension{ + }, nil) + m.On("VerifyVoteExtension", mock.Anything, mock.Anything).Return(&abci.ResponseVerifyVoteExtension{ Status: abci.ResponseVerifyVoteExtension_ACCEPT, - }) - m.On("FinalizeBlock", mock.Anything).Return(abci.ResponseFinalizeBlock{}).Maybe() - cs1, vss := makeState(ctx, t, makeStateArgs{config: config, application: m}) + }, nil) + 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 := randStateWithApp(4, m) height, round := cs1.Height, cs1.Round - proposalCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryCompleteProposal) - newRoundCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryNewRound) - pv1, err := cs1.privValidator.GetPubKey(ctx) + proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal) + newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound) + pv1, err := cs1.privValidator.GetPubKey() require.NoError(t, err) addr := pv1.Address() - voteCh := subscribeToVoter(ctx, t, cs1, addr) + voteCh := subscribeToVoter(cs1, addr) - startTestRound(ctx, cs1, cs1.Height, round) - ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(t, proposalCh, height, round) + startTestRound(cs1, cs1.Height, round) + ensureNewRound(newRoundCh, height, round) + ensureNewProposal(proposalCh, height, round) rs := cs1.GetRoundState() blockID := types.BlockID{ Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header(), } - signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vss[2:]...) + signAddVotes(cs1, tmproto.PrevoteType, blockID.Hash, blockID.PartSetHeader, vss[2:]...) ensurePrevoteMatch(t, voteCh, height, round, blockID.Hash) - ensurePrecommit(t, voteCh, height, round) + ensurePrecommit(voteCh, height, round) - m.AssertCalled(t, "ExtendVote", abci.RequestExtendVote{ + m.AssertCalled(t, "ExtendVote", context.TODO(), &abci.RequestExtendVote{ Height: height, Hash: blockID.Hash, }) - m.AssertCalled(t, "VerifyVoteExtension", abci.RequestVerifyVoteExtension{ + m.AssertCalled(t, "VerifyVoteExtension", context.TODO(), &abci.RequestVerifyVoteExtension{ Hash: blockID.Hash, ValidatorAddress: addr, Height: height, VoteExtension: []byte("extension"), }) - signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vss[2:]...) - ensureNewRound(t, newRoundCh, height+1, 0) + signAddVotes(cs1, tmproto.PrecommitType, blockID.Hash, blockID.PartSetHeader, vss[2:]...) + ensureNewRound(newRoundCh, height+1, 0) m.AssertExpectations(t) // vss[1] did not issue a precommit for the block, ensure that a vote extension // for its address was not sent to the application. - pv, err := vss[1].GetPubKey(ctx) + pv, err := vss[1].GetPubKey() require.NoError(t, err) addr = pv.Address() - m.AssertNotCalled(t, "VerifyVoteExtension", abci.RequestVerifyVoteExtension{ + m.AssertNotCalled(t, "VerifyVoteExtension", context.TODO(), &abci.RequestVerifyVoteExtension{ Hash: blockID.Hash, ValidatorAddress: addr, Height: height, @@ -1574,10 +1567,6 @@ func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) { // is the proposer again and ensures that the mock application receives the set of // vote extensions from the previous consensus instance. func TestPrepareProposalReceivesVoteExtensions(t *testing.T) { - config := configSetup(t) - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - // create a list of vote extensions, one for each validator. voteExtensions := [][]byte{ []byte("extension 0"), @@ -1586,39 +1575,50 @@ func TestPrepareProposalReceivesVoteExtensions(t *testing.T) { []byte("extension 3"), } - m := abcimocks.NewBaseMock() - m.On("ExtendVote", mock.Anything).Return(abci.ResponseExtendVote{ + m := abcimocks.NewApplication(t) + m.On("ExtendVote", mock.Anything, mock.Anything).Return(&abci.ResponseExtendVote{ VoteExtension: voteExtensions[0], - }) - m.On("PrepareProposal", mock.Anything).Return(abci.ResponsePrepareProposal{}).Once() + }, nil) + m.On("ProcessProposal", mock.Anything, mock.Anything).Return(&abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil) - cs1, vss := makeState(ctx, t, makeStateArgs{config: config, application: m}) + // capture the prepare proposal request. + rpp := &abci.RequestPrepareProposal{} + m.On("PrepareProposal", mock.Anything, mock.MatchedBy(func(r *abci.RequestPrepareProposal) bool { + rpp = r + return true + })).Return(&abci.ResponsePrepareProposal{}, nil) + + m.On("VerifyVoteExtension", mock.Anything, mock.Anything).Return(&abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil) + m.On("Commit", mock.Anything, mock.Anything).Return(&abci.ResponseCommit{}, nil).Maybe() + m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(&abci.ResponseFinalizeBlock{}, nil) + + cs1, vss := randStateWithApp(4, m) height, round := cs1.Height, cs1.Round - newRoundCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryNewRound) - proposalCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryCompleteProposal) - pv1, err := cs1.privValidator.GetPubKey(ctx) + newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound) + proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal) + pv1, err := cs1.privValidator.GetPubKey() require.NoError(t, err) addr := pv1.Address() - voteCh := subscribeToVoter(ctx, t, cs1, addr) + voteCh := subscribeToVoter(cs1, addr) - startTestRound(ctx, cs1, height, round) - ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(t, proposalCh, height, round) + startTestRound(cs1, height, round) + ensureNewRound(newRoundCh, height, round) + ensureNewProposal(proposalCh, height, round) rs := cs1.GetRoundState() blockID := types.BlockID{ Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header(), } - signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vss[1:]...) + signAddVotes(cs1, tmproto.PrevoteType, blockID.Hash, blockID.PartSetHeader, vss[1:]...) // create a precommit for each validator with the associated vote extension. for i, vs := range vss[1:] { - signAddPrecommitWithExtension(ctx, t, cs1, config.ChainID(), blockID, voteExtensions[i+1], vs) + signAddPrecommitWithExtension(t, cs1, blockID.Hash, blockID.PartSetHeader, voteExtensions[i+1], vs) } - ensurePrevote(t, voteCh, height, round) + ensurePrevote(voteCh, height, round) // ensure that the height is committed. ensurePrecommitMatch(t, voteCh, height, round, blockID.Hash) @@ -1626,25 +1626,20 @@ func TestPrepareProposalReceivesVoteExtensions(t *testing.T) { height++ round = 0 - ensureNewRound(t, newRoundCh, height, round) + ensureNewRound(newRoundCh, height, round) incrementRound(vss[1:]...) incrementRound(vss[1:]...) incrementRound(vss[1:]...) round = 3 - // capture the prepare proposal request. - rpp := abci.RequestPrepareProposal{} - m.On("PrepareProposal", mock.MatchedBy(func(r abci.RequestPrepareProposal) bool { - rpp = r - return true - })).Return(abci.ResponsePrepareProposal{}) - - signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vss[1:]...) - ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(t, proposalCh, height, round) + blockID2 := types.BlockID{} + signAddVotes(cs1, tmproto.PrecommitType, blockID2.Hash, blockID2.PartSetHeader, vss[1:]...) + ensureNewRound(newRoundCh, height, round) + ensureNewProposal(proposalCh, height, round) // ensure that the proposer received the list of vote extensions from the // previous height. + require.Len(t, rpp.LocalLastCommit.Votes, len(vss)) for i := range vss { require.Equal(t, rpp.LocalLastCommit.Votes[i].VoteExtension, voteExtensions[i]) } @@ -1673,6 +1668,10 @@ func TestFinalizeBlockCalled(t *testing.T) { Status: abci.ResponseProcessProposal_ACCEPT, }, nil) m.On("PrepareProposal", mock.Anything, mock.Anything).Return(&abci.ResponsePrepareProposal{}, nil) + m.On("ExtendVote", mock.Anything, mock.Anything).Return(&abci.ResponseExtendVote{}, nil) + m.On("VerifyVoteExtension", mock.Anything, mock.Anything).Return(&abci.ResponseVerifyVoteExtension{ + Status: abci.ResponseVerifyVoteExtension_ACCEPT, + }, nil) r := &abci.ResponseFinalizeBlock{AgreedAppData: []byte("the_hash")} m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(r, nil).Maybe() m.On("Commit", mock.Anything, mock.Anything).Return(&abci.ResponseCommit{}, nil).Maybe() @@ -2320,14 +2319,14 @@ func subscribeUnBuffered(eventBus *types.EventBus, q tmpubsub.Query) <-chan tmpu return sub.Out() } -func signAddPrecommitWithExtension(ctx context.Context, +func signAddPrecommitWithExtension( t *testing.T, cs *State, - chainID string, - blockID types.BlockID, + hash []byte, + header types.PartSetHeader, extension []byte, stub *validatorStub) { - v, err := stub.signVote(ctx, tmproto.PrecommitType, chainID, blockID, extension) + v, err := stub.signVote(tmproto.PrecommitType, hash, header, extension) require.NoError(t, err, "failed to sign vote") addVotes(cs, v) } diff --git a/internal/test/commit.go b/internal/test/commit.go index de346fef1..d94bd1054 100644 --- a/internal/test/commit.go +++ b/internal/test/commit.go @@ -80,11 +80,10 @@ func MakeCommit(blockID types.BlockID, height int64, round int32, valSet *types. } sigs[idx] = types.CommitSig{ - BlockIDFlag: types.BlockIDFlagCommit, - ValidatorAddress: addr, - Timestamp: now, - Signature: v.Signature, - ExtensionSignature: v.ExtensionSignature, + BlockIDFlag: types.BlockIDFlagCommit, + ValidatorAddress: addr, + Timestamp: now, + Signature: v.Signature, } } diff --git a/privval/file_test.go b/privval/file_test.go index 33d75044e..5b034c6d9 100644 --- a/privval/file_test.go +++ b/privval/file_test.go @@ -1,7 +1,6 @@ package privval import ( - "context" "encoding/base64" "fmt" "os" @@ -29,16 +28,11 @@ func TestGenLoadValidator(t *testing.T) { addr := privVal.GetAddress() privVal = LoadFilePV(tempKeyFileName, tempStateFileName) - assert.Equal(addr, privVal.GetAddress(), "expected privval addr to be the same") - assert.Equal(height, privVal.LastSignState.Height, "expected privval.LastHeight to have been saved") + assert.Equal(t, addr, privVal.GetAddress(), "expected privval addr to be the same") + assert.Equal(t, height, privVal.LastSignState.Height, "expected privval.LastHeight to have been saved") } func TestResetValidator(t *testing.T) { - tempKeyFile, err := os.CreateTemp("", "priv_validator_key_") - require.Nil(t, err) - tempStateFile, err := os.CreateTemp("", "priv_validator_state_") - require.Nil(t, err) - privVal, _, tempStateFileName := newTestFilePV(t) emptyState := FilePVLastSignState{filePath: tempStateFileName} @@ -51,7 +45,7 @@ func TestResetValidator(t *testing.T) { randBytes := tmrand.Bytes(tmhash.Size) blockID := types.BlockID{Hash: randBytes, PartSetHeader: types.PartSetHeader{}} vote := newVote(privVal.Key.Address, 0, height, round, voteType, blockID, nil) - err = privVal.SignVote("mychainid", vote.ToProto()) + err := privVal.SignVote("mychainid", vote.ToProto()) assert.NoError(t, err, "expected no error signing vote") // priv val after signing is not same as empty @@ -307,11 +301,8 @@ func TestDifferByTimestamp(t *testing.T) { } func TestVoteExtensionsAreAlwaysSigned(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - privVal, _, _ := newTestFilePV(t) - pubKey, err := privVal.GetPubKey(ctx) + pubKey, err := privVal.GetPubKey() assert.NoError(t, err) block := types.BlockID{ @@ -326,7 +317,7 @@ func TestVoteExtensionsAreAlwaysSigned(t *testing.T) { vote1 := newVote(privVal.Key.Address, 0, height, round, voteType, block, nil) vpb1 := vote1.ToProto() - err = privVal.SignVote(ctx, "mychainid", vpb1) + err = privVal.SignVote("mychainid", vpb1) assert.NoError(t, err, "expected no error signing vote") assert.NotNil(t, vpb1.ExtensionSignature) @@ -339,7 +330,7 @@ func TestVoteExtensionsAreAlwaysSigned(t *testing.T) { vote2.Extension = []byte("new extension") vpb2 := vote2.ToProto() - err = privVal.SignVote(ctx, "mychainid", vpb2) + err = privVal.SignVote("mychainid", vpb2) assert.NoError(t, err, "expected no error signing same vote with manipulated vote extension") // We need to ensure that a valid new extension signature has been created @@ -358,7 +349,7 @@ func TestVoteExtensionsAreAlwaysSigned(t *testing.T) { vpb2.Signature = nil vpb2.ExtensionSignature = nil - err = privVal.SignVote(ctx, "mychainid", vpb2) + err = privVal.SignVote("mychainid", vpb2) assert.NoError(t, err, "expected no error signing same vote with manipulated timestamp and vote extension") assert.Equal(t, expectedTimestamp, vpb2.Timestamp) @@ -396,8 +387,7 @@ func newTestFilePV(t *testing.T) (*FilePV, string, string) { tempStateFile, err := os.CreateTemp(t.TempDir(), "priv_validator_state_") require.NoError(t, err) - privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "") - require.NoError(t, err) + privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name()) return privVal, tempKeyFile.Name(), tempStateFile.Name() } diff --git a/privval/msgs_test.go b/privval/msgs_test.go index 7bb713c33..a187624d4 100644 --- a/privval/msgs_test.go +++ b/privval/msgs_test.go @@ -79,8 +79,8 @@ func TestPrivvalVectors(t *testing.T) { {"pubKey request", &privproto.PubKeyRequest{}, "0a00"}, {"pubKey response", &privproto.PubKeyResponse{PubKey: ppk, Error: nil}, "12240a220a20556a436f1218d30942efe798420f51dc9b6a311b929c578257457d05c5fcf230"}, {"pubKey response with error", &privproto.PubKeyResponse{PubKey: cryptoproto.PublicKey{}, Error: remoteError}, "12140a0012100801120c697427732061206572726f72"}, - {"Vote Request", &privproto.SignVoteRequest{Vote: votepb}, "1aa8010aa501080110031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0608f49a8ded0532146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb034a2f0a0f6170705f646174615f7369676e6564121c6170705f646174615f73656c665f61757468656e7469636174696e67"}, - {"Vote Response", &privproto.SignedVoteResponse{Vote: *votepb, Error: nil}, "22a8010aa501080110031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0608f49a8ded0532146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb034a2f0a0f6170705f646174615f7369676e6564121c6170705f646174615f73656c665f61757468656e7469636174696e67"}, + {"Vote Request", &privproto.SignVoteRequest{Vote: votepb}, "1a81010a7f080210031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0608f49a8ded0532146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb034a09657874656e73696f6e"}, + {"Vote Response", &privproto.SignedVoteResponse{Vote: *votepb, Error: nil}, "2281010a7f080210031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0608f49a8ded0532146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb034a09657874656e73696f6e"}, {"Vote Response with error", &privproto.SignedVoteResponse{Vote: tmproto.Vote{}, Error: remoteError}, "22250a11220212002a0b088092b8c398feffffff0112100801120c697427732061206572726f72"}, {"Proposal Request", &privproto.SignProposalRequest{Proposal: proposalpb}, "2a700a6e08011003180220022a4a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a320608f49a8ded053a10697427732061207369676e6174757265"}, {"Proposal Response", &privproto.SignedProposalResponse{Proposal: *proposalpb, Error: nil}, "32700a6e08011003180220022a4a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a320608f49a8ded053a10697427732061207369676e6174757265"}, diff --git a/state/execution_test.go b/state/execution_test.go index bc9224878..9d516be2e 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -179,13 +179,11 @@ func TestFinalizeBlockValidators(t *testing.T) { []byte("Signature1"), state.Validators.Validators[0].Address, now, - types.VoteExtensionToSign{}, ) commitSig1 = types.NewCommitSigForBlock( []byte("Signature2"), state.Validators.Validators[1].Address, now, - types.VoteExtensionToSign{}, ) absentSig = types.NewCommitSigAbsent() ) diff --git a/state/helpers_test.go b/state/helpers_test.go index 51152f4e6..59d4344d7 100644 --- a/state/helpers_test.go +++ b/state/helpers_test.go @@ -89,14 +89,13 @@ func makeValidCommit( vals *types.ValidatorSet, privVals map[string]types.PrivValidator, ) (*types.Commit, []*types.Vote, error) { - t.Helper() sigs := make([]types.CommitSig, vals.Size()) votes := make([]*types.Vote, vals.Size()) for i := 0; i < vals.Size(); i++ { _, val := vals.GetByIndex(int32(i)) vote, err := types.MakeVote(height, blockID, vals, privVals[val.Address.String()], chainID, time.Now()) if err != nil { - return nil, err + return nil, nil, err } sigs[i] = vote.CommitSig() votes[i] = vote diff --git a/test/e2e/tests/app_test.go b/test/e2e/tests/app_test.go index 717d1a530..7b700da5e 100644 --- a/test/e2e/tests/app_test.go +++ b/test/e2e/tests/app_test.go @@ -2,7 +2,6 @@ package e2e_test import ( "bytes" - "context" "fmt" "math/rand" "strconv" @@ -107,7 +106,7 @@ func TestApp_Tx(t *testing.T) { } func TestApp_VoteExtensions(t *testing.T) { - testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) { + testNode(t, func(t *testing.T, node e2e.Node) { client, err := node.Client() require.NoError(t, err) diff --git a/types/validation_test.go b/types/validation_test.go index ccb9f1845..518a1512d 100644 --- a/types/validation_test.go +++ b/types/validation_test.go @@ -148,7 +148,7 @@ func TestValidatorSet_VerifyCommit_CheckAllSignatures(t *testing.T) { err = vals[3].SignVote("CentaurusA", v) require.NoError(t, err) vote.Signature = v.Signature - vote.ExtendedSignature = v.ExtendedSignature + vote.ExtensionSignature = v.ExtensionSignature commit.Signatures[3] = vote.CommitSig() err = valSet.VerifyCommit(chainID, blockID, h, commit) @@ -175,7 +175,7 @@ func TestValidatorSet_VerifyCommitLight_ReturnsAsSoonAsMajorityOfVotingPowerSign err = vals[3].SignVote("CentaurusA", v) require.NoError(t, err) vote.Signature = v.Signature - vote.ExtendedSignature = v.ExtendedSignature + vote.ExtensionSignature = v.ExtensionSignature commit.Signatures[3] = vote.CommitSig() err = valSet.VerifyCommitLight(chainID, blockID, h, commit) @@ -200,7 +200,7 @@ func TestValidatorSet_VerifyCommitLightTrusting_ReturnsAsSoonAsTrustLevelOfVotin err = vals[2].SignVote("CentaurusA", v) require.NoError(t, err) vote.Signature = v.Signature - vote.ExtendedSignature = v.ExtendedSignature + vote.ExtensionSignature = v.ExtensionSignature commit.Signatures[2] = vote.CommitSig() err = valSet.VerifyCommitLightTrusting(chainID, commit, tmmath.Fraction{Numerator: 1, Denominator: 3}) diff --git a/types/vote_test.go b/types/vote_test.go index 78f069e1b..2cdd61de9 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -1,7 +1,6 @@ package types import ( - "context" "testing" "time" @@ -13,8 +12,8 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/libs/protoio" - tmtime "github.com/tendermint/tendermint/libs/time" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmtime "github.com/tendermint/tendermint/types/time" ) func examplePrevote() *Vote { @@ -203,9 +202,6 @@ func TestVoteVerifySignature(t *testing.T) { // TestVoteExtension tests that the vote verification behaves correctly in each case // of vote extension being set on the vote. func TestVoteExtension(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - testCases := []struct { name string extension []byte @@ -244,7 +240,7 @@ func TestVoteExtension(t *testing.T) { t.Run(tc.name, func(t *testing.T) { height, round := int64(1), int32(0) privVal := NewMockPV() - pk, err := privVal.GetPubKey(ctx) + pk, err := privVal.GetPubKey() require.NoError(t, err) blk := Block{} ps, err := blk.MakePartSet(BlockPartSizeBytes) @@ -260,7 +256,7 @@ func TestVoteExtension(t *testing.T) { } v := vote.ToProto() - err = privVal.SignVote(ctx, "test_chain_id", v) + err = privVal.SignVote("test_chain_id", v) require.NoError(t, err) vote.Signature = v.Signature if tc.includeSignature {