Fix failed to call EstimateGas (#761)
* fix failed to call function EstimateGas * add ut to test estimateGas after contract deployed
This commit is contained in:
parent
177574aafa
commit
fae8147352
@ -44,6 +44,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
|
||||||
|
* (evm) [\#760](https://github.com/cosmos/ethermint/issues/760) Fix Failed to call function EstimateGas.
|
||||||
* (evm) [\#767](https://github.com/cosmos/ethermint/issues/767) Fix error of timeout when using Truffle to deploy contract.
|
* (evm) [\#767](https://github.com/cosmos/ethermint/issues/767) Fix error of timeout when using Truffle to deploy contract.
|
||||||
* (evm) [\#751](https://github.com/cosmos/ethermint/issues/751) Fix misused method to calculate block hash in evm related function.
|
* (evm) [\#751](https://github.com/cosmos/ethermint/issues/751) Fix misused method to calculate block hash in evm related function.
|
||||||
* (evm) [\#721](https://github.com/cosmos/ethermint/issues/721) Fix mismatch block hash in rpc response when use eht.getBlock.
|
* (evm) [\#721](https://github.com/cosmos/ethermint/issues/721) Fix mismatch block hash in rpc response when use eht.getBlock.
|
||||||
|
@ -551,6 +551,8 @@ func (api *PublicEthereumAPI) doCall(
|
|||||||
addr = *args.From
|
addr = *args.From
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nonce, _ := api.accountNonce(api.clientCtx, addr, true)
|
||||||
|
|
||||||
// Set default gas & gas price if none were set
|
// Set default gas & gas price if none were set
|
||||||
// Change this to uint64(math.MaxUint64 / 2) if gas cap can be configured
|
// Change this to uint64(math.MaxUint64 / 2) if gas cap can be configured
|
||||||
gas := uint64(ethermint.DefaultRPCGasLimit)
|
gas := uint64(ethermint.DefaultRPCGasLimit)
|
||||||
@ -588,7 +590,7 @@ func (api *PublicEthereumAPI) doCall(
|
|||||||
|
|
||||||
var msgs []sdk.Msg
|
var msgs []sdk.Msg
|
||||||
// Create new call message
|
// Create new call message
|
||||||
msg := evmtypes.NewMsgEthermint(0, &toAddr, sdk.NewIntFromBigInt(value), gas,
|
msg := evmtypes.NewMsgEthermint(nonce, &toAddr, sdk.NewIntFromBigInt(value), gas,
|
||||||
sdk.NewIntFromBigInt(gasPrice), data, sdk.AccAddress(addr.Bytes()))
|
sdk.NewIntFromBigInt(gasPrice), data, sdk.AccAddress(addr.Bytes()))
|
||||||
msgs = append(msgs, msg)
|
msgs = append(msgs, msg)
|
||||||
|
|
||||||
@ -1086,8 +1088,9 @@ func (api *PublicEthereumAPI) pendingMsgs() ([]sdk.Msg, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pendingData := pendingTx.Input
|
pendingData := pendingTx.Input
|
||||||
|
nonce, _ := api.accountNonce(api.clientCtx, pendingTx.From, true)
|
||||||
|
|
||||||
msg := evmtypes.NewMsgEthermint(0, &pendingTo, sdk.NewIntFromBigInt(pendingValue), pendingGas,
|
msg := evmtypes.NewMsgEthermint(nonce, &pendingTo, sdk.NewIntFromBigInt(pendingValue), pendingGas,
|
||||||
sdk.NewIntFromBigInt(pendingGasPrice), pendingData, pendingFrom)
|
sdk.NewIntFromBigInt(pendingGasPrice), pendingData, pendingFrom)
|
||||||
|
|
||||||
msgs = append(msgs, msg)
|
msgs = append(msgs, msg)
|
||||||
|
@ -526,6 +526,7 @@ func TestEth_PendingTransactionFilter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEth_EstimateGas(t *testing.T) {
|
func TestEth_EstimateGas(t *testing.T) {
|
||||||
|
|
||||||
param := make([]map[string]string, 1)
|
param := make([]map[string]string, 1)
|
||||||
param[0] = make(map[string]string)
|
param[0] = make(map[string]string)
|
||||||
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
|
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
|
||||||
@ -539,18 +540,25 @@ func TestEth_EstimateGas(t *testing.T) {
|
|||||||
err := json.Unmarshal(rpcRes.Result, &gas)
|
err := json.Unmarshal(rpcRes.Result, &gas)
|
||||||
require.NoError(t, err, string(rpcRes.Result))
|
require.NoError(t, err, string(rpcRes.Result))
|
||||||
|
|
||||||
require.Equal(t, "0xf54c", gas)
|
require.Equal(t, "0xf560", gas)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEth_EstimateGas_ContractDeployment(t *testing.T) {
|
func TestEth_EstimateGas_ContractDeployment(t *testing.T) {
|
||||||
bytecode := "0x608060405234801561001057600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a260d08061004d6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063eb8ac92114602d575b600080fd5b606060048036036040811015604157600080fd5b8101908080359060200190929190803590602001909291905050506062565b005b8160008190555080827ff3ca124a697ba07e8c5e80bebcfcc48991fc16a63170e8a9206e30508960d00360405160405180910390a3505056fea265627a7a723158201d94d2187aaf3a6790527b615fcc40970febf0385fa6d72a2344848ebd0df3e964736f6c63430005110032"
|
bytecode := "0x608060405234801561001057600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a260d08061004d6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063eb8ac92114602d575b600080fd5b606060048036036040811015604157600080fd5b8101908080359060200190929190803590602001909291905050506062565b005b8160008190555080827ff3ca124a697ba07e8c5e80bebcfcc48991fc16a63170e8a9206e30508960d00360405160405180910390a3505056fea265627a7a723158201d94d2187aaf3a6790527b615fcc40970febf0385fa6d72a2344848ebd0df3e964736f6c63430005110032"
|
||||||
|
|
||||||
|
//deploy contract befor call estimateGas, make account nonce changed
|
||||||
|
hash, _ := DeployTestContract(t, from)
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
paramdeploy := []string{hash.String()}
|
||||||
|
rpcRes := Call(t, "eth_getTransactionReceipt", paramdeploy)
|
||||||
|
require.Nil(t, rpcRes.Error)
|
||||||
|
|
||||||
param := make([]map[string]string, 1)
|
param := make([]map[string]string, 1)
|
||||||
param[0] = make(map[string]string)
|
param[0] = make(map[string]string)
|
||||||
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
|
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
|
||||||
param[0]["data"] = bytecode
|
param[0]["data"] = bytecode
|
||||||
|
|
||||||
rpcRes := Call(t, "eth_estimateGas", param)
|
rpcRes = Call(t, "eth_estimateGas", param)
|
||||||
require.NotNil(t, rpcRes)
|
require.NotNil(t, rpcRes)
|
||||||
require.NotEmpty(t, rpcRes.Result)
|
require.NotEmpty(t, rpcRes.Result)
|
||||||
|
|
||||||
@ -558,7 +566,7 @@ func TestEth_EstimateGas_ContractDeployment(t *testing.T) {
|
|||||||
err := json.Unmarshal(rpcRes.Result, &gas)
|
err := json.Unmarshal(rpcRes.Result, &gas)
|
||||||
require.NoError(t, err, string(rpcRes.Result))
|
require.NoError(t, err, string(rpcRes.Result))
|
||||||
|
|
||||||
require.Equal(t, "0x1a724", gas.String())
|
require.Equal(t, "0x1a738", gas.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEth_GetBlockByNumber(t *testing.T) {
|
func TestEth_GetBlockByNumber(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user