diff --git a/pkg/solana/logpoller/log_poller_test.go b/pkg/solana/logpoller/log_poller_test.go index 32ecc911e..324dae943 100644 --- a/pkg/solana/logpoller/log_poller_test.go +++ b/pkg/solana/logpoller/log_poller_test.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "encoding/json" "errors" + "fmt" "math/rand" "sync/atomic" "testing" @@ -350,3 +351,47 @@ func TestProcess(t *testing.T) { err = lp.UnregisterFilter(ctx, filter.Name) require.NoError(t, err) } + +func Test_LogPoller_Replay(t *testing.T) { + ctx := tests.Context(t) + fromBlock := int64(5) + + lp := newMockedLP(t) + assertReplayInfo := func(requestBlock int64, pending bool) { + assert.Equal(t, requestBlock, lp.LogPoller.replay.requestBlock) + assert.Equal(t, pending, lp.LogPoller.replay.pending) + } + + t.Run("ReplayInfo state initialized propery", func(t *testing.T) { + assertReplayInfo(NoNewReplayRequests, false) + }) + + t.Run("ordinary replay request", func(t *testing.T) { + lp.Filters.EXPECT().UpdateStartingBlocks(mock.Anything, fromBlock).Once().Return(nil) + err := lp.LogPoller.Replay(ctx, fromBlock) + require.NoError(t, err) + assertReplayInfo(fromBlock, false) + }) + + t.Run("redundant replay request", func(t *testing.T) { + err := lp.LogPoller.Replay(ctx, fromBlock) + require.NoError(t, err) + assertReplayInfo(fromBlock, false) + }) + + t.Run("replay request updated", func(t *testing.T) { + lp.Filters.EXPECT().UpdateStartingBlocks(mock.Anything, fromBlock-1).Once().Return(nil) + err := lp.LogPoller.Replay(ctx, fromBlock-1) + require.NoError(t, err) + assertReplayInfo(fromBlock-1, false) + }) + + t.Run("shouldn't update requestBlock if UpdateStartingBlocks fails", func(t *testing.T) { + expectedErr := fmt.Errorf("error") + lp.LogPoller.replay.requestBlock = NoNewReplayRequests + lp.Filters.EXPECT().UpdateStartingBlocks(mock.Anything, fromBlock-3).Once().Return(expectedErr) + err := lp.LogPoller.Replay(ctx, fromBlock-3) + assert.ErrorIs(t, err, expectedErr) + assertReplayInfo(NoNewReplayRequests, false) + }) +}