prysm-pulse/validator/node/node_test.go
Raul Jordan 1fbfd52e52
Simpler and Safer Attester Slashing Protection (#8086)
* att sign validations

* eliminate old cached methods and use a simple approach in the db

* redefined db methods

* db package builds

* add multilock to attest and propose

* gaz

* removed concurrency tests that are no longer relevant

* add cache to db functions for attesting history checks

* passing

* add in feature flag --disable-attesting-history-db-cache

* remove lock

* Revert "remove lock"

This reverts commit b1a65020e406b9fa6e4f57c5cc6a5a0b2a11a240.

* comment

* gaz
2020-12-11 12:31:35 -06:00

63 lines
2.0 KiB
Go

package node
import (
"context"
"flag"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/validator/accounts"
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
"github.com/prysmaticlabs/prysm/validator/flags"
"github.com/prysmaticlabs/prysm/validator/keymanager"
logTest "github.com/sirupsen/logrus/hooks/test"
"github.com/urfave/cli/v2"
)
// Test that the sharding node can build with default flag values.
func TestNode_Builds(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String("datadir", t.TempDir()+"/datadir", "the node data directory")
dir := t.TempDir() + "/walletpath"
passwordDir := t.TempDir() + "/password"
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")
set.String("keymanager-kind", "imported", "keymanager kind")
set.String("verbosity", "debug", "log verbosity")
require.NoError(t, set.Set(flags.WalletPasswordFileFlag.Name, passwordFile))
context := cli.NewContext(&app, set, nil)
_, err := accounts.CreateWalletWithKeymanager(context.Context, &accounts.CreateWalletConfig{
WalletCfg: &wallet.Config{
WalletDir: dir,
KeymanagerKind: keymanager.Imported,
WalletPassword: walletPassword,
},
})
require.NoError(t, err)
valClient, err := NewValidatorClient(context)
require.NoError(t, err, "Failed to create ValidatorClient")
err = valClient.db.Close()
require.NoError(t, err)
}
// TestClearDB tests clearing the database
func TestClearDB(t *testing.T) {
hook := logTest.NewGlobal()
tmp := filepath.Join(t.TempDir(), "datadirtest")
require.NoError(t, clearDB(context.Background(), tmp, true))
require.LogsContain(t, hook, "Removing database")
}