diff --git a/node/api_test.go b/node/api_test.go deleted file mode 100644 index 2e028eb9ad..0000000000 --- a/node/api_test.go +++ /dev/null @@ -1,352 +0,0 @@ -// Copyright 2020 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package node - -import ( - "bytes" - "io" - "net" - "net/http" - "net/url" - "strings" - "testing" - - "github.com/dominant-strategies/go-quai/rpc" - "github.com/stretchr/testify/assert" -) - -// This test uses the admin_startRPC and admin_startWS APIs, -// checking whether the HTTP server is started correctly. -func TestStartRPC(t *testing.T) { - type test struct { - name string - cfg Config - fn func(*testing.T, *Node, *privateAdminAPI) - - // Checks. These run after the node is configured and all API calls have been made. - wantReachable bool // whether the HTTP server should be reachable at all - wantHandlers bool // whether RegisterHandler handlers should be accessible - wantRPC bool // whether JSON-RPC/HTTP should be accessible - wantWS bool // whether JSON-RPC/WS should be accessible - } - - tests := []test{ - { - name: "all off", - cfg: Config{}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - }, - wantReachable: false, - wantHandlers: false, - wantRPC: false, - wantWS: false, - }, - { - name: "rpc enabled through config", - cfg: Config{HTTPHost: "127.0.0.1"}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - }, - wantReachable: true, - wantHandlers: true, - wantRPC: true, - wantWS: false, - }, - { - name: "rpc enabled through API", - cfg: Config{}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - _, err := api.StartHTTP(sp("127.0.0.1"), ip(0), nil, nil, nil) - assert.NoError(t, err) - }, - wantReachable: true, - wantHandlers: true, - wantRPC: true, - wantWS: false, - }, - { - name: "rpc start again after failure", - cfg: Config{}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - // Listen on a random port. - listener, err := net.Listen("tcp", "127.0.0.1:0") - if err != nil { - t.Fatal("can't listen:", err) - } - defer listener.Close() - port := listener.Addr().(*net.TCPAddr).Port - - // Now try to start RPC on that port. This should fail. - _, err = api.StartHTTP(sp("127.0.0.1"), ip(port), nil, nil, nil) - if err == nil { - t.Fatal("StartHTTP should have failed on port", port) - } - - // Try again after unblocking the port. It should work this time. - listener.Close() - _, err = api.StartHTTP(sp("127.0.0.1"), ip(port), nil, nil, nil) - assert.NoError(t, err) - }, - wantReachable: true, - wantHandlers: true, - wantRPC: true, - wantWS: false, - }, - { - name: "rpc stopped through API", - cfg: Config{HTTPHost: "127.0.0.1"}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - _, err := api.StopHTTP() - assert.NoError(t, err) - }, - wantReachable: false, - wantHandlers: false, - wantRPC: false, - wantWS: false, - }, - { - name: "rpc stopped twice", - cfg: Config{HTTPHost: "127.0.0.1"}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - _, err := api.StopHTTP() - assert.NoError(t, err) - - _, err = api.StopHTTP() - assert.NoError(t, err) - }, - wantReachable: false, - wantHandlers: false, - wantRPC: false, - wantWS: false, - }, - { - name: "ws enabled through config", - cfg: Config{WSHost: "127.0.0.1"}, - wantReachable: true, - wantHandlers: false, - wantRPC: false, - wantWS: true, - }, - { - name: "ws enabled through API", - cfg: Config{}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - _, err := api.StartWS(sp("127.0.0.1"), ip(0), nil, nil) - assert.NoError(t, err) - }, - wantReachable: true, - wantHandlers: false, - wantRPC: false, - wantWS: true, - }, - { - name: "ws stopped through API", - cfg: Config{WSHost: "127.0.0.1"}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - _, err := api.StopWS() - assert.NoError(t, err) - }, - wantReachable: false, - wantHandlers: false, - wantRPC: false, - wantWS: false, - }, - { - name: "ws stopped twice", - cfg: Config{WSHost: "127.0.0.1"}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - _, err := api.StopWS() - assert.NoError(t, err) - - _, err = api.StopWS() - assert.NoError(t, err) - }, - wantReachable: false, - wantHandlers: false, - wantRPC: false, - wantWS: false, - }, - { - name: "ws enabled after RPC", - cfg: Config{HTTPHost: "127.0.0.1"}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - wsport := n.http.port - _, err := api.StartWS(sp("127.0.0.1"), ip(wsport), nil, nil) - assert.NoError(t, err) - }, - wantReachable: true, - wantHandlers: true, - wantRPC: true, - wantWS: true, - }, - { - name: "ws enabled after RPC then stopped", - cfg: Config{HTTPHost: "127.0.0.1"}, - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - wsport := n.http.port - _, err := api.StartWS(sp("127.0.0.1"), ip(wsport), nil, nil) - assert.NoError(t, err) - - _, err = api.StopWS() - assert.NoError(t, err) - }, - wantReachable: true, - wantHandlers: true, - wantRPC: true, - wantWS: false, - }, - { - name: "rpc stopped with ws enabled", - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - _, err := api.StartHTTP(sp("127.0.0.1"), ip(0), nil, nil, nil) - assert.NoError(t, err) - - wsport := n.http.port - _, err = api.StartWS(sp("127.0.0.1"), ip(wsport), nil, nil) - assert.NoError(t, err) - - _, err = api.StopHTTP() - assert.NoError(t, err) - }, - wantReachable: false, - wantHandlers: false, - wantRPC: false, - wantWS: false, - }, - { - name: "rpc enabled after ws", - fn: func(t *testing.T, n *Node, api *privateAdminAPI) { - _, err := api.StartWS(sp("127.0.0.1"), ip(0), nil, nil) - assert.NoError(t, err) - - wsport := n.http.port - _, err = api.StartHTTP(sp("127.0.0.1"), ip(wsport), nil, nil, nil) - assert.NoError(t, err) - }, - wantReachable: true, - wantHandlers: true, - wantRPC: true, - wantWS: true, - }, - } - - for _, test := range tests { - test := test - t.Run(test.name, func(t *testing.T) { - t.Parallel() - - // Apply some sane defaults. - config := test.cfg - // config.Logger = test*log.Logger(t, log.LvlDebug) - config.P2P.NoDiscovery = true - - // Create Node. - stack, err := New(&config) - if err != nil { - t.Fatal("can't create node:", err) - } - defer stack.Close() - - // Register the test handler. - stack.RegisterHandler("test", "/test", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("OK")) - })) - - if err := stack.Start(); err != nil { - t.Fatal("can't start node:", err) - } - - // Run the API call hook. - if test.fn != nil { - test.fn(t, stack, &privateAdminAPI{stack}) - } - - // Check if the HTTP endpoints are available. - baseURL := stack.HTTPEndpoint() - reachable := checkReachable(baseURL) - handlersAvailable := checkBodyOK(baseURL + "/test") - rpcAvailable := checkRPC(baseURL) - wsAvailable := checkRPC(strings.Replace(baseURL, "http://", "ws://", 1)) - if reachable != test.wantReachable { - t.Errorf("HTTP server is %sreachable, want it %sreachable", not(reachable), not(test.wantReachable)) - } - if handlersAvailable != test.wantHandlers { - t.Errorf("RegisterHandler handlers %savailable, want them %savailable", not(handlersAvailable), not(test.wantHandlers)) - } - if rpcAvailable != test.wantRPC { - t.Errorf("HTTP RPC %savailable, want it %savailable", not(rpcAvailable), not(test.wantRPC)) - } - if wsAvailable != test.wantWS { - t.Errorf("WS RPC %savailable, want it %savailable", not(wsAvailable), not(test.wantWS)) - } - }) - } -} - -// checkReachable checks if the TCP endpoint in rawurl is open. -func checkReachable(rawurl string) bool { - u, err := url.Parse(rawurl) - if err != nil { - panic(err) - } - conn, err := net.Dial("tcp", u.Host) - if err != nil { - return false - } - conn.Close() - return true -} - -// checkBodyOK checks whether the given HTTP URL responds with 200 OK and body "OK". -func checkBodyOK(url string) bool { - resp, err := http.Get(url) - if err != nil { - return false - } - defer resp.Body.Close() - - if resp.StatusCode != 200 { - return false - } - buf := make([]byte, 2) - if _, err = io.ReadFull(resp.Body, buf); err != nil { - return false - } - return bytes.Equal(buf, []byte("OK")) -} - -// checkRPC checks whether JSON-RPC works against the given URL. -func checkRPC(url string) bool { - c, err := rpc.Dial(url) - if err != nil { - return false - } - defer c.Close() - - _, err = c.SupportedModules() - return err == nil -} - -// string/int pointer helpers. -func sp(s string) *string { return &s } -func ip(i int) *int { return &i } - -func not(ok bool) string { - if ok { - return "" - } - return "not " -} diff --git a/node/config_test.go b/node/config_test.go index c96586f434..b2373b3594 100644 --- a/node/config_test.go +++ b/node/config_test.go @@ -17,15 +17,12 @@ package node import ( - "bytes" "io/ioutil" "os" "path/filepath" - "runtime" "testing" - "github.com/dominant-strategies/go-quai/crypto" - "github.com/dominant-strategies/go-quai/p2p" + "github.com/dominant-strategies/go-quai/log" ) // Tests that datadirs can be successfully created, be them manually configured @@ -38,7 +35,7 @@ func TestDatadirCreation(t *testing.T) { } defer os.RemoveAll(dir) - node, err := New(&Config{DataDir: dir}) + node, err := New(&Config{DataDir: dir}, log.Global) if err != nil { t.Fatalf("failed to create stack with existing datadir: %v", err) } @@ -47,7 +44,7 @@ func TestDatadirCreation(t *testing.T) { } // Generate a long non-existing datadir path and check that it gets created by a node dir = filepath.Join(dir, "a", "b", "c", "d", "e", "f") - node, err = New(&Config{DataDir: dir}) + node, err = New(&Config{DataDir: dir}, log.Global) if err != nil { t.Fatalf("failed to create stack with creatable datadir: %v", err) } @@ -65,7 +62,7 @@ func TestDatadirCreation(t *testing.T) { defer os.Remove(file.Name()) dir = filepath.Join(file.Name(), "invalid/path") - node, err = New(&Config{DataDir: dir}) + node, err = New(&Config{DataDir: dir}, log.Global) if err == nil { t.Fatalf("protocol stack created with an invalid datadir") if err := node.Close(); err != nil { @@ -73,90 +70,3 @@ func TestDatadirCreation(t *testing.T) { } } } - -// Tests that IPC paths are correctly resolved to valid endpoints of different -// platforms. -func TestIPCPathResolution(t *testing.T) { - var tests = []struct { - DataDir string - IPCPath string - Windows bool - Endpoint string - }{ - {"", "", false, ""}, - {"data", "", false, ""}, - {"", "quai.ipc", false, filepath.Join(os.TempDir(), "quai.ipc")}, - {"data", "quai.ipc", false, "data/quai.ipc"}, - {"data", "./quai.ipc", false, "./quai.ipc"}, - {"data", "/quai.ipc", false, "/quai.ipc"}, - {"", "", true, ``}, - {"data", "", true, ``}, - {"", "quai.ipc", true, `\\.\pipe\quai.ipc`}, - {"data", "quai.ipc", true, `\\.\pipe\quai.ipc`}, - {"data", `\\.\pipe\quai.ipc`, true, `\\.\pipe\quai.ipc`}, - } - for i, test := range tests { - // Only run when platform/test match - if (runtime.GOOS == "windows") == test.Windows { - if endpoint := (&Config{DataDir: test.DataDir, IPCPath: test.IPCPath}).IPCEndpoint(); endpoint != test.Endpoint { - t.Errorf("test %d: IPC endpoint mismatch: have %s, want %s", i, endpoint, test.Endpoint) - } - } - } -} - -// Tests that node keys can be correctly created, persisted, loaded and/or made -// ephemeral. -func TestNodeKeyPersistency(t *testing.T) { - // Create a temporary folder and make sure no key is present - dir, err := ioutil.TempDir("", "node-test") - if err != nil { - t.Fatalf("failed to create temporary data directory: %v", err) - } - defer os.RemoveAll(dir) - - keyfile := filepath.Join(dir, "unit-test", datadirPrivateKey) - - // Configure a node with a preset key and ensure it's not persisted - key, err := crypto.GenerateKey() - if err != nil { - t.Fatalf("failed to generate one-shot node key: %v", err) - } - config := &Config{Name: "unit-test", DataDir: dir, P2P: p2p.Config{PrivateKey: key}} - config.NodeKey() - if _, err := os.Stat(filepath.Join(keyfile)); err == nil { - t.Fatalf("one-shot node key persisted to data directory") - } - - // Configure a node with no preset key and ensure it is persisted this time - config = &Config{Name: "unit-test", DataDir: dir} - config.NodeKey() - if _, err := os.Stat(keyfile); err != nil { - t.Fatalf("node key not persisted to data directory: %v", err) - } - if _, err = crypto.LoadECDSA(keyfile); err != nil { - t.Fatalf("failed to load freshly persisted node key: %v", err) - } - blob1, err := ioutil.ReadFile(keyfile) - if err != nil { - t.Fatalf("failed to read freshly persisted node key: %v", err) - } - - // Configure a new node and ensure the previously persisted key is loaded - config = &Config{Name: "unit-test", DataDir: dir} - config.NodeKey() - blob2, err := ioutil.ReadFile(filepath.Join(keyfile)) - if err != nil { - t.Fatalf("failed to read previously persisted node key: %v", err) - } - if !bytes.Equal(blob1, blob2) { - t.Fatalf("persisted node key mismatch: have %x, want %x", blob2, blob1) - } - - // Configure ephemeral node and ensure no key is dumped locally - config = &Config{Name: "unit-test", DataDir: ""} - config.NodeKey() - if _, err := os.Stat(filepath.Join(".", "unit-test", datadirPrivateKey)); err == nil { - t.Fatalf("ephemeral node key persisted to disk") - } -} diff --git a/node/node_example_test.go b/node/node_example_test.go index 71487427f0..2f3f80a1e6 100644 --- a/node/node_example_test.go +++ b/node/node_example_test.go @@ -18,8 +18,8 @@ package node_test import ( "fmt" - "log" + "github.com/dominant-strategies/go-quai/log" "github.com/dominant-strategies/go-quai/node" ) @@ -36,7 +36,7 @@ func (s *SampleLifecycle) Stop() error { fmt.Println("Service stopping..."); re func ExampleLifecycle() { // Create a network node to run protocols with the default values. - stack, err := node.New(&node.Config{}) + stack, err := node.New(&node.Config{}, log.Global) if err != nil { log.Global.Fatalf("Failed to create network node: %v", err) } diff --git a/node/node_test.go b/node/node_test.go index a92c675f30..ebf9d69154 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -21,16 +21,14 @@ import ( "fmt" "io" "io/ioutil" - "net" "net/http" "os" "reflect" - "strings" "testing" "github.com/dominant-strategies/go-quai/crypto" "github.com/dominant-strategies/go-quai/ethdb" - "github.com/dominant-strategies/go-quai/p2p" + "github.com/dominant-strategies/go-quai/log" "github.com/dominant-strategies/go-quai/rpc" "github.com/stretchr/testify/assert" @@ -43,13 +41,12 @@ var ( func testNodeConfig() *Config { return &Config{ Name: "test node", - P2P: p2p.Config{PrivateKey: testNodeKey}, } } // Tests that an empty protocol stack can be closed more than once. func TestNodeCloseMultipleTimes(t *testing.T) { - stack, err := New(testNodeConfig()) + stack, err := New(testNodeConfig(), log.Global) if err != nil { t.Fatalf("failed to create protocol stack: %v", err) } @@ -64,7 +61,7 @@ func TestNodeCloseMultipleTimes(t *testing.T) { } func TestNodeStartMultipleTimes(t *testing.T) { - stack, err := New(testNodeConfig()) + stack, err := New(testNodeConfig(), log.Global) if err != nil { t.Fatalf("failed to create protocol stack: %v", err) } @@ -95,7 +92,7 @@ func TestNodeUsedDataDir(t *testing.T) { defer os.RemoveAll(dir) // Create a new node based on the data directory - original, err := New(&Config{DataDir: dir}) + original, err := New(&Config{DataDir: dir}, log.Global) if err != nil { t.Fatalf("failed to create original protocol stack: %v", err) } @@ -105,7 +102,7 @@ func TestNodeUsedDataDir(t *testing.T) { } // Create a second node based on the same data directory and ensure failure - _, err = New(&Config{DataDir: dir}) + _, err = New(&Config{DataDir: dir}, log.Global) if err != ErrDatadirUsed { t.Fatalf("duplicate datadir failure mismatch: have %v, want %v", err, ErrDatadirUsed) } @@ -113,7 +110,7 @@ func TestNodeUsedDataDir(t *testing.T) { // Tests whether a Lifecycle can be registered. func TestLifecycleRegistry_Successful(t *testing.T) { - stack, err := New(testNodeConfig()) + stack, err := New(testNodeConfig(), log.Global) if err != nil { t.Fatalf("failed to create protocol stack: %v", err) } @@ -127,35 +124,9 @@ func TestLifecycleRegistry_Successful(t *testing.T) { } } -// Tests whether a service's protocols can be registered properly on the node's p2p server. -func TestRegisterProtocols(t *testing.T) { - stack, err := New(testNodeConfig()) - if err != nil { - t.Fatalf("failed to create protocol stack: %v", err) - } - defer stack.Close() - - fs, err := NewFullService(stack) - if err != nil { - t.Fatalf("could not create full service: %v", err) - } - - for _, protocol := range fs.Protocols() { - if !containsProtocol(stack.server.Protocols, protocol) { - t.Fatalf("protocol %v was not successfully registered", protocol) - } - } - - for _, api := range fs.APIs() { - if !containsAPI(stack.rpcAPIs, api) { - t.Fatalf("api %v was not successfully registered", api) - } - } -} - // This test checks that open databases are closed with node. func TestNodeCloseClosesDB(t *testing.T) { - stack, _ := New(testNodeConfig()) + stack, _ := New(testNodeConfig(), log.Global) defer stack.Close() db, err := stack.OpenDatabase("mydb", 0, 0, "", false) @@ -174,7 +145,7 @@ func TestNodeCloseClosesDB(t *testing.T) { // This test checks that OpenDatabase can be used from within a Lifecycle Start method. func TestNodeOpenDatabaseFromLifecycleStart(t *testing.T) { - stack, _ := New(testNodeConfig()) + stack, _ := New(testNodeConfig(), log.Global) defer stack.Close() var db ethdb.Database @@ -197,7 +168,7 @@ func TestNodeOpenDatabaseFromLifecycleStart(t *testing.T) { // This test checks that OpenDatabase can be used from within a Lifecycle Stop method. func TestNodeOpenDatabaseFromLifecycleStop(t *testing.T) { - stack, _ := New(testNodeConfig()) + stack, _ := New(testNodeConfig(), log.Global) defer stack.Close() stack.RegisterLifecycle(&InstrumentedService{ @@ -216,7 +187,7 @@ func TestNodeOpenDatabaseFromLifecycleStop(t *testing.T) { // Tests that registered Lifecycles get started and stopped correctly. func TestLifecycleLifeCycle(t *testing.T) { - stack, _ := New(testNodeConfig()) + stack, _ := New(testNodeConfig(), log.Global) defer stack.Close() started := make(map[string]bool) @@ -267,7 +238,7 @@ func TestLifecycleLifeCycle(t *testing.T) { // Tests that if a Lifecycle fails to start, all others started before it will be // shut down. func TestLifecycleStartupError(t *testing.T) { - stack, err := New(testNodeConfig()) + stack, err := New(testNodeConfig(), log.Global) if err != nil { t.Fatalf("failed to create protocol stack: %v", err) } @@ -317,7 +288,7 @@ func TestLifecycleStartupError(t *testing.T) { // Tests that even if a registered Lifecycle fails to shut down cleanly, it does // not influence the rest of the shutdown invocations. func TestLifecycleTerminationGuarantee(t *testing.T) { - stack, err := New(testNodeConfig()) + stack, err := New(testNodeConfig(), log.Global) if err != nil { t.Fatalf("failed to create protocol stack: %v", err) } @@ -384,9 +355,6 @@ func TestLifecycleTerminationGuarantee(t *testing.T) { delete(started, id) delete(stopped, id) } - - stack.server = &p2p.Server{} - stack.server.PrivateKey = testNodeKey } // Tests whether a handler can be successfully mounted on the canonical HTTP server @@ -424,7 +392,7 @@ func TestRegisterHandler_Successful(t *testing.T) { // Tests that the given handler will not be successfully mounted since no HTTP server // is enabled for RPC func TestRegisterHandler_Unsuccessful(t *testing.T) { - node, err := New(&DefaultConfig) + node, err := New(&DefaultConfig, log.Global) if err != nil { t.Fatalf("could not create new node: %v", err) } @@ -436,55 +404,6 @@ func TestRegisterHandler_Unsuccessful(t *testing.T) { node.RegisterHandler("test", "/test", handler) } -// Tests whether websocket requests can be handled on the same port as a regular http server. -func TestWebsocketHTTPOnSamePort_WebsocketRequest(t *testing.T) { - node := startHTTP(t, 0, 0) - defer node.Close() - - ws := strings.Replace(node.HTTPEndpoint(), "http://", "ws://", 1) - - if node.WSEndpoint() != ws { - t.Fatalf("endpoints should be the same") - } - if !checkRPC(ws) { - t.Fatalf("ws request failed") - } - if !checkRPC(node.HTTPEndpoint()) { - t.Fatalf("http request failed") - } -} - -func TestWebsocketHTTPOnSeparatePort_WSRequest(t *testing.T) { - // try and get a free port - listener, err := net.Listen("tcp", "127.0.0.1:0") - if err != nil { - t.Fatal("can't listen:", err) - } - port := listener.Addr().(*net.TCPAddr).Port - listener.Close() - - node := startHTTP(t, 0, port) - defer node.Close() - - wsOnHTTP := strings.Replace(node.HTTPEndpoint(), "http://", "ws://", 1) - ws := fmt.Sprintf("ws://127.0.0.1:%d", port) - - if node.WSEndpoint() == wsOnHTTP { - t.Fatalf("endpoints should not be the same") - } - // ensure ws endpoint matches the expected endpoint - if node.WSEndpoint() != ws { - t.Fatalf("ws endpoint is incorrect: expected %s, got %s", ws, node.WSEndpoint()) - } - - if !checkRPC(ws) { - t.Fatalf("ws request failed") - } - if !checkRPC(node.HTTPEndpoint()) { - t.Fatalf("http request failed") - } -} - type rpcPrefixTest struct { httpPrefix, wsPrefix string // These lists paths on which JSON-RPC should be served / not served. @@ -542,7 +461,7 @@ func TestNodeRPCPrefix(t *testing.T) { WSHost: "127.0.0.1", WSPathPrefix: test.wsPrefix, } - node, err := New(cfg) + node, err := New(cfg, log.Global) if err != nil { t.Fatal("can't create node:", err) } @@ -598,7 +517,7 @@ func createNode(t *testing.T, httpPort, wsPort int) *Node { WSHost: "127.0.0.1", WSPort: wsPort, } - node, err := New(conf) + node, err := New(conf, log.Global) if err != nil { t.Fatalf("could not create a new node: %v", err) } @@ -625,15 +544,6 @@ func doHTTPRequest(t *testing.T, req *http.Request) *http.Response { return resp } -func containsProtocol(stackProtocols []p2p.Protocol, protocol p2p.Protocol) bool { - for _, a := range stackProtocols { - if reflect.DeepEqual(a, protocol) { - return true - } - } - return false -} - func containsAPI(stackAPIs []rpc.API, api rpc.API) bool { for _, a := range stackAPIs { if reflect.DeepEqual(a, api) { diff --git a/node/rpcstack_test.go b/node/rpcstack_test.go index fe7b993a43..0b7d5ecfba 100644 --- a/node/rpcstack_test.go +++ b/node/rpcstack_test.go @@ -231,7 +231,7 @@ func Test_checkPath(t *testing.T) { func createAndStartServer(t *testing.T, conf *httpConfig, ws bool, wsConf *wsConfig) *httpServer { t.Helper() - srv := newHTTPServer(test*log.Logger(t, log.LvlDebug), rpc.DefaultHTTPTimeouts) + srv := newHTTPServer(log.Global, rpc.DefaultHTTPTimeouts) assert.NoError(t, srv.enableRPC(nil, *conf)) if ws { assert.NoError(t, srv.enableWS(nil, *wsConf)) diff --git a/node/utils_test.go b/node/utils_test.go index 1f28623461..a7fe151994 100644 --- a/node/utils_test.go +++ b/node/utils_test.go @@ -20,7 +20,6 @@ package node import ( - "github.com/dominant-strategies/go-quai/p2p" "github.com/dominant-strategies/go-quai/rpc" ) @@ -47,8 +46,6 @@ type InstrumentedService struct { startHook func() stopHook func() - - protocols []p2p.Protocol } func (s *InstrumentedService) Start() error { @@ -70,7 +67,6 @@ type FullService struct{} func NewFullService(stack *Node) (*FullService, error) { fs := new(FullService) - stack.RegisterProtocols(fs.Protocols()) stack.RegisterAPIs(fs.APIs()) stack.RegisterLifecycle(fs) return fs, nil @@ -80,19 +76,6 @@ func (f *FullService) Start() error { return nil } func (f *FullService) Stop() error { return nil } -func (f *FullService) Protocols() []p2p.Protocol { - return []p2p.Protocol{ - { - Name: "test1", - Version: uint(1), - }, - { - Name: "test2", - Version: uint(2), - }, - } -} - func (f *FullService) APIs() []rpc.API { return []rpc.API{ {