diff --git a/synchronizer/l2_sync/l2_shared/processor_trusted_batch_sync.go b/synchronizer/l2_sync/l2_shared/processor_trusted_batch_sync.go index e9f85b8a63..7bb1a326dc 100644 --- a/synchronizer/l2_sync/l2_shared/processor_trusted_batch_sync.go +++ b/synchronizer/l2_sync/l2_shared/processor_trusted_batch_sync.go @@ -218,7 +218,7 @@ func (s *ProcessorTrustedBatchSync) ExecuteProcessBatch(ctx context.Context, pro log.Debugf("%s is partially synchronized but we don't have intermediate stateRoot so it needs to be fully reprocessed", processMode.DebugPrefix) processBatchResp, err = s.Steps.ReProcess(ctx, processMode, dbTx) } - if processMode.BatchMustBeClosed { + if processBatchResp != nil && err == nil && processMode.BatchMustBeClosed { err = checkProcessBatchResultMatchExpected(processMode, processBatchResp.ProcessBatchResponse) if err != nil { log.Error("%s error verifying batch result! Error: ", processMode.DebugPrefix, err) diff --git a/synchronizer/l2_sync/l2_shared/tests/processor_trusted_batch_sync_test.go b/synchronizer/l2_sync/l2_shared/tests/processor_trusted_batch_sync_test.go index 5730dfad1b..1e96f58d2b 100644 --- a/synchronizer/l2_sync/l2_shared/tests/processor_trusted_batch_sync_test.go +++ b/synchronizer/l2_sync/l2_shared/tests/processor_trusted_batch_sync_test.go @@ -1,6 +1,8 @@ package test_l2_shared import ( + "context" + "errors" "testing" "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" @@ -9,6 +11,7 @@ import ( "github.com/0xPolygonHermez/zkevm-node/synchronizer/l2_sync/l2_shared" mock_l2_shared "github.com/0xPolygonHermez/zkevm-node/synchronizer/l2_sync/l2_shared/mocks" "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -321,3 +324,16 @@ func TestGetNextStatusUpdateExecutionResult(t *testing.T) { require.NoError(t, err) require.Equal(t, common.HexToHash("0x123"), newStatus.LastTrustedBatches[0].StateRoot) } + +func TestExecuteProcessBatchError(t *testing.T) { + testData := newTestDataForProcessorTrustedBatchSync(t) + + data := l2_shared.ProcessData{ + Mode: l2_shared.NothingProcessMode, + BatchMustBeClosed: true, + } + returnedError := errors.New("error") + testData.mockExecutor.EXPECT().NothingProcess(mock.Anything, mock.Anything, mock.Anything).Return(nil, returnedError) + _, err := testData.sut.ExecuteProcessBatch(context.Background(), &data, nil) + require.ErrorIs(t, returnedError, err) +}