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

test: JS IPFS 0.34 #51

Merged
merged 15 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,41 @@
},
"homepage": "https://github.com/ipfs/interop#readme",
"devDependencies": {
"aegir": "^17.0.1",
"async": "^2.6.1",
"bl": "^2.1.2",
"aegir": "^18.1.0",
"async": "^2.6.2",
"bl": "^2.2.0",
"bs58": "^4.0.1",
"chai": "^4.2.0",
"cids": "~0.5.5",
"cids": "~0.5.7",
"cross-env": "^5.2.0",
"detect-node": "^2.0.4",
"dir-compare": "^1.4.0",
"dir-compare": "^1.7.1",
"dirty-chai": "^2.0.1",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.4",
"expose-loader": "~0.7.5",
"form-data": "^2.3.3",
"go-ipfs-dep": "~0.4.18",
"hat": "0.0.3",
"ipfs": "~0.33.0",
"ipfs-api": "^26.1.2",
"ipfs": "~0.34.4",
"ipfs-http-client": "^29.1.0",
"ipfs-unixfs": "~0.1.16",
"ipfsd-ctl": "~0.40.0",
"ipfs-repo": "~0.26.1",
"ipfsd-ctl": "~0.42.0",
"is-ci": "^2.0.0",
"left-pad": "^1.3.0",
"libp2p-websocket-star-rendezvous": "~0.2.4",
"libp2p-websocket-star-rendezvous": "~0.3.0",
"lodash": "^4.17.11",
"mocha": "^5.2.0",
"ncp": "^2.0.0",
"pretty-bytes": "^5.1.0",
"random-fs": "^1.0.3",
"rimraf": "^2.6.2",
"rimraf": "^2.6.3",
"stream-to-promise": "^2.2.0",
"transform-loader": "~0.2.4",
"is-ci": "^1.2.1"
"transform-loader": "~0.2.4"
},
"contributors": [],
"dependencies": {
"is-os": "^1.0.1"
"is-os": "^1.0.1",
"promisify-es6": "^1.0.3"
}
}
145 changes: 145 additions & 0 deletions test/cid-version-agnostic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const hat = require('hat')
const CID = require('cids')
const {
spawnInitAndStartGoDaemon,
spawnInitAndStartJsDaemon,
stopDaemon
} = require('./utils/daemon')

describe('CID version agnostic', () => {
const daemons = {}

before(async function () {
this.timeout(30 * 1000)

const [ js0, js1, go0, go1 ] = await Promise.all([
spawnInitAndStartJsDaemon(),
spawnInitAndStartJsDaemon(),
spawnInitAndStartGoDaemon(),
spawnInitAndStartGoDaemon()
])
Object.assign(daemons, { js0, js1, go0, go1 })

// Get peer IDs
await Promise.all(Object.keys(daemons).map(async k => {
daemons[k].peerId = await daemons[k].api.id()
}))

await Promise.all([
js0.api.swarm.connect(js1.peerId.addresses[0]),
js1.api.swarm.connect(js0.peerId.addresses[0]),
go0.api.swarm.connect(go1.peerId.addresses[0]),
go1.api.swarm.connect(go0.peerId.addresses[0]),
js0.api.swarm.connect(go0.peerId.addresses[0]),
go0.api.swarm.connect(js0.peerId.addresses[0])
])
})

after(function () {
this.timeout(30 * 1000)
return Promise.all(Object.values(daemons).map(stopDaemon))
})

it('should add v0 and cat v1 (go0 -> go0)', async () => {
const input = Buffer.from(hat())
const res = await daemons.go0.api.add(input, { cidVersion: 0 })
const cidv1 = new CID(res[0].hash).toV1()
const output = await daemons.go0.api.cat(cidv1)
expect(output).to.deep.equal(input)
})

it('should add v0 and cat v1 (js0 -> js0)', async () => {
const input = Buffer.from(hat())
const res = await daemons.js0.api.add(input, { cidVersion: 0 })
const cidv1 = new CID(res[0].hash).toV1()
const output = await daemons.js0.api.cat(cidv1)
expect(output).to.deep.equal(input)
})

it('should add v0 and cat v1 (go0 -> go1)', async () => {
const input = Buffer.from(hat())
const res = await daemons.go0.api.add(input, { cidVersion: 0 })
const cidv1 = new CID(res[0].hash).toV1()
const output = await daemons.go1.api.cat(cidv1)
expect(output).to.deep.equal(input)
})

it('should add v0 and cat v1 (js0 -> js1)', async () => {
const input = Buffer.from(hat())
const res = await daemons.js0.api.add(input, { cidVersion: 0 })
const cidv1 = new CID(res[0].hash).toV1()
const output = await daemons.js1.api.cat(cidv1)
expect(output).to.deep.equal(input)
})

it('should add v0 and cat v1 (js0 -> go0)', async () => {
const input = Buffer.from(hat())
const res = await daemons.js0.api.add(input, { cidVersion: 0 })
const cidv1 = new CID(res[0].hash).toV1()
const output = await daemons.go0.api.cat(cidv1)
expect(output).to.deep.equal(input)
})

it('should add v0 and cat v1 (go0 -> js0)', async () => {
const input = Buffer.from(hat())
const res = await daemons.go0.api.add(input, { cidVersion: 0 })
const cidv1 = new CID(res[0].hash).toV1()
const output = await daemons.js0.api.cat(cidv1)
expect(output).to.deep.equal(input)
})

it('should add v1 and cat v0 (go0 -> go0)', async () => {
const input = Buffer.from(hat())
const res = await daemons.go0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = new CID(res[0].hash).toV0()
const output = await daemons.go0.api.cat(cidv0)
expect(output).to.deep.equal(input)
})

it('should add v1 and cat v0 (js0 -> js0)', async () => {
const input = Buffer.from(hat())
const res = await daemons.js0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = new CID(res[0].hash).toV0()
const output = await daemons.js0.api.cat(cidv0)
expect(output).to.deep.equal(input)
})

it('should add v1 and cat v0 (go0 -> go1)', async () => {
const input = Buffer.from(hat())
const res = await daemons.go0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = new CID(res[0].hash).toV0()
const output = await daemons.go1.api.cat(cidv0)
expect(output).to.deep.equal(input)
})

it('should add v1 and cat v0 (js0 -> js1)', async () => {
const input = Buffer.from(hat())
const res = await daemons.js0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = new CID(res[0].hash).toV0()
const output = await daemons.js1.api.cat(cidv0)
expect(output).to.deep.equal(input)
})

it('should add v1 and cat v0 (js0 -> go0)', async () => {
const input = Buffer.from(hat())
const res = await daemons.js0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = new CID(res[0].hash).toV0()
const output = await daemons.go0.api.cat(cidv0)
expect(output).to.deep.equal(input)
})

it('should add v1 and cat v0 (go0 -> js0)', async () => {
const input = Buffer.from(hat())
const res = await daemons.go0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = new CID(res[0].hash).toV0()
const output = await daemons.js0.api.cat(cidv0)
expect(output).to.deep.equal(input)
})
})
26 changes: 13 additions & 13 deletions test/exchange-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ describe('exchange files', () => {
this.timeout(timeout)

parallel([
(cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb),
(cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb),
(cb) => jsDf.spawn({ type: 'js', initOptions: { bits: 512 } }, cb),
(cb) => jsDf.spawn({ type: 'js', initOptions: { bits: 512 } }, cb)
(cb) => goDf.spawn({ initOptions: { bits: 1024 }, config: { Bootstrap: [] } }, cb),
(cb) => goDf.spawn({ initOptions: { bits: 1024 }, config: { Bootstrap: [] } }, cb),
(cb) => jsDf.spawn({ type: 'js', initOptions: { bits: 512 }, config: { Bootstrap: [] } }, cb),
(cb) => jsDf.spawn({ type: 'js', initOptions: { bits: 512 }, config: { Bootstrap: [] } }, cb)
], (err, n) => {
expect(err).to.not.exist()
nodes = n
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('exchange files', () => {
})
}))

if (isWindows) { return }
if (isWindows()) { return }
// TODO fix dir tests on Windows

describe('get directory', () => depth.forEach((d) => dirs.forEach((num) => {
Expand All @@ -297,10 +297,10 @@ describe('exchange files', () => {
depth: d,
number: num
}).then(() => {
return goDaemon.api.util.addFromFs(dir, { recursive: true })
return goDaemon.api.addFromFs(dir, { recursive: true })
}).then((res) => {
const hash = res[res.length - 1].hash
return jsDaemon.api.files.get(hash)
return jsDaemon.api.get(hash)
}).then((res) => {
expect(res).to.exist()
return rmDir(dir)
Expand All @@ -316,10 +316,10 @@ describe('exchange files', () => {
depth: d,
number: num
}).then(() => {
return jsDaemon.api.util.addFromFs(dir, { recursive: true })
return jsDaemon.api.addFromFs(dir, { recursive: true })
}).then((res) => {
const hash = res[res.length - 1].hash
return goDaemon.api.files.get(hash)
return goDaemon.api.get(hash)
}).then((res) => {
expect(res).to.exist()
return rmDir(dir)
Expand All @@ -335,10 +335,10 @@ describe('exchange files', () => {
depth: d,
number: num
}).then(() => {
return jsDaemon2.api.util.addFromFs(dir, { recursive: true })
return jsDaemon2.api.addFromFs(dir, { recursive: true })
}).then((res) => {
const hash = res[res.length - 1].hash
return jsDaemon.api.files.get(hash)
return jsDaemon.api.get(hash)
}).then((res) => {
expect(res).to.exist()
return rmDir(dir)
Expand All @@ -354,10 +354,10 @@ describe('exchange files', () => {
depth: d,
number: num
}).then(() => {
return goDaemon2.api.util.addFromFs(dir, { recursive: true })
return goDaemon2.api.addFromFs(dir, { recursive: true })
}).then((res) => {
const hash = res[res.length - 1].hash
return goDaemon.api.files.get(hash)
return goDaemon.api.get(hash)
}).then((res) => {
expect(res).to.exist()
return rmDir(dir)
Expand Down
22 changes: 17 additions & 5 deletions test/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function checkNodeTypes (daemon, file) {
expect(node.links.length).to.equal(2)

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

expect(childMeta.type).to.equal('raw')
Expand Down Expand Up @@ -67,11 +67,11 @@ const compare = (...ops) => {
})
}

const compareErrors = (...ops) => {
const compareErrors = (expectedMessage, ...ops) => {
expect(ops.length).to.be.above(1)

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

// all implementations should have similar error messages
results.forEach(res => {
expect(res.message.toLowerCase()).to.contain(expectedMessage.toLowerCase())
})

const result = results.pop()

results.forEach(res => expect(res).to.deep.equal(result))
// all implementations should have the same error code
results.forEach(res => {
expect(res.code).to.equal(result.code)
})
})
}

Expand Down Expand Up @@ -138,6 +146,7 @@ describe('files', function () {
}

return compareErrors(
'does not exist',
readNonExistentFile(go),
readNonExistentFile(js)
)
Expand All @@ -149,6 +158,7 @@ describe('files', function () {
}

return compareErrors(
'does not exist',
readNonExistentFile(go),
readNonExistentFile(js)
)
Expand All @@ -171,6 +181,7 @@ describe('files', function () {
const path = `/test-dir-${Math.random()}`

return compareErrors(
'already exists',
go.api.files.mkdir(path).then(() => go.api.files.mkdir(path)),
js.api.files.mkdir(path).then(() => js.api.files.mkdir(path))
)
Expand All @@ -189,14 +200,15 @@ describe('files', function () {
const path = '/'

return compareErrors(
'already exists',
go.api.files.mkdir(path).then(() => go.api.files.mkdir(path)),
js.api.files.mkdir(path).then(() => js.api.files.mkdir(path))
)
})

describe('has the same hashes for', () => {
const testHashesAreEqual = (daemon, data, options) => {
return daemon.api.files.add(data, options)
return daemon.api.add(data, options)
.then(files => files[0].hash)
}

Expand Down
1 change: 1 addition & 0 deletions test/node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */
'use strict'

require('./cid-version-agnostic')
require('./pubsub')
require('./circuit')
require('./repo')
Expand Down
4 changes: 2 additions & 2 deletions test/utils/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ exports.createGoNode = (addrs, callback) => {
const data = crypto.randomBytes(128)
exports.send = (nodeA, nodeB, callback) => {
waterfall([
(cb) => nodeA.files.add(data, cb),
(res, cb) => nodeB.files.cat(res[0].hash, cb),
(cb) => nodeA.add(data, cb),
(res, cb) => nodeB.cat(res[0].hash, cb),
(buffer, cb) => {
expect(buffer).to.deep.equal(data)
cb()
Expand Down
3 changes: 2 additions & 1 deletion test/utils/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const spawnInitAndStartDaemon = (factory) => {
factory.spawn({
initOptions: {
bits: 1024
}
},
config: { Bootstrap: [] }
}, (error, instance) => {
if (error) {
return reject(error)
Expand Down