From 866382c4187cc63acaf31ea4cf375b2ce29108a9 Mon Sep 17 00:00:00 2001 From: Matt Curtis Date: Fri, 24 May 2024 12:19:11 +0100 Subject: [PATCH] Gateway: hardcode response to clientVersion request --- .../networktest/tests/gateway/gateway_test.go | 11 ++++++++++ tools/walletextension/rpcapi/web3_api.go | 20 +++++++++++++++++++ .../walletextension_container.go | 3 +++ 3 files changed, 34 insertions(+) create mode 100644 tools/walletextension/rpcapi/web3_api.go diff --git a/integration/networktest/tests/gateway/gateway_test.go b/integration/networktest/tests/gateway/gateway_test.go index 6a2bc1985d..f919db84d9 100644 --- a/integration/networktest/tests/gateway/gateway_test.go +++ b/integration/networktest/tests/gateway/gateway_test.go @@ -66,6 +66,17 @@ func TestGatewayHappyPath(t *testing.T) { return fmt.Errorf("expected net_version to be %s but got %s", expectedResult, result) } + // check web3_clientVersion response + var cvResult string + err = rpcClient.CallContext(ctx, &cvResult, "web3_clientVersion") + if err != nil { + return fmt.Errorf("failed to get web3_clientVersion: %w", err) + } + fmt.Println("web3_clientVersion response:", cvResult) + if cvResult == "" { + return fmt.Errorf("expected web3_clientVersion to be non-empty") + } + return nil }), ), diff --git a/tools/walletextension/rpcapi/web3_api.go b/tools/walletextension/rpcapi/web3_api.go new file mode 100644 index 0000000000..4794e6fd0e --- /dev/null +++ b/tools/walletextension/rpcapi/web3_api.go @@ -0,0 +1,20 @@ +package rpcapi + +import ( + "context" +) + +var _hardcodedClientVersion = "Geth/v10.0.0/drpc" + +type Web3API struct { + we *Services +} + +func NewWeb3API(we *Services) *Web3API { + return &Web3API{we} +} + +func (api *Web3API) ClientVersion(_ context.Context) (*string, error) { + // todo: have this return the Ten version from the node + return &_hardcodedClientVersion, nil +} diff --git a/tools/walletextension/walletextension_container.go b/tools/walletextension/walletextension_container.go index 96e322b08c..f5bf5d36f7 100644 --- a/tools/walletextension/walletextension_container.go +++ b/tools/walletextension/walletextension_container.go @@ -86,6 +86,9 @@ func NewContainerFromConfig(config wecommon.Config, logger gethlog.Logger) *Cont }, { Namespace: "net", Service: rpcapi.NewNetAPI(walletExt), + }, { + Namespace: "web3", + Service: rpcapi.NewWeb3API(walletExt), }, })