Skip to content

Commit

Permalink
Redo the test fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikiyer56 committed Nov 5, 2024
1 parent bec2299 commit d2dcc0f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion services/horizon/cmd/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ var ingestBuildStateCmd = &cobra.Command{
}

mngr := historyarchive.NewCheckpointManager(globalConfig.CheckpointFrequency)
if !mngr.IsCheckpoint(ingestBuildStateSequence) && ingestBuildStateSequence != 1 {
if !mngr.IsCheckpoint(ingestBuildStateSequence) {
return fmt.Errorf("`--sequence` must be a checkpoint ledger")
}

Expand Down
3 changes: 0 additions & 3 deletions services/horizon/internal/ingest/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ func (b buildState) run(s *system) (transition, error) {

// We don't need to prepare range for genesis checkpoint because we don't
// perform protocol version and bucket list hash checks.
// In the long term we should probably create artificial xdr.LedgerCloseMeta
// for ledger #1 instead of using `ingest.GenesisChange` reader in
// ProcessorRunner.RunHistoryArchiveIngestion().
// We can also skip preparing range if `skipChecks` is `true` because we
// won't need bucket list hash and protocol version.
var protocolVersion uint32
Expand Down
41 changes: 37 additions & 4 deletions services/horizon/internal/ingest/processor_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ingest
import (
"context"
"fmt"
"github.com/stellar/go/amount"
"io"
"reflect"
"testing"
Expand All @@ -29,14 +30,33 @@ func TestProcessorRunnerRunHistoryArchiveIngestionHistoryArchive(t *testing.T) {
q := &mockDBQ{}
defer mock.AssertExpectationsForObjects(t, q)
historyAdapter := &mockHistoryArchiveAdapter{}
defer mock.AssertExpectationsForObjects(t, historyAdapter)
defer mock.AssertExpectationsForObjects(t, historyAdapter) // this will fail

m := &ingest.MockChangeReader{}
m.On("Read").Return(ingest.Change{}, io.EOF).Once()
m.On("Close").Return(nil).Once()
bucketListHash := xdr.Hash([32]byte{0, 1, 2})
m.On("VerifyBucketList", bucketListHash).Return(nil).Once()

changeEntry := ingest.Change{
Type: xdr.LedgerEntryTypeAccount,
Post: &xdr.LedgerEntry{
LastModifiedLedgerSeq: 1,
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeAccount,
Account: &xdr.AccountEntry{
// Master account address from Ledger 1
AccountId: xdr.MustAddress("GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7"),
// 100B
Balance: amount.MustParse("100000000000"),
SeqNum: 0,
Thresholds: xdr.Thresholds{1, 0, 0, 0},
},
},
},
}
m.On("Read").Return(changeEntry, nil).Once()
m.On("Read").Return(ingest.Change{}, io.EOF).Once()

historyAdapter.
On("GetState", ctx, uint32(63)).
Return(
Expand All @@ -45,10 +65,23 @@ func TestProcessorRunnerRunHistoryArchiveIngestionHistoryArchive(t *testing.T) {
).Once()

batchBuilders := mockChangeProcessorBatchBuilders(q, ctx, true)
defer mock.AssertExpectationsForObjects(t, batchBuilders...)
defer mock.AssertExpectationsForObjects(t, batchBuilders...) // currently failing

assert.IsType(t, &history.MockAccountSignersBatchInsertBuilder{}, batchBuilders[0])
assert.IsType(t, &history.MockAccountsBatchInsertBuilder{}, batchBuilders[1])
batchBuilders[1].(*history.MockAccountsBatchInsertBuilder).On("Add", history.AccountEntry{
LastModifiedLedger: 1,
AccountID: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7",
Balance: int64(1000000000000000000),
SequenceNumber: 0,
MasterWeight: 1,
}).Return(nil).Once()

assert.IsType(t, &history.MockAccountSignersBatchInsertBuilder{}, batchBuilders[0])
batchBuilders[0].(*history.MockAccountSignersBatchInsertBuilder).On("Add", history.AccountSigner{
Account: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7",
Signer: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7",
Weight: 1,
}).Return(nil).Once()

q.MockQAssetStats.On("InsertAssetStats", ctx, []history.ExpAssetStat{}, 100000).
Return(nil)
Expand Down

0 comments on commit d2dcc0f

Please sign in to comment.