From ca3ae28f4625f9b788079b4bd9d6456584174aa2 Mon Sep 17 00:00:00 2001 From: Eduard S Date: Wed, 30 Sep 2020 11:58:31 +0200 Subject: [PATCH] Add missing error handling --- eth/auction.go | 8 +++++--- eth/ethereum.go | 3 +++ eth/main_test.go | 10 ++++++++-- eth/wdelayer.go | 8 +++++--- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/eth/auction.go b/eth/auction.go index 27d07ce..d2cccb8 100644 --- a/eth/auction.go +++ b/eth/auction.go @@ -958,7 +958,9 @@ var ( logHEZClaimed = crypto.Keccak256Hash([]byte("HEZClaimed(address,uint128)")) ) -// AuctionEventsByBlock returns the events in a block that happened in the Auction Smart Contract +// AuctionEventsByBlock returns the events in a block that happened in the +// Auction Smart Contract and the blockHash where the eents happened. If there +// are no events in that block, blockHash is nil. func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error) { var auctionEvents AuctionEvents var blockHash ethCommon.Hash @@ -974,14 +976,14 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e logs, err := c.client.client.FilterLogs(context.TODO(), query) if err != nil { - fmt.Println(err) + return nil, nil, err } if len(logs) > 0 { blockHash = logs[0].BlockHash } for _, vLog := range logs { if vLog.BlockHash != blockHash { - return nil, nil, err + return nil, nil, ErrBlockHashMismatchEvent } switch vLog.Topics[0] { case logNewBid: diff --git a/eth/ethereum.go b/eth/ethereum.go index 711e4c9..89617f8 100644 --- a/eth/ethereum.go +++ b/eth/ethereum.go @@ -30,6 +30,9 @@ var ( ErrReceiptStatusFailed = fmt.Errorf("receipt status is failed") // ErrReceiptNotReceived is used when unable to retrieve a transaction ErrReceiptNotReceived = fmt.Errorf("receipt not available") + // ErrBlockHashMismatchEvent is used when there's a block hash mismatch + // beetween different events of the same block + ErrBlockHashMismatchEvent = fmt.Errorf("block hash mismatch in event log") ) const ( diff --git a/eth/main_test.go b/eth/main_test.go index 2fba7eb..63589b7 100644 --- a/eth/main_test.go +++ b/eth/main_test.go @@ -126,9 +126,15 @@ func TestMain(m *testing.M) { // Controllable Governance Address ethereumClientGov := NewEthereumClient(ethClient, accountGov, ks, nil) - auctionClient, _ = NewAuctionClient(ethereumClientGov, auctionAddressConst, tokenHezAddressConst) + auctionClient, err = NewAuctionClient(ethereumClientGov, auctionAddressConst, tokenHezAddressConst) + if err != nil { + panic(err) + } rollupClient = NewRollupClient(ethereumClientGov, hermezRollupAddressConst) - wdelayerClient, _ = NewWDelayerClient(ethereumClientGov, wdelayerAddressConst) + wdelayerClient, err = NewWDelayerClient(ethereumClientGov, wdelayerAddressConst) + if err != nil { + panic(err) + } ethereumClientKep = NewEthereumClient(ethClient, accountKep, ks, nil) ethereumClientWhite = NewEthereumClient(ethClient, accountWhite, ks, nil) diff --git a/eth/wdelayer.go b/eth/wdelayer.go index 43584ea..b89bb68 100644 --- a/eth/wdelayer.go +++ b/eth/wdelayer.go @@ -430,7 +430,9 @@ var ( logNewHermezGovernanceDAOAddress = crypto.Keccak256Hash([]byte("NewHermezGovernanceDAOAddress(address)")) ) -// WDelayerEventsByBlock returns the events in a block that happened in the WDelayer Smart Contract +// WDelayerEventsByBlock returns the events in a block that happened in the +// WDelayer Smart Contract and the blockHash where the eents happened. If +// there are no events in that block, blockHash is nil. func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, *ethCommon.Hash, error) { var wdelayerEvents WDelayerEvents var blockHash ethCommon.Hash @@ -447,14 +449,14 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, logs, err := c.client.client.FilterLogs(context.Background(), query) if err != nil { - fmt.Println(err) + return nil, nil, err } if len(logs) > 0 { blockHash = logs[0].BlockHash } for _, vLog := range logs { if vLog.BlockHash != blockHash { - return nil, nil, err + return nil, nil, ErrBlockHashMismatchEvent } switch vLog.Topics[0] { case logDeposit: