mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
node: make tests compile
This commit is contained in:
parent
e6e5664396
commit
6bb697d649
3 changed files with 6 additions and 21 deletions
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tests that datadirs can be successfully created, be them manually configured
|
// Tests that datadirs can be successfully created, be them manually configured
|
||||||
|
|
@ -109,7 +110,7 @@ func TestNodeKeyPersistency(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to generate one-shot node key: %v", err)
|
t.Fatalf("failed to generate one-shot node key: %v", err)
|
||||||
}
|
}
|
||||||
config := &Config{Name: "unit-test", DataDir: dir, PrivateKey: key}
|
config := &Config{Name: "unit-test", DataDir: dir, P2P: p2p.Config{PrivateKey: key}}
|
||||||
config.NodeKey()
|
config.NodeKey()
|
||||||
if _, err := os.Stat(filepath.Join(keyfile)); err == nil {
|
if _, err := os.Stat(filepath.Join(keyfile)); err == nil {
|
||||||
t.Fatalf("one-shot node key persisted to data directory")
|
t.Fatalf("one-shot node key persisted to data directory")
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -42,23 +41,8 @@ func (s *SampleService) Start(*p2p.Server) error { fmt.Println("Service starti
|
||||||
func (s *SampleService) Stop() error { fmt.Println("Service stopping..."); return nil }
|
func (s *SampleService) Stop() error { fmt.Println("Service stopping..."); return nil }
|
||||||
|
|
||||||
func ExampleService() {
|
func ExampleService() {
|
||||||
// Create a network node to run protocols with the default values. The below list
|
// Create a network node to run protocols with the default values.
|
||||||
// is only used to display each of the configuration options. All of these could
|
stack, err := node.New(&node.Config{})
|
||||||
// have been omitted if the default behavior is desired.
|
|
||||||
nodeConfig := &node.Config{
|
|
||||||
DataDir: "", // Empty uses ephemeral storage
|
|
||||||
PrivateKey: nil, // Nil generates a node key on the fly
|
|
||||||
Name: "", // Any textual node name is allowed
|
|
||||||
NoDiscovery: false, // Can disable discovering remote nodes
|
|
||||||
BootstrapNodes: []*discover.Node{}, // List of bootstrap nodes to use
|
|
||||||
ListenAddr: ":0", // Network interface to listen on
|
|
||||||
NAT: nil, // UPnP port mapper to use for crossing firewalls
|
|
||||||
Dialer: nil, // Custom dialer to use for establishing peer connections
|
|
||||||
NoDial: false, // Can prevent this node from dialing out
|
|
||||||
MaxPeers: 0, // Number of peers to allow
|
|
||||||
MaxPendingPeers: 0, // Number of peers allowed to handshake concurrently
|
|
||||||
}
|
|
||||||
stack, err := node.New(nodeConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to create network node: %v", err)
|
log.Fatalf("Failed to create network node: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ var (
|
||||||
|
|
||||||
func testNodeConfig() *Config {
|
func testNodeConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
PrivateKey: testNodeKey,
|
|
||||||
Name: "test node",
|
Name: "test node",
|
||||||
|
P2P: p2p.Config{PrivateKey: testNodeKey},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue