From 2937c1803dd024bfec6e087403b3839f525df11d Mon Sep 17 00:00:00 2001 From: Shawn Reuland Date: Mon, 19 Aug 2024 23:26:56 -0700 Subject: [PATCH] #4538: use LedgerBackend interface for NewCaptive, fix unit tests that use catchup --- ingest/ledger_change_reader_test.go | 10 +- ingest/ledgerbackend/captive_core_backend.go | 17 +- .../captive_core_backend_test.go | 348 ++++++++++++++++-- ingest/ledgerbackend/mock_database_backend.go | 14 +- .../galexie/internal/exportmanager_test.go | 4 +- .../internal/ingest/build_state_test.go | 12 +- .../internal/ingest/db_integration_test.go | 4 +- .../ingest/ingest_history_range_state_test.go | 10 +- .../internal/ingest/resume_state_test.go | 12 +- .../ingest/verify_range_state_test.go | 4 +- 10 files changed, 364 insertions(+), 71 deletions(-) diff --git a/ingest/ledger_change_reader_test.go b/ingest/ledger_change_reader_test.go index 0b077007e5..8826ffa289 100644 --- a/ingest/ledger_change_reader_test.go +++ b/ingest/ledger_change_reader_test.go @@ -23,7 +23,7 @@ const ( func TestNewLedgerChangeReaderFails(t *testing.T) { ctx := context.Background() - mock := &ledgerbackend.MockDatabaseBackend{} + mock := &ledgerbackend.MockLedgerBackend{} seq := uint32(123) mock.On("GetLedger", ctx, seq).Return( xdr.LedgerCloseMeta{}, @@ -39,7 +39,7 @@ func TestNewLedgerChangeReaderFails(t *testing.T) { func TestNewLedgerChangeReaderSucceeds(t *testing.T) { ctx := context.Background() - mock := &ledgerbackend.MockDatabaseBackend{} + mock := &ledgerbackend.MockLedgerBackend{} seq := uint32(123) header := xdr.LedgerHeaderHistoryEntry{ @@ -146,7 +146,7 @@ func assertChangesEqual( func TestLedgerChangeReaderOrder(t *testing.T) { ctx := context.Background() - mock := &ledgerbackend.MockDatabaseBackend{} + mock := &ledgerbackend.MockLedgerBackend{} seq := uint32(123) src := xdr.MustAddress("GBXGQJWVLWOYHFLVTKWV5FGHA3LNYY2JQKM7OAJAUEQFU6LPCSEFVXON") @@ -353,7 +353,7 @@ func TestLedgerChangeReaderOrder(t *testing.T) { func TestLedgerChangeLedgerCloseMetaV2(t *testing.T) { ctx := context.Background() - mock := &ledgerbackend.MockDatabaseBackend{} + mock := &ledgerbackend.MockLedgerBackend{} seq := uint32(123) src := xdr.MustAddress("GBXGQJWVLWOYHFLVTKWV5FGHA3LNYY2JQKM7OAJAUEQFU6LPCSEFVXON") @@ -600,7 +600,7 @@ func TestLedgerChangeLedgerCloseMetaV2(t *testing.T) { func TestLedgerChangeLedgerCloseMetaV2Empty(t *testing.T) { ctx := context.Background() - mock := &ledgerbackend.MockDatabaseBackend{} + mock := &ledgerbackend.MockLedgerBackend{} seq := uint32(123) baseFee := xdr.Int64(100) diff --git a/ingest/ledgerbackend/captive_core_backend.go b/ingest/ledgerbackend/captive_core_backend.go index d759a53eb6..286f91c249 100644 --- a/ingest/ledgerbackend/captive_core_backend.go +++ b/ingest/ledgerbackend/captive_core_backend.go @@ -95,7 +95,8 @@ type CaptiveStellarCore struct { stellarCoreLock sync.RWMutex // For testing - stellarCoreRunnerFactory func() stellarCoreRunnerInterface + stellarCoreRunnerFactory func() stellarCoreRunnerInterface + trustedHashBackendFactory func(config CaptiveCoreConfig) (LedgerBackend, error) // cachedMeta keeps that ledger data of the last fetched ledger. Updated in GetLedger(). cachedMeta *xdr.LedgerCloseMeta @@ -163,7 +164,7 @@ type CaptiveCoreConfig struct { } // NewCaptive returns a new CaptiveStellarCore instance. -func NewCaptive(config CaptiveCoreConfig) (*CaptiveStellarCore, error) { +func NewCaptive(config CaptiveCoreConfig) (LedgerBackend, error) { // Here we set defaults in the config. Because config is not a pointer this code should // not mutate the original CaptiveCoreConfig instance which was passed into NewCaptive() @@ -233,6 +234,8 @@ func NewCaptive(config CaptiveCoreConfig) (*CaptiveStellarCore, error) { return newStellarCoreRunner(config) } + c.trustedHashBackendFactory = NewCaptive + if config.Toml != nil && config.Toml.HTTPPort != 0 { c.stellarCoreClient = &stellarcore.Client{ HTTP: &http.Client{ @@ -338,8 +341,8 @@ func (c *CaptiveStellarCore) getTrustedHashForLedger(sequence uint32) (uint32, s // first, direct from network which is considered trusted, after which the captive core instance is closed. captiveConfigTrustedHash := c.config captiveConfigTrustedHash.LedgerHashStore = nil - captiveConfigTrustedHash.Context = context.Background() - captiveTrustedHash, err := NewCaptive(captiveConfigTrustedHash) + captiveConfigTrustedHash.Context, _ = context.WithCancel(c.config.Context) + captiveTrustedHash, err := c.trustedHashBackendFactory(captiveConfigTrustedHash) if sequence <= 2 { // The line below is to support minimum edge case for streaming ledgers from core in run 'from' @@ -353,16 +356,16 @@ func (c *CaptiveStellarCore) getTrustedHashForLedger(sequence uint32) (uint32, s defer func() { if closeErr := captiveTrustedHash.Close(); closeErr != nil { - captiveTrustedHash.config.Log.Error("error when closing captive core for network hash", closeErr) + captiveConfigTrustedHash.Log.Error("error when closing captive core for network hash", closeErr) } }() - err = captiveTrustedHash.PrepareRange(captiveTrustedHash.config.Context, UnboundedRange(sequence)) + err = captiveTrustedHash.PrepareRange(captiveConfigTrustedHash.Context, UnboundedRange(sequence)) if err != nil { return 0, "", errors.Wrapf(err, "error preparing to get network hash for Ledger %v", sequence) } - networkLCM, err := captiveTrustedHash.GetLedger(captiveTrustedHash.config.Context, sequence) + networkLCM, err := captiveTrustedHash.GetLedger(captiveConfigTrustedHash.Context, sequence) if err != nil { return 0, "", errors.Wrapf(err, "error getting network hash for Ledger %v", sequence) } diff --git a/ingest/ledgerbackend/captive_core_backend_test.go b/ingest/ledgerbackend/captive_core_backend_test.go index 03aa7a0b1e..4f77b6762a 100644 --- a/ingest/ledgerbackend/captive_core_backend_test.go +++ b/ingest/ledgerbackend/captive_core_backend_test.go @@ -151,7 +151,7 @@ func TestCaptiveNew(t *testing.T) { networkPassphrase := network.PublicNetworkPassphrase historyURLs := []string{server.URL} - captiveStellarCore, err := NewCaptive( + captiveLedgerBackend, err := NewCaptive( CaptiveCoreConfig{ BinaryPath: executablePath, NetworkPassphrase: networkPassphrase, @@ -161,6 +161,7 @@ func TestCaptiveNew(t *testing.T) { CoreProtocolVersionFn: func(string) (uint, error) { return 21, nil }, }, ) + captiveStellarCore := captiveLedgerBackend.(*CaptiveStellarCore) assert.NoError(t, err) assert.Equal(t, uint32(0), captiveStellarCore.nextLedger) @@ -212,10 +213,25 @@ func TestCaptivePrepareRange(t *testing.T) { ctx := context.Background() mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(100), uint32(200)).Return(nil).Once() + mockRunner.On("catchup", uint32(100), uint32(200), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil).Once() mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) mockRunner.On("context").Return(ctx) + bounded := BoundedRange(100, 200) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(bounded.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + + mockLedgerBackend := &MockLedgerBackend{} mockArchive := &historyarchive.MockArchive{} mockArchive. On("GetRootHAS"). @@ -233,9 +249,18 @@ func TestCaptivePrepareRange(t *testing.T) { cancel: context.CancelFunc(func() { cancelCalled = true }), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(bounded.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, bounded.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - err := captiveBackend.PrepareRange(ctx, BoundedRange(100, 200)) + err := captiveBackend.PrepareRange(ctx, bounded) assert.NoError(t, err) mockRunner.On("close").Return(nil).Once() err = captiveBackend.Close() @@ -250,12 +275,27 @@ func TestCaptivePrepareRangeCrash(t *testing.T) { close(metaChan) ctx := context.Background() mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(100), uint32(200)).Return(nil).Once() + mockRunner.On("catchup", uint32(100), uint32(200), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil).Once() mockRunner.On("getProcessExitError").Return(errors.New("exit code -1"), true) mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) mockRunner.On("close").Return(nil).Once() mockRunner.On("context").Return(ctx) + bounded := BoundedRange(100, 200) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(bounded.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + mockArchive := &historyarchive.MockArchive{} mockArchive. On("GetRootHAS"). @@ -269,9 +309,18 @@ func TestCaptivePrepareRangeCrash(t *testing.T) { return mockRunner }, checkpointManager: historyarchive.NewCheckpointManager(64), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(bounded.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, bounded.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - err := captiveBackend.PrepareRange(ctx, BoundedRange(100, 200)) + err := captiveBackend.PrepareRange(ctx, bounded) assert.EqualError(t, err, "Error fast-forwarding to 100: stellar core exited unexpectedly: exit code -1") mockRunner.AssertExpectations(t) mockArchive.AssertExpectations(t) @@ -291,10 +340,25 @@ func TestCaptivePrepareRangeTerminated(t *testing.T) { close(metaChan) ctx := context.Background() mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(100), uint32(200)).Return(nil).Once() + mockRunner.On("catchup", uint32(100), uint32(200), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil).Once() mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) mockRunner.On("context").Return(ctx) + bounded := BoundedRange(100, 200) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(bounded.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + mockArchive := &historyarchive.MockArchive{} mockArchive. On("GetRootHAS"). @@ -308,9 +372,18 @@ func TestCaptivePrepareRangeTerminated(t *testing.T) { return mockRunner }, checkpointManager: historyarchive.NewCheckpointManager(64), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(bounded.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, bounded.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - err := captiveBackend.PrepareRange(ctx, BoundedRange(100, 200)) + err := captiveBackend.PrepareRange(ctx, bounded) assert.NoError(t, err) mockRunner.AssertExpectations(t) mockArchive.AssertExpectations(t) @@ -327,7 +400,7 @@ func TestCaptivePrepareRangeCloseNotFullyTerminated(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(100), uint32(200)).Return(nil).Twice() + mockRunner.On("catchup", uint32(100), uint32(200), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil).Twice() mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) mockRunner.On("context").Return(ctx) mockRunner.On("close").Return(nil) @@ -339,21 +412,45 @@ func TestCaptivePrepareRangeCloseNotFullyTerminated(t *testing.T) { CurrentLedger: uint32(200), }, nil) + bounded := BoundedRange(100, 200) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(bounded.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + captiveBackend := CaptiveStellarCore{ archive: mockArchive, stellarCoreRunnerFactory: func() stellarCoreRunnerInterface { return mockRunner }, checkpointManager: historyarchive.NewCheckpointManager(64), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(bounded.to)).Return(nil).Twice() + mockLedgerBackend.On("GetLedger", config.Context, bounded.to).Return(lcm, nil).Twice() + mockLedgerBackend.On("Close").Return(nil).Twice() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - err := captiveBackend.PrepareRange(ctx, BoundedRange(100, 200)) + err := captiveBackend.PrepareRange(ctx, bounded) assert.NoError(t, err) // Simulates a long (but graceful) shutdown... cancel() - err = captiveBackend.PrepareRange(ctx, BoundedRange(100, 200)) + err = captiveBackend.PrepareRange(ctx, bounded) assert.NoError(t, err) mockRunner.AssertExpectations(t) @@ -516,7 +613,7 @@ func TestCaptivePrepareRange_ToIsAheadOfRootHAS(t *testing.T) { func TestCaptivePrepareRange_ErrCatchup(t *testing.T) { mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(100), uint32(192)).Return(errors.New("transient error")).Once() + mockRunner.On("catchup", uint32(100), uint32(192), "0000000000000000000000000000000000000000000000000000000000000000").Return(errors.New("transient error")).Once() mockArchive := &historyarchive.MockArchive{} mockArchive. @@ -525,6 +622,21 @@ func TestCaptivePrepareRange_ErrCatchup(t *testing.T) { CurrentLedger: uint32(192), }, nil) + bounded := BoundedRange(100, 192) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(bounded.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + ctx := context.Background() cancelCalled := false captiveBackend := CaptiveStellarCore{ @@ -535,9 +647,18 @@ func TestCaptivePrepareRange_ErrCatchup(t *testing.T) { cancel: context.CancelFunc(func() { cancelCalled = true }), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(bounded.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, bounded.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - err := captiveBackend.PrepareRange(ctx, BoundedRange(100, 192)) + err := captiveBackend.PrepareRange(ctx, bounded) assert.EqualError(t, err, "error starting prepare range: opening subprocess: error running stellar-core: transient error") // make sure we can Close without errors @@ -763,7 +884,7 @@ func TestCaptiveGetLedger(t *testing.T) { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(65), uint32(66)).Return(nil) + mockRunner.On("catchup", uint32(65), uint32(66), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil) mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) mockRunner.On("context").Return(ctx) mockRunner.On("getProcessExitError").Return(nil, false) @@ -775,19 +896,42 @@ func TestCaptiveGetLedger(t *testing.T) { CurrentLedger: uint32(200), }, nil) + ledgerRange := BoundedRange(65, 66) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(ledgerRange.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + captiveBackend := CaptiveStellarCore{ archive: mockArchive, stellarCoreRunnerFactory: func() stellarCoreRunnerInterface { return mockRunner }, checkpointManager: historyarchive.NewCheckpointManager(64), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(ledgerRange.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, ledgerRange.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } // requires PrepareRange _, err := captiveBackend.GetLedger(ctx, 64) tt.EqualError(err, "session is not prepared, call PrepareRange first") - ledgerRange := BoundedRange(65, 66) tt.False(captiveBackend.isPrepared(ledgerRange), "core is not prepared until explicitly prepared") tt.False(captiveBackend.closed) err = captiveBackend.PrepareRange(ctx, ledgerRange) @@ -916,7 +1060,7 @@ func TestCaptiveGetLedger_NextLedgerIsDifferentToLedgerFromBuffer(t *testing.T) ctx := context.Background() mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(65), uint32(66)).Return(nil) + mockRunner.On("catchup", uint32(65), uint32(66), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil) mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) mockRunner.On("context").Return(ctx) mockRunner.On("close").Return(nil) @@ -928,15 +1072,39 @@ func TestCaptiveGetLedger_NextLedgerIsDifferentToLedgerFromBuffer(t *testing.T) CurrentLedger: uint32(200), }, nil) + ledgerRange := BoundedRange(65, 66) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(ledgerRange.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + captiveBackend := CaptiveStellarCore{ archive: mockArchive, stellarCoreRunnerFactory: func() stellarCoreRunnerInterface { return mockRunner }, checkpointManager: historyarchive.NewCheckpointManager(64), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(ledgerRange.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, ledgerRange.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - err := captiveBackend.PrepareRange(ctx, BoundedRange(65, 66)) + err := captiveBackend.PrepareRange(ctx, ledgerRange) assert.NoError(t, err) _, err = captiveBackend.GetLedger(ctx, 66) @@ -1011,7 +1179,7 @@ func TestCaptiveStellarCore_PrepareRangeAfterClose(t *testing.T) { captiveCoreToml, err := NewCaptiveCoreToml(CaptiveCoreTomlParams{}) assert.NoError(t, err) - captiveStellarCore, err := NewCaptive( + captiveLedgerBackend, err := NewCaptive( CaptiveCoreConfig{ BinaryPath: executablePath, NetworkPassphrase: networkPassphrase, @@ -1022,6 +1190,7 @@ func TestCaptiveStellarCore_PrepareRangeAfterClose(t *testing.T) { }, ) assert.NoError(t, err) + captiveStellarCore := captiveLedgerBackend.(*CaptiveStellarCore) assert.NoError(t, captiveStellarCore.Close()) @@ -1040,10 +1209,12 @@ func TestCaptiveStellarCore_PrepareRangeAfterClose(t *testing.T) { CurrentLedger: uint32(200), }, nil) captiveStellarCore.archive = mockArchive - assert.EqualError( + + assert.ErrorContains( t, captiveStellarCore.PrepareRange(ctx, BoundedRange(65, 66)), - "error starting prepare range: opening subprocess: error running stellar-core: context canceled", + "error calculating ledger and hash for stellar-core run: error getting latest checkpoint sequence: "+ + "error getting root HAS: Get \"http://localhost/.well-known/stellar-history.json\": context canceled", ) mockArchive.AssertExpectations(t) } @@ -1064,7 +1235,7 @@ func TestCaptiveGetLedger_ErrReadingMetaResult(t *testing.T) { ctx := context.Background() mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(65), uint32(66)).Return(nil) + mockRunner.On("catchup", uint32(65), uint32(66), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil) mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) ctx, cancel := context.WithCancel(ctx) mockRunner.On("context").Return(ctx) @@ -1081,15 +1252,39 @@ func TestCaptiveGetLedger_ErrReadingMetaResult(t *testing.T) { CurrentLedger: uint32(200), }, nil) + ledgerRange := BoundedRange(65, 66) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(ledgerRange.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + captiveBackend := CaptiveStellarCore{ archive: mockArchive, stellarCoreRunnerFactory: func() stellarCoreRunnerInterface { return mockRunner }, checkpointManager: historyarchive.NewCheckpointManager(64), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(ledgerRange.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, ledgerRange.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - err := captiveBackend.PrepareRange(ctx, BoundedRange(65, 66)) + err := captiveBackend.PrepareRange(ctx, ledgerRange) assert.NoError(t, err) meta, err := captiveBackend.GetLedger(ctx, 65) @@ -1122,7 +1317,7 @@ func TestCaptiveGetLedger_ErrClosingAfterLastLedger(t *testing.T) { ctx := context.Background() mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(65), uint32(66)).Return(nil) + mockRunner.On("catchup", uint32(65), uint32(66), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil) mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) mockRunner.On("context").Return(ctx) mockRunner.On("close").Return(fmt.Errorf("transient error")).Once() @@ -1134,15 +1329,39 @@ func TestCaptiveGetLedger_ErrClosingAfterLastLedger(t *testing.T) { CurrentLedger: uint32(200), }, nil) + ledgerRange := BoundedRange(65, 66) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(ledgerRange.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + captiveBackend := CaptiveStellarCore{ archive: mockArchive, stellarCoreRunnerFactory: func() stellarCoreRunnerInterface { return mockRunner }, checkpointManager: historyarchive.NewCheckpointManager(64), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(ledgerRange.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, ledgerRange.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - err := captiveBackend.PrepareRange(ctx, BoundedRange(65, 66)) + err := captiveBackend.PrepareRange(ctx, ledgerRange) assert.NoError(t, err) _, err = captiveBackend.GetLedger(ctx, 66) @@ -1164,7 +1383,7 @@ func TestCaptiveAfterClose(t *testing.T) { mockRunner := &stellarCoreRunnerMock{} ctx, cancel := context.WithCancel(context.Background()) - mockRunner.On("catchup", uint32(65), uint32(66)).Return(nil) + mockRunner.On("catchup", uint32(65), uint32(66), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil) mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) mockRunner.On("context").Return(ctx) mockRunner.On("close").Return(nil).Once() @@ -1176,6 +1395,21 @@ func TestCaptiveAfterClose(t *testing.T) { CurrentLedger: uint32(200), }, nil) + boundedRange := BoundedRange(65, 66) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(boundedRange.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + captiveBackend := CaptiveStellarCore{ archive: mockArchive, stellarCoreRunnerFactory: func() stellarCoreRunnerInterface { @@ -1183,9 +1417,17 @@ func TestCaptiveAfterClose(t *testing.T) { }, checkpointManager: historyarchive.NewCheckpointManager(64), cancel: cancel, + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(boundedRange.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, boundedRange.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - boundedRange := BoundedRange(65, 66) err := captiveBackend.PrepareRange(ctx, boundedRange) assert.NoError(t, err) @@ -1219,7 +1461,7 @@ func TestGetLedgerBoundsCheck(t *testing.T) { ctx := context.Background() mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(128), uint32(130)).Return(nil).Once() + mockRunner.On("catchup", uint32(128), uint32(130), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil).Once() mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) mockRunner.On("context").Return(ctx) @@ -1230,15 +1472,39 @@ func TestGetLedgerBoundsCheck(t *testing.T) { CurrentLedger: uint32(200), }, nil) + boundedRange := BoundedRange(128, 130) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(boundedRange.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + captiveBackend := CaptiveStellarCore{ archive: mockArchive, stellarCoreRunnerFactory: func() stellarCoreRunnerInterface { return mockRunner }, checkpointManager: historyarchive.NewCheckpointManager(64), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(boundedRange.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, boundedRange.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - err := captiveBackend.PrepareRange(ctx, BoundedRange(128, 130)) + err := captiveBackend.PrepareRange(ctx, boundedRange) assert.NoError(t, err) meta, err := captiveBackend.GetLedger(ctx, 128) @@ -1343,7 +1609,7 @@ func TestCaptiveGetLedgerTerminatedUnexpectedly(t *testing.T) { ctx := testCase.ctx mockRunner := &stellarCoreRunnerMock{} - mockRunner.On("catchup", uint32(64), uint32(100)).Return(nil).Once() + mockRunner.On("catchup", uint32(64), uint32(100), "0000000000000000000000000000000000000000000000000000000000000000").Return(nil).Once() mockRunner.On("getMetaPipe").Return((<-chan metaResult)(metaChan), true) mockRunner.On("context").Return(ctx) mockRunner.On("getProcessExitError").Return(testCase.processExitedError, testCase.processExited) @@ -1356,15 +1622,39 @@ func TestCaptiveGetLedgerTerminatedUnexpectedly(t *testing.T) { CurrentLedger: uint32(200), }, nil) + boundedRange := BoundedRange(64, 100) + lcm := xdr.LedgerCloseMeta{ + V: 0, + V0: &xdr.LedgerCloseMetaV0{ + LedgerHeader: xdr.LedgerHeaderHistoryEntry{ + Hash: xdr.Hash{}, + Header: xdr.LedgerHeader{ + LedgerSeq: xdr.Uint32(boundedRange.to), + PreviousLedgerHash: xdr.Hash{}, + }, + }, + }, + } + mockLedgerBackend := &MockLedgerBackend{} + captiveBackend := CaptiveStellarCore{ archive: mockArchive, stellarCoreRunnerFactory: func() stellarCoreRunnerInterface { return mockRunner }, checkpointManager: historyarchive.NewCheckpointManager(64), + trustedHashBackendFactory: func(config CaptiveCoreConfig) (LedgerBackend, error) { + mockLedgerBackend.On("PrepareRange", config.Context, UnboundedRange(boundedRange.to)).Return(nil).Once() + mockLedgerBackend.On("GetLedger", config.Context, boundedRange.to).Return(lcm, nil).Once() + mockLedgerBackend.On("Close").Return(nil).Once() + return mockLedgerBackend, nil + }, + config: CaptiveCoreConfig{ + Context: ctx, + }, } - err := captiveBackend.PrepareRange(ctx, BoundedRange(64, 100)) + err := captiveBackend.PrepareRange(ctx, boundedRange) assert.NoError(t, err) meta, err := captiveBackend.GetLedger(ctx, 64) diff --git a/ingest/ledgerbackend/mock_database_backend.go b/ingest/ledgerbackend/mock_database_backend.go index c5f85ecef7..591309eb9b 100644 --- a/ingest/ledgerbackend/mock_database_backend.go +++ b/ingest/ledgerbackend/mock_database_backend.go @@ -8,33 +8,33 @@ import ( "github.com/stellar/go/xdr" ) -var _ LedgerBackend = (*MockDatabaseBackend)(nil) +var _ LedgerBackend = (*MockLedgerBackend)(nil) -type MockDatabaseBackend struct { +type MockLedgerBackend struct { mock.Mock } -func (m *MockDatabaseBackend) GetLatestLedgerSequence(ctx context.Context) (uint32, error) { +func (m *MockLedgerBackend) GetLatestLedgerSequence(ctx context.Context) (uint32, error) { args := m.Called(ctx) return args.Get(0).(uint32), args.Error(1) } -func (m *MockDatabaseBackend) PrepareRange(ctx context.Context, ledgerRange Range) error { +func (m *MockLedgerBackend) PrepareRange(ctx context.Context, ledgerRange Range) error { args := m.Called(ctx, ledgerRange) return args.Error(0) } -func (m *MockDatabaseBackend) IsPrepared(ctx context.Context, ledgerRange Range) (bool, error) { +func (m *MockLedgerBackend) IsPrepared(ctx context.Context, ledgerRange Range) (bool, error) { args := m.Called(ctx, ledgerRange) return args.Bool(0), args.Error(1) } -func (m *MockDatabaseBackend) GetLedger(ctx context.Context, sequence uint32) (xdr.LedgerCloseMeta, error) { +func (m *MockLedgerBackend) GetLedger(ctx context.Context, sequence uint32) (xdr.LedgerCloseMeta, error) { args := m.Called(ctx, sequence) return args.Get(0).(xdr.LedgerCloseMeta), args.Error(1) } -func (m *MockDatabaseBackend) Close() error { +func (m *MockLedgerBackend) Close() error { args := m.Called() return args.Error(0) } diff --git a/services/galexie/internal/exportmanager_test.go b/services/galexie/internal/exportmanager_test.go index 08829a8f8e..0ad573a0ee 100644 --- a/services/galexie/internal/exportmanager_test.go +++ b/services/galexie/internal/exportmanager_test.go @@ -46,12 +46,12 @@ func TestExporterSuite(t *testing.T) { type ExportManagerSuite struct { suite.Suite ctx context.Context - mockBackend ledgerbackend.MockDatabaseBackend + mockBackend ledgerbackend.MockLedgerBackend } func (s *ExportManagerSuite) SetupTest() { s.ctx = context.Background() - s.mockBackend = ledgerbackend.MockDatabaseBackend{} + s.mockBackend = ledgerbackend.MockLedgerBackend{} } func (s *ExportManagerSuite) TearDownTest() { diff --git a/services/horizon/internal/ingest/build_state_test.go b/services/horizon/internal/ingest/build_state_test.go index d1409182d9..473da03776 100644 --- a/services/horizon/internal/ingest/build_state_test.go +++ b/services/horizon/internal/ingest/build_state_test.go @@ -22,7 +22,7 @@ type BuildStateTestSuite struct { ctx context.Context historyQ *mockDBQ historyAdapter *mockHistoryArchiveAdapter - ledgerBackend *ledgerbackend.MockDatabaseBackend + ledgerBackend *ledgerbackend.MockLedgerBackend system *system runner *mockProcessorsRunner stellarCoreClient *mockStellarCoreClient @@ -35,7 +35,7 @@ func (s *BuildStateTestSuite) SetupTest() { s.historyQ = &mockDBQ{} s.runner = &mockProcessorsRunner{} s.historyAdapter = &mockHistoryArchiveAdapter{} - s.ledgerBackend = &ledgerbackend.MockDatabaseBackend{} + s.ledgerBackend = &ledgerbackend.MockLedgerBackend{} s.stellarCoreClient = &mockStellarCoreClient{} s.checkpointLedger = uint32(63) s.lastLedger = 0 @@ -87,7 +87,7 @@ func (s *BuildStateTestSuite) mockCommonHistoryQ() { func (s *BuildStateTestSuite) TestCheckPointLedgerIsZero() { // Recreate mock in this single test to remove assertions. *s.historyQ = mockDBQ{} - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} next, err := buildState{checkpointLedger: 0}.run(s.system) s.Assert().Error(err) @@ -98,7 +98,7 @@ func (s *BuildStateTestSuite) TestCheckPointLedgerIsZero() { func (s *BuildStateTestSuite) TestRangeNotPreparedFailPrepare() { // Recreate mock in this single test to remove assertions. *s.historyQ = mockDBQ{} - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} s.ledgerBackend.On("IsPrepared", s.ctx, ledgerbackend.UnboundedRange(63)).Return(false, nil).Once() s.ledgerBackend.On("PrepareRange", s.ctx, ledgerbackend.UnboundedRange(63)).Return(errors.New("my error")).Once() @@ -113,7 +113,7 @@ func (s *BuildStateTestSuite) TestRangeNotPreparedFailPrepare() { func (s *BuildStateTestSuite) TestRangeNotPreparedSuccessPrepareGetLedgerFail() { // Recreate mock in this single test to remove assertions. *s.historyQ = mockDBQ{} - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} s.ledgerBackend.On("IsPrepared", s.ctx, ledgerbackend.UnboundedRange(63)).Return(false, nil).Once() s.ledgerBackend.On("PrepareRange", s.ctx, ledgerbackend.UnboundedRange(63)).Return(nil).Once() @@ -218,7 +218,7 @@ func (s *BuildStateTestSuite) TestRunHistoryArchiveIngestionReturnsError() { func (s *BuildStateTestSuite) TestRunHistoryArchiveIngestionGenesisReturnsError() { // Recreate mock in this single test to remove assertions. - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} s.historyQ.On("GetLastLedgerIngest", s.ctx).Return(uint32(0), nil).Once() s.historyQ.On("GetIngestVersion", s.ctx).Return(CurrentVersion, nil).Once() diff --git a/services/horizon/internal/ingest/db_integration_test.go b/services/horizon/internal/ingest/db_integration_test.go index 0ac6e9d796..d8fd19c763 100644 --- a/services/horizon/internal/ingest/db_integration_test.go +++ b/services/horizon/internal/ingest/db_integration_test.go @@ -82,7 +82,7 @@ type DBTestSuite struct { sampleFile string sequence uint32 checkpointHash xdr.Hash - ledgerBackend *ledgerbackend.MockDatabaseBackend + ledgerBackend *ledgerbackend.MockLedgerBackend historyAdapter *mockHistoryArchiveAdapter system *system tt *test.T @@ -98,7 +98,7 @@ func (s *DBTestSuite) SetupTest() { // and commit the new file to the git repo. s.sampleFile = filepath.Join("testdata", "sample-changes.xdr") s.checkpointHash = xdr.Hash{1, 2, 3} - s.ledgerBackend = &ledgerbackend.MockDatabaseBackend{} + s.ledgerBackend = &ledgerbackend.MockLedgerBackend{} s.historyAdapter = &mockHistoryArchiveAdapter{} var err error diff --git a/services/horizon/internal/ingest/ingest_history_range_state_test.go b/services/horizon/internal/ingest/ingest_history_range_state_test.go index ce63151fb4..379a59b329 100644 --- a/services/horizon/internal/ingest/ingest_history_range_state_test.go +++ b/services/horizon/internal/ingest/ingest_history_range_state_test.go @@ -24,7 +24,7 @@ type IngestHistoryRangeStateTestSuite struct { ctx context.Context historyQ *mockDBQ historyAdapter *mockHistoryArchiveAdapter - ledgerBackend *ledgerbackend.MockDatabaseBackend + ledgerBackend *ledgerbackend.MockLedgerBackend runner *mockProcessorsRunner system *system } @@ -32,7 +32,7 @@ type IngestHistoryRangeStateTestSuite struct { func (s *IngestHistoryRangeStateTestSuite) SetupTest() { s.ctx = context.Background() s.historyQ = &mockDBQ{} - s.ledgerBackend = &ledgerbackend.MockDatabaseBackend{} + s.ledgerBackend = &ledgerbackend.MockLedgerBackend{} s.historyAdapter = &mockHistoryArchiveAdapter{} s.runner = &mockProcessorsRunner{} s.system = &system{ @@ -57,7 +57,7 @@ func (s *IngestHistoryRangeStateTestSuite) TearDownTest() { } func (s *IngestHistoryRangeStateTestSuite) TestHistoryRangeInvalidRange() { - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} next, err := historyRangeState{fromLedger: 0, toLedger: 0}.run(s.system) s.Assert().Error(err) @@ -81,7 +81,7 @@ func (s *IngestHistoryRangeStateTestSuite) TestHistoryRangeInvalidRange() { } func (s *IngestHistoryRangeStateTestSuite) TestHistoryRangeInvalidMaxFlush() { - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} s.system.maxLedgerPerFlush = 0 next, err := historyRangeState{fromLedger: 100, toLedger: 200}.run(s.system) @@ -91,7 +91,7 @@ func (s *IngestHistoryRangeStateTestSuite) TestHistoryRangeInvalidMaxFlush() { } func (s *IngestHistoryRangeStateTestSuite) TestHistoryRangeFailPrepare() { - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} s.ledgerBackend.On("IsPrepared", s.ctx, ledgerbackend.UnboundedRange(100)).Return(false, nil).Once() s.ledgerBackend.On("PrepareRange", s.ctx, ledgerbackend.UnboundedRange(100)).Return(errors.New("my error")).Once() diff --git a/services/horizon/internal/ingest/resume_state_test.go b/services/horizon/internal/ingest/resume_state_test.go index feb5e13bb0..0afc0cc527 100644 --- a/services/horizon/internal/ingest/resume_state_test.go +++ b/services/horizon/internal/ingest/resume_state_test.go @@ -22,7 +22,7 @@ func TestResumeTestTestSuite(t *testing.T) { type ResumeTestTestSuite struct { suite.Suite ctx context.Context - ledgerBackend *ledgerbackend.MockDatabaseBackend + ledgerBackend *ledgerbackend.MockLedgerBackend historyQ *mockDBQ historyAdapter *mockHistoryArchiveAdapter runner *mockProcessorsRunner @@ -32,7 +32,7 @@ type ResumeTestTestSuite struct { func (s *ResumeTestTestSuite) SetupTest() { s.ctx = context.Background() - s.ledgerBackend = &ledgerbackend.MockDatabaseBackend{} + s.ledgerBackend = &ledgerbackend.MockLedgerBackend{} s.historyQ = &mockDBQ{} s.historyAdapter = &mockHistoryArchiveAdapter{} s.runner = &mockProcessorsRunner{} @@ -78,7 +78,7 @@ func (s *ResumeTestTestSuite) TearDownTest() { func (s *ResumeTestTestSuite) TestInvalidParam() { // Recreate mock in this single test to remove Rollback assertion. *s.historyQ = mockDBQ{} - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} next, err := resumeState{latestSuccessfullyProcessedLedger: 0}.run(s.system) s.Assert().Error(err) @@ -92,7 +92,7 @@ func (s *ResumeTestTestSuite) TestInvalidParam() { func (s *ResumeTestTestSuite) TestRangeNotPreparedFailPrepare() { // Recreate mock in this single test to remove Rollback assertion. *s.historyQ = mockDBQ{} - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} s.ledgerBackend.On("IsPrepared", s.ctx, ledgerbackend.UnboundedRange(101)).Return(false, nil).Once() s.ledgerBackend.On("PrepareRange", s.ctx, ledgerbackend.UnboundedRange(101)).Return(errors.New("my error")).Once() @@ -109,7 +109,7 @@ func (s *ResumeTestTestSuite) TestRangeNotPreparedFailPrepare() { func (s *ResumeTestTestSuite) TestRangeNotPreparedSuccessPrepareGetLedgerFail() { // Recreate mock in this single test to remove Rollback assertion. *s.historyQ = mockDBQ{} - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} s.ledgerBackend.On("IsPrepared", s.ctx, ledgerbackend.UnboundedRange(101)).Return(false, nil).Once() s.ledgerBackend.On("PrepareRange", s.ctx, ledgerbackend.UnboundedRange(101)).Return(nil).Once() @@ -286,7 +286,7 @@ func (s *ResumeTestTestSuite) mockSuccessfulIngestion() { s.historyQ.On("GetExpStateInvalid", s.ctx).Return(false, nil).Once() } func (s *ResumeTestTestSuite) TestBumpIngestLedger() { - *s.ledgerBackend = ledgerbackend.MockDatabaseBackend{} + *s.ledgerBackend = ledgerbackend.MockLedgerBackend{} s.ledgerBackend.On("IsPrepared", s.ctx, ledgerbackend.UnboundedRange(100)).Return(false, nil).Once() s.ledgerBackend.On("PrepareRange", s.ctx, ledgerbackend.UnboundedRange(100)).Return(nil).Once() diff --git a/services/horizon/internal/ingest/verify_range_state_test.go b/services/horizon/internal/ingest/verify_range_state_test.go index a1df30d854..45484bb0cb 100644 --- a/services/horizon/internal/ingest/verify_range_state_test.go +++ b/services/horizon/internal/ingest/verify_range_state_test.go @@ -32,7 +32,7 @@ func TestVerifyRangeStateTestSuite(t *testing.T) { type VerifyRangeStateTestSuite struct { suite.Suite ctx context.Context - ledgerBackend *ledgerbackend.MockDatabaseBackend + ledgerBackend *ledgerbackend.MockLedgerBackend historyQ *mockDBQ historyAdapter *mockHistoryArchiveAdapter runner *mockProcessorsRunner @@ -41,7 +41,7 @@ type VerifyRangeStateTestSuite struct { func (s *VerifyRangeStateTestSuite) SetupTest() { s.ctx = context.Background() - s.ledgerBackend = &ledgerbackend.MockDatabaseBackend{} + s.ledgerBackend = &ledgerbackend.MockLedgerBackend{} s.historyQ = &mockDBQ{} s.historyAdapter = &mockHistoryArchiveAdapter{} s.runner = &mockProcessorsRunner{}