From 5bd25618b59dd2cc5f3b98cf4ce65572bb6f108b Mon Sep 17 00:00:00 2001 From: Adu Date: Wed, 10 Nov 2021 18:46:45 +0800 Subject: [PATCH 1/4] Problem: need to add JSON-RPC endpoint personal_initializeWallet Closes #738 * this is aimed at smartcard wallet which is not supported yet. --- rpc/ethereum/namespaces/personal/api.go | 8 ++++++++ tests/rpc/personal_test.go | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/rpc/ethereum/namespaces/personal/api.go b/rpc/ethereum/namespaces/personal/api.go index b5786e5935..945e6918ae 100644 --- a/rpc/ethereum/namespaces/personal/api.go +++ b/rpc/ethereum/namespaces/personal/api.go @@ -230,3 +230,11 @@ func (api *PrivateAccountAPI) Unpair(_ context.Context, url, pin string) error { // TODO: Smartcard wallet not supported yet, refer to: https://github.com/ethereum/go-ethereum/blob/master/accounts/scwallet/README.md return fmt.Errorf("smartcard wallet not supported yet") } + +// InitializeWallet initializes a new wallet at the provided URL, by generating and returning a new private key. +func (api *PrivateAccountAPI) InitializeWallet(_ context.Context, url string) (string, error) { + api.logger.Debug("personal_initializeWallet", "url", url) + api.logger.Info("personal_initializeWallet for smartcard wallet not supported") + // TODO: Smartcard wallet not supported yet, refer to: https://github.com/ethereum/go-ethereum/blob/master/accounts/scwallet/README.md + return "", fmt.Errorf("smartcard wallet not supported yet") +} diff --git a/tests/rpc/personal_test.go b/tests/rpc/personal_test.go index b0614ee586..ccba68c861 100644 --- a/tests/rpc/personal_test.go +++ b/tests/rpc/personal_test.go @@ -148,9 +148,13 @@ func TestPersonal_LockAccount(t *testing.T) { func TestPersonal_Unpair(t *testing.T) { t.Skip("skipping TestPersonal_Unpair") - rpcRes := Call(t, "personal_unpair", []interface{}{"", 0}) + _, err := CallWithError(t, "personal_unpair", []interface{}{"", 0}) + require.True(t, errors.Is(err, fmt.Errorf("smartcard wallet not supported yet"))) +} - var res error - err := json.Unmarshal(rpcRes.Result, &res) +func TestPersonal_InitializeWallet(t *testing.T) { + t.Skip("skipping TestPersonal_InitializeWallet") + + _, err := CallWithError(t, "personal_initializeWallet", []interface{}{""}) require.True(t, errors.Is(err, fmt.Errorf("smartcard wallet not supported yet"))) } From d083005e4cd4ec95b7437fe12d57779f7dd1d810 Mon Sep 17 00:00:00 2001 From: Adu Date: Wed, 10 Nov 2021 19:10:19 +0800 Subject: [PATCH 2/4] changelog and not skip for expecting error --- CHANGELOG.md | 1 + tests/rpc/personal_test.go | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 987f22078a..5fb08d4636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (evm) [tharsis#662](https://github.com/tharsis/ethermint/pull/662) Disable basefee for non london blocks * (cmd) [tharsis#712](https://github.com/tharsis/ethermint/pull/712) add tx cli to build evm transaction * (rpc) [tharsis#733](https://github.com/tharsis/ethermint/pull/733) add JSON_RPC endpoint personal_unpair +* (rpc) [tharsis#740](https://github.com/tharsis/ethermint/pull/740) add JSON_RPC endpoint personal_initializeWallet ### Bug Fixes diff --git a/tests/rpc/personal_test.go b/tests/rpc/personal_test.go index ccba68c861..5a1ea87f4e 100644 --- a/tests/rpc/personal_test.go +++ b/tests/rpc/personal_test.go @@ -146,15 +146,11 @@ func TestPersonal_LockAccount(t *testing.T) { } func TestPersonal_Unpair(t *testing.T) { - t.Skip("skipping TestPersonal_Unpair") - - _, err := CallWithError(t, "personal_unpair", []interface{}{"", 0}) + _, err := CallWithError("personal_unpair", []interface{}{"", 0}) require.True(t, errors.Is(err, fmt.Errorf("smartcard wallet not supported yet"))) } func TestPersonal_InitializeWallet(t *testing.T) { - t.Skip("skipping TestPersonal_InitializeWallet") - - _, err := CallWithError(t, "personal_initializeWallet", []interface{}{""}) + _, err := CallWithError("personal_initializeWallet", []interface{}{""}) require.True(t, errors.Is(err, fmt.Errorf("smartcard wallet not supported yet"))) } From 5fb1964c37e077efd852be8607aac99e7f2d7477 Mon Sep 17 00:00:00 2001 From: Adu Date: Thu, 11 Nov 2021 19:36:35 +0800 Subject: [PATCH 3/4] fix personal_test error message assertion --- tests/rpc/personal_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/rpc/personal_test.go b/tests/rpc/personal_test.go index 5a1ea87f4e..78c771f791 100644 --- a/tests/rpc/personal_test.go +++ b/tests/rpc/personal_test.go @@ -2,8 +2,6 @@ package rpc import ( "encoding/json" - "errors" - "fmt" "testing" "github.com/stretchr/testify/require" @@ -146,11 +144,11 @@ func TestPersonal_LockAccount(t *testing.T) { } func TestPersonal_Unpair(t *testing.T) { - _, err := CallWithError("personal_unpair", []interface{}{"", 0}) - require.True(t, errors.Is(err, fmt.Errorf("smartcard wallet not supported yet"))) + _, err := CallWithError("personal_unpair", []interface{}{"", ""}) + require.True(t, err.Error() == "smartcard wallet not supported yet") } func TestPersonal_InitializeWallet(t *testing.T) { _, err := CallWithError("personal_initializeWallet", []interface{}{""}) - require.True(t, errors.Is(err, fmt.Errorf("smartcard wallet not supported yet"))) + require.True(t, err.Error() == "smartcard wallet not supported yet") } From a2d47ca0285fe0e9daed81460a2e7225c871c4c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Thu, 11 Nov 2021 15:57:38 +0100 Subject: [PATCH 4/4] Apply suggestions from code review --- tests/rpc/personal_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rpc/personal_test.go b/tests/rpc/personal_test.go index 78c771f791..9b9d858c95 100644 --- a/tests/rpc/personal_test.go +++ b/tests/rpc/personal_test.go @@ -145,10 +145,10 @@ func TestPersonal_LockAccount(t *testing.T) { func TestPersonal_Unpair(t *testing.T) { _, err := CallWithError("personal_unpair", []interface{}{"", ""}) - require.True(t, err.Error() == "smartcard wallet not supported yet") + require.Equal(t, "smartcard wallet not supported yet", err.Error()) } func TestPersonal_InitializeWallet(t *testing.T) { _, err := CallWithError("personal_initializeWallet", []interface{}{""}) - require.True(t, err.Error() == "smartcard wallet not supported yet") + require.Equal(t, "smartcard wallet not supported yet", err.Error()) }