Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
refactor: use new ctl api (#2529)
Browse files Browse the repository at this point in the history
* feat: support the new interface core tests setup

* fix: fix key rename output

* fix: skip troublesome test

* fix: ipfsd-ctl args handling

* fix: change http api interface-core tests to new setup

* fix: add reason to skip

* fix: make aegir tests setup async

* fix: fix ctl setup

* fix: add pass option

* fix: interface and cli tests ported

plus #2625

* fix: support new ctl in core and http tests

* fix: fix linter

* chore: fix tests timeout

* chore: fix tests timeout more

* chore: fix webworker

* chore: debug key exhcnage

* chore: debug key exhcnage 2

* fix: key exchange fixed

* fix: overrides correctly in pubsub tests

* fix: refactor missing pieces and await clean in bitswap tests

* fix: skip test that dont work in firefox

* chore: bump chromedriver

* fix: fix circuit relay example

* fix: linter

* fix: more examples
  • Loading branch information
hugomrdias authored and Alan Shaw committed Dec 12, 2019
1 parent 1d19c4f commit 6395730
Show file tree
Hide file tree
Showing 36 changed files with 522 additions and 1,382 deletions.
37 changes: 19 additions & 18 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,27 @@ module.exports = {
},
hooks: {
node: {
pre: () => Promise.all([
preloadNode.start(),
echoServer.start()
]),
post: () => Promise.all([
preloadNode.stop(),
echoServer.stop()
])
pre: async () => {
await preloadNode.start(),
await echoServer.start()
},
post: async () => {
await preloadNode.stop(),
await echoServer.stop()

}
},
browser: {
pre: () => Promise.all([
ipfsdServer.start(),
preloadNode.start(),
echoServer.start()
]),
post: () => Promise.all([
ipfsdServer.stop(),
preloadNode.stop(),
echoServer.stop()
])
pre: async () => {
await ipfsdServer.start()
await preloadNode.start()
await echoServer.start()
},
post: async () => {
await ipfsdServer.stop()
await preloadNode.stop()
await echoServer.stop()
}
}
}
}
4 changes: 2 additions & 2 deletions examples/circuit-relaying/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ document.addEventListener('DOMContentLoaded', async () => {
const $room = document.querySelector('#room')
const $roomId = document.querySelector('#room-id')

let roomName = `default`
let roomName = 'default'
const fragment = window.location.hash.substr(1)
if (fragment) {
roomName = fragment
Expand Down Expand Up @@ -68,7 +68,7 @@ document.addEventListener('DOMContentLoaded', async () => {
$roomId.addEventListener('keyup', (event) => {
const kp = event.keyCode || event.which
if (kp === 13 && $roomId.value.length > 0) {
let name = $roomId.value
const name = $roomId.value
$room.innerText = name

$room.setAttribute('style', 'display: inline')
Expand Down
35 changes: 21 additions & 14 deletions examples/circuit-relaying/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ const os = require('os')
const path = require('path')
const execa = require('execa')
const delay = require('delay')
const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({
type: 'js',
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
IpfsClient: require('ipfs-http-client')
const { createFactory } = require('ipfsd-ctl')
const df = createFactory({
ipfsModule: {
path: require.resolve('../../src'),
ref: require('../../src')
},
ipfsHttpModule: {
path: require.resolve('ipfs-http-client'),
ref: require('ipfs-http-client')
}
})
const {
startServer
Expand Down Expand Up @@ -38,19 +43,21 @@ async function testUI (url, relay, localPeerIdFile, remotePeerIdFile) {

async function runTest () {
const ipfsd = await df.spawn({
initOptions: { bits: 512 },
config: {
Addresses: {
Swarm: [
'/ip4/127.0.0.1/tcp/0/ws'
]
},
Bootstrap: [],
type: 'proc',
test: true,
ipfsOptions: {
relay: {
enabled: true,
hop: {
enabled: true
}
},
config: {
Addresses: {
Swarm: [
'/ip4/127.0.0.1/tcp/0/ws'
]
}
}
}
})
Expand Down Expand Up @@ -116,7 +123,7 @@ module.exports[pkg.name] = function (browser) {

break
} catch (err) {

// ignore
}

await delay(1000)
Expand Down
38 changes: 24 additions & 14 deletions examples/exchange-files-in-browser/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ const path = require('path')
const os = require('os')
const execa = require('execa')
const delay = require('delay')
const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({
type: 'js',
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
IpfsClient: require('ipfs-http-client')
})
const { createFactory } = require('ipfsd-ctl')
const df = createFactory({
ipfsModule: {
path: require.resolve('../../src'),
ref: require('../../src')
},
ipfsHttpModule: {
path: require.resolve('ipfs-http-client'),
ref: require('ipfs-http-client')
}
}, {
js: {
ipfsBin: path.resolve(`${__dirname}/../../src/cli/bin.js`)
}
}
)
const {
startServer
} = require('../utils')
Expand All @@ -35,14 +45,14 @@ async function testUI (env) {

async function runTest () {
const ipfsd = await df.spawn({
initOptions: { bits: 512 },
config: {
Addresses: {
Swarm: [
'/ip4/127.0.0.1/tcp/0/ws'
]
},
Bootstrap: []
ipfsOptions: {
config: {
Addresses: {
Swarm: [
'/ip4/127.0.0.1/tcp/0/ws'
]
}
}
}
})

Expand Down
28 changes: 16 additions & 12 deletions examples/explore-ethereum-blockchain/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

const fs = require('fs-extra')
const path = require('path')
const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({
type: 'proc',
exec: require('../../')
const { createFactory } = require('ipfsd-ctl')
const df = createFactory({
ipfsModule: {
path: require.resolve('../../src'),
ref: require('../../src')
},
ipfsHttpModule: {
path: require.resolve('ipfs-http-client'),
ref: require('ipfs-http-client')
}
}, {
js: {
ipfsBin: path.resolve(`${__dirname}/../../src/cli/bin.js`)
}
})

async function runTest () {
const ipfsd = await df.spawn({
initOptions: { bits: 512 },
config: {
Addresses: {
Swarm: []
},
Bootstrap: []
},
disposable: true
type: 'proc',
test: true
})

const cids = []
Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"license": "MIT",
"dependencies": {
"chromedriver": "^77.0.0",
"chromedriver": "^79.0.0",
"delay": "^4.1.0",
"execa": "^3.2.0",
"fs-extra": "^8.1.0",
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@
"execa": "^3.0.0",
"form-data": "^3.0.0",
"hat": "0.0.3",
"interface-ipfs-core": "^0.124.1",
"interface-ipfs-core": "^0.125.0",
"ipfs-interop": "^0.1.1",
"ipfsd-ctl": "^0.47.2",
"ipfsd-ctl": "^1.0.2",
"libp2p-websocket-star": "~0.10.2",
"lodash": "^4.17.15",
"ncp": "^2.0.0",
"p-event": "^4.1.0",
"p-map": "^3.0.0",
"qs": "^6.5.2",
"rimraf": "^3.0.0",
"sinon": "^7.4.2",
Expand Down
2 changes: 1 addition & 1 deletion src/http/api/resources/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports.rename = async (request, h) => {
const key = await ipfs.key.rename(oldName, newName)
return h.response({
Was: key.was,
Now: key.name,
Now: key.now,
Id: key.id,
Overwrite: key.overwrite
})
Expand Down
31 changes: 5 additions & 26 deletions test/cli/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,12 @@
'use strict'

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const path = require('path')
const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({
type: 'js',
IpfsClient: require('ipfs-http-client')
})

const factory = require('../utils/factory')
const ipfsExec = require('../utils/ipfs-exec')

const daemonOpts = {
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
config: {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false
},
webRTCStar: {
Enabled: false
}
}
},
initOptions: { bits: 512 }
}

// TODO: unskip when DHT is enabled: https://github.com/ipfs/js-ipfs/pull/1994
describe.skip('dht', () => {
const df = factory({ type: 'js' })
const nodes = []
let ipfsA
let ipfsB
Expand All @@ -41,11 +20,11 @@ describe.skip('dht', () => {
before(async function () {
this.timeout(80 * 1000)

const ipfsdA = await df.spawn(daemonOpts)
const ipfsdA = await df.spawn()
ipfsA = ipfsExec(ipfsdA.repoPath)
nodes.push(ipfsdA)

const ipfsdB = await df.spawn(daemonOpts)
const ipfsdB = await df.spawn()
ipfsB = ipfsExec(ipfsdB.repoPath)
nodes.push(ipfsdB)
})
Expand All @@ -71,7 +50,7 @@ describe.skip('dht', () => {
return nodes[0].api.swarm.connect(multiaddrB)
})

after(() => Promise.all(nodes.map((node) => node.stop())))
after(() => df.clean())

it('should be able to put a value to the dht and get it afterwards', async function () {
this.timeout(60 * 1000)
Expand Down
Loading

0 comments on commit 6395730

Please sign in to comment.