@@ -11,15 +11,16 @@ import (
1111 "github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/engines/engine_v2"
1212 "github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils"
1313 "github.com/XinFinOrg/XDPoSChain/core"
14+ "github.com/XinFinOrg/XDPoSChain/core/types"
1415 "github.com/stretchr/testify/assert"
1516)
1617
1718// make different votes based on Signatures
18- func makeVotes (n int ) []utils .Vote {
19- var votes []utils .Vote
19+ func makeVotes (n int ) []types .Vote {
20+ var votes []types .Vote
2021 for i := 0 ; i < n ; i ++ {
21- votes = append (votes , utils .Vote {
22- ProposedBlockInfo : & utils .BlockInfo {},
22+ votes = append (votes , types .Vote {
23+ ProposedBlockInfo : & types .BlockInfo {},
2324 Signature : []byte {byte (i )},
2425 GapNumber : 0 ,
2526 })
@@ -55,17 +56,17 @@ func TestSequentialVotes(t *testing.T) {
5556 broadcastCounter := uint32 (0 )
5657 targetVotes := 10
5758
58- tester .bfter .consensus .verifyVote = func (chain consensus.ChainReader , vote * utils .Vote ) (bool , error ) {
59+ tester .bfter .consensus .verifyVote = func (chain consensus.ChainReader , vote * types .Vote ) (bool , error ) {
5960 atomic .AddUint32 (& verifyCounter , 1 )
6061 return true , nil
6162 }
6263
63- tester .bfter .consensus .voteHandler = func (chain consensus.ChainReader , vote * utils .Vote ) error {
64+ tester .bfter .consensus .voteHandler = func (chain consensus.ChainReader , vote * types .Vote ) error {
6465 atomic .AddUint32 (& handlerCounter , 1 )
6566 return nil
6667 }
6768
68- tester .bfter .broadcast .Vote = func (* utils .Vote ) {
69+ tester .bfter .broadcast .Vote = func (* types .Vote ) {
6970 atomic .AddUint32 (& broadcastCounter , 1 )
7071 }
7172
@@ -91,19 +92,19 @@ func TestNotBoardcastInvalidVote(t *testing.T) {
9192 broadcastCounter := uint32 (0 )
9293 targetVotes := 0
9394
94- tester .bfter .consensus .verifyVote = func (chain consensus.ChainReader , vote * utils .Vote ) (bool , error ) {
95+ tester .bfter .consensus .verifyVote = func (chain consensus.ChainReader , vote * types .Vote ) (bool , error ) {
9596 return false , fmt .Errorf ("This is invalid vote" )
9697 }
9798
98- tester .bfter .consensus .voteHandler = func (chain consensus.ChainReader , vote * utils .Vote ) error {
99+ tester .bfter .consensus .voteHandler = func (chain consensus.ChainReader , vote * types .Vote ) error {
99100 atomic .AddUint32 (& handlerCounter , 1 )
100101 return nil
101102 }
102- tester .bfter .broadcast .Vote = func (* utils .Vote ) {
103+ tester .bfter .broadcast .Vote = func (* types .Vote ) {
103104 atomic .AddUint32 (& broadcastCounter , 1 )
104105 }
105106
106- vote := utils .Vote {ProposedBlockInfo : & utils .BlockInfo {}}
107+ vote := types .Vote {ProposedBlockInfo : & types .BlockInfo {}}
107108 tester .bfter .Vote (& vote )
108109
109110 time .Sleep (50 * time .Millisecond )
@@ -118,19 +119,19 @@ func TestBoardcastButNotProcessDisqualifiedVotes(t *testing.T) {
118119 broadcastCounter := uint32 (0 )
119120 targetVotes := 0
120121
121- tester .bfter .consensus .verifyVote = func (chain consensus.ChainReader , vote * utils .Vote ) (bool , error ) {
122+ tester .bfter .consensus .verifyVote = func (chain consensus.ChainReader , vote * types .Vote ) (bool , error ) {
122123 return false , nil // return false but with nil in error means the message is valid but disqualified
123124 }
124125
125- tester .bfter .consensus .voteHandler = func (chain consensus.ChainReader , vote * utils .Vote ) error {
126+ tester .bfter .consensus .voteHandler = func (chain consensus.ChainReader , vote * types .Vote ) error {
126127 atomic .AddUint32 (& handlerCounter , 1 )
127128 return nil
128129 }
129- tester .bfter .broadcast .Vote = func (* utils .Vote ) {
130+ tester .bfter .broadcast .Vote = func (* types .Vote ) {
130131 atomic .AddUint32 (& broadcastCounter , 1 )
131132 }
132133
133- vote := utils .Vote {ProposedBlockInfo : & utils .BlockInfo {}}
134+ vote := types .Vote {ProposedBlockInfo : & types .BlockInfo {}}
134135 tester .bfter .Vote (& vote )
135136
136137 time .Sleep (50 * time .Millisecond )
@@ -145,19 +146,19 @@ func TestBoardcastButNotProcessDisqualifiedTimeout(t *testing.T) {
145146 broadcastCounter := uint32 (0 )
146147 targetTimeout := 0
147148
148- tester .bfter .consensus .verifyTimeout = func (chain consensus.ChainReader , timeout * utils .Timeout ) (bool , error ) {
149+ tester .bfter .consensus .verifyTimeout = func (chain consensus.ChainReader , timeout * types .Timeout ) (bool , error ) {
149150 return false , nil // return false but with nil in error means the message is valid but disqualified
150151 }
151152
152- tester .bfter .consensus .timeoutHandler = func (chain consensus.ChainReader , timeout * utils .Timeout ) error {
153+ tester .bfter .consensus .timeoutHandler = func (chain consensus.ChainReader , timeout * types .Timeout ) error {
153154 atomic .AddUint32 (& handlerCounter , 1 )
154155 return nil
155156 }
156- tester .bfter .broadcast .Timeout = func (* utils .Timeout ) {
157+ tester .bfter .broadcast .Timeout = func (* types .Timeout ) {
157158 atomic .AddUint32 (& broadcastCounter , 1 )
158159 }
159160
160- timeout := utils .Timeout {}
161+ timeout := types .Timeout {}
161162 tester .bfter .Timeout (& timeout )
162163
163164 time .Sleep (50 * time .Millisecond )
@@ -172,19 +173,19 @@ func TestBoardcastButNotProcessDisqualifiedSyncInfo(t *testing.T) {
172173 broadcastCounter := uint32 (0 )
173174 targetSyncInfo := 0
174175
175- tester .bfter .consensus .verifySyncInfo = func (chain consensus.ChainReader , syncInfo * utils .SyncInfo ) (bool , error ) {
176+ tester .bfter .consensus .verifySyncInfo = func (chain consensus.ChainReader , syncInfo * types .SyncInfo ) (bool , error ) {
176177 return false , nil // return false but with nil in error means the message is valid but disqualified
177178 }
178179
179- tester .bfter .consensus .syncInfoHandler = func (chain consensus.ChainReader , syncInfo * utils .SyncInfo ) error {
180+ tester .bfter .consensus .syncInfoHandler = func (chain consensus.ChainReader , syncInfo * types .SyncInfo ) error {
180181 atomic .AddUint32 (& handlerCounter , 1 )
181182 return nil
182183 }
183- tester .bfter .broadcast .SyncInfo = func (* utils .SyncInfo ) {
184+ tester .bfter .broadcast .SyncInfo = func (* types .SyncInfo ) {
184185 atomic .AddUint32 (& broadcastCounter , 1 )
185186 }
186187
187- syncInfo := utils .SyncInfo {}
188+ syncInfo := types .SyncInfo {}
188189 tester .bfter .SyncInfo (& syncInfo )
189190
190191 time .Sleep (50 * time .Millisecond )
@@ -203,21 +204,21 @@ func TestTimeoutHandler(t *testing.T) {
203204 broadcastCounter := uint32 (0 )
204205 targetVotes := 1
205206
206- tester .bfter .consensus .verifyTimeout = func (consensus.ChainReader , * utils .Timeout ) (bool , error ) {
207+ tester .bfter .consensus .verifyTimeout = func (consensus.ChainReader , * types .Timeout ) (bool , error ) {
207208 atomic .AddUint32 (& verifyCounter , 1 )
208209 return true , nil
209210 }
210211
211- tester .bfter .consensus .timeoutHandler = func (chain consensus.ChainReader , timeout * utils .Timeout ) error {
212+ tester .bfter .consensus .timeoutHandler = func (chain consensus.ChainReader , timeout * types .Timeout ) error {
212213 atomic .AddUint32 (& handlerCounter , 1 )
213214 return nil
214215 }
215216
216- tester .bfter .broadcast .Timeout = func (* utils .Timeout ) {
217+ tester .bfter .broadcast .Timeout = func (* types .Timeout ) {
217218 atomic .AddUint32 (& broadcastCounter , 1 )
218219 }
219220
220- timeoutMsg := & utils .Timeout {}
221+ timeoutMsg := & types .Timeout {}
221222
222223 err := tester .bfter .Timeout (timeoutMsg )
223224 if err != nil {
@@ -234,21 +235,21 @@ func TestTimeoutHandler(t *testing.T) {
234235func TestTimeoutHandlerRoundNotEqual (t * testing.T ) {
235236 tester := newTester ()
236237
237- tester .bfter .consensus .verifyTimeout = func (consensus.ChainReader , * utils .Timeout ) (bool , error ) {
238+ tester .bfter .consensus .verifyTimeout = func (consensus.ChainReader , * types .Timeout ) (bool , error ) {
238239 return true , nil
239240 }
240241
241- tester .bfter .consensus .timeoutHandler = func (chain consensus.ChainReader , timeout * utils .Timeout ) error {
242+ tester .bfter .consensus .timeoutHandler = func (chain consensus.ChainReader , timeout * types .Timeout ) error {
242243 return & utils.ErrIncomingMessageRoundNotEqualCurrentRound {
243244 Type : "timeout" ,
244- IncomingRound : utils .Round (1 ),
245- CurrentRound : utils .Round (2 ),
245+ IncomingRound : types .Round (1 ),
246+ CurrentRound : types .Round (2 ),
246247 }
247248 }
248249
249- tester .bfter .broadcast .Timeout = func (* utils .Timeout ) {}
250+ tester .bfter .broadcast .Timeout = func (* types .Timeout ) {}
250251
251- timeoutMsg := & utils .Timeout {}
252+ timeoutMsg := & types .Timeout {}
252253
253254 err := tester .bfter .Timeout (timeoutMsg )
254255 assert .Equal (t , "timeout message round number: 1 does not match currentRound: 2" , err .Error ())
0 commit comments