mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 23:41:22 +00:00
50e92a018e
Former-commit-id: 7cbd81db9421e1517ad92829a2dbbdfcf5f38699 [formerly 76607161435699e18a970c82f9838d20e94f04d7] Former-commit-id: f6db97246aa70eda35e59a2a05fa55316289bd76
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package sharding
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"math/rand"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
cli "gopkg.in/urfave/cli.v1"
|
|
)
|
|
|
|
func randomEndpoint() string {
|
|
return fmt.Sprintf("/tmp/go-ethereum-test-ipc-%d-%d", os.Getpid(), rand.Int63())
|
|
}
|
|
|
|
func newTestServer(endpoint string) (*rpc.Server, error) {
|
|
server := rpc.NewServer()
|
|
|
|
l, err := rpc.CreateIPCListener(endpoint)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
go server.ServeListener(l)
|
|
|
|
return server, nil
|
|
}
|
|
|
|
func createContext() *cli.Context {
|
|
set := flag.NewFlagSet("test", 0)
|
|
set.String(utils.DataDirFlag.Name, "", "")
|
|
return cli.NewContext(nil, set, nil)
|
|
}
|
|
|
|
func TestStart(t *testing.T) {
|
|
endpoint := randomEndpoint()
|
|
server, err := newTestServer(endpoint)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create a test server: %v", err)
|
|
}
|
|
defer server.Stop()
|
|
|
|
ctx := createContext()
|
|
if err := ctx.GlobalSet(utils.DataDirFlag.Name, endpoint); err != nil {
|
|
t.Fatalf("Failed to set global variable for flag %s. Error: %v", utils.DataDirFlag.Name, err)
|
|
}
|
|
|
|
c := MakeShardingClient(ctx)
|
|
if err := c.Start(); err != nil {
|
|
t.Errorf("Failed to start server: %v", err)
|
|
}
|
|
}
|