Fix small issues from review
This commit is contained in:
parent
13eacf2081
commit
1a2f46b308
@ -48,9 +48,13 @@ var _ = Describe("Reading from the Geth blockchain", func() {
|
||||
|
||||
It("reads two blocks", func(done Done) {
|
||||
blocks := fakes.NewMockBlockRepository()
|
||||
lastBlock, _ := blockChain.LastBlock()
|
||||
lastBlock, err := blockChain.LastBlock()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
queriedBlocks := []int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6}
|
||||
history.RetrieveAndUpdateBlocks(blockChain, blocks, queriedBlocks)
|
||||
_, err = history.RetrieveAndUpdateBlocks(blockChain, blocks, queriedBlocks)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
blocks.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(2, []int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6})
|
||||
close(done)
|
||||
}, 30)
|
||||
@ -60,8 +64,9 @@ var _ = Describe("Reading from the Geth blockchain", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
firstBlock, err := blockChain.GetBlockByNumber(int64(1))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
lastBlockNumber, _ := blockChain.LastBlock()
|
||||
lastBlockNumber, err := blockChain.LastBlock()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(genesisBlock.Number).To(Equal(int64(0)))
|
||||
Expect(firstBlock.Number).To(Equal(int64(1)))
|
||||
Expect(lastBlockNumber.Int64()).To(BeNumerically(">", 0))
|
||||
|
@ -49,10 +49,8 @@ func (blockRepository BlockRepository) SetBlocksStatus(chainHead int64) error {
|
||||
UPDATE blocks SET is_final = TRUE
|
||||
WHERE is_final = FALSE AND number < $1`,
|
||||
cutoff)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (blockRepository BlockRepository) CreateOrUpdateBlock(block core.Block) (int64, error) {
|
||||
|
@ -40,13 +40,19 @@ func (logRepository LogRepository) CreateLogs(lgs []core.Log, receiptId int64) e
|
||||
tlog.BlockNumber, tlog.Address, tlog.TxHash, tlog.Index, tlog.Topics[0], tlog.Topics[1], tlog.Topics[2], tlog.Topics[3], tlog.Data, receiptId,
|
||||
)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
logrus.Error("CreateLogs: could not perform rollback: ", err)
|
||||
}
|
||||
return postgres.ErrDBInsertFailed
|
||||
}
|
||||
}
|
||||
err := tx.Commit()
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
logrus.Error("CreateLogs: could not perform rollback: ", err)
|
||||
}
|
||||
return postgres.ErrDBInsertFailed
|
||||
}
|
||||
return nil
|
||||
@ -83,7 +89,8 @@ func (logRepository LogRepository) loadLogs(logsRows *sql.Rows) ([]core.Log, err
|
||||
var topics core.Topics
|
||||
err := logsRows.Scan(&blockNumber, &address, &txHash, &index, &topics[0], &topics[1], &topics[2], &topics[3], &data)
|
||||
if err != nil {
|
||||
logrus.Warn("loadLogs: Error scanning a row in logRows")
|
||||
logrus.Error("loadLogs: Error scanning a row in logRows: ", err)
|
||||
return []core.Log{}, err
|
||||
}
|
||||
lg := core.Log{
|
||||
BlockNumber: blockNumber,
|
||||
|
@ -56,7 +56,7 @@ var _ = Describe("Logs Repository", func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
logsRepository.CreateLogs([]core.Log{{
|
||||
err = logsRepository.CreateLogs([]core.Log{{
|
||||
BlockNumber: blockNumber,
|
||||
Index: 0,
|
||||
Address: "x123",
|
||||
@ -64,6 +64,7 @@ var _ = Describe("Logs Repository", func() {
|
||||
Topics: core.Topics{0: "x777", 1: "x888", 2: "x999"},
|
||||
Data: "xabc",
|
||||
}}, receiptId)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
log, err := logsRepository.GetLogs("x123", blockNumber)
|
||||
|
||||
@ -91,7 +92,8 @@ var _ = Describe("Logs Repository", func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_ = logsRepository.CreateLogs([]core.Log{{
|
||||
|
||||
err = logsRepository.CreateLogs([]core.Log{{
|
||||
BlockNumber: blockNumber,
|
||||
Index: 0,
|
||||
Address: "x123",
|
||||
@ -99,7 +101,9 @@ var _ = Describe("Logs Repository", func() {
|
||||
Topics: core.Topics{0: "x777", 1: "x888", 2: "x999"},
|
||||
Data: "xabc",
|
||||
}}, receiptId)
|
||||
_ = logsRepository.CreateLogs([]core.Log{{
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = logsRepository.CreateLogs([]core.Log{{
|
||||
BlockNumber: blockNumber,
|
||||
Index: 1,
|
||||
Address: "x123",
|
||||
@ -107,7 +111,9 @@ var _ = Describe("Logs Repository", func() {
|
||||
Topics: core.Topics{0: "x111", 1: "x222", 2: "x333"},
|
||||
Data: "xdef",
|
||||
}}, receiptId)
|
||||
_ = logsRepository.CreateLogs([]core.Log{{
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = logsRepository.CreateLogs([]core.Log{{
|
||||
BlockNumber: 2,
|
||||
Index: 0,
|
||||
Address: "x123",
|
||||
@ -115,6 +121,7 @@ var _ = Describe("Logs Repository", func() {
|
||||
Topics: core.Topics{0: "x777", 1: "x888", 2: "x999"},
|
||||
Data: "xabc",
|
||||
}}, receiptId)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
log, err := logsRepository.GetLogs("x123", blockNumber)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -221,7 +221,8 @@ var _ = Describe("Geth blockchain", func() {
|
||||
blockNumber := int64(100)
|
||||
mockClient.SetHeaderByNumberReturnHeader(&types.Header{Number: big.NewInt(blockNumber)})
|
||||
|
||||
result, _ := blockChain.LastBlock()
|
||||
result, err := blockChain.LastBlock()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
mockClient.AssertHeaderByNumberCalledWith(context.Background(), nil)
|
||||
Expect(result).To(Equal(big.NewInt(blockNumber)))
|
||||
|
Loading…
Reference in New Issue
Block a user