|
| 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 | +}) |
0 commit comments