@@ -2290,7 +2290,9 @@ func TestSubroundEndRound_SendProof(t *testing.T) {
22902290 },
22912291 }
22922292 container .SetBroadcastMessenger (bm )
2293- sr .SendProof ()
2293+ wasSent , err := sr .SendProof ()
2294+ require .False (t , wasSent )
2295+ require .NoError (t , err )
22942296 })
22952297 t .Run ("not enough signatures should not send proof" , func (t * testing.T ) {
22962298 t .Parallel ()
@@ -2305,18 +2307,97 @@ func TestSubroundEndRound_SendProof(t *testing.T) {
23052307 },
23062308 }
23072309 container .SetBroadcastMessenger (bm )
2308- sr .SendProof ()
2310+ wasSent , err := sr .SendProof ()
2311+ require .False (t , wasSent )
2312+ require .Error (t , err )
2313+ })
2314+ t .Run ("signature aggregation failure should not send proof" , func (t * testing.T ) {
2315+ t .Parallel ()
2316+
2317+ container := consensusMocks .InitConsensusCore ()
2318+ sr := initSubroundEndRoundWithContainer (container , & statusHandler.AppStatusHandlerStub {})
2319+
2320+ bm := & consensusMocks.BroadcastMessengerMock {
2321+ BroadcastEquivalentProofCalled : func (proof data.HeaderProofHandler , pkBytes []byte ) error {
2322+ require .Fail (t , "should have not been called" )
2323+ return nil
2324+ },
2325+ }
2326+ container .SetBroadcastMessenger (bm )
2327+ signingHandler := & consensusMocks.SigningHandlerStub {
2328+ AggregateSigsCalled : func (bitmap []byte , epoch uint32 ) ([]byte , error ) {
2329+ return nil , expectedErr
2330+ },
2331+ }
2332+ container .SetSigningHandler (signingHandler )
2333+
2334+ for _ , pubKey := range sr .ConsensusGroup () {
2335+ _ = sr .SetJobDone (pubKey , bls .SrSignature , true )
2336+ }
2337+
2338+ wasSent , err := sr .SendProof ()
2339+ require .False (t , wasSent )
2340+ require .Equal (t , expectedErr , err )
2341+ })
2342+ t .Run ("no time left should not send proof" , func (t * testing.T ) {
2343+ t .Parallel ()
2344+
2345+ container := consensusMocks .InitConsensusCore ()
2346+ sr := initSubroundEndRoundWithContainer (container , & statusHandler.AppStatusHandlerStub {})
2347+
2348+ bm := & consensusMocks.BroadcastMessengerMock {
2349+ BroadcastEquivalentProofCalled : func (proof data.HeaderProofHandler , pkBytes []byte ) error {
2350+ require .Fail (t , "should have not been called" )
2351+ return nil
2352+ },
2353+ }
2354+ container .SetBroadcastMessenger (bm )
2355+ roundHandler := & consensusMocks.RoundHandlerMock {
2356+ RemainingTimeCalled : func (startTime time.Time , maxTime time.Duration ) time.Duration {
2357+ return - 1 // no time left
2358+ },
2359+ }
2360+ container .SetRoundHandler (roundHandler )
2361+
2362+ for _ , pubKey := range sr .ConsensusGroup () {
2363+ _ = sr .SetJobDone (pubKey , bls .SrSignature , true )
2364+ }
2365+
2366+ wasSent , err := sr .SendProof ()
2367+ require .False (t , wasSent )
2368+ require .Equal (t , v2 .ErrTimeOut , err )
2369+ })
2370+ t .Run ("broadcast failure should not send proof" , func (t * testing.T ) {
2371+ t .Parallel ()
2372+
2373+ container := consensusMocks .InitConsensusCore ()
2374+ sr := initSubroundEndRoundWithContainer (container , & statusHandler.AppStatusHandlerStub {})
2375+
2376+ bm := & consensusMocks.BroadcastMessengerMock {
2377+ BroadcastEquivalentProofCalled : func (proof data.HeaderProofHandler , pkBytes []byte ) error {
2378+ return expectedErr
2379+ },
2380+ }
2381+ container .SetBroadcastMessenger (bm )
2382+
2383+ for _ , pubKey := range sr .ConsensusGroup () {
2384+ _ = sr .SetJobDone (pubKey , bls .SrSignature , true )
2385+ }
2386+
2387+ wasSent , err := sr .SendProof ()
2388+ require .False (t , wasSent )
2389+ require .Equal (t , expectedErr , err )
23092390 })
23102391 t .Run ("should send" , func (t * testing.T ) {
23112392 t .Parallel ()
23122393
23132394 container := consensusMocks .InitConsensusCore ()
23142395 sr := initSubroundEndRoundWithContainer (container , & statusHandler.AppStatusHandlerStub {})
23152396
2316- wasSent := false
2397+ wasBroadcastEquivalentProofCalled := false
23172398 bm := & consensusMocks.BroadcastMessengerMock {
23182399 BroadcastEquivalentProofCalled : func (proof data.HeaderProofHandler , pkBytes []byte ) error {
2319- wasSent = true
2400+ wasBroadcastEquivalentProofCalled = true
23202401 return nil
23212402 },
23222403 }
@@ -2326,7 +2407,9 @@ func TestSubroundEndRound_SendProof(t *testing.T) {
23262407 _ = sr .SetJobDone (pubKey , bls .SrSignature , true )
23272408 }
23282409
2329- sr .SendProof ()
2410+ wasSent , err := sr .SendProof ()
23302411 require .True (t , wasSent )
2412+ require .NoError (t , err )
2413+ require .True (t , wasBroadcastEquivalentProofCalled )
23312414 })
23322415}
0 commit comments