Skip to content

Commit f10454b

Browse files
authored
test: adds a test for getting the same multihash from different CID versions (#89)
Just a small example test
1 parent b4c5cf3 commit f10454b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/ipfs-unixfs-importer/test/importer.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const blockApi = require('./helpers/block')
2020
const uint8ArrayConcat = require('uint8arrays/concat')
2121
const uint8ArrayFromString = require('uint8arrays/from-string')
2222
const uint8ArrayToString = require('uint8arrays/to-string')
23+
const last = require('it-last')
2324

2425
function stringifyMh (files) {
2526
return files.map((file) => {
@@ -1059,4 +1060,26 @@ describe('configuration', () => {
10591060
expect(validated).to.be.true()
10601061
expect(chunked).to.be.true()
10611062
})
1063+
1064+
it('imports the same data with different CID versions and gets the same multihash', async () => {
1065+
const ipld = await inMemory(IPLD)
1066+
const block = blockApi(ipld)
1067+
const buf = uint8ArrayFromString('content')
1068+
1069+
const { cid: cidV0 } = await last(importer([{
1070+
content: buf
1071+
}], block, {
1072+
cidVersion: 0,
1073+
rawLeaves: false
1074+
}))
1075+
1076+
const { cid: cidV1 } = await last(importer([{
1077+
content: buf
1078+
}], block, {
1079+
cidVersion: 1,
1080+
rawLeaves: false
1081+
}))
1082+
1083+
expect(cidV0.multihash).to.deep.equal(cidV1.multihash)
1084+
})
10621085
})

0 commit comments

Comments
 (0)