lotus/node/node_test.go

86 lines
1.8 KiB
Go
Raw Normal View History

2019-07-10 13:06:04 +00:00
package node_test
2019-07-09 16:27:07 +00:00
import (
2019-07-24 23:23:06 +00:00
"bytes"
2019-07-09 16:27:07 +00:00
"context"
2019-07-09 16:36:40 +00:00
"net/http/httptest"
2019-07-09 16:27:07 +00:00
"testing"
2019-07-24 23:25:14 +00:00
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
2019-07-10 17:28:49 +00:00
"github.com/filecoin-project/go-lotus/node"
2019-07-24 23:23:06 +00:00
"github.com/filecoin-project/go-lotus/node/modules"
modtest "github.com/filecoin-project/go-lotus/node/modules/testing"
2019-07-24 23:25:14 +00:00
"github.com/filecoin-project/go-lotus/node/repo"
2019-07-10 17:28:49 +00:00
2019-07-09 16:27:07 +00:00
"github.com/filecoin-project/go-lotus/api"
2019-07-09 16:36:40 +00:00
"github.com/filecoin-project/go-lotus/api/client"
"github.com/filecoin-project/go-lotus/api/test"
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
2019-07-09 16:27:07 +00:00
)
2019-07-24 00:09:34 +00:00
func builder(t *testing.T, n int) []api.FullNode {
2019-07-09 16:27:07 +00:00
ctx := context.Background()
mn := mocknet.New(ctx)
2019-07-24 00:09:34 +00:00
out := make([]api.FullNode, n)
2019-07-09 16:27:07 +00:00
2019-07-24 23:23:06 +00:00
var genbuf bytes.Buffer
2019-07-09 16:27:07 +00:00
for i := 0; i < n; i++ {
2019-07-24 23:23:06 +00:00
var genesis node.Option
if i == 0 {
genesis = node.Override(new(modules.Genesis), modtest.MakeGenesisMem(&genbuf))
} else {
genesis = node.Override(new(modules.Genesis), modules.LoadGenesis(genbuf.Bytes()))
}
2019-07-09 16:27:07 +00:00
var err error
2019-07-23 22:34:13 +00:00
err = node.New(ctx,
node.FullAPI(&out[i]),
2019-07-10 13:06:04 +00:00
node.Online(),
node.Repo(repo.NewMemory(nil)),
2019-07-29 19:34:34 +00:00
node.MockHost(mn),
2019-07-24 23:23:06 +00:00
genesis,
2019-07-09 16:27:07 +00:00
)
if err != nil {
t.Fatal(err)
}
}
2019-07-09 17:03:36 +00:00
if err := mn.LinkAll(); err != nil {
t.Fatal(err)
}
2019-07-09 16:27:07 +00:00
return out
}
func TestAPI(t *testing.T) {
test.TestApis(t, builder)
}
2019-07-09 16:36:40 +00:00
var nextApi int
2019-07-24 00:09:34 +00:00
func rpcBuilder(t *testing.T, n int) []api.FullNode {
2019-07-09 16:36:40 +00:00
nodeApis := builder(t, n)
2019-07-24 00:09:34 +00:00
out := make([]api.FullNode, n)
2019-07-09 16:36:40 +00:00
for i, a := range nodeApis {
rpcServer := jsonrpc.NewServer()
rpcServer.Register("Filecoin", a)
testServ := httptest.NewServer(rpcServer) // todo: close
2019-07-15 16:28:00 +00:00
var err error
out[i], err = client.NewFullNodeRPC("ws://"+testServ.Listener.Addr().String(), nil)
2019-07-15 16:28:00 +00:00
if err != nil {
t.Fatal(err)
}
2019-07-09 16:36:40 +00:00
}
return out
}
func TestAPIRPC(t *testing.T) {
test.TestApis(t, rpcBuilder)
}