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

Commit

Permalink
rpc: add NoBaseFee check in backend.BaseFee (#697)
Browse files Browse the repository at this point in the history
Co-authored-by: Federico Kunze Küllmer <[email protected]>
  • Loading branch information
JayT106 and fedekunze authored Oct 23, 2021
1 parent 5ff2a2c commit 08a8191
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
10 changes: 10 additions & 0 deletions rpc/ethereum/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,16 @@ func (e *EVMBackend) BaseFee(height int64) (*big.Int, error) {
return nil, nil
}

// Checks the feemarket param NoBaseFee settings, return 0 if it is enabled.
resParams, err := e.queryClient.FeeMarket.Params(e.ctx, &feemarkettypes.QueryParamsRequest{})
if err != nil {
return nil, err
}

if resParams.Params.NoBaseFee {
return big.NewInt(0), nil
}

blockRes, err := e.clientCtx.Client.BlockResults(e.ctx, &height)
if err != nil {
return nil, err
Expand Down
33 changes: 24 additions & 9 deletions tests/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,20 +412,22 @@ func TestEth_SendTransaction_Transfer(t *testing.T) {
}

func TestEth_SendTransaction_ContractDeploy(t *testing.T) {
param := make([]map[string]string, 1)
param[0] = make(map[string]string)
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
param[0]["data"] = "0x6080604052348015600f57600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a2603580604b6000396000f3fe6080604052600080fdfea165627a7a723058206cab665f0f557620554bb45adf266708d2bd349b8a4314bdff205ee8440e3c240029"
param[0]["gas"] = "0x200000"
param[0]["gasPrice"] = "0x1"

rpcRes := call(t, "eth_sendTransaction", param)
param := makeTestContractDeployParam(true)
rpcRes, err := callWithError("eth_sendTransaction", param)
require.NoError(t, err)

var hash hexutil.Bytes
err := json.Unmarshal(rpcRes.Result, &hash)
err = json.Unmarshal(rpcRes.Result, &hash)
require.NoError(t, err)
}

func TestEth_SendTransaction_ContractDeploy_no_gas_param(t *testing.T) {
param := makeTestContractDeployParam(false)
_, err := callWithError("eth_sendTransaction", param)
// server returns internal error.
require.Error(t, err)
}

func TestEth_NewFilter(t *testing.T) {
param := make([]map[string][]string, 1)
param[0] = make(map[string][]string)
Expand Down Expand Up @@ -1026,6 +1028,19 @@ func makeEthTxParam() []map[string]string {
return param
}

func makeTestContractDeployParam(withGas bool) []map[string]string {
param := make([]map[string]string, 1)
param[0] = make(map[string]string)
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
param[0]["data"] = "0x6080604052348015600f57600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a2603580604b6000396000f3fe6080604052600080fdfea165627a7a723058206cab665f0f557620554bb45adf266708d2bd349b8a4314bdff205ee8440e3c240029"
if withGas {
param[0]["gas"] = "0x200000"
param[0]["gasPrice"] = "0x1"
}

return param
}

func TestEth_EthResend(t *testing.T) {
tx := make(map[string]string)
tx["from"] = "0x" + fmt.Sprintf("%x", from)
Expand Down

0 comments on commit 08a8191

Please sign in to comment.