88 crypto "github.com/multiversx/mx-chain-crypto-go"
99 "github.com/stretchr/testify/require"
1010
11- chainCommon "github.com/multiversx/mx-chain-go/common"
1211 mock2 "github.com/multiversx/mx-chain-go/consensus/mock"
1312 "github.com/multiversx/mx-chain-go/testscommon"
1413 "github.com/multiversx/mx-chain-go/testscommon/bootstrapperStubs"
@@ -17,6 +16,7 @@ import (
1716 "github.com/multiversx/mx-chain-go/testscommon/cryptoMocks"
1817 "github.com/multiversx/mx-chain-go/testscommon/dataRetriever"
1918 "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
19+ epochNotifierMock "github.com/multiversx/mx-chain-go/testscommon/epochNotifier"
2020 mock "github.com/multiversx/mx-chain-go/testscommon/epochstartmock"
2121 outportStub "github.com/multiversx/mx-chain-go/testscommon/outport"
2222 "github.com/multiversx/mx-chain-go/testscommon/shardingMocks"
@@ -29,6 +29,7 @@ func getDefaultArgumentsSubroundHandler() (*SubroundsHandlerArgs, *consensus.Con
2929 epochsEnable := & enableEpochsHandlerMock.EnableEpochsHandlerStub {}
3030 epochStartNotifier := & mock.EpochStartNotifierStub {}
3131 consensusState := & consensus.ConsensusStateMock {}
32+ epochNotifier := & epochNotifierMock.EpochNotifierStub {}
3233 worker := & consensus.SposWorkerMock {
3334 RemoveAllReceivedMessagesCallsCalled : func () {},
3435 GetConsensusStateChangedChannelsCalled : func () chan bool {
@@ -78,6 +79,7 @@ func getDefaultArgumentsSubroundHandler() (*SubroundsHandlerArgs, *consensus.Con
7879 consensusCore .SetSigningHandler (& consensus.SigningHandlerStub {})
7980 consensusCore .SetEnableEpochsHandler (epochsEnable )
8081 consensusCore .SetEquivalentProofsPool (& dataRetriever.ProofsPoolMock {})
82+ consensusCore .SetEpochNotifier (epochNotifier )
8183 handlerArgs .ConsensusCoreHandler = consensusCore
8284
8385 return handlerArgs , consensusCore
@@ -221,12 +223,14 @@ func TestSubroundsHandler_initSubroundsForEpoch(t *testing.T) {
221223 sh , err := NewSubroundsHandler (handlerArgs )
222224 require .Nil (t , err )
223225 require .NotNil (t , sh )
226+ // first call on register to EpochNotifier
227+ require .Equal (t , int32 (1 ), startCalled .Load ())
224228 sh .currentConsensusType = consensusNone
225229
226230 err = sh .initSubroundsForEpoch (0 )
227231 require .Nil (t , err )
228232 require .Equal (t , consensusV1 , sh .currentConsensusType )
229- require .Equal (t , int32 (1 ), startCalled .Load ())
233+ require .Equal (t , int32 (2 ), startCalled .Load ())
230234 })
231235 t .Run ("equivalent messages not enabled, with previous consensus type consensusV1" , func (t * testing.T ) {
232236 t .Parallel ()
@@ -251,12 +255,15 @@ func TestSubroundsHandler_initSubroundsForEpoch(t *testing.T) {
251255 sh , err := NewSubroundsHandler (handlerArgs )
252256 require .Nil (t , err )
253257 require .NotNil (t , sh )
258+ // first call on register to EpochNotifier
259+ require .Equal (t , int32 (1 ), startCalled .Load ())
254260 sh .currentConsensusType = consensusV1
255261
256262 err = sh .initSubroundsForEpoch (0 )
257263 require .Nil (t , err )
258264 require .Equal (t , consensusV1 , sh .currentConsensusType )
259- require .Equal (t , int32 (0 ), startCalled .Load ())
265+ require .Equal (t , int32 (1 ), startCalled .Load ())
266+
260267 })
261268 t .Run ("equivalent messages enabled, with previous consensus type consensusNone" , func (t * testing.T ) {
262269 t .Parallel ()
@@ -280,12 +287,14 @@ func TestSubroundsHandler_initSubroundsForEpoch(t *testing.T) {
280287 sh , err := NewSubroundsHandler (handlerArgs )
281288 require .Nil (t , err )
282289 require .NotNil (t , sh )
290+ // first call on register to EpochNotifier
291+ require .Equal (t , int32 (1 ), startCalled .Load ())
283292 sh .currentConsensusType = consensusNone
284293
285294 err = sh .initSubroundsForEpoch (0 )
286295 require .Nil (t , err )
287296 require .Equal (t , consensusV2 , sh .currentConsensusType )
288- require .Equal (t , int32 (1 ), startCalled .Load ())
297+ require .Equal (t , int32 (2 ), startCalled .Load ())
289298 })
290299 t .Run ("equivalent messages enabled, with previous consensus type consensusV1" , func (t * testing.T ) {
291300 t .Parallel ()
@@ -309,12 +318,14 @@ func TestSubroundsHandler_initSubroundsForEpoch(t *testing.T) {
309318 sh , err := NewSubroundsHandler (handlerArgs )
310319 require .Nil (t , err )
311320 require .NotNil (t , sh )
321+ // first call on register to EpochNotifier
322+ require .Equal (t , int32 (1 ), startCalled .Load ())
312323 sh .currentConsensusType = consensusV1
313324
314325 err = sh .initSubroundsForEpoch (0 )
315326 require .Nil (t , err )
316327 require .Equal (t , consensusV2 , sh .currentConsensusType )
317- require .Equal (t , int32 (1 ), startCalled .Load ())
328+ require .Equal (t , int32 (2 ), startCalled .Load ())
318329 })
319330 t .Run ("equivalent messages enabled, with previous consensus type consensusV2" , func (t * testing.T ) {
320331 t .Parallel ()
@@ -339,12 +350,14 @@ func TestSubroundsHandler_initSubroundsForEpoch(t *testing.T) {
339350 sh , err := NewSubroundsHandler (handlerArgs )
340351 require .Nil (t , err )
341352 require .NotNil (t , sh )
353+ // first call on register to EpochNotifier
354+ require .Equal (t , int32 (1 ), startCalled .Load ())
342355 sh .currentConsensusType = consensusV2
343356
344357 err = sh .initSubroundsForEpoch (0 )
345358 require .Nil (t , err )
346359 require .Equal (t , consensusV2 , sh .currentConsensusType )
347- require .Equal (t , int32 (0 ), startCalled .Load ())
360+ require .Equal (t , int32 (1 ), startCalled .Load ())
348361 })
349362}
350363
@@ -375,27 +388,17 @@ func TestSubroundsHandler_Start(t *testing.T) {
375388 sh , err := NewSubroundsHandler (handlerArgs )
376389 require .Nil (t , err )
377390 require .NotNil (t , sh )
391+ // first call on init of EpochNotifier
392+ require .Equal (t , int32 (1 ), startCalled .Load ())
378393 sh .currentConsensusType = consensusNone
379394
380395 err = sh .Start (0 )
381396 require .Nil (t , err )
382397 require .Equal (t , consensusV1 , sh .currentConsensusType )
383- require .Equal (t , int32 (1 ), startCalled .Load ())
398+ require .Equal (t , int32 (2 ), startCalled .Load ())
384399 })
385400}
386401
387- func TestSubroundsHandler_NotifyOrder (t * testing.T ) {
388- t .Parallel ()
389-
390- handlerArgs , _ := getDefaultArgumentsSubroundHandler ()
391- sh , err := NewSubroundsHandler (handlerArgs )
392- require .Nil (t , err )
393- require .NotNil (t , sh )
394-
395- order := sh .NotifyOrder ()
396- require .Equal (t , uint32 (chainCommon .ConsensusHandlerOrder ), order )
397- }
398-
399402func TestSubroundsHandler_IsInterfaceNil (t * testing.T ) {
400403 t .Parallel ()
401404
@@ -417,7 +420,7 @@ func TestSubroundsHandler_IsInterfaceNil(t *testing.T) {
417420 })
418421}
419422
420- func TestSubroundsHandler_EpochStartAction (t * testing.T ) {
423+ func TestSubroundsHandler_EpochConfirmed (t * testing.T ) {
421424 t .Parallel ()
422425
423426 t .Run ("nil handler does not panic" , func (t * testing.T ) {
@@ -431,7 +434,7 @@ func TestSubroundsHandler_EpochStartAction(t *testing.T) {
431434 handlerArgs , _ := getDefaultArgumentsSubroundHandler ()
432435 sh , err := NewSubroundsHandler (handlerArgs )
433436 require .Nil (t , err )
434- sh .EpochStartAction ( & testscommon. HeaderHandlerStub {} )
437+ sh .EpochConfirmed ( 0 , 0 )
435438 })
436439
437440 // tested through initSubroundsForEpoch
@@ -458,11 +461,13 @@ func TestSubroundsHandler_EpochStartAction(t *testing.T) {
458461 sh , err := NewSubroundsHandler (handlerArgs )
459462 require .Nil (t , err )
460463 require .NotNil (t , sh )
464+ // first call on register to EpochNotifier
465+ require .Equal (t , int32 (1 ), startCalled .Load ())
461466
462467 sh .currentConsensusType = consensusNone
463- sh .EpochStartAction ( & testscommon. HeaderHandlerStub {} )
468+ sh .EpochConfirmed ( 0 , 0 )
464469 require .Nil (t , err )
465470 require .Equal (t , consensusV1 , sh .currentConsensusType )
466- require .Equal (t , int32 (1 ), startCalled .Load ())
471+ require .Equal (t , int32 (2 ), startCalled .Load ())
467472 })
468473}
0 commit comments