prysm-pulse/beacon-chain/node/node_test.go
2020-03-19 14:46:44 -07:00

47 lines
1.2 KiB
Go

package node
import (
"flag"
"fmt"
"os"
"testing"
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/shared/testutil"
logTest "github.com/sirupsen/logrus/hooks/test"
"gopkg.in/urfave/cli.v2"
)
// Ensure BeaconNode implements interfaces.
var _ = statefeed.Notifier(&BeaconNode{})
// Test that beacon chain node can close.
func TestNodeClose_OK(t *testing.T) {
hook := logTest.NewGlobal()
tmp := fmt.Sprintf("%s/datadirtest2", testutil.TempDir())
os.RemoveAll(tmp)
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String("web3provider", "ws//127.0.0.1:8546", "web3 provider ws or IPC endpoint")
set.Bool("test-skip-pow", true, "skip pow dial")
set.String("datadir", tmp, "node data directory")
set.String("p2p-encoding", "ssz", "p2p encoding scheme")
set.Bool("demo-config", true, "demo configuration")
set.String("deposit-contract", "0x0000000000000000000000000000000000000000", "deposit contract address")
context := cli.NewContext(&app, set, nil)
node, err := NewBeaconNode(context)
if err != nil {
t.Fatalf("Failed to create BeaconNode: %v", err)
}
node.Close()
testutil.AssertLogsContain(t, hook, "Stopping beacon node")
os.RemoveAll(tmp)
}