forked from cerc-io/ipld-eth-server
Update tests for error propagation
This commit is contained in:
parent
6cd4e5ea95
commit
13eacf2081
@ -48,7 +48,7 @@ var _ = Describe("Reading from the Geth blockchain", func() {
|
|||||||
|
|
||||||
It("reads two blocks", func(done Done) {
|
It("reads two blocks", func(done Done) {
|
||||||
blocks := fakes.NewMockBlockRepository()
|
blocks := fakes.NewMockBlockRepository()
|
||||||
lastBlock := blockChain.LastBlock()
|
lastBlock, _ := blockChain.LastBlock()
|
||||||
queriedBlocks := []int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6}
|
queriedBlocks := []int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6}
|
||||||
history.RetrieveAndUpdateBlocks(blockChain, blocks, queriedBlocks)
|
history.RetrieveAndUpdateBlocks(blockChain, blocks, queriedBlocks)
|
||||||
blocks.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(2, []int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6})
|
blocks.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(2, []int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6})
|
||||||
@ -60,7 +60,7 @@ var _ = Describe("Reading from the Geth blockchain", func() {
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
firstBlock, err := blockChain.GetBlockByNumber(int64(1))
|
firstBlock, err := blockChain.GetBlockByNumber(int64(1))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
lastBlockNumber := blockChain.LastBlock()
|
lastBlockNumber, _ := blockChain.LastBlock()
|
||||||
|
|
||||||
Expect(genesisBlock.Number).To(Equal(int64(0)))
|
Expect(genesisBlock.Number).To(Equal(int64(0)))
|
||||||
Expect(firstBlock.Number).To(Equal(int64(1)))
|
Expect(firstBlock.Number).To(Equal(int64(1)))
|
||||||
|
@ -134,8 +134,9 @@ var _ = Describe("Postgres DB", func() {
|
|||||||
err := logRepository.CreateLogs([]core.Log{badLog}, 123)
|
err := logRepository.CreateLogs([]core.Log{badLog}, 123)
|
||||||
|
|
||||||
Expect(err).ToNot(BeNil())
|
Expect(err).ToNot(BeNil())
|
||||||
savedBlock := logRepository.GetLogs("x123", 1)
|
savedBlock, err := logRepository.GetLogs("x123", 1)
|
||||||
Expect(savedBlock).To(BeNil())
|
Expect(savedBlock).To(BeNil())
|
||||||
|
Expect(err).To(Not(HaveOccurred()))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("does not commit block or transactions if transaction is invalid", func() {
|
It("does not commit block or transactions if transaction is invalid", func() {
|
||||||
|
@ -273,21 +273,4 @@ var _ = Describe("Block header repository", func() {
|
|||||||
Expect(missingBlockNumbers).To(ConsistOf([]int64{1, 2, 3, 4, 5}))
|
Expect(missingBlockNumbers).To(ConsistOf([]int64{1, 2, 3, 4, 5}))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("HeaderExists", func() {
|
|
||||||
It("returns true if the header record exists", func() {
|
|
||||||
_, err = repo.CreateOrUpdateHeader(header)
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
|
|
||||||
result, err := repo.HeaderExists(header.BlockNumber)
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
Expect(result).To(BeTrue())
|
|
||||||
})
|
|
||||||
|
|
||||||
It("returns false if the header record doesn't exist", func() {
|
|
||||||
result, err := repo.HeaderExists(1)
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
Expect(result).To(BeFalse())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -65,8 +65,9 @@ var _ = Describe("Logs Repository", func() {
|
|||||||
Data: "xabc",
|
Data: "xabc",
|
||||||
}}, receiptId)
|
}}, receiptId)
|
||||||
|
|
||||||
log := logsRepository.GetLogs("x123", blockNumber)
|
log, err := logsRepository.GetLogs("x123", blockNumber)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(log).NotTo(BeNil())
|
Expect(log).NotTo(BeNil())
|
||||||
Expect(log[0].BlockNumber).To(Equal(blockNumber))
|
Expect(log[0].BlockNumber).To(Equal(blockNumber))
|
||||||
Expect(log[0].Address).To(Equal("x123"))
|
Expect(log[0].Address).To(Equal("x123"))
|
||||||
@ -79,7 +80,8 @@ var _ = Describe("Logs Repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("returns nil if log does not exist", func() {
|
It("returns nil if log does not exist", func() {
|
||||||
log := logsRepository.GetLogs("x123", 1)
|
log, err := logsRepository.GetLogs("x123", 1)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(log).To(BeNil())
|
Expect(log).To(BeNil())
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -89,7 +91,7 @@ var _ = Describe("Logs Repository", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{})
|
receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
logsRepository.CreateLogs([]core.Log{{
|
_ = logsRepository.CreateLogs([]core.Log{{
|
||||||
BlockNumber: blockNumber,
|
BlockNumber: blockNumber,
|
||||||
Index: 0,
|
Index: 0,
|
||||||
Address: "x123",
|
Address: "x123",
|
||||||
@ -97,7 +99,7 @@ var _ = Describe("Logs Repository", func() {
|
|||||||
Topics: core.Topics{0: "x777", 1: "x888", 2: "x999"},
|
Topics: core.Topics{0: "x777", 1: "x888", 2: "x999"},
|
||||||
Data: "xabc",
|
Data: "xabc",
|
||||||
}}, receiptId)
|
}}, receiptId)
|
||||||
logsRepository.CreateLogs([]core.Log{{
|
_ = logsRepository.CreateLogs([]core.Log{{
|
||||||
BlockNumber: blockNumber,
|
BlockNumber: blockNumber,
|
||||||
Index: 1,
|
Index: 1,
|
||||||
Address: "x123",
|
Address: "x123",
|
||||||
@ -105,7 +107,7 @@ var _ = Describe("Logs Repository", func() {
|
|||||||
Topics: core.Topics{0: "x111", 1: "x222", 2: "x333"},
|
Topics: core.Topics{0: "x111", 1: "x222", 2: "x333"},
|
||||||
Data: "xdef",
|
Data: "xdef",
|
||||||
}}, receiptId)
|
}}, receiptId)
|
||||||
logsRepository.CreateLogs([]core.Log{{
|
_ = logsRepository.CreateLogs([]core.Log{{
|
||||||
BlockNumber: 2,
|
BlockNumber: 2,
|
||||||
Index: 0,
|
Index: 0,
|
||||||
Address: "x123",
|
Address: "x123",
|
||||||
@ -114,12 +116,14 @@ var _ = Describe("Logs Repository", func() {
|
|||||||
Data: "xabc",
|
Data: "xabc",
|
||||||
}}, receiptId)
|
}}, receiptId)
|
||||||
|
|
||||||
log := logsRepository.GetLogs("x123", blockNumber)
|
log, err := logsRepository.GetLogs("x123", blockNumber)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
type logIndex struct {
|
type logIndex struct {
|
||||||
blockNumber int64
|
blockNumber int64
|
||||||
Index int64
|
Index int64
|
||||||
}
|
}
|
||||||
|
|
||||||
var uniqueBlockNumbers []logIndex
|
var uniqueBlockNumbers []logIndex
|
||||||
for _, log := range log {
|
for _, log := range log {
|
||||||
uniqueBlockNumbers = append(uniqueBlockNumbers,
|
uniqueBlockNumbers = append(uniqueBlockNumbers,
|
||||||
@ -199,8 +203,9 @@ var _ = Describe("Logs Repository", func() {
|
|||||||
block := core.Block{Transactions: []core.Transaction{transaction}}
|
block := core.Block{Transactions: []core.Transaction{transaction}}
|
||||||
_, err := blockRepository.CreateOrUpdateBlock(block)
|
_, err := blockRepository.CreateOrUpdateBlock(block)
|
||||||
Expect(err).To(Not(HaveOccurred()))
|
Expect(err).To(Not(HaveOccurred()))
|
||||||
retrievedLogs := logsRepository.GetLogs("0x99041f808d598b782d5a3e498681c2452a31da08", 4745407)
|
retrievedLogs, err := logsRepository.GetLogs("0x99041f808d598b782d5a3e498681c2452a31da08", 4745407)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
expected := logs[1:]
|
expected := logs[1:]
|
||||||
Expect(retrievedLogs).To(Equal(expected))
|
Expect(retrievedLogs).To(Equal(expected))
|
||||||
})
|
})
|
||||||
|
@ -87,14 +87,19 @@ var _ = Describe("Receipts Repository", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(persistedReceiptOne).NotTo(BeNil())
|
Expect(persistedReceiptOne).NotTo(BeNil())
|
||||||
Expect(persistedReceiptOne.TxHash).To(Equal(txHashOne))
|
Expect(persistedReceiptOne.TxHash).To(Equal(txHashOne))
|
||||||
|
|
||||||
persistedReceiptTwo, err := receiptRepository.GetReceipt(txHashTwo)
|
persistedReceiptTwo, err := receiptRepository.GetReceipt(txHashTwo)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(persistedReceiptTwo).NotTo(BeNil())
|
Expect(persistedReceiptTwo).NotTo(BeNil())
|
||||||
Expect(persistedReceiptTwo.TxHash).To(Equal(txHashTwo))
|
Expect(persistedReceiptTwo.TxHash).To(Equal(txHashTwo))
|
||||||
persistedAddressOneLogs := logRepository.GetLogs(addressOne, blockNumber)
|
|
||||||
|
persistedAddressOneLogs, err := logRepository.GetLogs(addressOne, blockNumber)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(persistedAddressOneLogs).NotTo(BeNil())
|
Expect(persistedAddressOneLogs).NotTo(BeNil())
|
||||||
Expect(len(persistedAddressOneLogs)).To(Equal(2))
|
Expect(len(persistedAddressOneLogs)).To(Equal(2))
|
||||||
persistedAddressTwoLogs := logRepository.GetLogs(addressTwo, blockNumber)
|
|
||||||
|
persistedAddressTwoLogs, err := logRepository.GetLogs(addressTwo, blockNumber)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(persistedAddressTwoLogs).NotTo(BeNil())
|
Expect(persistedAddressTwoLogs).NotTo(BeNil())
|
||||||
Expect(len(persistedAddressTwoLogs)).To(Equal(1))
|
Expect(len(persistedAddressTwoLogs)).To(Equal(1))
|
||||||
})
|
})
|
||||||
|
@ -85,9 +85,10 @@ func (repository *MockBlockRepository) MissingBlockNumbers(startingBlockNumber i
|
|||||||
return repository.missingBlockNumbersReturnArray
|
return repository.missingBlockNumbersReturnArray
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockBlockRepository) SetBlocksStatus(chainHead int64) {
|
func (repository *MockBlockRepository) SetBlocksStatus(chainHead int64) error {
|
||||||
repository.setBlockStatusCalled = true
|
repository.setBlockStatusCalled = true
|
||||||
repository.setBlockStatusPassedChainHead = chainHead
|
repository.setBlockStatusPassedChainHead = chainHead
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockBlockRepository) AssertCreateOrUpdateBlockCallCountEquals(times int) {
|
func (repository *MockBlockRepository) AssertCreateOrUpdateBlockCallCountEquals(times int) {
|
||||||
|
@ -108,8 +108,8 @@ func (chain *MockBlockChain) CallContract(contractHash string, input []byte, blo
|
|||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (chain *MockBlockChain) LastBlock() *big.Int {
|
func (chain *MockBlockChain) LastBlock() (*big.Int, error) {
|
||||||
return chain.lastBlock
|
return chain.lastBlock, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (chain *MockBlockChain) Node() core.Node {
|
func (chain *MockBlockChain) Node() core.Node {
|
||||||
|
@ -65,14 +65,6 @@ func (repository *MockHeaderRepository) MissingBlockNumbers(startingBlockNumber,
|
|||||||
return repository.missingBlockNumbers, nil
|
return repository.missingBlockNumbers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockHeaderRepository) HeaderExists(blockNumber int64) (bool, error) {
|
|
||||||
return repository.headerExists, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repository *MockHeaderRepository) SetHeaderExists(headerExists bool) {
|
|
||||||
repository.headerExists = headerExists
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repository *MockHeaderRepository) SetGetHeaderError(err error) {
|
func (repository *MockHeaderRepository) SetGetHeaderError(err error) {
|
||||||
repository.getHeaderError = err
|
repository.getHeaderError = err
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ var _ = Describe("Geth blockchain", func() {
|
|||||||
blockNumber := int64(100)
|
blockNumber := int64(100)
|
||||||
mockClient.SetHeaderByNumberReturnHeader(&types.Header{Number: big.NewInt(blockNumber)})
|
mockClient.SetHeaderByNumberReturnHeader(&types.Header{Number: big.NewInt(blockNumber)})
|
||||||
|
|
||||||
result := blockChain.LastBlock()
|
result, _ := blockChain.LastBlock()
|
||||||
|
|
||||||
mockClient.AssertHeaderByNumberCalledWith(context.Background(), nil)
|
mockClient.AssertHeaderByNumberCalledWith(context.Background(), nil)
|
||||||
Expect(result).To(Equal(big.NewInt(blockNumber)))
|
Expect(result).To(Equal(big.NewInt(blockNumber)))
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/geth/cold_import"
|
"github.com/vulcanize/vulcanizedb/pkg/geth/cold_import"
|
||||||
@ -55,7 +54,8 @@ var _ = Describe("Geth cold importer", func() {
|
|||||||
mockEthereumDatabase.SetReturnBlock(fakeGethBlock)
|
mockEthereumDatabase.SetReturnBlock(fakeGethBlock)
|
||||||
importer := cold_import.NewColdImporter(mockEthereumDatabase, mockBlockRepository, mockReceiptRepository, blockConverter)
|
importer := cold_import.NewColdImporter(mockEthereumDatabase, mockBlockRepository, mockReceiptRepository, blockConverter)
|
||||||
|
|
||||||
importer.Execute(startingBlockNumber, endingBlockNumber, nodeId)
|
err := importer.Execute(startingBlockNumber, endingBlockNumber, nodeId)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
mockBlockRepository.AssertMissingBlockNumbersCalledWith(startingBlockNumber, endingBlockNumber, nodeId)
|
mockBlockRepository.AssertMissingBlockNumbersCalledWith(startingBlockNumber, endingBlockNumber, nodeId)
|
||||||
mockEthereumDatabase.AssertGetBlockHashCalledWith(missingBlockNumber)
|
mockEthereumDatabase.AssertGetBlockHashCalledWith(missingBlockNumber)
|
||||||
@ -76,7 +76,8 @@ var _ = Describe("Geth cold importer", func() {
|
|||||||
mockEthereumDatabase.SetReturnBlock(fakeGethBlock)
|
mockEthereumDatabase.SetReturnBlock(fakeGethBlock)
|
||||||
importer := cold_import.NewColdImporter(mockEthereumDatabase, mockBlockRepository, mockReceiptRepository, blockConverter)
|
importer := cold_import.NewColdImporter(mockEthereumDatabase, mockBlockRepository, mockReceiptRepository, blockConverter)
|
||||||
|
|
||||||
importer.Execute(blockNumber, blockNumber, "node_id")
|
err := importer.Execute(blockNumber, blockNumber, "node_id")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
mockEthereumDatabase.AssertGetBlockHashCalledWith(blockNumber)
|
mockEthereumDatabase.AssertGetBlockHashCalledWith(blockNumber)
|
||||||
mockEthereumDatabase.AssertGetBlockCalledWith(fakeHash, blockNumber)
|
mockEthereumDatabase.AssertGetBlockCalledWith(fakeHash, blockNumber)
|
||||||
@ -101,8 +102,8 @@ var _ = Describe("Geth cold importer", func() {
|
|||||||
mockEthereumDatabase.SetReturnBlock(fakeGethBlock)
|
mockEthereumDatabase.SetReturnBlock(fakeGethBlock)
|
||||||
importer := cold_import.NewColdImporter(mockEthereumDatabase, mockBlockRepository, mockReceiptRepository, blockConverter)
|
importer := cold_import.NewColdImporter(mockEthereumDatabase, mockBlockRepository, mockReceiptRepository, blockConverter)
|
||||||
|
|
||||||
importer.Execute(startingBlockNumber, endingBlockNumber, "node_id")
|
err := importer.Execute(startingBlockNumber, endingBlockNumber, "node_id")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
mockBlockRepository.AssertSetBlockStatusCalledWith(endingBlockNumber)
|
mockBlockRepository.AssertSetBlockStatusCalledWith(endingBlockNumber)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -122,8 +123,8 @@ var _ = Describe("Geth cold importer", func() {
|
|||||||
mockEthereumDatabase.SetReturnReceipts(fakeReceipts)
|
mockEthereumDatabase.SetReturnReceipts(fakeReceipts)
|
||||||
importer := cold_import.NewColdImporter(mockEthereumDatabase, mockBlockRepository, mockReceiptRepository, blockConverter)
|
importer := cold_import.NewColdImporter(mockEthereumDatabase, mockBlockRepository, mockReceiptRepository, blockConverter)
|
||||||
|
|
||||||
importer.Execute(blockNumber, blockNumber, "node_id")
|
err := importer.Execute(blockNumber, blockNumber, "node_id")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
expectedReceipts := vulcCommon.ToCoreReceipts(fakeReceipts)
|
expectedReceipts := vulcCommon.ToCoreReceipts(fakeReceipts)
|
||||||
mockReceiptRepository.AssertCreateReceiptsAndLogsCalledWith(blockId, expectedReceipts)
|
mockReceiptRepository.AssertCreateReceiptsAndLogsCalledWith(blockId, expectedReceipts)
|
||||||
})
|
})
|
||||||
|
@ -44,9 +44,8 @@ var _ = Describe("Block header converter", func() {
|
|||||||
converter := common2.HeaderConverter{}
|
converter := common2.HeaderConverter{}
|
||||||
hash := fakes.FakeHash.String()
|
hash := fakes.FakeHash.String()
|
||||||
|
|
||||||
coreHeader, err := converter.Convert(gethHeader, hash)
|
coreHeader := converter.Convert(gethHeader, hash)
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
Expect(coreHeader.BlockNumber).To(Equal(gethHeader.Number.Int64()))
|
Expect(coreHeader.BlockNumber).To(Equal(gethHeader.Number.Int64()))
|
||||||
Expect(coreHeader.Hash).To(Equal(hash))
|
Expect(coreHeader.Hash).To(Equal(hash))
|
||||||
Expect(coreHeader.Timestamp).To(Equal(gethHeader.Time.String()))
|
Expect(coreHeader.Timestamp).To(Equal(gethHeader.Time.String()))
|
||||||
@ -56,9 +55,8 @@ var _ = Describe("Block header converter", func() {
|
|||||||
gethHeader := types.Header{Number: big.NewInt(123)}
|
gethHeader := types.Header{Number: big.NewInt(123)}
|
||||||
converter := common2.HeaderConverter{}
|
converter := common2.HeaderConverter{}
|
||||||
|
|
||||||
coreHeader, err := converter.Convert(&gethHeader, fakes.FakeHash.String())
|
coreHeader := converter.Convert(&gethHeader, fakes.FakeHash.String())
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
expectedJSON, err := json.Marshal(gethHeader)
|
expectedJSON, err := json.Marshal(gethHeader)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(coreHeader.Raw).To(Equal(expectedJSON))
|
Expect(coreHeader.Raw).To(Equal(expectedJSON))
|
||||||
|
@ -34,7 +34,8 @@ var _ = Describe("Blocks validator", func() {
|
|||||||
blocksRepository := fakes.NewMockBlockRepository()
|
blocksRepository := fakes.NewMockBlockRepository()
|
||||||
validator := history.NewBlockValidator(blockChain, blocksRepository, 2)
|
validator := history.NewBlockValidator(blockChain, blocksRepository, 2)
|
||||||
|
|
||||||
window := validator.ValidateBlocks()
|
window, err := validator.ValidateBlocks()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
Expect(window).To(Equal(history.ValidationWindow{LowerBound: 5, UpperBound: 7}))
|
Expect(window).To(Equal(history.ValidationWindow{LowerBound: 5, UpperBound: 7}))
|
||||||
blocksRepository.AssertCreateOrUpdateBlockCallCountEquals(3)
|
blocksRepository.AssertCreateOrUpdateBlockCallCountEquals(3)
|
||||||
@ -43,7 +44,7 @@ var _ = Describe("Blocks validator", func() {
|
|||||||
It("returns the number of largest block", func() {
|
It("returns the number of largest block", func() {
|
||||||
blockChain := fakes.NewMockBlockChain()
|
blockChain := fakes.NewMockBlockChain()
|
||||||
blockChain.SetLastBlock(big.NewInt(3))
|
blockChain.SetLastBlock(big.NewInt(3))
|
||||||
maxBlockNumber := blockChain.LastBlock()
|
maxBlockNumber, _ := blockChain.LastBlock()
|
||||||
|
|
||||||
Expect(maxBlockNumber.Int64()).To(Equal(int64(3)))
|
Expect(maxBlockNumber.Int64()).To(Equal(int64(3)))
|
||||||
})
|
})
|
||||||
|
@ -36,8 +36,9 @@ var _ = Describe("Populating blocks", func() {
|
|||||||
blockChain.SetLastBlock(big.NewInt(2))
|
blockChain.SetLastBlock(big.NewInt(2))
|
||||||
blockRepository.SetMissingBlockNumbersReturnArray([]int64{2})
|
blockRepository.SetMissingBlockNumbersReturnArray([]int64{2})
|
||||||
|
|
||||||
blocksAdded := history.PopulateMissingBlocks(blockChain, blockRepository, 1)
|
blocksAdded, err := history.PopulateMissingBlocks(blockChain, blockRepository, 1)
|
||||||
_, err := blockRepository.GetBlock(1)
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
_, err = blockRepository.GetBlock(1)
|
||||||
|
|
||||||
Expect(blocksAdded).To(Equal(1))
|
Expect(blocksAdded).To(Equal(1))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@ -48,8 +49,9 @@ var _ = Describe("Populating blocks", func() {
|
|||||||
blockChain.SetLastBlock(big.NewInt(13))
|
blockChain.SetLastBlock(big.NewInt(13))
|
||||||
blockRepository.SetMissingBlockNumbersReturnArray([]int64{5, 8, 10})
|
blockRepository.SetMissingBlockNumbersReturnArray([]int64{5, 8, 10})
|
||||||
|
|
||||||
blocksAdded := history.PopulateMissingBlocks(blockChain, blockRepository, 5)
|
blocksAdded, err := history.PopulateMissingBlocks(blockChain, blockRepository, 5)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(blocksAdded).To(Equal(3))
|
Expect(blocksAdded).To(Equal(3))
|
||||||
blockRepository.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(3, []int64{5, 8, 10})
|
blockRepository.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(3, []int64{5, 8, 10})
|
||||||
})
|
})
|
||||||
@ -59,16 +61,18 @@ var _ = Describe("Populating blocks", func() {
|
|||||||
blockChain.SetLastBlock(big.NewInt(6))
|
blockChain.SetLastBlock(big.NewInt(6))
|
||||||
blockRepository.SetMissingBlockNumbersReturnArray([]int64{4, 5})
|
blockRepository.SetMissingBlockNumbersReturnArray([]int64{4, 5})
|
||||||
|
|
||||||
numberOfBlocksCreated := history.PopulateMissingBlocks(blockChain, blockRepository, 3)
|
numberOfBlocksCreated, err := history.PopulateMissingBlocks(blockChain, blockRepository, 3)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(numberOfBlocksCreated).To(Equal(2))
|
Expect(numberOfBlocksCreated).To(Equal(2))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("updates the repository with a range of blocks w/in the range ", func() {
|
It("updates the repository with a range of blocks w/in the range ", func() {
|
||||||
blockChain := fakes.NewMockBlockChain()
|
blockChain := fakes.NewMockBlockChain()
|
||||||
|
|
||||||
history.RetrieveAndUpdateBlocks(blockChain, blockRepository, history.MakeRange(2, 5))
|
_, err := history.RetrieveAndUpdateBlocks(blockChain, blockRepository, history.MakeRange(2, 5))
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
blockRepository.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(4, []int64{2, 3, 4, 5})
|
blockRepository.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(4, []int64{2, 3, 4, 5})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -77,8 +81,9 @@ var _ = Describe("Populating blocks", func() {
|
|||||||
blockChain.SetGetBlockByNumberErr(fakes.FakeError)
|
blockChain.SetGetBlockByNumberErr(fakes.FakeError)
|
||||||
blocks := history.MakeRange(1, 10)
|
blocks := history.MakeRange(1, 10)
|
||||||
|
|
||||||
history.RetrieveAndUpdateBlocks(blockChain, blockRepository, blocks)
|
_, err := history.RetrieveAndUpdateBlocks(blockChain, blockRepository, blocks)
|
||||||
|
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
blockRepository.AssertCreateOrUpdateBlockCallCountEquals(0)
|
blockRepository.AssertCreateOrUpdateBlockCallCountEquals(0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -59,7 +59,6 @@ var _ = Describe("Populating headers", func() {
|
|||||||
It("returns early if the db is already synced up to the head of the chain", func() {
|
It("returns early if the db is already synced up to the head of the chain", func() {
|
||||||
blockChain := fakes.NewMockBlockChain()
|
blockChain := fakes.NewMockBlockChain()
|
||||||
blockChain.SetLastBlock(big.NewInt(2))
|
blockChain.SetLastBlock(big.NewInt(2))
|
||||||
headerRepository.SetHeaderExists(true)
|
|
||||||
headersAdded, err := history.PopulateMissingHeaders(blockChain, headerRepository, 2)
|
headersAdded, err := history.PopulateMissingHeaders(blockChain, headerRepository, 2)
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
@ -30,8 +30,9 @@ var _ = Describe("Validation window", func() {
|
|||||||
blockChain := fakes.NewMockBlockChain()
|
blockChain := fakes.NewMockBlockChain()
|
||||||
blockChain.SetLastBlock(big.NewInt(5))
|
blockChain.SetLastBlock(big.NewInt(5))
|
||||||
|
|
||||||
validationWindow := history.MakeValidationWindow(blockChain, 2)
|
validationWindow, err := history.MakeValidationWindow(blockChain, 2)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(validationWindow.LowerBound).To(Equal(int64(3)))
|
Expect(validationWindow.LowerBound).To(Equal(int64(3)))
|
||||||
Expect(validationWindow.UpperBound).To(Equal(int64(5)))
|
Expect(validationWindow.UpperBound).To(Equal(int64(5)))
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user