Files
tendermint/internal/consensus/peer_state_test.go
Sergio Mena 8df38db82e Remove ModifiedTxStatus from the spec and the code (#8210)
* Outstanding abci-gen changes to 'pb.go' files

* Removed modified_tx_status from spec and protobufs

* Fix sed for OSX

* Regenerated abci protobufs with 'abci-proto-gen'

* Code changes. UTs e2e tests passing

* Recovered UT: TestPrepareProposalModifiedTxStatusFalse

* Adapted UT

* Fixed UT

* Revert "Fix sed for OSX"

This reverts commit e576708c61.

* Update internal/state/execution_test.go

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* Update abci/example/kvstore/kvstore.go

Co-authored-by: M. J. Fromberger <fromberger@interchain.io>

* Update internal/state/execution_test.go

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* Update spec/abci++/abci++_tmint_expected_behavior_002_draft.md

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* Addressed some comments

* Added one test that tests error at the ABCI client + Fixed some mock calls

* Addressed remaining comments

* Update abci/example/kvstore/kvstore.go

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* Update abci/example/kvstore/kvstore.go

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* Update abci/example/kvstore/kvstore.go

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* Update spec/abci++/abci++_tmint_expected_behavior_002_draft.md

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* Addressed William's latest comments

* Adressed Michael's comment

* Fixed UT

* Some md fixes

* More md fixes

* gofmt

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
Co-authored-by: M. J. Fromberger <fromberger@interchain.io>
2022-04-04 12:43:01 +02:00

102 lines
2.5 KiB
Go

package consensus
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/types"
)
func peerStateSetup(h, r, v int) *PeerState {
ps := NewPeerState(log.NewNopLogger(), "testPeerState")
ps.PRS.Height = int64(h)
ps.PRS.Round = int32(r)
ps.ensureVoteBitArrays(int64(h), v)
return ps
}
func TestSetHasVote(t *testing.T) {
ps := peerStateSetup(1, 1, 1)
pva := ps.PRS.Prevotes.Copy()
// nil vote should return ErrPeerStateNilVote
err := ps.SetHasVote(nil)
require.Equal(t, ErrPeerStateSetNilVote, err)
// the peer giving an invalid index should returns ErrPeerStateInvalidVoteIndex
v0 := &types.Vote{
Height: 1,
ValidatorIndex: -1,
Round: 1,
Type: tmproto.PrevoteType,
}
err = ps.SetHasVote(v0)
require.Equal(t, ErrPeerStateInvalidVoteIndex, err)
// the peer giving an invalid index should returns ErrPeerStateInvalidVoteIndex
v1 := &types.Vote{
Height: 1,
ValidatorIndex: 1,
Round: 1,
Type: tmproto.PrevoteType,
}
err = ps.SetHasVote(v1)
require.Equal(t, ErrPeerStateInvalidVoteIndex, err)
// the peer giving a correct index should return nil (vote has been set)
v2 := &types.Vote{
Height: 1,
ValidatorIndex: 0,
Round: 1,
Type: tmproto.PrevoteType,
}
require.Nil(t, ps.SetHasVote(v2))
// verify vote
pva.SetIndex(0, true)
require.Equal(t, pva, ps.getVoteBitArray(1, 1, tmproto.PrevoteType))
// the vote is not in the correct height/round/voteType should return nil (ignore the vote)
v3 := &types.Vote{
Height: 2,
ValidatorIndex: 0,
Round: 1,
Type: tmproto.PrevoteType,
}
require.Nil(t, ps.SetHasVote(v3))
// prevote bitarray has no update
require.Equal(t, pva, ps.getVoteBitArray(1, 1, tmproto.PrevoteType))
}
func TestApplyHasVoteMessage(t *testing.T) {
ps := peerStateSetup(1, 1, 1)
pva := ps.PRS.Prevotes.Copy()
// ignore the message with an invalid height
msg := &HasVoteMessage{
Height: 2,
}
require.Nil(t, ps.ApplyHasVoteMessage(msg))
// apply a message like v2 in TestSetHasVote
msg2 := &HasVoteMessage{
Height: 1,
Index: 0,
Round: 1,
Type: tmproto.PrevoteType,
}
require.Nil(t, ps.ApplyHasVoteMessage(msg2))
// verify vote
pva.SetIndex(0, true)
require.Equal(t, pva, ps.getVoteBitArray(1, 1, tmproto.PrevoteType))
// skip test cases like v & v3 in TestSetHasVote due to the same path
}