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

Commit

Permalink
Fix small issues from review
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ar committed Feb 20, 2019
1 parent 13eacf2 commit 1a2f46b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
11 changes: 8 additions & 3 deletions integration_test/geth_blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down
6 changes: 2 additions & 4 deletions pkg/datastore/postgres/repositories/block_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions pkg/datastore/postgres/repositories/logs_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 11 additions & 4 deletions pkg/datastore/postgres/repositories/logs_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ 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",
TxHash: "x456",
Topics: core.Topics{0: "x777", 1: "x888", 2: "x999"},
Data: "xabc",
}}, receiptId)
Expect(err).NotTo(HaveOccurred())

log, err := logsRepository.GetLogs("x123", blockNumber)

Expand Down Expand Up @@ -91,30 +92,36 @@ 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",
TxHash: "x456",
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",
TxHash: "x789",
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",
TxHash: "x456",
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())
Expand Down
3 changes: 2 additions & 1 deletion pkg/geth/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit 1a2f46b

Please sign in to comment.