Skip to content
Draft
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
4 changes: 2 additions & 2 deletions rpc/backend/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (b *Backend) BlockNumberFromTendermintByHash(blockHash common.Hash) (*big.I
if err != nil {
return nil, err
}
if resHeader.Header == nil {
if resHeader == nil || resHeader.Header == nil {
return nil, errors.Errorf("header not found for hash %s", blockHash.Hex())
}
return big.NewInt(resHeader.Header.Height), nil
Expand Down Expand Up @@ -405,7 +405,7 @@ func (b *Backend) HeaderByHash(blockHash common.Hash) (*ethtypes.Header, error)
if err != nil {
return nil, err
}
if resHeader.Header == nil {
if resHeader == nil || resHeader.Header == nil {
return nil, errors.Errorf("header not found for hash %s", blockHash.Hex())
}
blockRes, err := b.TendermintBlockResultByNumber(&resHeader.Header.Height)
Expand Down
19 changes: 19 additions & 0 deletions rpc/backend/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,15 @@ func (suite *BackendTestSuite) TestBlockNumberFromTendermintByHash() {
},
false,
},
{
"fail - nil response from client",
common.BytesToHash(block.Hash()),
func(hash common.Hash) {
client := suite.backend.clientCtx.Client.(*mocks.Client)
RegisterHeaderByHashNilResult(client, hash)
},
false,
},
{
"pass - block without tx",
common.BytesToHash(emptyBlock.Hash()),
Expand Down Expand Up @@ -1334,6 +1343,16 @@ func (suite *BackendTestSuite) TestHeaderByHash() {
},
false,
},
{
"fail - nil response from client",
common.BytesToHash(block.Hash()),
sdkmath.NewInt(1).BigInt(),
func(hash common.Hash, baseFee sdkmath.Int) {
client := suite.backend.clientCtx.Client.(*mocks.Client)
RegisterHeaderByHashNilResult(client, hash)
},
false,
},
{
"fail - header not found for height",
common.BytesToHash(block.Hash()),
Expand Down
5 changes: 5 additions & 0 deletions rpc/backend/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ func RegisterHeaderByHashNotFound(client *mocks.Client, hash common.Hash, tx []b
Return(&tmrpctypes.ResultHeader{Header: nil}, nil)
}

func RegisterHeaderByHashNilResult(client *mocks.Client, hash common.Hash) {
client.On("HeaderByHash", rpc.ContextWithHeight(1), bytes.HexBytes(hash.Bytes())).
Return(nil, nil)
}

// Header
func RegisterHeader(client *mocks.Client, height *int64, tx []byte) (*tmrpctypes.ResultHeader, error) {
block := types.MakeBlock(*height, []types.Tx{tx}, nil, nil)
Expand Down
Loading