From a5cb817cdd3b554bcb8dc1d0b421c01d93e54f02 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 27 Nov 2018 15:50:19 +0000 Subject: [PATCH 1/2] test: add tests for CID version agnostic add and cat License: MIT Signed-off-by: Alan Shaw --- test/cid-version-agnostic.js | 145 +++++++++++++++++++++++++++++++++++ test/node.js | 1 + 2 files changed, 146 insertions(+) create mode 100644 test/cid-version-agnostic.js diff --git a/test/cid-version-agnostic.js b/test/cid-version-agnostic.js new file mode 100644 index 00000000..d6459d60 --- /dev/null +++ b/test/cid-version-agnostic.js @@ -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.only('CID version agnostic', () => { + const daemons = {} + + before(async function () { + this.timeout(10 * 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(10 * 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) + }) +}) diff --git a/test/node.js b/test/node.js index 2d4fbbe0..4edb14ea 100644 --- a/test/node.js +++ b/test/node.js @@ -1,6 +1,7 @@ /* eslint-env mocha */ 'use strict' +require('./cid-version-agnostic') require('./pubsub') require('./circuit') require('./repo') From f6087ccadcb18f34f20c808f7eb0dc8bb5b65203 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 27 Nov 2018 15:52:58 +0000 Subject: [PATCH 2/2] chore: remove .only License: MIT Signed-off-by: Alan Shaw --- test/cid-version-agnostic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cid-version-agnostic.js b/test/cid-version-agnostic.js index d6459d60..98491e58 100644 --- a/test/cid-version-agnostic.js +++ b/test/cid-version-agnostic.js @@ -13,7 +13,7 @@ const { stopDaemon } = require('./utils/daemon') -describe.only('CID version agnostic', () => { +describe('CID version agnostic', () => { const daemons = {} before(async function () {