From ddd9a558bb476aeca3d793d334c48ccac4de498a Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:11:43 +0100 Subject: [PATCH] feat: increase coverage --- aggsender/aggsender.go | 7 +++---- aggsender/aggsender_test.go | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/aggsender/aggsender.go b/aggsender/aggsender.go index b880e98c..7ffbff5f 100644 --- a/aggsender/aggsender.go +++ b/aggsender/aggsender.go @@ -55,7 +55,7 @@ func New( cfg Config, aggLayerClient agglayer.AgglayerClientInterface, l1InfoTreeSyncer *l1infotreesync.L1InfoTreeSync, - l2Syncer *bridgesync.BridgeSync, + l2Syncer types.L2BridgeSyncer, epochNotifier types.EpochNotifier) (*AggSender, error) { storage, err := db.NewAggSenderSQLStorage(logger, cfg.StoragePath) if err != nil { @@ -525,14 +525,13 @@ func (a *AggSender) checkPendingCertificatesStatus(ctx context.Context) bool { } } if slices.Contains(nonSettledStatuses, certificateHeader.Status) { - - logErrMsg += fmt.Sprintf("certificate %s is still pending, elapsed_time:%s ", certificateHeader.String(), elapsedTime) + logErrMsg += fmt.Sprintf("certificate %s is still pending, elapsed_time:%s ", + certificateHeader.String(), elapsedTime) } } if logErrMsg != "" { a.log.Infof(logErrMsg) return true - } return false } diff --git a/aggsender/aggsender_test.go b/aggsender/aggsender_test.go index 970f6153..35f1a640 100644 --- a/aggsender/aggsender_test.go +++ b/aggsender/aggsender_test.go @@ -280,20 +280,32 @@ func TestGetBridgeExits(t *testing.T) { } } -func TestNewAggSender(t *testing.T) { +func TestAggSendersendCertificates(t *testing.T) { AggLayerMock := agglayer.NewAgglayerClientMock(t) epochNotifierMock := mocks.NewEpochNotifier(t) - + bridgeL2SyncerMock := mocks.NewL2BridgeSyncer(t) + ctx, cancel := context.WithCancel(context.Background()) aggSender, err := New( - context.TODO(), + ctx, log.WithFields("test", "unittest"), - Config{}, + Config{ + StoragePath: "file::memory:?cache=shared", + }, AggLayerMock, nil, - nil, + bridgeL2SyncerMock, epochNotifierMock) require.NoError(t, err) require.NotNil(t, aggSender) + ch := make(chan aggsendertypes.EpochEvent) + epochNotifierMock.EXPECT().Subscribe("aggsender").Return(ch) + bridgeL2SyncerMock.EXPECT().GetLastProcessedBlock(mock.Anything).Return(uint64(0), nil) + go aggSender.Start(ctx) + ch <- aggsendertypes.EpochEvent{ + Epoch: 1, + } + time.Sleep(100 * time.Millisecond) + cancel() }