Skip to content

Commit

Permalink
fix engine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Gololicic committed Feb 21, 2024
1 parent 9078ceb commit 9d5b7dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 12 additions & 8 deletions services/ingestion/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func TestTransactionIngestion(t *testing.T) {

accounts := &storageMock.AccountIndexer{}
accounts.
On("Update").
Return(func() error { return nil })
On("Update", mock.AnythingOfType("*types.Transaction")).
Return(func(tx *gethTypes.Transaction) error { return nil })

eventsChan := make(chan flow.BlockEvents)
subscriber := &mocks.Subscriber{}
Expand All @@ -192,27 +192,29 @@ func TestTransactionIngestion(t *testing.T) {

engine := NewEventIngestionEngine(subscriber, blocks, receipts, transactions, accounts, zerolog.Nop())

done := make(chan struct{})
go func() {
err := engine.Start(context.Background())
require.NoError(t, err)
assert.ErrorIs(t, err, ErrDisconnected) // we disconnect at the end
close(done)
}()

txCdc, event, transaction, result, err := newTransaction()
require.NoError(t, err)

transactions.
On("Store", mock.AnythingOfType("*gethTypes.Transaction")).
On("Store", mock.AnythingOfType("*types.Transaction")).
Return(func(tx *gethTypes.Transaction) error {
assert.Equal(t, transaction, tx)
assert.Equal(t, transaction.Hash(), tx.Hash()) // if hashes are equal tx is equal
return nil
}).
Once()

receipts.
On("Store", mock.AnythingOfType("*gethTypes.Receipt")).
On("Store", mock.AnythingOfType("*types.Receipt")).
Return(func(rcp *gethTypes.Receipt) error {
assert.EqualValues(t, result.Logs, rcp.Logs)
assert.Equal(t, result.DeployedContractAddress, rcp.ContractAddress)
assert.Len(t, rcp.Logs, len(result.Logs))
assert.Equal(t, result.DeployedContractAddress.ToCommon().String(), rcp.ContractAddress.String())
return nil
}).
Once()
Expand All @@ -222,9 +224,11 @@ func TestTransactionIngestion(t *testing.T) {
Type: string(event.Etype),
Value: txCdc,
}},
Height: latestHeight + 1,
}

close(eventsChan)
<-done
// todo <-engine.Done()
}

Expand Down
1 change: 1 addition & 0 deletions storage/pebble/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestBlock(t *testing.T) {
blocks := NewBlocks(db)
err := blocks.InitCadenceHeight(1)
require.NoError(t, err)
_ = blocks.Store(2, mocks.NewBlock(1)) // init

bl, err := blocks.GetByHeight(11)
require.ErrorIs(t, err, errors.NotFound)
Expand Down

0 comments on commit 9d5b7dc

Please sign in to comment.