Test connecting two nodes
This commit is contained in:
+1
-1
@@ -36,7 +36,7 @@ type API interface {
|
||||
|
||||
NetPeers(context.Context) ([]peer.AddrInfo, error) // TODO: check serialization
|
||||
NetConnect(context.Context, peer.AddrInfo) error
|
||||
NetAddrsListen(context.Context) (MultiaddrSlice, error)
|
||||
NetAddrsListen(context.Context) (peer.AddrInfo, error)
|
||||
// // ping
|
||||
|
||||
// Struct
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ type Struct struct {
|
||||
|
||||
NetPeers func(context.Context) ([]peer.AddrInfo, error)
|
||||
NetConnect func(context.Context, peer.AddrInfo) error
|
||||
NetAddrsListen func(context.Context) (MultiaddrSlice, error)
|
||||
NetAddrsListen func(context.Context) (peer.AddrInfo, error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func (c *Struct) NetConnect(ctx context.Context, p peer.AddrInfo) error {
|
||||
return c.Internal.NetConnect(ctx, p)
|
||||
}
|
||||
|
||||
func (c *Struct) NetAddrsListen(ctx context.Context) (MultiaddrSlice, error) {
|
||||
func (c *Struct) NetAddrsListen(ctx context.Context) (peer.AddrInfo, error) {
|
||||
return c.Internal.NetAddrsListen(ctx)
|
||||
}
|
||||
|
||||
|
||||
+65
-2
@@ -2,6 +2,7 @@ package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/api"
|
||||
@@ -22,13 +23,16 @@ func TestApis(t *testing.T, b APIBuilder) {
|
||||
}
|
||||
|
||||
t.Run("version", ts.testVersion)
|
||||
t.Run("id", ts.testID)
|
||||
t.Run("testConnectTwo", ts.testConnectTwo)
|
||||
|
||||
}
|
||||
|
||||
func (ts *testSuite) testVersion(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
fc := ts.makeNodes(t, 1)[0]
|
||||
api := ts.makeNodes(t, 1)[0]
|
||||
|
||||
v, err := fc.Version(ctx)
|
||||
v, err := api.Version(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -36,3 +40,62 @@ func (ts *testSuite) testVersion(t *testing.T) {
|
||||
t.Error("Version didn't work properly")
|
||||
}
|
||||
}
|
||||
|
||||
func (ts *testSuite) testID(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
api := ts.makeNodes(t, 1)[0]
|
||||
|
||||
id, err := api.ID(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.HasPrefix(id.Pretty(), "Qm") {
|
||||
t.Error("expected identity to be Qm..")
|
||||
}
|
||||
}
|
||||
|
||||
func (ts *testSuite) testConnectTwo(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
apis := ts.makeNodes(t, 2)
|
||||
|
||||
p, err := apis[0].NetPeers(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(p) != 0 {
|
||||
t.Error("Node 0 has a peer")
|
||||
}
|
||||
|
||||
p, err = apis[1].NetPeers(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(p) != 0 {
|
||||
t.Error("Node 1 has a peer")
|
||||
}
|
||||
|
||||
addrs, err := apis[1].NetAddrsListen(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := apis[0].NetConnect(ctx, addrs); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p, err = apis[0].NetPeers(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(p) != 1 {
|
||||
t.Error("Node 0 doesn't have 1 peer")
|
||||
}
|
||||
|
||||
p, err = apis[1].NetPeers(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(p) != 1 {
|
||||
t.Error("Node 0 doesn't have 1 peer")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user