This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcid-version-agnostic.js
141 lines (122 loc) · 5.13 KB
/
cid-version-agnostic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* eslint-env mocha */
import { nanoid } from 'nanoid'
import concat from 'it-concat'
import { expect } from 'aegir/chai'
import { daemonFactory } from './utils/daemon-factory.js'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
/**
* @typedef {import('ipfsd-ctl').Controller} Controller
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
describe('CID version agnostic', function () {
this.timeout(50e3)
/** @type {Record<string, Controller>} */
const daemons = {}
/**
* @type {Factory}
*/
let factory
before(async function () {
factory = await daemonFactory()
const [js0, js1, go0, go1] = await Promise.all([
factory.spawn({ type: 'js' }),
factory.spawn({ type: 'js' }),
factory.spawn({ type: 'go' }),
factory.spawn({ type: 'go' })
])
Object.assign(daemons, { js0, js1, go0, go1 })
await Promise.all([
js0.api.swarm.connect(js1.peer.addresses[0]),
js1.api.swarm.connect(js0.peer.addresses[0]),
go0.api.swarm.connect(go1.peer.addresses[0]),
go1.api.swarm.connect(go0.peer.addresses[0]),
js0.api.swarm.connect(go0.peer.addresses[0]),
go0.api.swarm.connect(js0.peer.addresses[0])
])
})
after(() => factory.clean())
it('should add v0 and cat v1 (go0 -> go0)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.go0.api.add(input, { cidVersion: 0 })
const cidv1 = cid.toV1()
const output = await concat(daemons.go0.api.cat(cidv1))
expect(output.slice()).to.deep.equal(input)
})
it('should add v0 and cat v1 (js0 -> js0)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.js0.api.add(input, { cidVersion: 0 })
const cidv1 = cid.toV1()
const output = await concat(daemons.js0.api.cat(cidv1))
expect(output.slice()).to.deep.equal(input)
})
it('should add v0 and cat v1 (go0 -> go1)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.go0.api.add(input, { cidVersion: 0 })
const cidv1 = cid.toV1()
const output = await concat(daemons.go1.api.cat(cidv1))
expect(output.slice()).to.deep.equal(input)
})
it('should add v0 and cat v1 (js0 -> js1)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.js0.api.add(input, { cidVersion: 0 })
const cidv1 = cid.toV1()
const output = await concat(daemons.js1.api.cat(cidv1))
expect(output.slice()).to.deep.equal(input)
})
it('should add v0 and cat v1 (js0 -> go0)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.js0.api.add(input, { cidVersion: 0 })
const cidv1 = cid.toV1()
const output = await concat(daemons.go0.api.cat(cidv1))
expect(output.slice()).to.deep.equal(input)
})
it('should add v0 and cat v1 (go0 -> js0)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.go0.api.add(input, { cidVersion: 0 })
const cidv1 = cid.toV1()
const output = await concat(daemons.js0.api.cat(cidv1))
expect(output.slice()).to.deep.equal(input)
})
it('should add v1 and cat v0 (go0 -> go0)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.go0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = cid.toV0()
const output = await concat(daemons.go0.api.cat(cidv0))
expect(output.slice()).to.deep.equal(input)
})
it('should add v1 and cat v0 (js0 -> js0)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.js0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = cid.toV0()
const output = await concat(daemons.js0.api.cat(cidv0))
expect(output.slice()).to.deep.equal(input)
})
it('should add v1 and cat v0 (go0 -> go1)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.go0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = cid.toV0()
const output = await concat(daemons.go1.api.cat(cidv0))
expect(output.slice()).to.deep.equal(input)
})
it('should add v1 and cat v0 (js0 -> js1)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.js0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = cid.toV0()
const output = await concat(daemons.js1.api.cat(cidv0))
expect(output.slice()).to.deep.equal(input)
})
it('should add v1 and cat v0 (js0 -> go0)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.js0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = cid.toV0()
const output = await concat(daemons.go0.api.cat(cidv0))
expect(output.slice()).to.deep.equal(input)
})
it('should add v1 and cat v0 (go0 -> js0)', async () => {
const input = uint8ArrayFromString(nanoid())
const { cid } = await daemons.go0.api.add(input, { cidVersion: 1, rawLeaves: false })
const cidv0 = cid.toV0()
const output = await concat(daemons.js0.api.cat(cidv0))
expect(output.slice()).to.deep.equal(input)
})
})