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

Commit 6395730

Browse files
hugomrdiasAlan Shaw
authored andcommitted
refactor: use new ctl api (#2529)
* 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
1 parent 1d19c4f commit 6395730

36 files changed

+522
-1382
lines changed

.aegir.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,27 @@ module.exports = {
2727
},
2828
hooks: {
2929
node: {
30-
pre: () => Promise.all([
31-
preloadNode.start(),
32-
echoServer.start()
33-
]),
34-
post: () => Promise.all([
35-
preloadNode.stop(),
36-
echoServer.stop()
37-
])
30+
pre: async () => {
31+
await preloadNode.start(),
32+
await echoServer.start()
33+
},
34+
post: async () => {
35+
await preloadNode.stop(),
36+
await echoServer.stop()
37+
38+
}
3839
},
3940
browser: {
40-
pre: () => Promise.all([
41-
ipfsdServer.start(),
42-
preloadNode.start(),
43-
echoServer.start()
44-
]),
45-
post: () => Promise.all([
46-
ipfsdServer.stop(),
47-
preloadNode.stop(),
48-
echoServer.stop()
49-
])
41+
pre: async () => {
42+
await ipfsdServer.start()
43+
await preloadNode.start()
44+
await echoServer.start()
45+
},
46+
post: async () => {
47+
await ipfsdServer.stop()
48+
await preloadNode.stop()
49+
await echoServer.stop()
50+
}
5051
}
5152
}
5253
}

examples/circuit-relaying/src/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ document.addEventListener('DOMContentLoaded', async () => {
1515
const $room = document.querySelector('#room')
1616
const $roomId = document.querySelector('#room-id')
1717

18-
let roomName = `default`
18+
let roomName = 'default'
1919
const fragment = window.location.hash.substr(1)
2020
if (fragment) {
2121
roomName = fragment
@@ -68,7 +68,7 @@ document.addEventListener('DOMContentLoaded', async () => {
6868
$roomId.addEventListener('keyup', (event) => {
6969
const kp = event.keyCode || event.which
7070
if (kp === 13 && $roomId.value.length > 0) {
71-
let name = $roomId.value
71+
const name = $roomId.value
7272
$room.innerText = name
7373

7474
$room.setAttribute('style', 'display: inline')

examples/circuit-relaying/test.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ const os = require('os')
55
const path = require('path')
66
const execa = require('execa')
77
const delay = require('delay')
8-
const DaemonFactory = require('ipfsd-ctl')
9-
const df = DaemonFactory.create({
10-
type: 'js',
11-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
12-
IpfsClient: require('ipfs-http-client')
8+
const { createFactory } = require('ipfsd-ctl')
9+
const df = createFactory({
10+
ipfsModule: {
11+
path: require.resolve('../../src'),
12+
ref: require('../../src')
13+
},
14+
ipfsHttpModule: {
15+
path: require.resolve('ipfs-http-client'),
16+
ref: require('ipfs-http-client')
17+
}
1318
})
1419
const {
1520
startServer
@@ -38,19 +43,21 @@ async function testUI (url, relay, localPeerIdFile, remotePeerIdFile) {
3843

3944
async function runTest () {
4045
const ipfsd = await df.spawn({
41-
initOptions: { bits: 512 },
42-
config: {
43-
Addresses: {
44-
Swarm: [
45-
'/ip4/127.0.0.1/tcp/0/ws'
46-
]
47-
},
48-
Bootstrap: [],
46+
type: 'proc',
47+
test: true,
48+
ipfsOptions: {
4949
relay: {
5050
enabled: true,
5151
hop: {
5252
enabled: true
5353
}
54+
},
55+
config: {
56+
Addresses: {
57+
Swarm: [
58+
'/ip4/127.0.0.1/tcp/0/ws'
59+
]
60+
}
5461
}
5562
}
5663
})
@@ -116,7 +123,7 @@ module.exports[pkg.name] = function (browser) {
116123

117124
break
118125
} catch (err) {
119-
126+
// ignore
120127
}
121128

122129
await delay(1000)

examples/exchange-files-in-browser/test.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ const path = require('path')
55
const os = require('os')
66
const execa = require('execa')
77
const delay = require('delay')
8-
const DaemonFactory = require('ipfsd-ctl')
9-
const df = DaemonFactory.create({
10-
type: 'js',
11-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
12-
IpfsClient: require('ipfs-http-client')
13-
})
8+
const { createFactory } = require('ipfsd-ctl')
9+
const df = createFactory({
10+
ipfsModule: {
11+
path: require.resolve('../../src'),
12+
ref: require('../../src')
13+
},
14+
ipfsHttpModule: {
15+
path: require.resolve('ipfs-http-client'),
16+
ref: require('ipfs-http-client')
17+
}
18+
}, {
19+
js: {
20+
ipfsBin: path.resolve(`${__dirname}/../../src/cli/bin.js`)
21+
}
22+
}
23+
)
1424
const {
1525
startServer
1626
} = require('../utils')
@@ -35,14 +45,14 @@ async function testUI (env) {
3545

3646
async function runTest () {
3747
const ipfsd = await df.spawn({
38-
initOptions: { bits: 512 },
39-
config: {
40-
Addresses: {
41-
Swarm: [
42-
'/ip4/127.0.0.1/tcp/0/ws'
43-
]
44-
},
45-
Bootstrap: []
48+
ipfsOptions: {
49+
config: {
50+
Addresses: {
51+
Swarm: [
52+
'/ip4/127.0.0.1/tcp/0/ws'
53+
]
54+
}
55+
}
4656
}
4757
})
4858

examples/explore-ethereum-blockchain/test.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22

33
const fs = require('fs-extra')
44
const path = require('path')
5-
const DaemonFactory = require('ipfsd-ctl')
6-
const df = DaemonFactory.create({
7-
type: 'proc',
8-
exec: require('../../')
5+
const { createFactory } = require('ipfsd-ctl')
6+
const df = createFactory({
7+
ipfsModule: {
8+
path: require.resolve('../../src'),
9+
ref: require('../../src')
10+
},
11+
ipfsHttpModule: {
12+
path: require.resolve('ipfs-http-client'),
13+
ref: require('ipfs-http-client')
14+
}
15+
}, {
16+
js: {
17+
ipfsBin: path.resolve(`${__dirname}/../../src/cli/bin.js`)
18+
}
919
})
1020

1121
async function runTest () {
1222
const ipfsd = await df.spawn({
13-
initOptions: { bits: 512 },
14-
config: {
15-
Addresses: {
16-
Swarm: []
17-
},
18-
Bootstrap: []
19-
},
20-
disposable: true
23+
type: 'proc',
24+
test: true
2125
})
2226

2327
const cids = []

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"license": "MIT",
1010
"dependencies": {
11-
"chromedriver": "^77.0.0",
11+
"chromedriver": "^79.0.0",
1212
"delay": "^4.1.0",
1313
"execa": "^3.2.0",
1414
"fs-extra": "^8.1.0",

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,14 @@
204204
"execa": "^3.0.0",
205205
"form-data": "^3.0.0",
206206
"hat": "0.0.3",
207-
"interface-ipfs-core": "^0.124.1",
207+
"interface-ipfs-core": "^0.125.0",
208208
"ipfs-interop": "^0.1.1",
209-
"ipfsd-ctl": "^0.47.2",
209+
"ipfsd-ctl": "^1.0.2",
210210
"libp2p-websocket-star": "~0.10.2",
211211
"lodash": "^4.17.15",
212212
"ncp": "^2.0.0",
213213
"p-event": "^4.1.0",
214+
"p-map": "^3.0.0",
214215
"qs": "^6.5.2",
215216
"rimraf": "^3.0.0",
216217
"sinon": "^7.4.2",

src/http/api/resources/key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exports.rename = async (request, h) => {
2626
const key = await ipfs.key.rename(oldName, newName)
2727
return h.response({
2828
Was: key.was,
29-
Now: key.name,
29+
Now: key.now,
3030
Id: key.id,
3131
Overwrite: key.overwrite
3232
})

test/cli/dht.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,12 @@
33
'use strict'
44

55
const { expect } = require('interface-ipfs-core/src/utils/mocha')
6-
const path = require('path')
7-
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({
9-
type: 'js',
10-
IpfsClient: require('ipfs-http-client')
11-
})
12-
6+
const factory = require('../utils/factory')
137
const ipfsExec = require('../utils/ipfs-exec')
148

15-
const daemonOpts = {
16-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
17-
config: {
18-
Bootstrap: [],
19-
Discovery: {
20-
MDNS: {
21-
Enabled: false
22-
},
23-
webRTCStar: {
24-
Enabled: false
25-
}
26-
}
27-
},
28-
initOptions: { bits: 512 }
29-
}
30-
319
// TODO: unskip when DHT is enabled: https://github.com/ipfs/js-ipfs/pull/1994
3210
describe.skip('dht', () => {
11+
const df = factory({ type: 'js' })
3312
const nodes = []
3413
let ipfsA
3514
let ipfsB
@@ -41,11 +20,11 @@ describe.skip('dht', () => {
4120
before(async function () {
4221
this.timeout(80 * 1000)
4322

44-
const ipfsdA = await df.spawn(daemonOpts)
23+
const ipfsdA = await df.spawn()
4524
ipfsA = ipfsExec(ipfsdA.repoPath)
4625
nodes.push(ipfsdA)
4726

48-
const ipfsdB = await df.spawn(daemonOpts)
27+
const ipfsdB = await df.spawn()
4928
ipfsB = ipfsExec(ipfsdB.repoPath)
5029
nodes.push(ipfsdB)
5130
})
@@ -71,7 +50,7 @@ describe.skip('dht', () => {
7150
return nodes[0].api.swarm.connect(multiaddrB)
7251
})
7352

74-
after(() => Promise.all(nodes.map((node) => node.stop())))
53+
after(() => df.clean())
7554

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

0 commit comments

Comments
 (0)