2018-06-06 02:38:16 +00:00
|
|
|
package node
|
|
|
|
|
2018-06-17 02:26:03 +00:00
|
|
|
import (
|
2020-12-11 18:31:35 +00:00
|
|
|
"context"
|
2018-06-17 02:26:03 +00:00
|
|
|
"flag"
|
2020-10-14 22:20:20 +00:00
|
|
|
"io/ioutil"
|
2019-02-13 23:49:06 +00:00
|
|
|
"os"
|
2020-10-09 09:28:35 +00:00
|
|
|
"path/filepath"
|
2018-06-17 02:26:03 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-03-02 18:58:40 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/cmd/validator/flags"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
2020-10-15 22:31:52 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
2020-10-09 09:28:35 +00:00
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
2020-05-31 06:44:34 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-06-17 02:26:03 +00:00
|
|
|
)
|
2018-06-06 02:38:16 +00:00
|
|
|
|
2018-06-17 02:26:03 +00:00
|
|
|
// Test that the sharding node can build with default flag values.
|
|
|
|
func TestNode_Builds(t *testing.T) {
|
2020-03-19 21:46:44 +00:00
|
|
|
app := cli.App{}
|
2018-06-17 02:26:03 +00:00
|
|
|
set := flag.NewFlagSet("test", 0)
|
2020-11-10 22:45:17 +00:00
|
|
|
set.String("datadir", t.TempDir()+"/datadir", "the node data directory")
|
|
|
|
dir := t.TempDir() + "/walletpath"
|
|
|
|
passwordDir := t.TempDir() + "/password"
|
2020-10-14 22:20:20 +00:00
|
|
|
require.NoError(t, os.MkdirAll(passwordDir, os.ModePerm))
|
|
|
|
passwordFile := filepath.Join(passwordDir, "password.txt")
|
|
|
|
walletPassword := "$$Passw0rdz2$$"
|
|
|
|
require.NoError(t, ioutil.WriteFile(
|
|
|
|
passwordFile,
|
|
|
|
[]byte(walletPassword),
|
|
|
|
os.ModePerm,
|
|
|
|
))
|
|
|
|
set.String("wallet-dir", dir, "path to wallet")
|
|
|
|
set.String("wallet-password-file", passwordFile, "path to wallet password")
|
2020-10-16 18:45:14 +00:00
|
|
|
set.String("keymanager-kind", "imported", "keymanager kind")
|
2019-09-26 18:23:25 +00:00
|
|
|
set.String("verbosity", "debug", "log verbosity")
|
2020-10-14 22:20:20 +00:00
|
|
|
require.NoError(t, set.Set(flags.WalletPasswordFileFlag.Name, passwordFile))
|
2020-03-19 21:46:44 +00:00
|
|
|
context := cli.NewContext(&app, set, nil)
|
2020-10-20 02:26:31 +00:00
|
|
|
_, err := accounts.CreateWalletWithKeymanager(context.Context, &accounts.CreateWalletConfig{
|
2020-10-14 22:20:20 +00:00
|
|
|
WalletCfg: &wallet.Config{
|
|
|
|
WalletDir: dir,
|
2020-10-16 18:45:14 +00:00
|
|
|
KeymanagerKind: keymanager.Imported,
|
2020-10-14 22:20:20 +00:00
|
|
|
WalletPassword: walletPassword,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2018-06-17 02:26:03 +00:00
|
|
|
|
2020-10-09 09:28:35 +00:00
|
|
|
valClient, err := NewValidatorClient(context)
|
2020-07-23 01:13:52 +00:00
|
|
|
require.NoError(t, err, "Failed to create ValidatorClient")
|
2020-10-09 09:28:35 +00:00
|
|
|
err = valClient.db.Close()
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestClearDB tests clearing the database
|
|
|
|
func TestClearDB(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
2020-11-10 22:45:17 +00:00
|
|
|
tmp := filepath.Join(t.TempDir(), "datadirtest")
|
2020-12-11 18:31:35 +00:00
|
|
|
require.NoError(t, clearDB(context.Background(), tmp, true))
|
2020-10-09 09:28:35 +00:00
|
|
|
require.LogsContain(t, hook, "Removing database")
|
2018-06-17 02:26:03 +00:00
|
|
|
}
|