mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
2fd7c926ed
* Use t.TempDir and b.TempDir for temporary test dirs * Remove redundant dir cleanup
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package node
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
|
mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing"
|
|
"github.com/prysmaticlabs/prysm/cmd"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// Ensure BeaconNode implements interfaces.
|
|
var _ statefeed.Notifier = (*BeaconNode)(nil)
|
|
|
|
// Test that beacon chain node can close.
|
|
func TestNodeClose_OK(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
|
|
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
|
|
|
|
app := cli.App{}
|
|
set := flag.NewFlagSet("test", 0)
|
|
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 := New(context)
|
|
require.NoError(t, err)
|
|
|
|
node.Close()
|
|
|
|
require.LogsContain(t, hook, "Stopping beacon node")
|
|
}
|
|
|
|
// TestClearDB tests clearing the database
|
|
func TestClearDB(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
srv, endpoint, err := mockPOW.SetupRPCServer()
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() {
|
|
srv.Stop()
|
|
})
|
|
|
|
tmp := filepath.Join(t.TempDir(), "datadirtest")
|
|
|
|
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)
|
|
_, err = New(context, WithPowchainFlagOptions([]powchain.Option{
|
|
powchain.WithHttpEndpoints([]string{endpoint}),
|
|
}))
|
|
require.NoError(t, err)
|
|
|
|
require.LogsContain(t, hook, "Removing database")
|
|
}
|