From 43349eb9503fc77e5ab8a292c9129323ac8541d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E7=8B=97=E5=90=8C=E5=AD=A6?= Date: Mon, 6 Jul 2026 11:38:41 +0800 Subject: [PATCH] ethclient: include data in call arguments --- ethclient/ethclient.go | 4 +++- ethclient/gethclient/gethclient.go | 4 +++- ethclient/gethclient/gethclient_test.go | 16 ++++++++++++++++ ethclient/types_test.go | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index e888acc222..0c237da351 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -786,7 +786,9 @@ func toCallArg(msg ethereum.CallMsg) interface{} { "to": msg.To, } if len(msg.Data) > 0 { - arg["input"] = hexutil.Bytes(msg.Data) + input := hexutil.Bytes(msg.Data) + arg["input"] = input + arg["data"] = input } if msg.Value != nil { arg["value"] = (*hexutil.Big)(msg.Value) diff --git a/ethclient/gethclient/gethclient.go b/ethclient/gethclient/gethclient.go index e677e2bb21..69ae5c3674 100644 --- a/ethclient/gethclient/gethclient.go +++ b/ethclient/gethclient/gethclient.go @@ -370,7 +370,9 @@ func toCallArg(msg ethereum.CallMsg) interface{} { "to": msg.To, } if len(msg.Data) > 0 { - arg["input"] = hexutil.Bytes(msg.Data) + input := hexutil.Bytes(msg.Data) + arg["input"] = input + arg["data"] = input } if msg.Value != nil { arg["value"] = (*hexutil.Big)(msg.Value) diff --git a/ethclient/gethclient/gethclient_test.go b/ethclient/gethclient/gethclient_test.go index 4d8ccfcb6f..636458d1c5 100644 --- a/ethclient/gethclient/gethclient_test.go +++ b/ethclient/gethclient/gethclient_test.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -275,6 +276,21 @@ func testAccessList(t *testing.T, client *rpc.Client) { } } +func TestToCallArgIncludesDataAndInput(t *testing.T) { + input := common.FromHex("0x01020304") + arg := toCallArg(ethereum.CallMsg{Data: input}).(map[string]interface{}) + + for _, key := range []string{"input", "data"} { + have, ok := arg[key].(hexutil.Bytes) + if !ok { + t.Fatalf("missing call arg %q", key) + } + if !bytes.Equal(have, input) { + t.Fatalf("call arg %q = %x, want %x", key, have, input) + } + } +} + func testGetProof(t *testing.T, client *rpc.Client, addr common.Address) { ec := New(client) ethcl := ethclient.NewClient(client) diff --git a/ethclient/types_test.go b/ethclient/types_test.go index 8820b11162..09b3fb8a26 100644 --- a/ethclient/types_test.go +++ b/ethclient/types_test.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" ) func TestToFilterArg(t *testing.T) { @@ -179,3 +180,18 @@ func TestToFilterArg(t *testing.T) { }) } } + +func TestToCallArgIncludesDataAndInput(t *testing.T) { + input := common.FromHex("0x01020304") + arg := toCallArg(ethereum.CallMsg{Data: input}).(map[string]interface{}) + + for _, key := range []string{"input", "data"} { + have, ok := arg[key].(hexutil.Bytes) + if !ok { + t.Fatalf("missing call arg %q", key) + } + if !reflect.DeepEqual(have, hexutil.Bytes(input)) { + t.Fatalf("call arg %q = %x, want %x", key, have, input) + } + } +}