@@ -47,7 +47,7 @@ func TestCheckMessage(t *testing.T) {
4747 }
4848
4949 testStates := []State {StateAcceptRequest , StatePreprepared , StatePrepared , StateCommitted }
50- testCode := []uint64 {msgPreprepare , msgPrepare , msgCommit }
50+ testCode := []uint64 {msgPreprepare , msgPrepare , msgCommit , msgRoundChange }
5151
5252 // future sequence
5353 v := & istanbul.View {
@@ -73,7 +73,11 @@ func TestCheckMessage(t *testing.T) {
7373 c .state = testStates [i ]
7474 for j := 0 ; j < len (testCode ); j ++ {
7575 err := c .checkMessage (testCode [j ], v )
76- if err != errFutureMessage {
76+ if testCode [j ] == msgRoundChange {
77+ if err != nil {
78+ t .Errorf ("error mismatch: have %v, want nil" , err )
79+ }
80+ } else if err != errFutureMessage {
7781 t .Errorf ("error mismatch: have %v, want %v" , err , errFutureMessage )
7882 }
7983 }
@@ -89,7 +93,11 @@ func TestCheckMessage(t *testing.T) {
8993 c .state = testStates [i ]
9094 for j := 0 ; j < len (testCode ); j ++ {
9195 err := c .checkMessage (testCode [j ], v )
92- if err != errFutureMessage {
96+ if testCode [j ] == msgRoundChange {
97+ if err != nil {
98+ t .Errorf ("error mismatch: have %v, want nil" , err )
99+ }
100+ } else if err != errFutureMessage {
93101 t .Errorf ("error mismatch: have %v, want %v" , err , errFutureMessage )
94102 }
95103 }
@@ -101,7 +109,11 @@ func TestCheckMessage(t *testing.T) {
101109 c .state = StateAcceptRequest
102110 for i := 0 ; i < len (testCode ); i ++ {
103111 err = c .checkMessage (testCode [i ], v )
104- if testCode [i ] == msgPreprepare {
112+ if testCode [i ] == msgRoundChange {
113+ if err != nil {
114+ t .Errorf ("error mismatch: have %v, want nil" , err )
115+ }
116+ } else if testCode [i ] == msgPreprepare {
105117 if err != nil {
106118 t .Errorf ("error mismatch: have %v, want nil" , err )
107119 }
@@ -116,7 +128,11 @@ func TestCheckMessage(t *testing.T) {
116128 c .state = StatePreprepared
117129 for i := 0 ; i < len (testCode ); i ++ {
118130 err = c .checkMessage (testCode [i ], v )
119- if err != nil {
131+ if testCode [i ] == msgRoundChange {
132+ if err != nil {
133+ t .Errorf ("error mismatch: have %v, want nil" , err )
134+ }
135+ } else if err != nil {
120136 t .Errorf ("error mismatch: have %v, want nil" , err )
121137 }
122138 }
@@ -125,7 +141,11 @@ func TestCheckMessage(t *testing.T) {
125141 c .state = StatePrepared
126142 for i := 0 ; i < len (testCode ); i ++ {
127143 err = c .checkMessage (testCode [i ], v )
128- if err != nil {
144+ if testCode [i ] == msgRoundChange {
145+ if err != nil {
146+ t .Errorf ("error mismatch: have %v, want nil" , err )
147+ }
148+ } else if err != nil {
129149 t .Errorf ("error mismatch: have %v, want nil" , err )
130150 }
131151 }
@@ -134,7 +154,11 @@ func TestCheckMessage(t *testing.T) {
134154 c .state = StateCommitted
135155 for i := 0 ; i < len (testCode ); i ++ {
136156 err = c .checkMessage (testCode [i ], v )
137- if err != nil {
157+ if testCode [i ] == msgRoundChange {
158+ if err != nil {
159+ t .Errorf ("error mismatch: have %v, want nil" , err )
160+ }
161+ } else if err != nil {
138162 t .Errorf ("error mismatch: have %v, want nil" , err )
139163 }
140164 }
@@ -195,6 +219,17 @@ func TestStoreBacklog(t *testing.T) {
195219 if ! reflect .DeepEqual (msg , m ) {
196220 t .Errorf ("message mismatch: have %v, want %v" , msg , m )
197221 }
222+
223+ // push roundChange msg
224+ m = & message {
225+ Code : msgRoundChange ,
226+ Msg : subjectPayload ,
227+ }
228+ c .storeBacklog (m , p )
229+ msg = c .backlogs [p ].PopItem ()
230+ if ! reflect .DeepEqual (msg , m ) {
231+ t .Errorf ("message mismatch: have %v, want %v" , msg , m )
232+ }
198233}
199234
200235func TestProcessFutureBacklog (t * testing.T ) {
@@ -276,6 +311,10 @@ func TestProcessBacklog(t *testing.T) {
276311 Code : msgCommit ,
277312 Msg : subjectPayload ,
278313 },
314+ & message {
315+ Code : msgRoundChange ,
316+ Msg : subjectPayload ,
317+ },
279318 }
280319 for i := 0 ; i < len (msgs ); i ++ {
281320 testProcessBacklog (t , msgs [i ])
0 commit comments