2020-09-17 01:34:42 +00:00
|
|
|
package wallet_test
|
2020-07-01 21:30:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2020-07-23 03:10:23 +00:00
|
|
|
"path/filepath"
|
2020-07-01 21:30:01 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-08-01 00:08:40 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2020-07-20 10:56:45 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-10-15 22:31:52 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
2020-07-01 21:30:01 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-08-10 18:54:40 +00:00
|
|
|
)
|
|
|
|
|
2020-07-01 21:30:01 +00:00
|
|
|
func init() {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
logrus.SetOutput(ioutil.Discard)
|
|
|
|
}
|
|
|
|
|
2020-09-30 14:13:37 +00:00
|
|
|
func Test_Exists_RandomFiles(t *testing.T) {
|
2020-11-10 22:45:17 +00:00
|
|
|
path := filepath.Join(t.TempDir(), "wallet")
|
2020-09-30 14:13:37 +00:00
|
|
|
|
|
|
|
exists, err := wallet.Exists(path)
|
|
|
|
require.Equal(t, false, exists)
|
|
|
|
require.NoError(t, err)
|
2020-10-02 21:35:28 +00:00
|
|
|
require.NoError(t, os.MkdirAll(path+"/direct", params.BeaconIoConfig().ReadWriteExecutePermissions), "Failed to create directory")
|
2020-09-30 14:13:37 +00:00
|
|
|
|
|
|
|
exists, err = wallet.Exists(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, true, exists)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_IsValid_RandomFiles(t *testing.T) {
|
2020-11-10 22:45:17 +00:00
|
|
|
path := filepath.Join(t.TempDir(), "wallet")
|
2020-10-08 14:30:08 +00:00
|
|
|
valid, err := wallet.IsValid(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, false, valid)
|
|
|
|
|
2020-10-02 21:35:28 +00:00
|
|
|
require.NoError(t, os.MkdirAll(path, params.BeaconIoConfig().ReadWriteExecutePermissions), "Failed to create directory")
|
2020-09-30 14:13:37 +00:00
|
|
|
|
2020-10-08 14:30:08 +00:00
|
|
|
valid, err = wallet.IsValid(path)
|
2020-10-22 17:31:03 +00:00
|
|
|
require.ErrorContains(t, "no wallet found", err)
|
2020-09-30 14:13:37 +00:00
|
|
|
require.Equal(t, false, valid)
|
2020-08-01 00:08:40 +00:00
|
|
|
|
2020-09-30 14:13:37 +00:00
|
|
|
walletDir := filepath.Join(path, "direct")
|
|
|
|
require.NoError(t, os.MkdirAll(walletDir, params.BeaconIoConfig().ReadWriteExecutePermissions), "Failed to create directory")
|
|
|
|
|
|
|
|
valid, err = wallet.IsValid(path)
|
2020-08-01 00:08:40 +00:00
|
|
|
require.NoError(t, err)
|
2020-09-30 14:13:37 +00:00
|
|
|
require.Equal(t, true, valid)
|
2020-08-01 00:08:40 +00:00
|
|
|
}
|