Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Fix flaxy tests #108

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions integration_test/contract_watcher_header_sync_transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,18 @@ var _ = Describe("contractWatcher headerSync transformer", func() {
c, ok := t.Contracts[tusdAddr]
Expect(ok).To(Equal(true))

// TODO: Fix this
// This test sometimes randomly fails because
// for some reason the starting block number is not updated from
// its original value (5197514) to the block number (6194632)
// of the earliest header (mocks.MockHeader1) in the repository
// It is not clear how this happens without one of the above insertErrs
// having been thrown and without any errors thrown during the Init() call
Expect(c.StartingBlock).To(Equal(int64(6194632)))
Expect(c.Abi).To(Equal(constants.TusdAbiString))
Expect(c.Name).To(Equal("TrueUSD"))
Expect(c.Address).To(Equal(tusdAddr))
Eventually(func() int64 {
return c.StartingBlock
}).Should(Equal(int64(6194632)))
Eventually(func() string {
return c.Abi
}).Should(Equal(constants.TusdAbiString))
Eventually(func() string {
return c.Name
}).Should(Equal("TrueUSD"))
Eventually(func() string {
return c.Address
}).Should(Equal(tusdAddr))
})

It("Fails to initialize if first and block cannot be fetched from vDB headers table", func() {
Expand Down
7 changes: 6 additions & 1 deletion integration_test/geth_blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ var _ = Describe("Reading from the Geth blockchain", func() {
_, err = history.RetrieveAndUpdateBlocks(blockChain, blocks, queriedBlocks)
Expect(err).NotTo(HaveOccurred())

blocks.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(2, []int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6})
Eventually(func() int {
return blocks.CreateOrUpdateBlockCallCount
}).Should(Equal(2))
Eventually(func() []int64 {
return blocks.CreateOrUpdateBlockPassedBlockNumbers
}).Should(Equal([]int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6}))
close(done)
}, 30)

Expand Down
79 changes: 21 additions & 58 deletions pkg/fakes/mock_block_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,34 @@
package fakes

import (
. "github.com/onsi/gomega"

"github.com/vulcanize/vulcanizedb/pkg/core"
)

type MockBlockRepository struct {
createOrUpdateBlockCallCount int
createOrUpdateBlockCalled bool
createOrUpdateBlockPassedBlock core.Block
createOrUpdateBlockPassedBlockNumbers []int64
CreateOrUpdateBlockCallCount int
CreateOrUpdateBlockPassedBlock core.Block
CreateOrUpdateBlockPassedBlockNumbers []int64
createOrUpdateBlockReturnErr error
createOrUpdateBlockReturnInt int64
missingBlockNumbersCalled bool
missingBlockNumbersPassedEndingBlockNumber int64
missingBlockNumbersPassedNodeId string
missingBlockNumbersPassedStartingBlockNumber int64
MissingBlockNumbersPassedEndingBlockNumber int64
MissingBlockNumbersPassedNodeId string
MissingBlockNumbersPassedStartingBlockNumber int64
missingBlockNumbersReturnArray []int64
setBlockStatusCalled bool
setBlockStatusPassedChainHead int64
SetBlockStatusPassedChainHead int64
}

func NewMockBlockRepository() *MockBlockRepository {
return &MockBlockRepository{
createOrUpdateBlockCallCount: 0,
createOrUpdateBlockCalled: false,
createOrUpdateBlockPassedBlock: core.Block{},
createOrUpdateBlockPassedBlockNumbers: nil,
CreateOrUpdateBlockCallCount: 0,
CreateOrUpdateBlockPassedBlock: core.Block{},
CreateOrUpdateBlockPassedBlockNumbers: nil,
createOrUpdateBlockReturnErr: nil,
createOrUpdateBlockReturnInt: 0,
missingBlockNumbersCalled: false,
missingBlockNumbersPassedEndingBlockNumber: 0,
missingBlockNumbersPassedNodeId: "",
missingBlockNumbersPassedStartingBlockNumber: 0,
MissingBlockNumbersPassedEndingBlockNumber: 0,
MissingBlockNumbersPassedNodeId: "",
MissingBlockNumbersPassedStartingBlockNumber: 0,
missingBlockNumbersReturnArray: nil,
setBlockStatusCalled: false,
setBlockStatusPassedChainHead: 0,
SetBlockStatusPassedChainHead: 0,
}
}

Expand All @@ -66,10 +58,9 @@ func (repository *MockBlockRepository) SetMissingBlockNumbersReturnArray(returnA
}

func (repository *MockBlockRepository) CreateOrUpdateBlock(block core.Block) (int64, error) {
repository.createOrUpdateBlockCallCount++
repository.createOrUpdateBlockCalled = true
repository.createOrUpdateBlockPassedBlock = block
repository.createOrUpdateBlockPassedBlockNumbers = append(repository.createOrUpdateBlockPassedBlockNumbers, block.Number)
repository.CreateOrUpdateBlockCallCount++
repository.CreateOrUpdateBlockPassedBlock = block
repository.CreateOrUpdateBlockPassedBlockNumbers = append(repository.CreateOrUpdateBlockPassedBlockNumbers, block.Number)
return repository.createOrUpdateBlockReturnInt, repository.createOrUpdateBlockReturnErr
}

Expand All @@ -78,41 +69,13 @@ func (repository *MockBlockRepository) GetBlock(blockNumber int64) (core.Block,
}

func (repository *MockBlockRepository) MissingBlockNumbers(startingBlockNumber int64, endingBlockNumber int64, nodeId string) []int64 {
repository.missingBlockNumbersCalled = true
repository.missingBlockNumbersPassedStartingBlockNumber = startingBlockNumber
repository.missingBlockNumbersPassedEndingBlockNumber = endingBlockNumber
repository.missingBlockNumbersPassedNodeId = nodeId
repository.MissingBlockNumbersPassedStartingBlockNumber = startingBlockNumber
repository.MissingBlockNumbersPassedEndingBlockNumber = endingBlockNumber
repository.MissingBlockNumbersPassedNodeId = nodeId
return repository.missingBlockNumbersReturnArray
}

func (repository *MockBlockRepository) SetBlocksStatus(chainHead int64) error {
repository.setBlockStatusCalled = true
repository.setBlockStatusPassedChainHead = chainHead
repository.SetBlockStatusPassedChainHead = chainHead
return nil
}

func (repository *MockBlockRepository) AssertCreateOrUpdateBlockCallCountEquals(times int) {
Expect(repository.createOrUpdateBlockCallCount).To(Equal(times))
}

func (repository *MockBlockRepository) AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(times int, blockNumbers []int64) {
Expect(repository.createOrUpdateBlockCallCount).To(Equal(times))
Expect(repository.createOrUpdateBlockPassedBlockNumbers).To(Equal(blockNumbers))
}

func (repository *MockBlockRepository) AssertCreateOrUpdateBlockCalledWith(block core.Block) {
Expect(repository.createOrUpdateBlockCalled).To(BeTrue())
Expect(repository.createOrUpdateBlockPassedBlock).To(Equal(block))
}

func (repository *MockBlockRepository) AssertMissingBlockNumbersCalledWith(startingBlockNumber int64, endingBlockNumber int64, nodeId string) {
Expect(repository.missingBlockNumbersCalled).To(BeTrue())
Expect(repository.missingBlockNumbersPassedStartingBlockNumber).To(Equal(startingBlockNumber))
Expect(repository.missingBlockNumbersPassedEndingBlockNumber).To(Equal(endingBlockNumber))
Expect(repository.missingBlockNumbersPassedNodeId).To(Equal(nodeId))
}

func (repository *MockBlockRepository) AssertSetBlockStatusCalledWith(chainHead int64) {
Expect(repository.setBlockStatusCalled).To(BeTrue())
Expect(repository.setBlockStatusPassedChainHead).To(Equal(chainHead))
}
8 changes: 5 additions & 3 deletions pkg/geth/cold_import/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ var _ = Describe("Geth cold importer", func() {
err := importer.Execute(startingBlockNumber, endingBlockNumber, nodeId)
Expect(err).NotTo(HaveOccurred())

mockBlockRepository.AssertMissingBlockNumbersCalledWith(startingBlockNumber, endingBlockNumber, nodeId)
Expect(mockBlockRepository.MissingBlockNumbersPassedStartingBlockNumber).To(Equal(startingBlockNumber))
Expect(mockBlockRepository.MissingBlockNumbersPassedEndingBlockNumber).To(Equal(endingBlockNumber))
Expect(mockBlockRepository.MissingBlockNumbersPassedNodeId).To(Equal(nodeId))
mockEthereumDatabase.AssertGetBlockHashCalledWith(missingBlockNumber)
mockEthereumDatabase.AssertGetBlockCalledWith(fakeHash, missingBlockNumber)
})
Expand Down Expand Up @@ -85,7 +87,7 @@ var _ = Describe("Geth cold importer", func() {
Expect(mockTransactionConverter.ConvertBlockTransactionsToCorePassedBlock).To(Equal(fakeGethBlock))
convertedBlock, err := blockConverter.ToCoreBlock(fakeGethBlock)
Expect(err).NotTo(HaveOccurred())
mockBlockRepository.AssertCreateOrUpdateBlockCalledWith(convertedBlock)
Expect(mockBlockRepository.CreateOrUpdateBlockPassedBlock).To(Equal(convertedBlock))
})

It("sets is_final status on populated blocks", func() {
Expand All @@ -105,7 +107,7 @@ var _ = Describe("Geth cold importer", func() {

err := importer.Execute(startingBlockNumber, endingBlockNumber, "node_id")
Expect(err).NotTo(HaveOccurred())
mockBlockRepository.AssertSetBlockStatusCalledWith(endingBlockNumber)
Expect(mockBlockRepository.SetBlockStatusPassedChainHead).To(Equal(endingBlockNumber))
})

It("fetches receipts from level db and persists them to pg", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/history/block_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var _ = Describe("Blocks validator", func() {
Expect(err).NotTo(HaveOccurred())

Expect(window).To(Equal(history.ValidationWindow{LowerBound: 5, UpperBound: 7}))
blocksRepository.AssertCreateOrUpdateBlockCallCountEquals(3)
Expect(blocksRepository.CreateOrUpdateBlockCallCount).To(Equal(3))
})

It("returns the number of largest block", func() {
Expand Down
8 changes: 5 additions & 3 deletions pkg/history/populate_blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ var _ = Describe("Populating blocks", func() {

Expect(err).NotTo(HaveOccurred())
Expect(blocksAdded).To(Equal(3))
blockRepository.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(3, []int64{5, 8, 10})
Expect(blockRepository.CreateOrUpdateBlockCallCount).To(Equal(3))
Expect(blockRepository.CreateOrUpdateBlockPassedBlockNumbers).To(Equal([]int64{5, 8, 10}))
})

It("returns the number of blocks created", func() {
Expand All @@ -73,7 +74,8 @@ var _ = Describe("Populating blocks", func() {
_, err := history.RetrieveAndUpdateBlocks(blockChain, blockRepository, history.MakeRange(2, 5))

Expect(err).NotTo(HaveOccurred())
blockRepository.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(4, []int64{2, 3, 4, 5})
Expect(blockRepository.CreateOrUpdateBlockCallCount).To(Equal(4))
Expect(blockRepository.CreateOrUpdateBlockPassedBlockNumbers).To(Equal([]int64{2, 3, 4, 5}))
})

It("does not call repository create block when there is an error", func() {
Expand All @@ -84,6 +86,6 @@ var _ = Describe("Populating blocks", func() {
_, err := history.RetrieveAndUpdateBlocks(blockChain, blockRepository, blocks)

Expect(err).To(HaveOccurred())
blockRepository.AssertCreateOrUpdateBlockCallCountEquals(0)
Expect(blockRepository.CreateOrUpdateBlockCallCount).To(Equal(0))
})
})