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

tests(rpc): add backend blocks tests #1296

Merged
merged 26 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3889e5c
wip
danburck Aug 24, 2022
813c6bc
rename GetTendermintBlockByNumber to TendermintBlockByNumber
danburck Aug 24, 2022
8539048
rename GetTendermintBlockResultByNumber to TendermintBlockResultByNumber
danburck Aug 24, 2022
6c81666
rename GetTendermintBlockByHash to TendermintBlockByHash
danburck Aug 24, 2022
7635cd5
rename BlockByNumber to EthBlockByNumber
danburck Aug 24, 2022
7849438
rename BlockByHash to EthBlockByHash
danburck Aug 24, 2022
262a82f
rename GetBlockNumberByHash to BlockNumberFromTendermintByHash
danburck Aug 24, 2022
c86944e
rename GetBlockNumber to BlockNumberFromTendermint
danburck Aug 24, 2022
0225d93
rename GetEthereumMsgsFromTendermintBlock to EthMsgsFromTendermintBlock
danburck Aug 24, 2022
ab6ccb5
rename GetEthBlockFromTendermint to BlockFromTendermintBlock
danburck Aug 24, 2022
f5bbeed
rename EthBlockFromTendermint to EthBlockFromTendermintBlock
danburck Aug 24, 2022
0eb790d
add TestEthBlockFromTendermintBlock with no transactions. Note that t…
danburck Aug 24, 2022
0b81c15
add block transaction count tests
danburck Aug 24, 2022
41c6d85
add TendermintBlockByHash test'
danburck Aug 24, 2022
1e23245
add TestBlockNumberFromTendermint tests
danburck Aug 25, 2022
cf529ed
add HeaderByHash and HeaderByNumber tests
danburck Aug 25, 2022
192cb19
add EthBlockFromTendermintBlock test
danburck Aug 26, 2022
793396d
add TestEthBlockByNumber tests
danburck Aug 26, 2022
23f9503
Merge branch 'main' into 1248-improve-rpc-backend-coverage
danburck Aug 26, 2022
711a90e
Specificy that the endpoints are getting Etherum transactions in comm…
danburck Sep 2, 2022
56af7a2
Refactor shared logic into GetBlockTransactionCount
danburck Sep 2, 2022
5f4e693
rename BlockFromTendermintBlock to RPCBlockFromTendermintBlock
danburck Sep 2, 2022
f4023fd
Merge branch 'main' into 1248-improve-rpc-backend-coverage
danburck Sep 2, 2022
01282de
add CHangelog
danburck Sep 2, 2022
aa3d59e
Merge branch '1248-improve-rpc-backend-coverage' of https://github.co…
danburck Sep 2, 2022
9ae3458
Merge branch 'main' into 1248-improve-rpc-backend-coverage
danburck Sep 5, 2022
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
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)
BlockFromTendermintBlock(resBlock *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults, fullTx bool) (map[string]interface{}, error)
danburck marked this conversation as resolved.
Show resolved Hide resolved
EthBlockByNumber(blockNum rpctypes.BlockNumber) (*ethtypes.Block, error)
EthBlockFromTendermintBlock(resBlock *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) (*ethtypes.Block, error)
danburck marked this conversation as resolved.
Show resolved Hide resolved

// 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