2018-07-13 21:15:37 -05:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
2018-07-14 14:48:42 -05:00
|
|
|
"flag"
|
2018-07-30 23:41:27 -05:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2020-10-09 04:28:35 -05:00
|
|
|
"path/filepath"
|
2018-07-13 21:15:37 -05:00
|
|
|
"testing"
|
|
|
|
|
2019-12-07 09:57:26 -08:00
|
|
|
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
2021-09-21 13:11:16 -05:00
|
|
|
"github.com/prysmaticlabs/prysm/cmd"
|
2021-09-23 13:53:46 -05:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
2018-08-20 08:50:11 -07:00
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
2020-05-30 23:44:34 -07:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-07-13 21:15:37 -05:00
|
|
|
)
|
|
|
|
|
2019-11-19 22:15:48 +00:00
|
|
|
// Ensure BeaconNode implements interfaces.
|
2020-10-10 03:36:48 +03:00
|
|
|
var _ statefeed.Notifier = (*BeaconNode)(nil)
|
2019-11-19 22:15:48 +00:00
|
|
|
|
2018-08-20 08:50:11 -07:00
|
|
|
// Test that beacon chain node can close.
|
2019-02-22 10:11:26 -05:00
|
|
|
func TestNodeClose_OK(t *testing.T) {
|
2018-08-20 08:50:11 -07:00
|
|
|
hook := logTest.NewGlobal()
|
2018-11-06 22:43:10 +01:00
|
|
|
|
2020-11-11 01:45:17 +03:00
|
|
|
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
|
2018-11-06 22:43:10 +01:00
|
|
|
|
2020-03-19 14:46:44 -07:00
|
|
|
app := cli.App{}
|
2018-08-20 08:50:11 -07:00
|
|
|
set := flag.NewFlagSet("test", 0)
|
2019-03-04 15:10:03 -05:00
|
|
|
set.Bool("test-skip-pow", true, "skip pow dial")
|
2018-08-20 08:50:11 -07:00
|
|
|
set.String("datadir", tmp, "node data directory")
|
2019-09-05 09:04:06 -07:00
|
|
|
set.String("p2p-encoding", "ssz", "p2p encoding scheme")
|
2018-10-01 21:04:37 -05:00
|
|
|
set.Bool("demo-config", true, "demo configuration")
|
2019-03-04 15:10:03 -05:00
|
|
|
set.String("deposit-contract", "0x0000000000000000000000000000000000000000", "deposit contract address")
|
2018-08-20 08:50:11 -07:00
|
|
|
|
2020-03-19 14:46:44 -07:00
|
|
|
context := cli.NewContext(&app, set, nil)
|
2018-08-20 08:50:11 -07:00
|
|
|
|
2021-02-01 18:12:52 +01:00
|
|
|
node, err := New(context)
|
2020-08-25 18:23:06 +03:00
|
|
|
require.NoError(t, err)
|
2018-08-20 08:50:11 -07:00
|
|
|
|
|
|
|
node.Close()
|
|
|
|
|
2020-08-13 19:22:25 +03:00
|
|
|
require.LogsContain(t, hook, "Stopping beacon node")
|
2020-08-25 18:23:06 +03:00
|
|
|
require.NoError(t, os.RemoveAll(tmp))
|
2018-07-13 21:15:37 -05:00
|
|
|
}
|
2020-06-26 06:23:38 -05:00
|
|
|
|
2020-10-09 04:28:35 -05:00
|
|
|
// TestClearDB tests clearing the database
|
|
|
|
func TestClearDB(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
|
2020-11-11 01:45:17 +03:00
|
|
|
tmp := filepath.Join(t.TempDir(), "datadirtest")
|
2020-10-09 04:28:35 -05:00
|
|
|
|
|
|
|
app := cli.App{}
|
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
set.String("datadir", tmp, "node data directory")
|
|
|
|
set.Bool(cmd.ForceClearDB.Name, true, "force clear db")
|
|
|
|
|
|
|
|
context := cli.NewContext(&app, set, nil)
|
2021-02-01 18:12:52 +01:00
|
|
|
_, err := New(context)
|
2020-10-09 04:28:35 -05:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.LogsContain(t, hook, "Removing database")
|
|
|
|
require.NoError(t, os.RemoveAll(tmp))
|
|
|
|
}
|