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.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: still load dag-pb, dag-cbor and raw when specifying custom forma…
…ts (#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
- Loading branch information
1 parent
343bd45
commit a96e3bc
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { expect } = require('interface-ipfs-core/src/utils/mocha') | ||
const factory = require('../utils/factory') | ||
const ipldDagPb = require('ipld-dag-pb') | ||
|
||
describe('ipld', function () { | ||
this.timeout(10 * 1000) | ||
const df = factory() | ||
|
||
after(() => df.clean()) | ||
|
||
it('should allow formats to be specified without overwriting others', async () => { | ||
const ipfs = (await df.spawn({ | ||
type: 'proc', | ||
ipfsOptions: { | ||
ipld: { | ||
formats: [ | ||
require('ipld-dag-pb') | ||
] | ||
} | ||
} | ||
})).api | ||
|
||
const dagCborNode = { | ||
hello: 'world' | ||
} | ||
const cid1 = await ipfs.dag.put(dagCborNode, { | ||
format: 'dag-cbor', | ||
hashAlg: 'sha2-256' | ||
}) | ||
|
||
const dagPbNode = new ipldDagPb.DAGNode(Buffer.alloc(0), [], 0) | ||
const cid2 = await ipfs.dag.put(dagPbNode, { | ||
format: 'dag-pb', | ||
hashAlg: 'sha2-256' | ||
}) | ||
|
||
await expect(ipfs.dag.get(cid1)).to.eventually.have.property('value').that.deep.equals(dagCborNode) | ||
await expect(ipfs.dag.get(cid2)).to.eventually.have.property('value').that.deep.equals(dagPbNode) | ||
}) | ||
}) |