This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
dag.spec.js
58 lines (43 loc) · 1.84 KB
/
dag.spec.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
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'
const { Buffer } = require('buffer')
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const { DAGNode } = require('ipld-dag-pb')
const CID = require('cids')
const f = require('./utils/factory')()
let ipfs
describe('.dag', function () {
this.timeout(20 * 1000)
before(async function () {
ipfs = (await f.spawn()).api
})
after(() => f.clean())
it('should be able to put and get a DAG node with format dag-pb', async () => {
const data = Buffer.from('some data')
const node = new DAGNode(data)
let cid = await ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' })
cid = cid.toV0()
expect(cid.codec).to.equal('dag-pb')
cid = cid.toBaseEncodedString('base58btc')
// expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u')
expect(cid).to.equal('Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr')
const result = await ipfs.dag.get(cid)
expect(result.value.Data).to.deep.equal(data)
})
it('should be able to put and get a DAG node with format dag-cbor', async () => {
const cbor = { foo: 'dag-cbor-bar' }
let cid = await ipfs.dag.put(cbor, { format: 'dag-cbor', hashAlg: 'sha2-256' })
expect(cid.codec).to.equal('dag-cbor')
cid = cid.toBaseEncodedString('base32')
expect(cid).to.equal('bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce')
const result = await ipfs.dag.get(cid)
expect(result.value).to.deep.equal(cbor)
})
it('should error when missing DAG resolver for multicodec from requested CID', async () => {
const block = await ipfs.block.put(Buffer.from([0, 1, 2, 3]), {
cid: new CID('z8mWaJ1dZ9fH5EetPuRsj8jj26pXsgpsr')
})
await expect(ipfs.dag.get(block.cid)).to.be.rejectedWith('Missing IPLD format "git-raw"')
})
})