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

Commit 4271c7a

Browse files
achingbrainAlan Shaw
authored and
Alan Shaw
committed
chore: upgrade ipfsd-ctl (#1088)
Also converts all tests to async/await
1 parent 33b090a commit 4271c7a

19 files changed

+628
-824
lines changed

.aegir.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ module.exports = {
2222
singleRun: true
2323
},
2424
hooks: {
25-
pre: server.start.bind(server),
26-
post: server.stop.bind(server)
25+
browser: {
26+
pre: () => server.start(),
27+
post: () => server.stop()
28+
}
2729
}
2830
}

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
"test:node": "aegir test -t node",
2727
"test:browser": "aegir test -t browser",
2828
"test:webworker": "aegir test -t webworker",
29+
"test:electron-main": "aegir test -t electron-main",
30+
"test:electron-renderer": "aegir test -t electron-renderer",
31+
"test:chrome": "aegir test -t browser -t webworker -- --browsers ChromeHeadless",
32+
"test:firefox": "aegir test -t browser -t webworker -- --browsers FirefoxHeadless",
2933
"lint": "aegir lint",
3034
"build": "aegir build",
3135
"release": "aegir release ",
@@ -90,11 +94,12 @@
9094
"aegir": "^20.0.0",
9195
"browser-process-platform": "~0.1.1",
9296
"chai": "^4.2.0",
97+
"chai-as-promised": "^7.1.1",
9398
"cross-env": "^5.2.0",
9499
"dirty-chai": "^2.0.1",
95100
"go-ipfs-dep": "^0.4.22",
96101
"interface-ipfs-core": "^0.111.0",
97-
"ipfsd-ctl": "~0.43.0",
102+
"ipfsd-ctl": "~0.45.0",
98103
"nock": "^10.0.2",
99104
"stream-equal": "^1.1.1"
100105
},

src/utils/send-files-stream.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ module.exports = (send, path) => {
7878
qs['raw-leaves'] = propOrProp(options, 'raw-leaves', 'rawLeaves')
7979
qs['only-hash'] = propOrProp(options, 'only-hash', 'onlyHash')
8080
qs['wrap-with-directory'] = propOrProp(options, 'wrap-with-directory', 'wrapWithDirectory')
81-
qs['pin'] = propOrProp(options, 'pin')
82-
qs['preload'] = propOrProp(options, 'preload')
81+
qs.pin = propOrProp(options, 'pin')
82+
qs.preload = propOrProp(options, 'preload')
8383
qs.hash = propOrProp(options, 'hash', 'hashAlg')
8484

8585
if (options.strategy === 'trickle' || options.trickle) {

test/commands.spec.js

+14-23
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,25 @@ describe('.commands', function () {
1616
let ipfsd
1717
let ipfs
1818

19-
before((done) => {
20-
f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, _ipfsd) => {
21-
expect(err).to.not.exist()
22-
ipfsd = _ipfsd
23-
ipfs = ipfsClient(_ipfsd.apiAddr)
24-
done()
19+
before(async () => {
20+
ipfsd = await f.spawn({
21+
initOptions: {
22+
bits: 1024,
23+
profile: 'test'
24+
}
2525
})
26+
ipfs = ipfsClient(ipfsd.apiAddr)
2627
})
2728

28-
after((done) => {
29-
if (!ipfsd) return done()
30-
ipfsd.stop(done)
29+
after(async () => {
30+
if (ipfsd) {
31+
await ipfsd.stop()
32+
}
3133
})
3234

33-
it('lists commands', (done) => {
34-
ipfs.commands((err, res) => {
35-
expect(err).to.not.exist()
36-
expect(res).to.exist()
37-
done()
38-
})
39-
})
35+
it('lists commands', async () => {
36+
const res = await ipfs.commands()
4037

41-
describe('promise', () => {
42-
it('lists commands', () => {
43-
return ipfs.commands()
44-
.then((res) => {
45-
expect(res).to.exist()
46-
})
47-
})
38+
expect(res).to.exist()
4839
})
4940
})

test/constructor.spec.js

+13-19
Original file line numberDiff line numberDiff line change
@@ -109,36 +109,30 @@ describe('ipfs-http-client constructor tests', () => {
109109
let apiAddr
110110
let ipfsd
111111

112-
before(function (done) {
112+
before(async function () {
113113
this.timeout(60 * 1000) // slow CI
114114

115-
f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, node) => {
116-
expect(err).to.not.exist()
117-
ipfsd = node
118-
apiAddr = node.apiAddr.toString()
119-
done()
120-
})
115+
ipfsd = await f.spawn({ initOptions: { bits: 1024, profile: 'test' } })
116+
apiAddr = ipfsd.apiAddr.toString()
121117
})
122118

123-
after((done) => {
124-
if (!ipfsd) return done()
125-
ipfsd.stop(done)
119+
after(async () => {
120+
if (ipfsd) {
121+
await ipfsd.stop()
122+
}
126123
})
127124

128-
it('can connect to an ipfs http api', (done) => {
129-
clientWorks(ipfsClient(apiAddr), done)
125+
it('can connect to an ipfs http api', async () => {
126+
await clientWorks(ipfsClient(apiAddr))
130127
})
131128
})
132129
})
133130

134-
function clientWorks (client, done) {
135-
client.id((err, id) => {
136-
expect(err).to.not.exist()
131+
async function clientWorks (client) {
132+
const id = await client.id()
137133

138-
expect(id).to.have.a.property('id')
139-
expect(id).to.have.a.property('publicKey')
140-
done()
141-
})
134+
expect(id).to.have.a.property('id')
135+
expect(id).to.have.a.property('publicKey')
142136
}
143137

144138
function expectConfig (ipfs, { host, port, protocol, apiPath }) {

test/custom-headers.spec.js

+21-15
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,25 @@ describe('custom headers', function () {
1717
let ipfs
1818
let ipfsd
1919
// initialize ipfs with custom headers
20-
before(done => {
21-
f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, _ipfsd) => {
22-
expect(err).to.not.exist()
23-
ipfsd = _ipfsd
24-
ipfs = ipfsClient({
25-
host: 'localhost',
26-
port: 6001,
27-
protocol: 'http',
28-
headers: {
29-
authorization: 'Bearer ' + 'YOLO'
30-
}
31-
})
32-
done()
20+
before(async () => {
21+
ipfsd = await f.spawn({
22+
initOptions: {
23+
bits: 1024,
24+
profile: 'test'
25+
}
26+
})
27+
28+
ipfs = ipfsClient({
29+
host: 'localhost',
30+
port: 6001,
31+
protocol: 'http',
32+
headers: {
33+
authorization: 'Bearer ' + 'YOLO'
34+
}
3335
})
3436
})
3537

36-
it('are supported', done => {
38+
it('are supported', (done) => {
3739
// spin up a test http server to inspect the requests made by the library
3840
const server = require('http').createServer((req, res) => {
3941
req.on('data', () => {})
@@ -57,5 +59,9 @@ describe('custom headers', function () {
5759
})
5860
})
5961

60-
after(done => ipfsd.stop(done))
62+
after(async () => {
63+
if (ipfsd) {
64+
await ipfsd.stop()
65+
}
66+
})
6167
})

test/dag.spec.js

+39-49
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
const chai = require('chai')
77
const dirtyChai = require('dirty-chai')
8+
const chaiAsPromised = require('chai-as-promised')
89
const expect = chai.expect
910
chai.use(dirtyChai)
10-
const series = require('async/series')
11+
chai.use(chaiAsPromised)
1112
const { DAGNode } = require('ipld-dag-pb')
1213
const CID = require('cids')
1314
const ipfsClient = require('../src')
@@ -18,67 +19,56 @@ let ipfs
1819

1920
describe('.dag', function () {
2021
this.timeout(20 * 1000)
21-
before(function (done) {
22-
series([
23-
(cb) => f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, _ipfsd) => {
24-
expect(err).to.not.exist()
25-
ipfsd = _ipfsd
26-
ipfs = ipfsClient(_ipfsd.apiAddr)
27-
cb()
28-
})
29-
], done)
22+
before(async function () {
23+
ipfsd = await f.spawn({
24+
initOptions: {
25+
bits: 1024,
26+
profile: 'test'
27+
}
28+
})
29+
ipfs = ipfsClient(ipfsd.apiAddr)
3030
})
3131

32-
after((done) => {
33-
if (!ipfsd) return done()
34-
ipfsd.stop(done)
32+
after(async () => {
33+
if (ipfsd) {
34+
await ipfsd.stop()
35+
}
3536
})
3637

37-
it('should be able to put and get a DAG node with format dag-pb', (done) => {
38+
it('should be able to put and get a DAG node with format dag-pb', async () => {
3839
const data = Buffer.from('some data')
3940
const node = DAGNode.create(data)
4041

41-
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
42-
expect(err).to.not.exist()
43-
cid = cid.toV0()
44-
expect(cid.codec).to.equal('dag-pb')
45-
cid = cid.toBaseEncodedString('base58btc')
46-
// expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u')
47-
expect(cid).to.equal('Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr')
48-
ipfs.dag.get(cid, (err, result) => {
49-
expect(err).to.not.exist()
50-
expect(result.value.Data).to.deep.equal(data)
51-
done()
52-
})
53-
})
42+
let cid = await ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' })
43+
cid = cid.toV0()
44+
expect(cid.codec).to.equal('dag-pb')
45+
cid = cid.toBaseEncodedString('base58btc')
46+
// expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u')
47+
expect(cid).to.equal('Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr')
48+
49+
const result = await ipfs.dag.get(cid)
50+
51+
expect(result.value.Data).to.deep.equal(data)
5452
})
5553

56-
it('should be able to put and get a DAG node with format dag-cbor', (done) => {
54+
it('should be able to put and get a DAG node with format dag-cbor', async () => {
5755
const cbor = { foo: 'dag-cbor-bar' }
58-
ipfs.dag.put(cbor, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid) => {
59-
expect(err).to.not.exist()
60-
expect(cid.codec).to.equal('dag-cbor')
61-
cid = cid.toBaseEncodedString('base32')
62-
expect(cid).to.equal('bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce')
63-
ipfs.dag.get(cid, (err, result) => {
64-
expect(err).to.not.exist()
65-
expect(result.value).to.deep.equal(cbor)
66-
done()
67-
})
68-
})
56+
let cid = await ipfs.dag.put(cbor, { format: 'dag-cbor', hashAlg: 'sha2-256' })
57+
58+
expect(cid.codec).to.equal('dag-cbor')
59+
cid = cid.toBaseEncodedString('base32')
60+
expect(cid).to.equal('bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce')
61+
62+
const result = await ipfs.dag.get(cid)
63+
64+
expect(result.value).to.deep.equal(cbor)
6965
})
7066

71-
it('should callback with error when missing DAG resolver for multicodec from requested CID', (done) => {
72-
ipfs.block.put(Buffer.from([0, 1, 2, 3]), {
67+
it('should callback with error when missing DAG resolver for multicodec from requested CID', async () => {
68+
const block = await ipfs.block.put(Buffer.from([0, 1, 2, 3]), {
7369
cid: new CID('z8mWaJ1dZ9fH5EetPuRsj8jj26pXsgpsr')
74-
}, (err, block) => {
75-
expect(err).to.not.exist()
76-
77-
ipfs.dag.get(block.cid, (err, result) => {
78-
expect(result).to.not.exist()
79-
expect(err.message).to.equal('Missing IPLD format "git-raw"')
80-
done()
81-
})
8270
})
71+
72+
await expect(ipfs.dag.get(block.cid)).to.be.rejectedWith('Missing IPLD format "git-raw"')
8373
})
8474
})

0 commit comments

Comments
 (0)