Skip to content

Commit

Permalink
Add Replay tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Feb 13, 2025
1 parent fce7c2b commit a95e491
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/solana/logpoller/log_poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"math/rand"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -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)
})
}

0 comments on commit a95e491

Please sign in to comment.