Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
tests(rpc): add backend blocks tests (#1296)
Browse files Browse the repository at this point in the history
* wip

* rename GetTendermintBlockByNumber to TendermintBlockByNumber

* rename GetTendermintBlockResultByNumber to TendermintBlockResultByNumber

* rename GetTendermintBlockByHash to TendermintBlockByHash

* rename BlockByNumber to EthBlockByNumber

* rename BlockByHash to EthBlockByHash

* rename GetBlockNumberByHash to BlockNumberFromTendermintByHash

* rename GetBlockNumber to BlockNumberFromTendermint

* rename GetEthereumMsgsFromTendermintBlock to EthMsgsFromTendermintBlock

* rename GetEthBlockFromTendermint to BlockFromTendermintBlock

* rename EthBlockFromTendermint to EthBlockFromTendermintBlock

* add TestEthBlockFromTendermintBlock with no transactions. Note that this endpoint is breaking when querying a block with transactions

* add block transaction count tests

* add TendermintBlockByHash test'

* add TestBlockNumberFromTendermint tests

* add HeaderByHash and HeaderByNumber tests

* add EthBlockFromTendermintBlock test

* add TestEthBlockByNumber tests

* Specificy that the endpoints are getting Etherum transactions in comments

* Refactor shared logic into GetBlockTransactionCount

* rename BlockFromTendermintBlock to RPCBlockFromTendermintBlock

* add CHangelog
  • Loading branch information
danburck authored Sep 5, 2022
1 parent 7bef408 commit 9f03ca7
Show file tree
Hide file tree
Showing 16 changed files with 1,110 additions and 362 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (cli) [#1230](https://github.com/evmos/ethermint/pull/1230) Remove redundant positional height parameter from feemarket's query cli.
* (ante) [#1289](https://github.com/evmos/ethermint/pull/1289) Change the fallback tx priority mechanism to be based on gas price.
* (test) [#1311](https://github.com/evmos/ethermint/pull/1311) add integration test for the rollback cmd
* (rpc) [#1296](https://github.com/evmos/ethermint/pull/1296) add backend blocks.go unit tests.

### Bug Fixes

Expand Down
17 changes: 7 additions & 10 deletions rpc/backend/account_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// GetCode returns the contract code at the given address and block number.
func (b *Backend) GetCode(address common.Address, blockNrOrHash rpctypes.BlockNumberOrHash) (hexutil.Bytes, error) {
blockNum, err := b.GetBlockNumber(blockNrOrHash)
blockNum, err := b.BlockNumberFromTendermint(blockNrOrHash)
if err != nil {
return nil, err
}
Expand All @@ -35,17 +35,14 @@ func (b *Backend) GetCode(address common.Address, blockNrOrHash rpctypes.BlockNu
}

// GetProof returns an account object with proof and any storage proofs
func (b *Backend) GetProof(address common.Address,
storageKeys []string,
blockNrOrHash rpctypes.BlockNumberOrHash,
) (*rpctypes.AccountResult, error) {
blockNum, err := b.GetBlockNumber(blockNrOrHash)
func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNrOrHash rpctypes.BlockNumberOrHash) (*rpctypes.AccountResult, error) {
blockNum, err := b.BlockNumberFromTendermint(blockNrOrHash)
if err != nil {
return nil, err
}

height := blockNum.Int64()
_, err = b.GetTendermintBlockByNumber(blockNum)
_, err = b.TendermintBlockByNumber(blockNum)
if err != nil {
// the error message imitates geth behavior
return nil, errors.New("header not found")
Expand Down Expand Up @@ -132,7 +129,7 @@ func (b *Backend) GetProof(address common.Address,

// GetStorageAt returns the contract storage at the given address, block number, and key.
func (b *Backend) GetStorageAt(address common.Address, key string, blockNrOrHash rpctypes.BlockNumberOrHash) (hexutil.Bytes, error) {
blockNum, err := b.GetBlockNumber(blockNrOrHash)
blockNum, err := b.BlockNumberFromTendermint(blockNrOrHash)
if err != nil {
return nil, err
}
Expand All @@ -153,7 +150,7 @@ func (b *Backend) GetStorageAt(address common.Address, key string, blockNrOrHash

// GetBalance returns the provided account's balance up to the provided block number.
func (b *Backend) GetBalance(address common.Address, blockNrOrHash rpctypes.BlockNumberOrHash) (*hexutil.Big, error) {
blockNum, err := b.GetBlockNumber(blockNrOrHash)
blockNum, err := b.BlockNumberFromTendermint(blockNrOrHash)
if err != nil {
return nil, err
}
Expand All @@ -162,7 +159,7 @@ func (b *Backend) GetBalance(address common.Address, blockNrOrHash rpctypes.Bloc
Address: address.String(),
}

_, err = b.GetTendermintBlockByNumber(blockNum)
_, err = b.TendermintBlockByNumber(blockNum)
if err != nil {
return nil, err
}
Expand Down
20 changes: 10 additions & 10 deletions rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,21 @@ type EVMBackend interface {
// Blocks Info
BlockNumber() (hexutil.Uint64, error)
GetBlockByNumber(blockNum rpctypes.BlockNumber, fullTx bool) (map[string]interface{}, error)
GetTendermintBlockByNumber(blockNum rpctypes.BlockNumber) (*tmrpctypes.ResultBlock, error)
GetTendermintBlockResultByNumber(height *int64) (*tmrpctypes.ResultBlockResults, error)
GetTendermintBlockByHash(blockHash common.Hash) (*tmrpctypes.ResultBlock, error)
GetBlockByHash(hash common.Hash, fullTx bool) (map[string]interface{}, error)
BlockByNumber(blockNum rpctypes.BlockNumber) (*ethtypes.Block, error)
BlockByHash(blockHash common.Hash) (*ethtypes.Block, error)
GetBlockNumberByHash(blockHash common.Hash) (*big.Int, error)
GetBlockNumber(blockNrOrHash rpctypes.BlockNumberOrHash) (rpctypes.BlockNumber, error)
GetBlockTransactionCountByHash(hash common.Hash) *hexutil.Uint
GetBlockTransactionCountByNumber(blockNum rpctypes.BlockNumber) *hexutil.Uint
TendermintBlockByNumber(blockNum rpctypes.BlockNumber) (*tmrpctypes.ResultBlock, error)
TendermintBlockResultByNumber(height *int64) (*tmrpctypes.ResultBlockResults, error)
TendermintBlockByHash(blockHash common.Hash) (*tmrpctypes.ResultBlock, error)
BlockNumberFromTendermint(blockNrOrHash rpctypes.BlockNumberOrHash) (rpctypes.BlockNumber, error)
BlockNumberFromTendermintByHash(blockHash common.Hash) (*big.Int, error)
EthMsgsFromTendermintBlock(block *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) []*evmtypes.MsgEthereumTx
BlockBloom(blockRes *tmrpctypes.ResultBlockResults) (ethtypes.Bloom, error)
GetEthereumMsgsFromTendermintBlock(block *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) []*evmtypes.MsgEthereumTx
HeaderByNumber(blockNum rpctypes.BlockNumber) (*ethtypes.Header, error)
HeaderByHash(blockHash common.Hash) (*ethtypes.Header, error)
EthBlockFromTendermint(resBlock *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults, fullTx bool) (map[string]interface{}, error)
EthBlockFromTm(resBlock *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) (*ethtypes.Block, error)
RPCBlockFromTendermintBlock(resBlock *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults, fullTx bool) (map[string]interface{}, error)
EthBlockByNumber(blockNum rpctypes.BlockNumber) (*ethtypes.Block, error)
EthBlockFromTendermintBlock(resBlock *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) (*ethtypes.Block, error)

// Account Info
GetCode(address common.Address, blockNrOrHash rpctypes.BlockNumberOrHash) (hexutil.Bytes, error)
Expand Down Expand Up @@ -117,6 +116,7 @@ type EVMBackend interface {
SetTxDefaults(args evmtypes.TransactionArgs) (evmtypes.TransactionArgs, error)
EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rpctypes.BlockNumber) (hexutil.Uint64, error)
DoCall(args evmtypes.TransactionArgs, blockNr rpctypes.BlockNumber) (*evmtypes.MsgEthereumTxResponse, error)
GasPrice() (*hexutil.Big, error)

// Filter API
GetLogs(hash common.Hash) ([][]*ethtypes.Log, error)
Expand Down
Loading

0 comments on commit 9f03ca7

Please sign in to comment.