[ENG-626] Rpc types integration tests (#1207)

* types tests

* cleanup

* cleanup

* fix differences in the rpc calls with geth

* cleanup

* fix linter. getProof future queries now behave as geth

* fix spelling

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
Ramiro Carlucho
2022-08-08 09:01:42 -04:00
committed by GitHub
co-authored by Federico Kunze Küllmer
parent 0b294b74bc
commit d1543ce678
6 changed files with 454 additions and 23 deletions
+7 -7
View File
@@ -62,7 +62,7 @@ func (b *Backend) BlockNumber() (hexutil.Uint64, error) {
func (b *Backend) GetBlockByNumber(blockNum types.BlockNumber, fullTx bool) (map[string]interface{}, error) {
resBlock, err := b.GetTendermintBlockByNumber(blockNum)
if err != nil {
return nil, err
return nil, nil
}
// return if requested block height is greater than the current one
@@ -939,18 +939,18 @@ func (b *Backend) FeeHistory(
// fetch block
for blockID := blockStart; blockID < blockEnd; blockID++ {
index := int32(blockID - blockStart)
// eth block
ethBlock, err := b.GetBlockByNumber(types.BlockNumber(blockID), true)
if ethBlock == nil {
return nil, err
}
// tendermint block
tendermintblock, err := b.GetTendermintBlockByNumber(types.BlockNumber(blockID))
if tendermintblock == nil {
return nil, err
}
// eth block
ethBlock, err := b.GetBlockByNumber(types.BlockNumber(blockID), true)
if ethBlock == nil {
return nil, err
}
// tendermint block result
tendermintBlockResult, err := b.GetTendermintBlockResultByNumber(&tendermintblock.Block.Height)
if tendermintBlockResult == nil {
+3 -3
View File
@@ -98,7 +98,7 @@ func (suite *BackendTestSuite) TestGetBlockByNumber() {
expPass bool
}{
{
"fail - tendermint block error",
"pass - tendermint block not found",
ethrpc.BlockNumber(1),
true,
sdk.NewInt(1).BigInt(),
@@ -110,8 +110,8 @@ func (suite *BackendTestSuite) TestGetBlockByNumber() {
client := suite.backend.clientCtx.Client.(*mocks.Client)
RegisterBlockError(client, height)
},
false,
false,
true,
true,
},
{
"pass - block not found (e.g. request block height that is greater than current one)",
+11 -1
View File
@@ -284,6 +284,11 @@ func (e *PublicAPI) GetBalance(address common.Address, blockNrOrHash rpctypes.Bl
Address: address.String(),
}
_, err = e.backend.GetTendermintBlockByNumber(blockNum)
if err != nil {
return nil, err
}
res, err := e.queryClient.Balance(rpctypes.ContextWithHeight(blockNum.Int64()), req)
if err != nil {
return nil, err
@@ -951,7 +956,6 @@ func (e *PublicAPI) GetTransactionReceipt(hash common.Hash) (map[string]interfac
"transactionHash": hash,
"contractAddress": nil,
"gasUsed": hexutil.Uint64(parsedTx.GasUsed),
"type": hexutil.Uint(txData.TxType()),
// Inclusion information: These fields provide information about the inclusion of the
// transaction corresponding to this receipt.
@@ -1043,6 +1047,12 @@ func (e *PublicAPI) GetProof(address common.Address, storageKeys []string, block
}
height := blockNum.Int64()
_, err = e.backend.GetTendermintBlockByNumber(blockNum)
if err != nil {
// Get 'latest' proof if query is in the future
// this imitates geth behavior
height = 0
}
ctx := rpctypes.ContextWithHeight(height)
// if the height is equal to zero, meaning the query condition of the block is either "pending" or "latest"