Fix wallet check for Windows by addresses differences in error message text (#7461)

* fix

* test

Co-authored-by: dv8silencer <15720668+dv8silencer@users.noreply.github.com>
Co-authored-by: Radosław Kapka <rkapka@wp.pl>
Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
This commit is contained in:
dv8silencer 2020-10-08 09:30:08 -05:00 committed by GitHub
parent 48fcb08ebc
commit 796c336a29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -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)