From 796c336a29420da4ffb89e035f19f66697de3b61 Mon Sep 17 00:00:00 2001 From: dv8silencer <15720668+dv8silencer@users.noreply.github.com> Date: Thu, 8 Oct 2020 09:30:08 -0500 Subject: [PATCH] Fix wallet check for Windows by addresses differences in error message text (#7461) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix * test Co-authored-by: dv8silencer <15720668+dv8silencer@users.noreply.github.com> Co-authored-by: Radosław Kapka Co-authored-by: Victor Farazdagi --- validator/accounts/v2/wallet/wallet.go | 3 ++- validator/accounts/v2/wallet/wallet_test.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/validator/accounts/v2/wallet/wallet.go b/validator/accounts/v2/wallet/wallet.go index aa5e746f27..5d298aef1b 100644 --- a/validator/accounts/v2/wallet/wallet.go +++ b/validator/accounts/v2/wallet/wallet.go @@ -130,7 +130,8 @@ func IsValid(walletDir string) (bool, error) { } f, err := os.Open(expanded) if err != nil { - if strings.Contains(err.Error(), "no such file") { + if strings.Contains(err.Error(), "no such file") || + strings.Contains(err.Error(), "cannot find the path") { return false, nil } return false, err diff --git a/validator/accounts/v2/wallet/wallet_test.go b/validator/accounts/v2/wallet/wallet_test.go index 5add7f44da..9565fd7388 100644 --- a/validator/accounts/v2/wallet/wallet_test.go +++ b/validator/accounts/v2/wallet/wallet_test.go @@ -132,12 +132,16 @@ func Test_IsValid_RandomFiles(t *testing.T) { randPath, err := rand.Int(rand.Reader, big.NewInt(1000000)) require.NoError(t, err, "Could not generate random file path") path := filepath.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath), "wallet") + valid, err := wallet.IsValid(path) + require.NoError(t, err) + require.Equal(t, false, valid) + t.Cleanup(func() { require.NoError(t, os.RemoveAll(path), "Failed to remove directory") }) require.NoError(t, os.MkdirAll(path, params.BeaconIoConfig().ReadWriteExecutePermissions), "Failed to create directory") - valid, err := wallet.IsValid(path) + valid, err = wallet.IsValid(path) require.ErrorContains(t, "no wallet found at path", err) require.Equal(t, false, valid)