Skip to content

Commit

Permalink
Update Replay tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Apr 11, 2024
1 parent 682bbfb commit 4e434a9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions core/chains/evm/logpoller/log_poller_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ func TestLogPoller_BackupPollerStartup(t *testing.T) {
ec.On("HeadByNumber", mock.Anything, mock.Anything).Return(&head, nil)
ec.On("FilterLogs", mock.Anything, mock.Anything).Return([]types.Log{log1}, nil)
ec.On("ConfiguredChainID").Return(chainID, nil)
mockBatchCallContext(t, ec)

ctx := testutils.Context(t)
lpOpts := Opts{
Expand Down Expand Up @@ -297,11 +296,11 @@ func TestLogPoller_Replay(t *testing.T) {

ec := evmclimocks.NewClient(t)
ec.On("HeadByNumber", mock.Anything, mock.Anything).Return(&head, nil)
ec.On("FilterLogs", mock.Anything, mock.Anything).Return([]types.Log{log1}, nil).Twice()
ec.On("FilterLogs", mock.Anything, mock.Anything).Return([]types.Log{log1}, nil).Once()
ec.On("ConfiguredChainID").Return(chainID, nil)

lpOpts := Opts{
PollPeriod: time.Hour,
PollPeriod: time.Second,
FinalityDepth: 3,
BackfillBatchSize: 3,
RpcBatchSize: 3,
Expand Down Expand Up @@ -336,6 +335,7 @@ func TestLogPoller_Replay(t *testing.T) {

// Replay() should return error code received from replayComplete
t.Run("returns error code on replay complete", func(t *testing.T) {
ec.On("FilterLogs", mock.Anything, mock.Anything).Return([]types.Log{log1}, nil).Once()
mockBatchCallContext(t, ec)
anyErr := pkgerrors.New("any error")
done := make(chan struct{})
Expand Down Expand Up @@ -374,6 +374,7 @@ func TestLogPoller_Replay(t *testing.T) {
var wg sync.WaitGroup
defer func() { wg.Wait() }()
ec.On("FilterLogs", mock.Anything, mock.Anything).Once().Return([]types.Log{log1}, nil).Run(func(args mock.Arguments) {
head = evmtypes.Head{Number: 4}
wg.Add(1)
go func() {
defer wg.Done()
Expand All @@ -400,6 +401,7 @@ func TestLogPoller_Replay(t *testing.T) {

ec.On("FilterLogs", mock.Anything, mock.Anything).Return([]types.Log{log1}, nil).Maybe() // in case task gets delayed by >= 100ms

head = evmtypes.Head{Number: 5}
t.Cleanup(lp.reset)
servicetest.Run(t, lp)

Expand All @@ -424,6 +426,8 @@ func TestLogPoller_Replay(t *testing.T) {
ec.On("FilterLogs", mock.Anything, mock.Anything).Once().Return([]types.Log{log1}, nil).Run(func(args mock.Arguments) {
go func() {
defer close(done)

head = evmtypes.Head{Number: 4} // Restore latest block to 4, so this matches the fromBlock requested
select {
case lp.replayStart <- 4:
case <-ctx.Done():
Expand All @@ -434,9 +438,10 @@ func TestLogPoller_Replay(t *testing.T) {
lp.cancel()
close(pass)
})
ec.On("FilterLogs", mock.Anything, mock.Anything).Return([]types.Log{log1}, nil).Maybe() // in case task gets delayed by >= 100ms
ec.On("FilterLogs", mock.Anything, mock.Anything).Return([]types.Log{log1}, nil)

t.Cleanup(lp.reset)
head = evmtypes.Head{Number: 5} // Latest block must be > lastProcessed in order for SaveAndPollLogs() to call FilterLogs()
servicetest.Run(t, lp)

select {
Expand All @@ -449,6 +454,9 @@ func TestLogPoller_Replay(t *testing.T) {
// ReplayAsync should return as soon as replayStart is received
t.Run("ReplayAsync success", func(t *testing.T) {
t.Cleanup(lp.reset)
head = evmtypes.Head{Number: 5}
ec.On("FilterLogs", mock.Anything, mock.Anything).Return([]types.Log{log1}, nil)
mockBatchCallContext(t, ec)
servicetest.Run(t, lp)

lp.ReplayAsync(1)
Expand All @@ -459,6 +467,7 @@ func TestLogPoller_Replay(t *testing.T) {
t.Run("ReplayAsync error", func(t *testing.T) {
t.Cleanup(lp.reset)
servicetest.Run(t, lp)
head = evmtypes.Head{Number: 4}

anyErr := pkgerrors.New("async error")
observedLogs.TakeAll()
Expand Down Expand Up @@ -491,6 +500,9 @@ func TestLogPoller_Replay(t *testing.T) {
err = lp.orm.InsertBlock(ctx, head.Hash, head.Number, head.Timestamp, head.Number)
require.NoError(t, err)

ec.On("FilterLogs", mock.Anything, mock.Anything).Return([]types.Log{log1}, nil)
mockBatchCallContext(t, ec)

err = lp.Replay(ctx, 1)
require.NoError(t, err)
})
Expand Down

0 comments on commit 4e434a9

Please sign in to comment.