From de2d7f9a13c827c6346871beb6fe7f9a78bd2b75 Mon Sep 17 00:00:00 2001 From: jinhoonbang Date: Wed, 14 Feb 2024 12:28:53 -0800 Subject: [PATCH] handle nil gas and gasPrice in backend test client for estimateGas --- .../evm/client/simulated_backend_client.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/chains/evm/client/simulated_backend_client.go b/core/chains/evm/client/simulated_backend_client.go index 3a235b8db40..c49637e7890 100644 --- a/core/chains/evm/client/simulated_backend_client.go +++ b/core/chains/evm/client/simulated_backend_client.go @@ -728,6 +728,28 @@ func toCallMsg(params map[string]interface{}) ethereum.CallMsg { callMsg.Value = value } + switch gas := params["gas"].(type) { + case nil: + // This parameter is not required so nil is acceptable + case uint64: + callMsg.Gas = gas + case hexutil.Uint64: + callMsg.Gas = uint64(gas) + default: + panic("unexpected type of 'gas' parameter; try hexutil.Uint64, or uint64") + } + + switch gasPrice := params["gasPrice"].(type) { + case nil: + // This parameter is not required so nil is acceptable + case *big.Int: + callMsg.GasPrice = gasPrice + case *hexutil.Big: + callMsg.GasPrice = gasPrice.ToInt() + default: + panic("unexpected type of 'gasPrice' parameter; try *big.Int, or *hexutil.Big") + } + return callMsg }