|
2 | 2 | 'use strict'
|
3 | 3 |
|
4 | 4 | const expect = require('chai').expect
|
5 |
| -const IPFSFactory = require('ipfsd-ctl') |
| 5 | +const { createFactory } = require('ipfsd-ctl') |
6 | 6 | const CID = require('cids')
|
7 | 7 | const PeerId = require('peer-id')
|
8 | 8 | const all = require('it-all')
|
9 |
| -const factory = IPFSFactory.create({ |
10 |
| - type: 'go' |
| 9 | +const last = require('it-last') |
| 10 | +const drain = require('it-drain') |
| 11 | +const { isNode } = require('ipfs-utils/src/env') |
| 12 | +const factory = createFactory({ |
| 13 | + type: 'go', |
| 14 | + ipfsHttpModule: require('ipfs-http-client'), |
| 15 | + ipfsBin: isNode ? require('go-ipfs-dep').path() : undefined, |
| 16 | + test: true, |
| 17 | + endpoint: 'http://localhost:57483' |
11 | 18 | })
|
12 | 19 |
|
13 | 20 | const DelegatedContentRouting = require('../src')
|
14 | 21 |
|
15 | 22 | async function spawnNode (bootstrap = []) {
|
16 | 23 | const node = await factory.spawn({
|
17 | 24 | // Lock down the nodes so testing can be deterministic
|
18 |
| - config: { |
19 |
| - Bootstrap: bootstrap, |
20 |
| - Discovery: { |
21 |
| - MDNS: { |
22 |
| - Enabled: false |
| 25 | + ipfsOptions: { |
| 26 | + config: { |
| 27 | + Bootstrap: bootstrap, |
| 28 | + Discovery: { |
| 29 | + MDNS: { |
| 30 | + Enabled: false |
| 31 | + } |
23 | 32 | }
|
24 | 33 | }
|
25 | 34 | }
|
@@ -59,11 +68,7 @@ describe('DelegatedContentRouting', function () {
|
59 | 68 | })
|
60 | 69 |
|
61 | 70 | after(() => {
|
62 |
| - return Promise.all([ |
63 |
| - selfNode.stop(), |
64 |
| - delegateNode.stop(), |
65 |
| - bootstrapNode.stop() |
66 |
| - ]) |
| 71 | + return factory.clean() |
67 | 72 | })
|
68 | 73 |
|
69 | 74 | describe('create', () => {
|
@@ -109,11 +114,11 @@ describe('DelegatedContentRouting', function () {
|
109 | 114 | const cid = new CID('QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv')
|
110 | 115 |
|
111 | 116 | before('register providers', async () => {
|
112 |
| - await bootstrapNode.api.dht.provide(cid) |
113 |
| - await selfNode.api.dht.provide(cid) |
| 117 | + await drain(bootstrapNode.api.dht.provide(cid)) |
| 118 | + await drain(selfNode.api.dht.provide(cid)) |
114 | 119 | })
|
115 | 120 |
|
116 |
| - it('should be able to find providers through the delegate node', async () => { |
| 121 | + it('should be able to find providers through the delegate node', async function () { |
117 | 122 | const opts = delegateNode.apiAddr.toOptions()
|
118 | 123 | const routing = new DelegatedContentRouting(selfId, {
|
119 | 124 | protocol: 'http',
|
@@ -153,13 +158,14 @@ describe('DelegatedContentRouting', function () {
|
153 | 158 | host: opts.host
|
154 | 159 | })
|
155 | 160 |
|
156 |
| - const res = await selfNode.api.add(Buffer.from(`hello-${Math.random()}`)) |
157 |
| - const cid = new CID(res[0].hash) |
| 161 | + const { cid } = await last(selfNode.api.add(Buffer.from(`hello-${Math.random()}`))) |
| 162 | + |
158 | 163 | await contentRouter.provide(cid)
|
159 |
| - const providers = await delegateNode.api.dht.findProvs(cid.toBaseEncodedString()) |
| 164 | + |
| 165 | + const providers = await all(delegateNode.api.dht.findProvs(cid, { numProviders: 2 })) |
160 | 166 |
|
161 | 167 | // We are hosting the file, validate we're the provider
|
162 |
| - expect(providers.map((p) => p.id.toB58String())).to.include(selfId.toB58String(), 'Did not include self node') |
| 168 | + expect(providers.map((p) => p.id)).to.include(selfId.toB58String(), 'Did not include self node') |
163 | 169 | })
|
164 | 170 | })
|
165 | 171 | })
|
0 commit comments