From 2bf2b6758bed43b6889a72d7a436de36789ac51c Mon Sep 17 00:00:00 2001 From: Daniel Burckhardt Date: Tue, 23 Nov 2021 16:00:25 +0100 Subject: [PATCH] fix: RPC tests fail if FeeMarket `BaseFee` is enabled by default (#770) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix(FeeMarket): Enable FeeMarkat BaseFee * fix rpc tests * changelog Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Freddy Caceres Co-authored-by: Federico Kunze Küllmer --- CHANGELOG.md | 1 + tests/rpc/rpc_pending_test.go | 12 +++++++----- tests/rpc/rpc_test.go | 26 +++++++++++++++++--------- tests/rpc/utils.go | 9 +++++++++ x/feemarket/types/params.go | 2 +- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1eb6abc..3442be09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (feemarket) [tharsis#770](https://github.com/tharsis/ethermint/pull/770) Enable fee market (EIP1559) by default. * (rpc) [tharsis#769](https://github.com/tharsis/ethermint/pull/769) Fix default Ethereum signer for JSON-RPC. ## [v0.8.0] - 2021-11-17 diff --git a/tests/rpc/rpc_pending_test.go b/tests/rpc/rpc_pending_test.go index 575bb584..544ee08b 100644 --- a/tests/rpc/rpc_pending_test.go +++ b/tests/rpc/rpc_pending_test.go @@ -100,7 +100,7 @@ func TestEth_Pending_GetTransactionCount(t *testing.T) { t.Logf("Current nonce is %d", currentNonce) require.Equal(t, prePendingNonce, currentNonce) - param := makePendingTxParams() + param := makePendingTxParams(t) txRes := Call(t, "eth_sendTransaction", param) require.Nil(t, txRes.Error) @@ -278,7 +278,7 @@ func TestEth_Pending_GetTransactionByHash(t *testing.T) { // create a transaction. data := "0x608060405234801561001057600080fd5b5061011e806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806302eb691b14602d575b600080fd5b603360ab565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101560715780820151818401526020810190506058565b50505050905090810190601f168015609d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60606040518060400160405280600d81526020017f617261736b61776173686572650000000000000000000000000000000000000081525090509056fea264697066735822122060917c5c2fab8c058a17afa6d3c1d23a7883b918ea3c7157131ea5b396e1aa7564736f6c63430007050033" - param := makePendingTxParams() + param := makePendingTxParams(t) param[0]["data"] = data txRes := Call(t, "eth_sendTransaction", param) @@ -306,7 +306,7 @@ func TestEth_Pending_GetTransactionByHash(t *testing.T) { func TestEth_Pending_SendTransaction_PendingNonce(t *testing.T) { currNonce := GetNonce(t, "latest") - param := makePendingTxParams() + param := makePendingTxParams(t) // first transaction txRes1 := Call(t, "eth_sendTransaction", param) @@ -331,13 +331,15 @@ func TestEth_Pending_SendTransaction_PendingNonce(t *testing.T) { require.Greater(t, uint64(pendingNonce3), uint64(pendingNonce2)) } -func makePendingTxParams() []map[string]string { +func makePendingTxParams(t *testing.T) []map[string]string { + gasPrice := GetGasPrice(t) + param := make([]map[string]string, 1) param[0] = make(map[string]string) param[0]["from"] = "0x" + fmt.Sprintf("%x", from) param[0]["to"] = addrA param[0]["value"] = "0xA" param[0]["gasLimit"] = "0x5208" - param[0]["gasPrice"] = "0x1" + param[0]["gasPrice"] = gasPrice return param } diff --git a/tests/rpc/rpc_test.go b/tests/rpc/rpc_test.go index 7f2526c3..4d020f52 100644 --- a/tests/rpc/rpc_test.go +++ b/tests/rpc/rpc_test.go @@ -412,7 +412,7 @@ func TestEth_SendTransaction_Transfer(t *testing.T) { } func TestEth_SendTransaction_ContractDeploy(t *testing.T) { - param := makeTestContractDeployParam(true) + param := makeTestContractDeployParam(t, true) rpcRes, err := callWithError("eth_sendTransaction", param) require.NoError(t, err) @@ -422,7 +422,7 @@ func TestEth_SendTransaction_ContractDeploy(t *testing.T) { } func TestEth_SendTransaction_ContractDeploy_no_gas_param(t *testing.T) { - param := makeTestContractDeployParam(false) + param := makeTestContractDeployParam(t, false) _, err := callWithError("eth_sendTransaction", param) // server returns internal error. require.Error(t, err) @@ -503,12 +503,14 @@ func TestEth_GetFilterChanges_WrongID(t *testing.T) { // sendTestTransaction sends a dummy transaction func sendTestTransaction(t *testing.T) hexutil.Bytes { + gasPrice := GetGasPrice(t) + param := make([]map[string]string, 1) param[0] = make(map[string]string) param[0]["from"] = "0x" + fmt.Sprintf("%x", from) param[0]["to"] = "0x1122334455667788990011223344556677889900" param[0]["value"] = "0x1" - param[0]["gasPrice"] = "0x1" + param[0]["gasPrice"] = gasPrice rpcRes := call(t, "eth_sendTransaction", param) var hash hexutil.Bytes @@ -529,6 +531,8 @@ func TestEth_GetTransactionReceipt(t *testing.T) { // deployTestERC20Contract deploys a contract that emits an event in the constructor func deployTestERC20Contract(t *testing.T) common.Address { + gasPrice := GetGasPrice(t) + param := make([]map[string]string, 1) param[0] = make(map[string]string) param[0]["from"] = "0x" + fmt.Sprintf("%x", from) @@ -539,7 +543,7 @@ func deployTestERC20Contract(t *testing.T) common.Address { param[0]["data"] = hexutil.Encode(data) param[0]["gas"] = "0x200000" - param[0]["gasPrice"] = "0x1" + param[0]["gasPrice"] = gasPrice rpcRes := call(t, "eth_sendTransaction", param) @@ -559,6 +563,7 @@ func deployTestERC20Contract(t *testing.T) common.Address { // sendTestERC20Transaction sends a typical erc20 transfer transaction func sendTestERC20Transaction(t *testing.T, contract common.Address, amount *big.Int) hexutil.Bytes { // transfer + gasPrice := GetGasPrice(t) param := make([]map[string]string, 1) param[0] = make(map[string]string) param[0]["from"] = "0x" + fmt.Sprintf("%x", from) @@ -567,7 +572,7 @@ func sendTestERC20Transaction(t *testing.T, contract common.Address, amount *big require.NoError(t, err) param[0]["data"] = hexutil.Encode(data) param[0]["gas"] = "0x50000" - param[0]["gasPrice"] = "0x1" + param[0]["gasPrice"] = gasPrice rpcRes := call(t, "eth_sendTransaction", param) @@ -607,12 +612,13 @@ func TestEth_GetTransactionReceipt_ERC20Transfer(t *testing.T) { // deployTestContract deploys a contract that emits an event in the constructor func deployTestContract(t *testing.T) (hexutil.Bytes, map[string]interface{}) { + gasPrice := GetGasPrice(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" + param[0]["gasPrice"] = gasPrice rpcRes := call(t, "eth_sendTransaction", param) @@ -744,13 +750,14 @@ func deployTestContractWithFunction(t *testing.T) hexutil.Bytes { // } bytecode := "0x608060405234801561001057600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a260d08061004d6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063eb8ac92114602d575b600080fd5b606060048036036040811015604157600080fd5b8101908080359060200190929190803590602001909291905050506062565b005b8160008190555080827ff3ca124a697ba07e8c5e80bebcfcc48991fc16a63170e8a9206e30508960d00360405160405180910390a3505056fea265627a7a723158201d94d2187aaf3a6790527b615fcc40970febf0385fa6d72a2344848ebd0df3e964736f6c63430005110032" + gasPrice := GetGasPrice(t) param := make([]map[string]string, 1) param[0] = make(map[string]string) param[0]["from"] = "0x" + fmt.Sprintf("%x", from) param[0]["data"] = bytecode param[0]["gas"] = "0x200000" - param[0]["gasPrice"] = "0x1" + param[0]["gasPrice"] = gasPrice rpcRes := call(t, "eth_sendTransaction", param) @@ -1028,14 +1035,15 @@ func makeEthTxParam() []map[string]string { return param } -func makeTestContractDeployParam(withGas bool) []map[string]string { +func makeTestContractDeployParam(t *testing.T, 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 { + gasPrice := GetGasPrice(t) param[0]["gas"] = "0x200000" - param[0]["gasPrice"] = "0x1" + param[0]["gasPrice"] = gasPrice } return param diff --git a/tests/rpc/utils.go b/tests/rpc/utils.go index 0481ba64..3fa2abeb 100644 --- a/tests/rpc/utils.go +++ b/tests/rpc/utils.go @@ -267,6 +267,15 @@ func GetNonce(t *testing.T, block string) hexutil.Uint64 { return nonce } +func GetGasPrice(t *testing.T) string { + gasRes := Call(t, "eth_gasPrice", []interface{}{}) + + var gasPrice string + err := json.Unmarshal(gasRes.Result, &gasPrice) + require.NoError(t, err) + return gasPrice +} + func UnlockAllAccounts(t *testing.T) { var accts []common.Address rpcRes := Call(t, "eth_accounts", []map[string]string{}) diff --git a/x/feemarket/types/params.go b/x/feemarket/types/params.go index 78c80f51..f347181b 100644 --- a/x/feemarket/types/params.go +++ b/x/feemarket/types/params.go @@ -43,7 +43,7 @@ func NewParams(noBaseFee bool, baseFeeChangeDenom, elasticityMultiplier uint32, // DefaultParams returns default evm parameters func DefaultParams() Params { return Params{ - NoBaseFee: true, + NoBaseFee: false, BaseFeeChangeDenominator: params.BaseFeeChangeDenominator, ElasticityMultiplier: params.ElasticityMultiplier, InitialBaseFee: params.InitialBaseFee,