diff --git a/package.json b/package.json index 437109bd6..c26bfac22 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "bl": "^2.1.2", "bs58": "^4.0.1", "chai": "^4.2.0", - "cids": "~0.5.5", + "cids": "github:ipld/js-cid#refactor/cidv1base32-default", "concat-stream": "^2.0.0", "dirty-chai": "^2.0.1", "es6-promisify": "^6.0.1", diff --git a/src/block/put.js b/src/block/put.js index 205b93f32..ed7fb0bc0 100644 --- a/src/block/put.js +++ b/src/block/put.js @@ -32,26 +32,26 @@ module.exports = (createCommon, options) => { after((done) => common.teardown(done)) it('should put a buffer, using defaults', (done) => { - const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' + const expectedHash = 'bafybeiaxnnnb7qz2focittuqq3ya25q7rcv3bqynnczfzako47346wosmu' const blob = Buffer.from('blorb') ipfs.block.put(blob, (err, block) => { expect(err).to.not.exist() expect(block.data).to.be.eql(blob) - expect(block.cid.multihash).to.eql(multihash.fromB58String(expectedHash)) + expect(block.cid.toString()).to.eql(expectedHash) done() }) }) it('should put a buffer, using CID', (done) => { - const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' + const expectedHash = 'bafybeiaxnnnb7qz2focittuqq3ya25q7rcv3bqynnczfzako47346wosmu' const cid = new CID(expectedHash) const blob = Buffer.from('blorb') - ipfs.block.put(blob, { cid: cid }, (err, block) => { + ipfs.block.put(blob, { cid }, (err, block) => { expect(err).to.not.exist() expect(block.data).to.be.eql(blob) - expect(block.cid.multihash).to.eql(multihash.fromB58String(expectedHash)) + expect(block.cid.toString()).to.eql(expectedHash) done() }) }) @@ -74,14 +74,14 @@ module.exports = (createCommon, options) => { }) it('should put a Block instance', (done) => { - const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' + const expectedHash = 'bafybeiaxnnnb7qz2focittuqq3ya25q7rcv3bqynnczfzako47346wosmu' const cid = new CID(expectedHash) const b = new Block(Buffer.from('blorb'), cid) ipfs.block.put(b, (err, block) => { expect(err).to.not.exist() expect(block.data).to.eql(Buffer.from('blorb')) - expect(block.cid.multihash).to.eql(multihash.fromB58String(expectedHash)) + expect(block.cid.toString()).to.eql(expectedHash) done() }) }) diff --git a/src/block/stat.js b/src/block/stat.js index a420dc286..dde6c1d29 100644 --- a/src/block/stat.js +++ b/src/block/stat.js @@ -1,7 +1,6 @@ /* eslint-env mocha */ 'use strict' -const CID = require('cids') const auto = require('async/auto') const { getDescribe, getIt, expect } = require('../utils/mocha') @@ -12,7 +11,7 @@ module.exports = (createCommon, options) => { describe('.block.stat', () => { const data = Buffer.from('blorb') - let ipfs, hash + let ipfs, cid before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the @@ -26,7 +25,7 @@ module.exports = (createCommon, options) => { }, (err, res) => { if (err) return done(err) ipfs = res.ipfs - hash = res.block.cid.multihash + cid = res.block.cid done() }) }) @@ -34,8 +33,6 @@ module.exports = (createCommon, options) => { after((done) => common.teardown(done)) it('should stat by CID', (done) => { - const cid = new CID(hash) - ipfs.block.stat(cid, (err, stats) => { expect(err).to.not.exist() expect(stats).to.have.property('key') diff --git a/src/dag/get.js b/src/dag/get.js index 03855b784..58fd98832 100644 --- a/src/dag/get.js +++ b/src/dag/get.js @@ -228,7 +228,7 @@ module.exports = (createCommon, options) => { dagPB.DAGNode.create(input, (err, node) => { expect(err).to.not.exist() - ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => { + ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256', version: 0 }, (err, cid) => { expect(err).to.not.exist() expect(cid.version).to.equal(0) diff --git a/src/dag/put.js b/src/dag/put.js index 1e4a561c7..3c0ac1f19 100644 --- a/src/dag/put.js +++ b/src/dag/put.js @@ -107,6 +107,7 @@ module.exports = (createCommon, options) => { it('should set defaults when calling put without options', (done) => { ipfs.dag.put(cborNode, (err, cid) => { expect(err).to.not.exist() + expect(cid.version).to.equal(1) expect(cid.codec).to.equal('dag-cbor') expect(multihash.decode(cid.multihash).name).to.equal('sha2-256') done() @@ -116,6 +117,7 @@ module.exports = (createCommon, options) => { it('should set defaults when calling put without options (promised)', () => { return ipfs.dag.put(cborNode) .then((cid) => { + expect(cid.version).to.equal(1) expect(cid.codec).to.equal('dag-cbor') expect(multihash.decode(cid.multihash).name).to.equal('sha2-256') }) @@ -133,7 +135,17 @@ module.exports = (createCommon, options) => { }) }) - it.skip('should put by passing the cid instead of format and hashAlg', (done) => {}) + it('should put by passing the cid instead of format and hashAlg', (done) => { + dagCBOR.util.cid(cborNode, (err, cid) => { + expect(err).to.not.exist() + + ipfs.dag.put(cborNode, { cid }, (err, _cid) => { + expect(err).to.not.exist() + expect(cid.equals(_cid)).to.be.true() + done() + }) + }) + }) // TODO it.skip('Promises support', (done) => {}) }) diff --git a/src/files-regular/add-from-fs.js b/src/files-regular/add-from-fs.js index b2f35cfa9..f2d9f0c53 100644 --- a/src/files-regular/add-from-fs.js +++ b/src/files-regular/add-from-fs.js @@ -78,7 +78,7 @@ module.exports = (createCommon, options) => { expect(err).to.not.exist() expect(result.length).to.be.above(10) expect(result.map(object => object.path)).to.include('hidden-files-folder/.hiddenTest.txt') - expect(result.map(object => object.hash)).to.include('QmdbAjVmLRdpFyi8FFvjPfhTGB2cVXvWLuK7Sbt38HXrtt') + expect(result.map(object => object.hash)).to.include('bafkreieapodbusibovh26gwruowy7rchsgmoxwtwnfxsmjpbpgwh2guazu') done() }) }) diff --git a/src/files-regular/add-pull-stream.js b/src/files-regular/add-pull-stream.js index e51eb3eb0..add129043 100644 --- a/src/files-regular/add-pull-stream.js +++ b/src/files-regular/add-pull-stream.js @@ -70,7 +70,7 @@ module.exports = (createCommon, options) => { }) it('should add with object chunks and pull stream content', (done) => { - const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm' + const expectedCid = 'bafkreie7q3iidccmpvszul7kudcvvuavuo7u6gzlbobczuk5nqk3b4akba' pull( pull.values([{ content: pull.values([Buffer.from('test')]) }]), @@ -78,7 +78,7 @@ module.exports = (createCommon, options) => { pull.collect((err, res) => { if (err) return done(err) expect(res).to.have.length(1) - expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 }) + expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 4 }) done() }) ) diff --git a/src/files-regular/add.js b/src/files-regular/add.js index 0663ad25c..6dbcc829f 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -43,8 +43,7 @@ module.exports = (createCommon, options) => { const file = filesAdded[0] expect(file.hash).to.equal(fixtures.smallFile.cid) expect(file.path).to.equal(fixtures.smallFile.cid) - // file.size counts the overhead by IPLD nodes and unixfs protobuf - expect(file.size).greaterThan(fixtures.smallFile.data.length) + expect(file.size).to.equal(fixtures.smallFile.data.length) done() }) }) @@ -141,7 +140,7 @@ module.exports = (createCommon, options) => { }) it('should add readable stream', (done) => { - const expectedCid = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS' + const expectedCid = 'bafkreiata6mq425fzikf5m26temcvg7mizjrxrkn35swuybmpah2ajan5y' const rs = new Readable() rs.push(Buffer.from('some data')) @@ -153,14 +152,14 @@ module.exports = (createCommon, options) => { expect(filesAdded).to.be.length(1) const file = filesAdded[0] expect(file.path).to.equal(expectedCid) - expect(file.size).to.equal(17) + expect(file.size).to.equal(9) expect(file.hash).to.equal(expectedCid) done() }) }) it('should add array of objects with readable stream content', (done) => { - const expectedCid = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS' + const expectedCid = 'bafkreiata6mq425fzikf5m26temcvg7mizjrxrkn35swuybmpah2ajan5y' const rs = new Readable() rs.push(Buffer.from('some data')) @@ -174,40 +173,40 @@ module.exports = (createCommon, options) => { expect(filesAdded).to.be.length(1) const file = filesAdded[0] expect(file.path).to.equal('data.txt') - expect(file.size).to.equal(17) + expect(file.size).to.equal(9) expect(file.hash).to.equal(expectedCid) done() }) }) it('should add pull stream', (done) => { - const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm' + const expectedCid = 'bafkreie7q3iidccmpvszul7kudcvvuavuo7u6gzlbobczuk5nqk3b4akba' ipfs.add(pull.values([Buffer.from('test')]), (err, res) => { if (err) return done(err) expect(res).to.have.length(1) - expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 }) + expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 4 }) done() }) }) it('should add pull stream (promised)', () => { - const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm' + const expectedCid = 'bafkreie7q3iidccmpvszul7kudcvvuavuo7u6gzlbobczuk5nqk3b4akba' return ipfs.add(pull.values([Buffer.from('test')])) .then((res) => { expect(res).to.have.length(1) - expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 }) + expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 4 }) }) }) it('should add array of objects with pull stream content (promised)', () => { - const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm' + const expectedCid = 'bafkreie7q3iidccmpvszul7kudcvvuavuo7u6gzlbobczuk5nqk3b4akba' return ipfs.add([{ content: pull.values([Buffer.from('test')]) }]) .then((res) => { expect(res).to.have.length(1) - expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 }) + expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 4 }) }) }) diff --git a/src/files-regular/cat.js b/src/files-regular/cat.js index 048d9a9fc..c34aab999 100644 --- a/src/files-regular/cat.js +++ b/src/files-regular/cat.js @@ -41,7 +41,7 @@ module.exports = (createCommon, options) => { ], done) }) - it('should cat with a base58 string encoded multihash', (done) => { + it('should cat with a base32 string encoded CID', (done) => { ipfs.cat(fixtures.smallFile.cid, (err, data) => { expect(err).to.not.exist() expect(data.toString()).to.contain('Plz add me!') @@ -49,15 +49,15 @@ module.exports = (createCommon, options) => { }) }) - it('should cat with a base58 string encoded multihash (promised)', () => { + it('should cat with a base32 string encoded CID (promised)', () => { return ipfs.cat(fixtures.smallFile.cid) .then((data) => { expect(data.toString()).to.contain('Plz add me!') }) }) - it('should cat with a Buffer multihash', (done) => { - const cid = Buffer.from(bs58.decode(fixtures.smallFile.cid)) + it('should cat with a Buffer CID', (done) => { + const cid = new CID(fixtures.smallFile.cid).buffer ipfs.cat(cid, (err, data) => { expect(err).to.not.exist() diff --git a/src/files-regular/utils.js b/src/files-regular/utils.js index 8f6bf04d9..3f8298b8d 100644 --- a/src/files-regular/utils.js +++ b/src/files-regular/utils.js @@ -4,7 +4,7 @@ const loadFixture = require('aegir/fixtures') exports.fixtures = Object.freeze({ directory: Object.freeze({ - cid: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP', + cid: 'bafybeiaqxngbqbr5erl2ux2rfuoipy3b6caefjodi3gshpi3u7nsqruvuq', files: Object.freeze({ 'pp.txt': loadFixture('test/fixtures/test-folder/pp.txt', 'interface-ipfs-core'), 'holmes.txt': loadFixture('test/fixtures/test-folder/holmes.txt', 'interface-ipfs-core'), @@ -15,11 +15,11 @@ exports.fixtures = Object.freeze({ }) }), smallFile: Object.freeze({ - cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', + cid: 'bafkreidffqfydlguosmmyebv5rp72m45tbpbq6segnkosa45kjfnduix6u', data: loadFixture('test/fixtures/testfile.txt', 'interface-ipfs-core') }), bigFile: Object.freeze({ - cid: 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', + cid: 'bafybeih2sk5etf4biw7mcmzximj4zz5yite4lhqowiq2pfdwiz55qgsiqu', data: loadFixture('test/fixtures/15mb.random', 'interface-ipfs-core') }), sslOpts: Object.freeze({
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: