Skip to content

Commit

Permalink
make test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Nov 18, 2024
1 parent 1721e13 commit bd7c9ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/solana/logpoller/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (c *EncodedLogCollector) BackfillForAddress(ctx context.Context, address st
lowestSlotSig solana.Signature
)

for lowestSlotRead > fromSlot {
for lowestSlotRead > fromSlot || lowestSlotRead == 0 {
opts := rpc.GetSignaturesForAddressOpts{
Commitment: rpc.CommitmentFinalized,
MinContextSlot: &fromSlot,
Expand All @@ -115,7 +115,7 @@ func (c *EncodedLogCollector) BackfillForAddress(ctx context.Context, address st
var newSigsFound bool

for _, sig := range sigs {
if sig.Slot < lowestSlotRead {
if sig.Slot < lowestSlotRead || lowestSlotRead == 0 {
lowestSlotRead = sig.Slot
lowestSlotSig = sig.Signature
}
Expand Down
19 changes: 14 additions & 5 deletions pkg/solana/logpoller/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package logpoller_test

import (
"context"
"math/rand/v2"
"crypto/rand"
"sync"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -103,8 +103,7 @@ func TestEncodedLogCollector_BackfillForAddress(t *testing.T) {

pubKey := solana.PublicKey{2, 1, 4, 2}
slots := []uint64{42, 43, 44}
blockHeights := []uint64{21, 22, 23}
sig := solana.Signature{2, 1, 4, 2}
blockHeights := []uint64{21, 22, 23, 50}

client.EXPECT().GetSignaturesForAddressWithOpts(mock.Anything, pubKey, mock.Anything).Return([]*rpc.TransactionSignature{
{Slot: slots[0]},
Expand All @@ -113,6 +112,14 @@ func TestEncodedLogCollector_BackfillForAddress(t *testing.T) {
}, nil)

for idx := range len(slots) {
var (
sig1 solana.Signature
sig2 solana.Signature
)

_, _ = rand.Read(sig1[:])
_, _ = rand.Read(sig2[:])

client.EXPECT().GetBlockWithOpts(mock.Anything, slots[idx], mock.Anything).Return(&rpc.GetBlockResult{
Transactions: []rpc.TransactionWithMeta{
{
Expand All @@ -126,7 +133,7 @@ func TestEncodedLogCollector_BackfillForAddress(t *testing.T) {
},
},
},
Signatures: []solana.Signature{sig, sig},
Signatures: []solana.Signature{sig1, sig2},
BlockHeight: &blockHeights[idx],
}, nil).Twice()
}
Expand Down Expand Up @@ -206,7 +213,9 @@ func (p *testBlockProducer) makeEvent() {
p.mu.Lock()
defer p.mu.Unlock()

sig := solana.Signature{byte(rand.Int64())}
var sig solana.Signature

_, _ = rand.Read(sig[:])

p.blockSigs[p.nextSlot] = append(p.blockSigs[p.nextSlot], sig)
p.sigs[sig.String()] = true
Expand Down

0 comments on commit bd7c9ed

Please sign in to comment.