Commit 07fa9eec authored by Brian Tiger Chow's avatar Brian Tiger Chow

hotfix(core/mock) set Network field

parent 95ba056e
......@@ -10,12 +10,18 @@ import (
"github.com/jbenet/go-ipfs/exchange/offline"
mdag "github.com/jbenet/go-ipfs/merkledag"
nsys "github.com/jbenet/go-ipfs/namesys"
"github.com/jbenet/go-ipfs/net/mock"
path "github.com/jbenet/go-ipfs/path"
peer "github.com/jbenet/go-ipfs/peer"
dht "github.com/jbenet/go-ipfs/routing/dht"
ds2 "github.com/jbenet/go-ipfs/util/datastore2"
"github.com/jbenet/go-ipfs/util/testutil"
)
// TODO this is super sketch. Deprecate and initialize one that shares code
// with the actual core constructor. Lots of fields aren't initialized.
// Additionally, the context group isn't wired up. This is as good as broken.
// NewMockNode constructs an IpfsNode for use in tests.
func NewMockNode() (*IpfsNode, error) {
ctx := context.TODO()
......@@ -37,13 +43,17 @@ func NewMockNode() (*IpfsNode, error) {
nd.Peerstore = peer.NewPeerstore()
nd.Peerstore.AddPrivKey(p, sk)
nd.Peerstore.AddPubKey(p, pk)
nd.Network, err = mocknet.New(ctx).AddPeer(sk, testutil.RandLocalTCPAddress()) // effectively offline
if err != nil {
return nil, err
}
// Temp Datastore
dstore := ds.NewMapDatastore()
nd.Datastore = ds2.CloserWrap(syncds.MutexWrap(dstore))
// Routing
nd.Routing = dht.NewDHT(ctx, nd.Identity, nd.Network, nd.Datastore)
dht := dht.NewDHT(ctx, nd.Identity, nd.Network, nd.Datastore)
nd.Routing = dht
// Bitswap
bstore := blockstore.NewBlockstore(nd.Datastore)
......@@ -55,7 +65,7 @@ func NewMockNode() (*IpfsNode, error) {
nd.DAG = mdag.NewDAGService(bserv)
// Namespace resolver
nd.Namesys = nsys.NewNameSystem(nd.Routing)
nd.Namesys = nsys.NewNameSystem(dht)
// Path resolver
nd.Resolver = &path.Resolver{DAG: nd.DAG}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment