Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psheth9 committed Jun 3, 2024
1 parent 0a7e05a commit 9fa8c2a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
18 changes: 14 additions & 4 deletions cmd/soroban-rpc/internal/db/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/stellar/go/ingest"
"github.com/stellar/go/support/db"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/support/log"
"github.com/stellar/go/xdr"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/events"
Expand All @@ -29,12 +30,21 @@ type eventHandler struct {
ingestMetric, countMetric prometheus.Observer
}

func (eventHandler *eventHandler) InsertEvents(lcm xdr.LedgerCloseMeta) (err error) {
func (eventHandler *eventHandler) InsertEvents(lcm xdr.LedgerCloseMeta) error {
txCount := lcm.CountTransactions()

if eventHandler.stmtCache == nil {
return errors.New("EventWriter incorrectly initialized without stmtCache")
} else if txCount == 0 {
return nil
}

var txReader *ingest.LedgerTransactionReader
txReader, err = ingest.NewLedgerTransactionReaderFromLedgerCloseMeta(eventHandler.passphrase, lcm)
txReader, err := ingest.NewLedgerTransactionReaderFromLedgerCloseMeta(eventHandler.passphrase, lcm)
if err != nil {
return
return errors.Wrapf(err,
"failed to open transaction reader for ledger %d",
lcm.LedgerSequence())
}
defer func() {
closeErr := txReader.Close()
Expand All @@ -51,7 +61,7 @@ func (eventHandler *eventHandler) InsertEvents(lcm xdr.LedgerCloseMeta) (err err
break
}
if err != nil {
return
return err
}

if !tx.Result.Successful() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-rpc/internal/db/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ func TestInsertEvents(t *testing.T) {
EventType int `db:"event_type"`
}

query1 := sq.Select("*").From(fmt.Sprintf("%s", eventTableName))
err = db.Select(ctx, &rows, query1)
query := sq.Select("*").From(fmt.Sprintf("%s", eventTableName))
err = db.Select(ctx, &rows, query)

Check failure on line 177 in cmd/soroban-rpc/internal/db/event_test.go

View workflow job for this annotation

GitHub Actions / golangci

db.Select undefined (type *DB has no field or method Select) (typecheck)
assert.NoError(t, err)
assert.Equal(t, 10, len(rows))
}
5 changes: 5 additions & 0 deletions cmd/soroban-rpc/internal/ingest/mock_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type MockTx struct {
mock.Mock
}

func (m MockTx) EventWriter() db.EventWriter {
args := m.Called()

Check failure on line 40 in cmd/soroban-rpc/internal/ingest/mock_db_test.go

View workflow job for this annotation

GitHub Actions / golangci

m.Called undefined (type MockTx has no field or method Called) (typecheck)
return args.Get(0).(db.EventWriter)
}

func (m MockTx) LedgerEntryWriter() db.LedgerEntryWriter {
args := m.Called()
return args.Get(0).(db.LedgerEntryWriter)
Expand Down

0 comments on commit 9fa8c2a

Please sign in to comment.