Skip to content

Commit 02a3f0b

Browse files
authored
fix: still load dag-pb, dag-cbor and raw when specifying custom formats (#3132)
If we specify a `formats` array as part of the ipld options in in-proc nodes, it replaces the default list of dag-pb, dag-cbor and raw. This change allows the `loadFormat` function to still resolve those formats even if the user has passed a `format` array that does not contain them. Fixes #3129
1 parent a19239c commit 02a3f0b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

test/dag.spec.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
const { Buffer } = require('buffer')
77
const { expect } = require('interface-ipfs-core/src/utils/mocha')
8-
const { DAGNode } = require('ipld-dag-pb')
8+
const ipldDagPb = require('ipld-dag-pb')
9+
const { DAGNode } = ipldDagPb
910
const CID = require('cids')
1011
const f = require('./utils/factory')()
1112
const ipfsHttpClient = require('../src')
@@ -98,4 +99,32 @@ describe('.dag', function () {
9899

99100
expect(askedToLoadFormat).to.be.true()
100101
})
102+
103+
it('should allow formats to be specified without overwriting others', async () => {
104+
const ipfs2 = ipfsHttpClient({
105+
url: `http://${ipfs.apiHost}:${ipfs.apiPort}`,
106+
ipld: {
107+
formats: [
108+
ipldDagPb
109+
]
110+
}
111+
})
112+
113+
const dagCborNode = {
114+
hello: 'world'
115+
}
116+
const cid1 = await ipfs2.dag.put(dagCborNode, {
117+
format: 'dag-cbor',
118+
hashAlg: 'sha2-256'
119+
})
120+
121+
const dagPbNode = new DAGNode(Buffer.alloc(0), [], 0)
122+
const cid2 = await ipfs2.dag.put(dagPbNode, {
123+
format: 'dag-pb',
124+
hashAlg: 'sha2-256'
125+
})
126+
127+
await expect(ipfs2.dag.get(cid1)).to.eventually.have.property('value').that.deep.equals(dagCborNode)
128+
await expect(ipfs2.dag.get(cid2)).to.eventually.have.property('value').that.deep.equals(dagPbNode)
129+
})
101130
})

0 commit comments

Comments
 (0)