aboutsummaryrefslogtreecommitdiffstats
path: root/core/agreement-state_test.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-31 12:51:54 +0800
committerGitHub <noreply@github.com>2018-10-31 12:51:54 +0800
commiteccdddbff92c1588e628f874d73ae557351c76f7 (patch)
tree799e888f2223e53d88391b15f507226208ef349c /core/agreement-state_test.go
parent43a5264814bf318e6bd133fb0df51351f0811ddb (diff)
downloaddexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar
dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar.gz
dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar.bz2
dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar.lz
dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar.xz
dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar.zst
dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.zip
core: Add a repeat vote state. (#280)
Diffstat (limited to 'core/agreement-state_test.go')
-rw-r--r--core/agreement-state_test.go30
1 files changed, 26 insertions, 4 deletions
diff --git a/core/agreement-state_test.go b/core/agreement-state_test.go
index 429e124..862ac3e 100644
--- a/core/agreement-state_test.go
+++ b/core/agreement-state_test.go
@@ -233,14 +233,36 @@ func (s *AgreementStateTestSuite) TestCommitState() {
func (s *AgreementStateTestSuite) TestForwardState() {
a := s.newAgreement(4)
- state := newForwardState(a.data)
+ vote := &types.Vote{
+ BlockHash: common.NewRandomHash(),
+ }
+ state := newForwardState(a.data, vote)
s.Equal(stateForward, state.state())
- s.True(state.clocks() > 100000)
+ s.Equal(4, state.clocks())
- // nextState() should return instantly without doing anything.
- _, err := state.nextState()
+ newState, err := state.nextState()
s.Require().Nil(err)
s.Require().Len(s.voteChan, 0)
+ s.Equal(stateRepeatVote, newState.state())
+}
+
+func (s *AgreementStateTestSuite) TestRepeatVoteState() {
+ a := s.newAgreement(4)
+ vote := &types.Vote{
+ BlockHash: common.NewRandomHash(),
+ }
+ state := newRepeatVoteState(a.data, vote)
+ s.Equal(stateRepeatVote, state.state())
+ s.Equal(4, state.clocks())
+
+ for i := 0; i < 5; i++ {
+ newState, err := state.nextState()
+ s.Require().Nil(err)
+ s.Require().Len(s.voteChan, 1)
+ proposedVote := <-s.voteChan
+ s.Equal(vote, proposedVote)
+ s.Equal(stateRepeatVote, newState.state())
+ }
}
func TestAgreementState(t *testing.T) {