2019-07-10 13:06:04 +00:00
|
|
|
package node_test
|
2019-07-09 16:27:07 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-07-09 16:36:40 +00:00
|
|
|
"net/http/httptest"
|
2019-07-09 16:27:07 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-07-10 17:28:49 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/node"
|
|
|
|
|
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
|
|
|
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
|
|
|
|
)
|
|
|
|
|
|
|
|
func builder(t *testing.T, n int) []api.API {
|
|
|
|
ctx := context.Background()
|
|
|
|
mn := mocknet.New(ctx)
|
|
|
|
|
|
|
|
out := make([]api.API, n)
|
|
|
|
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
var err error
|
2019-07-10 13:06:04 +00:00
|
|
|
out[i], err = node.New(ctx,
|
|
|
|
node.Online(),
|
2019-07-09 16:27:07 +00:00
|
|
|
MockHost(mn),
|
|
|
|
)
|
|
|
|
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
|
|
|
|
|
|
|
|
func rpcBuilder(t *testing.T, n int) []api.API {
|
|
|
|
nodeApis := builder(t, n)
|
|
|
|
out := make([]api.API, n)
|
|
|
|
|
|
|
|
for i, a := range nodeApis {
|
|
|
|
rpcServer := jsonrpc.NewServer()
|
|
|
|
rpcServer.Register("Filecoin", a)
|
|
|
|
testServ := httptest.NewServer(rpcServer) // todo: close
|
|
|
|
out[i] = client.NewRPC(testServ.URL)
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPIRPC(t *testing.T) {
|
|
|
|
test.TestApis(t, rpcBuilder)
|
|
|
|
}
|