Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit a27cfa7

Browse files
hugomrdiasAlan Shaw
authored and
Alan Shaw
committed
feat: add support for new ipfsd-ctl (#541)
* feat: add support for a simpler and async test setup * fix: tweak some tests * fix: fix connecting multiples node in the browser when running with a 'proc' pre-setup we could end up with multiples in-browser setup connecting to each other. whihc isnt a very useful situation. with this the first node gets the pre-configured config and all the others get a JS daemon. * fix: change secondary node to Go * fix: one more to go * chore: update to the latest ctl api * fix: add connect to wantlist tests * fix: fix pubsub tests in firefox * fix: increase timeout findprovs * fix: revert pubsub to go * fix: add more info * chore: bump ipfsd-ctl
1 parent d25c6f6 commit a27cfa7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+945
-999
lines changed

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"ipld-dag-pb": "^0.18.1",
5656
"is-ipfs": "~0.6.1",
5757
"is-plain-object": "^3.0.0",
58-
"it-pushable": "^1.2.1",
58+
"it-pushable": "^1.3.1",
5959
"libp2p-crypto": "~0.16.0",
6060
"multiaddr": "^6.0.0",
6161
"multibase": "~0.6.0",
@@ -75,7 +75,8 @@
7575
"through2": "^3.0.0"
7676
},
7777
"devDependencies": {
78-
"aegir": "^20.0.0"
78+
"aegir": "^20.3.2",
79+
"ipfsd-ctl": "^1.0.0"
7980
},
8081
"contributors": [
8182
"Alan Shaw <alan.shaw@protocol.ai>",

src/bitswap/stat.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,35 @@
44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55
const { expectIsBitswap } = require('../stats/utils')
66

7-
module.exports = (createCommon, options) => {
7+
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
8+
/**
9+
* @param {Factory} common
10+
* @param {Object} options
11+
*/
12+
module.exports = (common, options) => {
813
const describe = getDescribe(options)
914
const it = getIt(options)
10-
const common = createCommon()
1115

12-
describe('.bitswap.stat', () => {
16+
describe('.bitswap.stat', function () {
17+
this.timeout(60 * 1000)
1318
let ipfs
1419

15-
before(async function () {
16-
// CI takes longer to instantiate the daemon, so we need to increase the
17-
// timeout for the before step
18-
this.timeout(60 * 1000)
19-
20-
ipfs = await common.setup()
20+
before(async () => {
21+
ipfs = (await common.spawn()).api
2122
})
2223

23-
after(() => common.teardown())
24+
after(() => common.clean())
2425

2526
it('should get bitswap stats', async () => {
2627
const res = await ipfs.bitswap.stat()
2728
expectIsBitswap(null, res)
2829
})
2930

30-
it('should not get bitswap stats when offline', async function () {
31-
this.timeout(60 * 1000)
32-
33-
const node = await createCommon().setup()
31+
it('should not get bitswap stats when offline', async () => {
32+
const node = await common.spawn()
3433
await node.stop()
3534

36-
return expect(node.bitswap.stat()).to.eventually.be.rejected()
35+
return expect(node.api.bitswap.stat()).to.eventually.be.rejected()
3736
})
3837
})
3938
}

src/bitswap/wantlist.js

+15-24
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,47 @@
44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55
const { waitForWantlistKey } = require('./utils')
66

7-
module.exports = (createCommon, options) => {
7+
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
8+
/**
9+
* @param {Factory} common
10+
* @param {Object} options
11+
*/
12+
module.exports = (common, options) => {
813
const describe = getDescribe(options)
914
const it = getIt(options)
10-
const common = createCommon()
1115

12-
describe('.bitswap.wantlist', () => {
16+
describe('.bitswap.wantlist', function () {
17+
this.timeout(60 * 1000)
1318
let ipfsA
1419
let ipfsB
1520
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
1621

17-
before(async function () {
18-
// CI takes longer to instantiate the daemon, so we need to increase the
19-
// timeout for the before step
20-
this.timeout(60 * 1000)
21-
22-
ipfsA = await common.setup()
23-
ipfsB = await common.setup()
24-
22+
before(async () => {
23+
ipfsA = (await common.spawn()).api
24+
ipfsB = (await common.spawn({ type: 'go' })).api
2525
// Add key to the wantlist for ipfsB
2626
ipfsB.block.get(key).catch(() => {})
27-
2827
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
2928
})
3029

31-
after(function () {
32-
this.timeout(30 * 1000)
33-
34-
return common.teardown()
35-
})
30+
after(() => common.clean())
3631

3732
it('should get the wantlist', function () {
38-
this.timeout(60 * 1000)
3933
return waitForWantlistKey(ipfsB, key)
4034
})
4135

4236
it('should get the wantlist by peer ID for a different node', function () {
43-
this.timeout(60 * 1000)
4437
return waitForWantlistKey(ipfsA, key, {
4538
peerId: ipfsB.peerId.id,
4639
timeout: 60 * 1000
4740
})
4841
})
4942

50-
it('should not get the wantlist when offline', async function () {
51-
this.timeout(60 * 1000)
52-
53-
const node = await createCommon().setup()
43+
it('should not get the wantlist when offline', async () => {
44+
const node = await common.spawn()
5445
await node.stop()
5546

56-
return expect(node.bitswap.wantlist()).to.eventually.be.rejected()
47+
return expect(node.api.bitswap.stat()).to.eventually.be.rejected()
5748
})
5849
})
5950
}

src/block/get.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ const multihash = require('multihashes')
55
const CID = require('cids')
66
const { getDescribe, getIt, expect } = require('../utils/mocha')
77

8-
module.exports = (createCommon, options) => {
8+
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
9+
/**
10+
* @param {Factory} common
11+
* @param {Object} options
12+
*/
13+
module.exports = (common, options) => {
914
const describe = getDescribe(options)
1015
const it = getIt(options)
11-
const common = createCommon()
1216

1317
describe('.block.get', () => {
1418
const data = Buffer.from('blorb')
1519
let ipfs, hash
1620

17-
before(async function () {
18-
// CI takes longer to instantiate the daemon, so we need to increase the
19-
// timeout for the before step
20-
this.timeout(60 * 1000)
21-
22-
ipfs = await common.setup()
21+
before(async () => {
22+
ipfs = (await common.spawn()).api
2323
const block = await ipfs.block.put(data)
2424
hash = block.cid.multihash
2525
})
2626

27-
after(() => common.teardown())
27+
after(() => common.clean())
2828

2929
it('should get by CID object', async () => {
3030
const cid = new CID(hash)

src/block/put.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ const multihash = require('multihashes')
66
const CID = require('cids')
77
const { getDescribe, getIt, expect } = require('../utils/mocha')
88

9-
module.exports = (createCommon, options) => {
9+
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
10+
/**
11+
* @param {Factory} common
12+
* @param {Object} options
13+
*/
14+
module.exports = (common, options) => {
1015
const describe = getDescribe(options)
1116
const it = getIt(options)
12-
const common = createCommon()
1317

1418
describe('.block.put', () => {
1519
let ipfs
1620

17-
before(async function () {
18-
// CI takes longer to instantiate the daemon, so we need to increase the
19-
// timeout for the before step
20-
this.timeout(60 * 1000)
21-
22-
ipfs = await common.setup()
21+
before(async () => {
22+
ipfs = (await common.spawn()).api
2323
})
2424

25-
after(() => common.teardown())
25+
after(() => common.clean())
2626

2727
it('should put a buffer, using defaults', async () => {
2828
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'

src/block/rm.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55
const hat = require('hat')
66

7-
module.exports = (createCommon, options) => {
7+
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
8+
/**
9+
* @param {Factory} common
10+
* @param {Object} options
11+
*/
12+
module.exports = (common, options) => {
813
const describe = getDescribe(options)
914
const it = getIt(options)
10-
const common = createCommon()
1115

1216
describe('.block.rm', () => {
1317
let ipfs
1418

15-
before(async function () {
16-
// CI takes longer to instantiate the daemon, so we need to increase the
17-
// timeout for the before step
18-
this.timeout(60 * 1000)
19+
before(async () => { ipfs = (await common.spawn()).api })
1920

20-
ipfs = await common.setup()
21-
})
22-
23-
after(() => common.teardown())
21+
after(() => common.clean())
2422

2523
it('should remove by CID object', async () => {
2624
const cid = await ipfs.dag.put(Buffer.from(hat()), {

src/block/stat.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
const CID = require('cids')
55
const { getDescribe, getIt, expect } = require('../utils/mocha')
66

7-
module.exports = (createCommon, options) => {
7+
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
8+
/**
9+
* @param {Factory} common
10+
* @param {Object} options
11+
*/
12+
module.exports = (common, options) => {
813
const describe = getDescribe(options)
914
const it = getIt(options)
10-
const common = createCommon()
1115

1216
describe('.block.stat', () => {
1317
const data = Buffer.from('blorb')
1418
let ipfs, hash
1519

16-
before(async function () {
17-
// CI takes longer to instantiate the daemon, so we need to increase the
18-
// timeout for the before step
19-
this.timeout(60 * 1000)
20-
21-
ipfs = await common.setup()
20+
before(async () => {
21+
ipfs = (await common.spawn()).api
2222
const block = await ipfs.block.put(data)
2323
hash = block.cid.multihash
2424
})
2525

26-
after(() => common.teardown())
26+
after(() => common.clean())
2727

2828
it('should stat by CID', async () => {
2929
const cid = new CID(hash)

src/bootstrap/add.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
66
const invalidArg = 'this/Is/So/Invalid/'
77
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
88

9-
module.exports = (createCommon, options) => {
9+
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
10+
/**
11+
* @param {Factory} common
12+
* @param {Object} options
13+
*/
14+
module.exports = (common, options) => {
1015
const describe = getDescribe(options)
1116
const it = getIt(options)
12-
const common = createCommon()
1317

1418
describe('.bootstrap.add', function () {
1519
this.timeout(100 * 1000)
1620

1721
let ipfs
1822

19-
before(async function () {
20-
// CI takes longer to instantiate the daemon, so we need to increase the
21-
// timeout for the before step
22-
this.timeout(60 * 1000)
23-
24-
ipfs = await common.setup()
23+
before(async () => {
24+
ipfs = (await common.spawn()).api
2525
})
2626

27-
after(() => common.teardown())
27+
after(() => common.clean())
2828

2929
it('should return an error when called with an invalid arg', () => {
3030
return expect(ipfs.bootstrap.add(invalidArg)).to.eventually.be.rejected

src/bootstrap/list.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,23 @@
33

44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55

6-
module.exports = (createCommon, options) => {
6+
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
7+
/**
8+
* @param {Factory} common
9+
* @param {Object} options
10+
*/
11+
module.exports = (common, options) => {
712
const describe = getDescribe(options)
813
const it = getIt(options)
9-
const common = createCommon()
1014

1115
describe('.bootstrap.list', function () {
1216
this.timeout(100 * 1000)
1317

1418
let ipfs
1519

16-
before(async function () {
17-
// CI takes longer to instantiate the daemon, so we need to increase the
18-
// timeout for the before step
19-
this.timeout(60 * 1000)
20+
before(async () => { ipfs = (await common.spawn()).api })
2021

21-
ipfs = await common.setup()
22-
})
23-
24-
after(() => common.teardown())
22+
after(() => common.clean())
2523

2624
it('should return a list of peers', async () => {
2725
const res = await ipfs.bootstrap.list()

src/bootstrap/rm.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33

44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55

6-
module.exports = (createCommon, options) => {
6+
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
7+
/**
8+
* @param {Factory} common
9+
* @param {Object} options
10+
*/
11+
module.exports = (common, options) => {
712
const describe = getDescribe(options)
813
const it = getIt(options)
9-
const common = createCommon()
1014

1115
const invalidArg = 'this/Is/So/Invalid/'
1216
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
@@ -16,15 +20,9 @@ module.exports = (createCommon, options) => {
1620

1721
let ipfs
1822

19-
before(async function () {
20-
// CI takes longer to instantiate the daemon, so we need to increase the
21-
// timeout for the before step
22-
this.timeout(60 * 1000)
23+
before(async () => { ipfs = (await common.spawn()).api })
2324

24-
ipfs = await common.setup()
25-
})
26-
27-
after(() => common.teardown())
25+
after(() => common.clean())
2826

2927
it('should return an error when called with an invalid arg', () => {
3028
return expect(ipfs.bootstrap.rm(invalidArg)).to.eventually.be.rejected

0 commit comments

Comments
 (0)