Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 6058954

Browse files
Alan Shawdaviddias
authored andcommitted
test: JS IPFS 0.34 (#51)
* test: add tests for CID version agnostic add and cat License: MIT Signed-off-by: Alan Shaw <[email protected]> * chore: remove .only License: MIT Signed-off-by: Alan Shaw <[email protected]> * fix: tests using files * fix: tests using files * fix: check for similar messages instead of identical * chore: update ipfs to RC License: MIT Signed-off-by: Alan Shaw <[email protected]> * chore: update dependencies License: MIT Signed-off-by: Alan Shaw <[email protected]> * fix: reinstate exchange directory tests License: MIT Signed-off-by: Alan Shaw <[email protected]> * refactor: remove bootstrap nodes in tests License: MIT Signed-off-by: Alan Shaw <[email protected]> * chore: update js-ipfs dep * chore: update js-ipfs version License: MIT Signed-off-by: Alan Shaw <[email protected]> * refactor: remove bootstrap nodes in tests License: MIT Signed-off-by: Alan Shaw <[email protected]> * chore: update deps * chore: add missing deps * chore: update timeout on cid tests
1 parent c3ad0e2 commit 6058954

File tree

7 files changed

+196
-35
lines changed

7 files changed

+196
-35
lines changed

package.json

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,41 @@
3535
},
3636
"homepage": "https://github.com/ipfs/interop#readme",
3737
"devDependencies": {
38-
"aegir": "^17.0.1",
39-
"async": "^2.6.1",
40-
"bl": "^2.1.2",
38+
"aegir": "^18.1.0",
39+
"async": "^2.6.2",
40+
"bl": "^2.2.0",
4141
"bs58": "^4.0.1",
4242
"chai": "^4.2.0",
43-
"cids": "~0.5.5",
43+
"cids": "~0.5.7",
4444
"cross-env": "^5.2.0",
4545
"detect-node": "^2.0.4",
46-
"dir-compare": "^1.4.0",
46+
"dir-compare": "^1.7.1",
4747
"dirty-chai": "^2.0.1",
48-
"eslint-plugin-react": "^7.11.1",
48+
"eslint-plugin-react": "^7.12.4",
4949
"expose-loader": "~0.7.5",
5050
"form-data": "^2.3.3",
5151
"go-ipfs-dep": "~0.4.18",
5252
"hat": "0.0.3",
53-
"ipfs": "~0.33.0",
54-
"ipfs-api": "^26.1.2",
53+
"ipfs": "~0.34.4",
54+
"ipfs-http-client": "^29.1.0",
5555
"ipfs-unixfs": "~0.1.16",
56-
"ipfsd-ctl": "~0.40.0",
56+
"ipfs-repo": "~0.26.1",
57+
"ipfsd-ctl": "~0.42.0",
58+
"is-ci": "^2.0.0",
5759
"left-pad": "^1.3.0",
58-
"libp2p-websocket-star-rendezvous": "~0.2.4",
60+
"libp2p-websocket-star-rendezvous": "~0.3.0",
5961
"lodash": "^4.17.11",
6062
"mocha": "^5.2.0",
6163
"ncp": "^2.0.0",
6264
"pretty-bytes": "^5.1.0",
6365
"random-fs": "^1.0.3",
64-
"rimraf": "^2.6.2",
66+
"rimraf": "^2.6.3",
6567
"stream-to-promise": "^2.2.0",
66-
"transform-loader": "~0.2.4",
67-
"is-ci": "^1.2.1"
68+
"transform-loader": "~0.2.4"
6869
},
6970
"contributors": [],
7071
"dependencies": {
71-
"is-os": "^1.0.1"
72+
"is-os": "^1.0.1",
73+
"promisify-es6": "^1.0.3"
7274
}
7375
}

test/cid-version-agnostic.js

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const chai = require('chai')
5+
const dirtyChai = require('dirty-chai')
6+
const expect = chai.expect
7+
chai.use(dirtyChai)
8+
const hat = require('hat')
9+
const CID = require('cids')
10+
const {
11+
spawnInitAndStartGoDaemon,
12+
spawnInitAndStartJsDaemon,
13+
stopDaemon
14+
} = require('./utils/daemon')
15+
16+
describe('CID version agnostic', () => {
17+
const daemons = {}
18+
19+
before(async function () {
20+
this.timeout(30 * 1000)
21+
22+
const [ js0, js1, go0, go1 ] = await Promise.all([
23+
spawnInitAndStartJsDaemon(),
24+
spawnInitAndStartJsDaemon(),
25+
spawnInitAndStartGoDaemon(),
26+
spawnInitAndStartGoDaemon()
27+
])
28+
Object.assign(daemons, { js0, js1, go0, go1 })
29+
30+
// Get peer IDs
31+
await Promise.all(Object.keys(daemons).map(async k => {
32+
daemons[k].peerId = await daemons[k].api.id()
33+
}))
34+
35+
await Promise.all([
36+
js0.api.swarm.connect(js1.peerId.addresses[0]),
37+
js1.api.swarm.connect(js0.peerId.addresses[0]),
38+
go0.api.swarm.connect(go1.peerId.addresses[0]),
39+
go1.api.swarm.connect(go0.peerId.addresses[0]),
40+
js0.api.swarm.connect(go0.peerId.addresses[0]),
41+
go0.api.swarm.connect(js0.peerId.addresses[0])
42+
])
43+
})
44+
45+
after(function () {
46+
this.timeout(30 * 1000)
47+
return Promise.all(Object.values(daemons).map(stopDaemon))
48+
})
49+
50+
it('should add v0 and cat v1 (go0 -> go0)', async () => {
51+
const input = Buffer.from(hat())
52+
const res = await daemons.go0.api.add(input, { cidVersion: 0 })
53+
const cidv1 = new CID(res[0].hash).toV1()
54+
const output = await daemons.go0.api.cat(cidv1)
55+
expect(output).to.deep.equal(input)
56+
})
57+
58+
it('should add v0 and cat v1 (js0 -> js0)', async () => {
59+
const input = Buffer.from(hat())
60+
const res = await daemons.js0.api.add(input, { cidVersion: 0 })
61+
const cidv1 = new CID(res[0].hash).toV1()
62+
const output = await daemons.js0.api.cat(cidv1)
63+
expect(output).to.deep.equal(input)
64+
})
65+
66+
it('should add v0 and cat v1 (go0 -> go1)', async () => {
67+
const input = Buffer.from(hat())
68+
const res = await daemons.go0.api.add(input, { cidVersion: 0 })
69+
const cidv1 = new CID(res[0].hash).toV1()
70+
const output = await daemons.go1.api.cat(cidv1)
71+
expect(output).to.deep.equal(input)
72+
})
73+
74+
it('should add v0 and cat v1 (js0 -> js1)', async () => {
75+
const input = Buffer.from(hat())
76+
const res = await daemons.js0.api.add(input, { cidVersion: 0 })
77+
const cidv1 = new CID(res[0].hash).toV1()
78+
const output = await daemons.js1.api.cat(cidv1)
79+
expect(output).to.deep.equal(input)
80+
})
81+
82+
it('should add v0 and cat v1 (js0 -> go0)', async () => {
83+
const input = Buffer.from(hat())
84+
const res = await daemons.js0.api.add(input, { cidVersion: 0 })
85+
const cidv1 = new CID(res[0].hash).toV1()
86+
const output = await daemons.go0.api.cat(cidv1)
87+
expect(output).to.deep.equal(input)
88+
})
89+
90+
it('should add v0 and cat v1 (go0 -> js0)', async () => {
91+
const input = Buffer.from(hat())
92+
const res = await daemons.go0.api.add(input, { cidVersion: 0 })
93+
const cidv1 = new CID(res[0].hash).toV1()
94+
const output = await daemons.js0.api.cat(cidv1)
95+
expect(output).to.deep.equal(input)
96+
})
97+
98+
it('should add v1 and cat v0 (go0 -> go0)', async () => {
99+
const input = Buffer.from(hat())
100+
const res = await daemons.go0.api.add(input, { cidVersion: 1, rawLeaves: false })
101+
const cidv0 = new CID(res[0].hash).toV0()
102+
const output = await daemons.go0.api.cat(cidv0)
103+
expect(output).to.deep.equal(input)
104+
})
105+
106+
it('should add v1 and cat v0 (js0 -> js0)', async () => {
107+
const input = Buffer.from(hat())
108+
const res = await daemons.js0.api.add(input, { cidVersion: 1, rawLeaves: false })
109+
const cidv0 = new CID(res[0].hash).toV0()
110+
const output = await daemons.js0.api.cat(cidv0)
111+
expect(output).to.deep.equal(input)
112+
})
113+
114+
it('should add v1 and cat v0 (go0 -> go1)', async () => {
115+
const input = Buffer.from(hat())
116+
const res = await daemons.go0.api.add(input, { cidVersion: 1, rawLeaves: false })
117+
const cidv0 = new CID(res[0].hash).toV0()
118+
const output = await daemons.go1.api.cat(cidv0)
119+
expect(output).to.deep.equal(input)
120+
})
121+
122+
it('should add v1 and cat v0 (js0 -> js1)', async () => {
123+
const input = Buffer.from(hat())
124+
const res = await daemons.js0.api.add(input, { cidVersion: 1, rawLeaves: false })
125+
const cidv0 = new CID(res[0].hash).toV0()
126+
const output = await daemons.js1.api.cat(cidv0)
127+
expect(output).to.deep.equal(input)
128+
})
129+
130+
it('should add v1 and cat v0 (js0 -> go0)', async () => {
131+
const input = Buffer.from(hat())
132+
const res = await daemons.js0.api.add(input, { cidVersion: 1, rawLeaves: false })
133+
const cidv0 = new CID(res[0].hash).toV0()
134+
const output = await daemons.go0.api.cat(cidv0)
135+
expect(output).to.deep.equal(input)
136+
})
137+
138+
it('should add v1 and cat v0 (go0 -> js0)', async () => {
139+
const input = Buffer.from(hat())
140+
const res = await daemons.go0.api.add(input, { cidVersion: 1, rawLeaves: false })
141+
const cidv0 = new CID(res[0].hash).toV0()
142+
const output = await daemons.js0.api.cat(cidv0)
143+
expect(output).to.deep.equal(input)
144+
})
145+
})

test/exchange-files.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ describe('exchange files', () => {
111111
this.timeout(timeout)
112112

113113
parallel([
114-
(cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb),
115-
(cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb),
116-
(cb) => jsDf.spawn({ type: 'js', initOptions: { bits: 512 } }, cb),
117-
(cb) => jsDf.spawn({ type: 'js', initOptions: { bits: 512 } }, cb)
114+
(cb) => goDf.spawn({ initOptions: { bits: 1024 }, config: { Bootstrap: [] } }, cb),
115+
(cb) => goDf.spawn({ initOptions: { bits: 1024 }, config: { Bootstrap: [] } }, cb),
116+
(cb) => jsDf.spawn({ type: 'js', initOptions: { bits: 512 }, config: { Bootstrap: [] } }, cb),
117+
(cb) => jsDf.spawn({ type: 'js', initOptions: { bits: 512 }, config: { Bootstrap: [] } }, cb)
118118
], (err, n) => {
119119
expect(err).to.not.exist()
120120
nodes = n
@@ -284,7 +284,7 @@ describe('exchange files', () => {
284284
})
285285
}))
286286

287-
if (isWindows) { return }
287+
if (isWindows()) { return }
288288
// TODO fix dir tests on Windows
289289

290290
describe('get directory', () => depth.forEach((d) => dirs.forEach((num) => {
@@ -297,10 +297,10 @@ describe('exchange files', () => {
297297
depth: d,
298298
number: num
299299
}).then(() => {
300-
return goDaemon.api.util.addFromFs(dir, { recursive: true })
300+
return goDaemon.api.addFromFs(dir, { recursive: true })
301301
}).then((res) => {
302302
const hash = res[res.length - 1].hash
303-
return jsDaemon.api.files.get(hash)
303+
return jsDaemon.api.get(hash)
304304
}).then((res) => {
305305
expect(res).to.exist()
306306
return rmDir(dir)
@@ -316,10 +316,10 @@ describe('exchange files', () => {
316316
depth: d,
317317
number: num
318318
}).then(() => {
319-
return jsDaemon.api.util.addFromFs(dir, { recursive: true })
319+
return jsDaemon.api.addFromFs(dir, { recursive: true })
320320
}).then((res) => {
321321
const hash = res[res.length - 1].hash
322-
return goDaemon.api.files.get(hash)
322+
return goDaemon.api.get(hash)
323323
}).then((res) => {
324324
expect(res).to.exist()
325325
return rmDir(dir)
@@ -335,10 +335,10 @@ describe('exchange files', () => {
335335
depth: d,
336336
number: num
337337
}).then(() => {
338-
return jsDaemon2.api.util.addFromFs(dir, { recursive: true })
338+
return jsDaemon2.api.addFromFs(dir, { recursive: true })
339339
}).then((res) => {
340340
const hash = res[res.length - 1].hash
341-
return jsDaemon.api.files.get(hash)
341+
return jsDaemon.api.get(hash)
342342
}).then((res) => {
343343
expect(res).to.exist()
344344
return rmDir(dir)
@@ -354,10 +354,10 @@ describe('exchange files', () => {
354354
depth: d,
355355
number: num
356356
}).then(() => {
357-
return goDaemon2.api.util.addFromFs(dir, { recursive: true })
357+
return goDaemon2.api.addFromFs(dir, { recursive: true })
358358
}).then((res) => {
359359
const hash = res[res.length - 1].hash
360-
return goDaemon.api.files.get(hash)
360+
return goDaemon.api.get(hash)
361361
}).then((res) => {
362362
expect(res).to.exist()
363363
return rmDir(dir)

test/files.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function checkNodeTypes (daemon, file) {
2626
expect(node.links.length).to.equal(2)
2727

2828
return Promise.all(
29-
node.links.map(link => daemon.api.object.get(link.toJSON().multihash).then(child => {
29+
node.links.map(link => daemon.api.object.get(link.toJSON().cid).then(child => {
3030
const childMeta = UnixFs.unmarshal(child.data)
3131

3232
expect(childMeta.type).to.equal('raw')
@@ -67,11 +67,11 @@ const compare = (...ops) => {
6767
})
6868
}
6969

70-
const compareErrors = (...ops) => {
70+
const compareErrors = (expectedMessage, ...ops) => {
7171
expect(ops.length).to.be.above(1)
7272

7373
return Promise.all(
74-
// even if operations fail, their errors should be the same
74+
// even if operations fail, their errors should be similar
7575
ops.map(op => op.then(() => {
7676
throw new ExpectedError('Expected operation to fail')
7777
}).catch(error => {
@@ -88,9 +88,17 @@ const compareErrors = (...ops) => {
8888
.then(results => {
8989
expect(results.length).to.equal(ops.length)
9090

91+
// all implementations should have similar error messages
92+
results.forEach(res => {
93+
expect(res.message.toLowerCase()).to.contain(expectedMessage.toLowerCase())
94+
})
95+
9196
const result = results.pop()
9297

93-
results.forEach(res => expect(res).to.deep.equal(result))
98+
// all implementations should have the same error code
99+
results.forEach(res => {
100+
expect(res.code).to.equal(result.code)
101+
})
94102
})
95103
}
96104

@@ -138,6 +146,7 @@ describe('files', function () {
138146
}
139147

140148
return compareErrors(
149+
'does not exist',
141150
readNonExistentFile(go),
142151
readNonExistentFile(js)
143152
)
@@ -149,6 +158,7 @@ describe('files', function () {
149158
}
150159

151160
return compareErrors(
161+
'does not exist',
152162
readNonExistentFile(go),
153163
readNonExistentFile(js)
154164
)
@@ -171,6 +181,7 @@ describe('files', function () {
171181
const path = `/test-dir-${Math.random()}`
172182

173183
return compareErrors(
184+
'already exists',
174185
go.api.files.mkdir(path).then(() => go.api.files.mkdir(path)),
175186
js.api.files.mkdir(path).then(() => js.api.files.mkdir(path))
176187
)
@@ -189,14 +200,15 @@ describe('files', function () {
189200
const path = '/'
190201

191202
return compareErrors(
203+
'already exists',
192204
go.api.files.mkdir(path).then(() => go.api.files.mkdir(path)),
193205
js.api.files.mkdir(path).then(() => js.api.files.mkdir(path))
194206
)
195207
})
196208

197209
describe('has the same hashes for', () => {
198210
const testHashesAreEqual = (daemon, data, options) => {
199-
return daemon.api.files.add(data, options)
211+
return daemon.api.add(data, options)
200212
.then(files => files[0].hash)
201213
}
202214

test/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4+
require('./cid-version-agnostic')
45
require('./pubsub')
56
require('./circuit')
67
require('./repo')

test/utils/circuit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ exports.createGoNode = (addrs, callback) => {
9898
const data = crypto.randomBytes(128)
9999
exports.send = (nodeA, nodeB, callback) => {
100100
waterfall([
101-
(cb) => nodeA.files.add(data, cb),
102-
(res, cb) => nodeB.files.cat(res[0].hash, cb),
101+
(cb) => nodeA.add(data, cb),
102+
(res, cb) => nodeB.cat(res[0].hash, cb),
103103
(buffer, cb) => {
104104
expect(buffer).to.deep.equal(data)
105105
cb()

test/utils/daemon.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const spawnInitAndStartDaemon = (factory) => {
99
factory.spawn({
1010
initOptions: {
1111
bits: 1024
12-
}
12+
},
13+
config: { Bootstrap: [] }
1314
}, (error, instance) => {
1415
if (error) {
1516
return reject(error)

0 commit comments

Comments
 (0)