Skip to content

Commit

Permalink
Fix test structures and mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Sep 12, 2022
1 parent b6028d9 commit 5289d48
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
19 changes: 11 additions & 8 deletions exp/lighthorizon/adapters/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/stellar/go/exp/lighthorizon/common"
"github.com/stellar/go/exp/lighthorizon/ingester"
"github.com/stellar/go/ingest"
"github.com/stellar/go/network"
protocol "github.com/stellar/go/protocols/horizon"
Expand Down Expand Up @@ -52,15 +53,17 @@ func TestTransactionAdapter(t *testing.T) {
closeTimestamp := expectedTx.LedgerCloseTime.UTC().Unix()

tx := common.Transaction{
LedgerTransaction: &ingest.LedgerTransaction{
Index: 0,
Envelope: txEnv,
Result: xdr.TransactionResultPair{
TransactionHash: xdr.Hash{},
Result: txResult,
LedgerTransaction: &ingester.LedgerTransaction{
LedgerTransaction: &ingest.LedgerTransaction{
Index: 0,
Envelope: txEnv,
Result: xdr.TransactionResultPair{
TransactionHash: xdr.Hash{},
Result: txResult,
},
FeeChanges: txFeeMeta,
UnsafeMeta: txMeta,
},
FeeChanges: txFeeMeta,
UnsafeMeta: txMeta,
},
LedgerHeader: &xdr.LedgerHeader{
LedgerSeq: xdr.Uint32(expectedTx.Ledger),
Expand Down
6 changes: 6 additions & 0 deletions exp/lighthorizon/ingester/mock_ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ingester
import (
"context"

"github.com/stellar/go/historyarchive"
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/mock"
)
Expand All @@ -28,6 +29,11 @@ func (m *MockIngester) GetLedger(ctx context.Context, sequence uint32) (xdr.Seri
return args.Get(0).(xdr.SerializedLedgerCloseMeta), args.Error(1)
}

func (m *MockIngester) PrepareRange(ctx context.Context, r historyarchive.Range) error {
args := m.Called(ctx, r)
return args.Error(0)
}

type MockLedgerTransactionReader struct {
mock.Mock
}
Expand Down
9 changes: 4 additions & 5 deletions exp/lighthorizon/services/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@ func mockArchiveAndIndex(ctx context.Context) (ingester.Ingester, index.Store) {
mockArchive.
On("NewLedgerTransactionReader", expectedLedger1).Return(mockReaderLedger1, nil).Once().
On("NewLedgerTransactionReader", expectedLedger2).Return(mockReaderLedger2, nil).Once().
On("NewLedgerTransactionReader", expectedLedger3).Return(mockReaderLedger3, nil).
On(
"NewLedgerTransactionReader",
mock.AnythingOfType("ingester.LedgerTransaction")).
Return(mockReaderLedgerTheRest, nil)
On("NewLedgerTransactionReader", expectedLedger3).Return(mockReaderLedger3, nil).Once().
On("NewLedgerTransactionReader", mock.AnythingOfType("xdr.SerializedLedgerCloseMeta")).
Return(mockReaderLedgerTheRest, nil).
On("PrepareRange", mock.Anything, mock.Anything).Return(nil)

// should be 24784
activeChk := uint32(index.GetCheckpointNumber(uint32(startLedgerSeq)))
Expand Down

0 comments on commit 5289d48

Please sign in to comment.