2020-02-14 07:09:54 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
2020-03-19 21:46:44 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
2020-02-14 07:09:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Test that slasher node can close.
|
|
|
|
func TestNodeClose_OK(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
|
|
|
|
tmp := fmt.Sprintf("%s/datadirtest2", testutil.TempDir())
|
|
|
|
if err := os.RemoveAll(tmp); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:46:44 +00:00
|
|
|
app := cli.App{}
|
2020-02-14 07:09:54 +00:00
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
set.String("beacon-rpc-provider", "localhost:4232", "beacon node RPC server")
|
|
|
|
set.String("datadir", tmp, "node data directory")
|
|
|
|
|
2020-03-19 21:46:44 +00:00
|
|
|
context := cli.NewContext(&app, set, nil)
|
2020-02-14 07:09:54 +00:00
|
|
|
|
|
|
|
node, err := NewSlasherNode(context)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create SlasherNode: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
node.Close()
|
|
|
|
|
|
|
|
testutil.AssertLogsContain(t, hook, "Stopping hash slinging slasher")
|
|
|
|
|
|
|
|
if err := os.RemoveAll(tmp); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|