Skip to content

Commit

Permalink
Update loader tests for interface
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Dec 12, 2024
1 parent 7dd0e72 commit 01c14d8
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions pkg/solana/logpoller/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ func TestEncodedLogCollector_ParseSingleEvent(t *testing.T) {
latest.Store(uint64(40))

client.EXPECT().
GetLatestBlockhash(mock.Anything, rpc.CommitmentFinalized).
LatestBlockhash(mock.Anything).
RunAndReturn(latestBlockhashReturnFunc(&latest))

client.EXPECT().
GetBlocks(
mock.Anything,
mock.MatchedBy(getBlocksStartValMatcher),
mock.MatchedBy(getBlocksEndValMatcher(&latest)),
rpc.CommitmentFinalized,
).
RunAndReturn(getBlocksReturnFunc(false))

Expand Down Expand Up @@ -138,15 +137,14 @@ func TestEncodedLogCollector_MultipleEventOrdered(t *testing.T) {
}

client.EXPECT().
GetLatestBlockhash(mock.Anything, rpc.CommitmentFinalized).
LatestBlockhash(mock.Anything).
RunAndReturn(latestBlockhashReturnFunc(&latest))

client.EXPECT().
GetBlocks(
mock.Anything,
mock.MatchedBy(getBlocksStartValMatcher),
mock.MatchedBy(getBlocksEndValMatcher(&latest)),
rpc.CommitmentFinalized,
).
RunAndReturn(getBlocksReturnFunc(false))

Expand Down Expand Up @@ -255,7 +253,7 @@ func TestEncodedLogCollector_BackfillForAddress(t *testing.T) {

// GetLatestBlockhash might be called at start-up; make it take some time because the result isn't needed for this test
client.EXPECT().
GetLatestBlockhash(mock.Anything, rpc.CommitmentFinalized).
LatestBlockhash(mock.Anything).
RunAndReturn(latestBlockhashReturnFunc(&latest)).
After(2 * time.Second).
Maybe()
Expand All @@ -265,7 +263,6 @@ func TestEncodedLogCollector_BackfillForAddress(t *testing.T) {
mock.Anything,
mock.MatchedBy(getBlocksStartValMatcher),
mock.MatchedBy(getBlocksEndValMatcher(&latest)),
rpc.CommitmentFinalized,
).
RunAndReturn(getBlocksReturnFunc(true))

Expand Down Expand Up @@ -412,7 +409,7 @@ func (p *testBlockProducer) Count() uint64 {
return p.count
}

func (p *testBlockProducer) GetLatestBlockhash(_ context.Context, _ rpc.CommitmentType) (out *rpc.GetLatestBlockhashResult, err error) {
func (p *testBlockProducer) LatestBlockhash(_ context.Context) (out *rpc.GetLatestBlockhashResult, err error) {
p.b.Helper()

p.mu.Lock()
Expand All @@ -431,7 +428,7 @@ func (p *testBlockProducer) GetLatestBlockhash(_ context.Context, _ rpc.Commitme
}, nil
}

func (p *testBlockProducer) GetBlocks(_ context.Context, startSlot uint64, endSlot *uint64, _ rpc.CommitmentType) (out rpc.BlocksResult, err error) {
func (p *testBlockProducer) GetBlocks(_ context.Context, startSlot uint64, endSlot *uint64) (out rpc.BlocksResult, err error) {
p.b.Helper()

p.mu.Lock()
Expand All @@ -443,7 +440,7 @@ func (p *testBlockProducer) GetBlocks(_ context.Context, startSlot uint64, endSl
blocks[idx] = startSlot + uint64(idx)
}

return rpc.BlocksResult(blocks), nil
return blocks, nil
}

func (p *testBlockProducer) GetBlockWithOpts(_ context.Context, block uint64, opts *rpc.GetBlockOpts) (*rpc.GetBlockResult, error) {
Expand Down Expand Up @@ -546,8 +543,8 @@ func (p *testParser) Events() []logpoller.ProgramEvent {
return p.events
}

func latestBlockhashReturnFunc(latest *atomic.Uint64) func(context.Context, rpc.CommitmentType) (*rpc.GetLatestBlockhashResult, error) {
return func(ctx context.Context, ct rpc.CommitmentType) (*rpc.GetLatestBlockhashResult, error) {
func latestBlockhashReturnFunc(latest *atomic.Uint64) func(context.Context) (*rpc.GetLatestBlockhashResult, error) {
return func(ctx context.Context) (*rpc.GetLatestBlockhashResult, error) {
defer func() {
latest.Store(latest.Load() + 2)
}()
Expand All @@ -565,8 +562,8 @@ func latestBlockhashReturnFunc(latest *atomic.Uint64) func(context.Context, rpc.
}
}

func getBlocksReturnFunc(empty bool) func(context.Context, uint64, *uint64, rpc.CommitmentType) (rpc.BlocksResult, error) {
return func(_ context.Context, u1 uint64, u2 *uint64, _ rpc.CommitmentType) (rpc.BlocksResult, error) {
func getBlocksReturnFunc(empty bool) func(context.Context, uint64, *uint64) (rpc.BlocksResult, error) {
return func(_ context.Context, u1 uint64, u2 *uint64) (rpc.BlocksResult, error) {
blocks := []uint64{}

if !empty {
Expand All @@ -576,7 +573,7 @@ func getBlocksReturnFunc(empty bool) func(context.Context, uint64, *uint64, rpc.
}
}

return rpc.BlocksResult(blocks), nil
return blocks, nil
}
}

Expand Down

0 comments on commit 01c14d8

Please sign in to comment.