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

Commit

Permalink
feat: add support for new ipfsd-ctl (#541)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hugomrdias authored and alanshaw committed Dec 11, 2019
1 parent d25c6f6 commit a27cfa7
Show file tree
Hide file tree
Showing 104 changed files with 945 additions and 999 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"ipld-dag-pb": "^0.18.1",
"is-ipfs": "~0.6.1",
"is-plain-object": "^3.0.0",
"it-pushable": "^1.2.1",
"it-pushable": "^1.3.1",
"libp2p-crypto": "~0.16.0",
"multiaddr": "^6.0.0",
"multibase": "~0.6.0",
Expand All @@ -75,7 +75,8 @@
"through2": "^3.0.0"
},
"devDependencies": {
"aegir": "^20.0.0"
"aegir": "^20.3.2",
"ipfsd-ctl": "^1.0.0"
},
"contributors": [
"Alan Shaw <alan.shaw@protocol.ai>",
Expand Down
29 changes: 14 additions & 15 deletions src/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,35 @@
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { expectIsBitswap } = require('../stats/utils')

module.exports = (createCommon, options) => {
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

describe('.bitswap.stat', () => {
describe('.bitswap.stat', function () {
this.timeout(60 * 1000)
let ipfs

before(async function () {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

ipfs = await common.setup()
before(async () => {
ipfs = (await common.spawn()).api
})

after(() => common.teardown())
after(() => common.clean())

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

it('should not get bitswap stats when offline', async function () {
this.timeout(60 * 1000)

const node = await createCommon().setup()
it('should not get bitswap stats when offline', async () => {
const node = await common.spawn()
await node.stop()

return expect(node.bitswap.stat()).to.eventually.be.rejected()
return expect(node.api.bitswap.stat()).to.eventually.be.rejected()
})
})
}
39 changes: 15 additions & 24 deletions src/bitswap/wantlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,47 @@
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { waitForWantlistKey } = require('./utils')

module.exports = (createCommon, options) => {
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

describe('.bitswap.wantlist', () => {
describe('.bitswap.wantlist', function () {
this.timeout(60 * 1000)
let ipfsA
let ipfsB
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'

before(async function () {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

ipfsA = await common.setup()
ipfsB = await common.setup()

before(async () => {
ipfsA = (await common.spawn()).api
ipfsB = (await common.spawn({ type: 'go' })).api
// Add key to the wantlist for ipfsB
ipfsB.block.get(key).catch(() => {})

await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
})

after(function () {
this.timeout(30 * 1000)

return common.teardown()
})
after(() => common.clean())

it('should get the wantlist', function () {
this.timeout(60 * 1000)
return waitForWantlistKey(ipfsB, key)
})

it('should get the wantlist by peer ID for a different node', function () {
this.timeout(60 * 1000)
return waitForWantlistKey(ipfsA, key, {
peerId: ipfsB.peerId.id,
timeout: 60 * 1000
})
})

it('should not get the wantlist when offline', async function () {
this.timeout(60 * 1000)

const node = await createCommon().setup()
it('should not get the wantlist when offline', async () => {
const node = await common.spawn()
await node.stop()

return expect(node.bitswap.wantlist()).to.eventually.be.rejected()
return expect(node.api.bitswap.stat()).to.eventually.be.rejected()
})
})
}
18 changes: 9 additions & 9 deletions src/block/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ const multihash = require('multihashes')
const CID = require('cids')
const { getDescribe, getIt, expect } = require('../utils/mocha')

module.exports = (createCommon, options) => {
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

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

before(async function () {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

ipfs = await common.setup()
before(async () => {
ipfs = (await common.spawn()).api
const block = await ipfs.block.put(data)
hash = block.cid.multihash
})

after(() => common.teardown())
after(() => common.clean())

it('should get by CID object', async () => {
const cid = new CID(hash)
Expand Down
18 changes: 9 additions & 9 deletions src/block/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ const multihash = require('multihashes')
const CID = require('cids')
const { getDescribe, getIt, expect } = require('../utils/mocha')

module.exports = (createCommon, options) => {
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

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

before(async function () {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

ipfs = await common.setup()
before(async () => {
ipfs = (await common.spawn()).api
})

after(() => common.teardown())
after(() => common.clean())

it('should put a buffer, using defaults', async () => {
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
Expand Down
18 changes: 8 additions & 10 deletions src/block/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
const { getDescribe, getIt, expect } = require('../utils/mocha')
const hat = require('hat')

module.exports = (createCommon, options) => {
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

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

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

ipfs = await common.setup()
})

after(() => common.teardown())
after(() => common.clean())

it('should remove by CID object', async () => {
const cid = await ipfs.dag.put(Buffer.from(hat()), {
Expand Down
18 changes: 9 additions & 9 deletions src/block/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
const CID = require('cids')
const { getDescribe, getIt, expect } = require('../utils/mocha')

module.exports = (createCommon, options) => {
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

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

before(async function () {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

ipfs = await common.setup()
before(async () => {
ipfs = (await common.spawn()).api
const block = await ipfs.block.put(data)
hash = block.cid.multihash
})

after(() => common.teardown())
after(() => common.clean())

it('should stat by CID', async () => {
const cid = new CID(hash)
Expand Down
18 changes: 9 additions & 9 deletions src/bootstrap/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
const invalidArg = 'this/Is/So/Invalid/'
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'

module.exports = (createCommon, options) => {
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

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

let ipfs

before(async function () {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

ipfs = await common.setup()
before(async () => {
ipfs = (await common.spawn()).api
})

after(() => common.teardown())
after(() => common.clean())

it('should return an error when called with an invalid arg', () => {
return expect(ipfs.bootstrap.add(invalidArg)).to.eventually.be.rejected
Expand Down
18 changes: 8 additions & 10 deletions src/bootstrap/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@

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

module.exports = (createCommon, options) => {
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

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

let ipfs

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

ipfs = await common.setup()
})

after(() => common.teardown())
after(() => common.clean())

it('should return a list of peers', async () => {
const res = await ipfs.bootstrap.list()
Expand Down
18 changes: 8 additions & 10 deletions src/bootstrap/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

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

module.exports = (createCommon, options) => {
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

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

let ipfs

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

ipfs = await common.setup()
})

after(() => common.teardown())
after(() => common.clean())

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

0 comments on commit a27cfa7

Please sign in to comment.