From 0186d775350957eb2c74834a4fb8805c5b79bf45 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 27 Feb 2019 13:59:51 +0000 Subject: [PATCH 1/5] refactor: block.put tests for CIDv1 base32 License: MIT Signed-off-by: Alan Shaw --- package.json | 2 +- src/block/put.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) 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() }) }) From 99fbadac7abdf3ba248c0a7e7134be32bd0a890d Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 27 Feb 2019 14:08:45 +0000 Subject: [PATCH 2/5] refactor: block.stat for CIDv1 base32 License: MIT Signed-off-by: Alan Shaw --- src/block/stat.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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') From 7dee4c05446fc91027608a4cb1c37b50024452d8 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 27 Feb 2019 14:27:39 +0000 Subject: [PATCH 3/5] refactor: dag.get for CIDv1 base32 License: MIT Signed-off-by: Alan Shaw --- src/dag/get.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 9f31b51de7859ab128c42ee50abc37b8b2259671 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 27 Feb 2019 14:28:00 +0000 Subject: [PATCH 4/5] refactor: dag.put for CIDv1 base32 License: MIT Signed-off-by: Alan Shaw --- src/dag/put.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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) => {}) }) From 96ba18745193cb3ea54341de66c2381f94ecef05 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 12 Mar 2019 17:00:34 +0000 Subject: [PATCH 5/5] refactor: files v1 base32 CID conversion License: MIT Signed-off-by: Alan Shaw --- src/files-regular/add-from-fs.js | 2 +- src/files-regular/add-pull-stream.js | 4 ++-- src/files-regular/add.js | 23 +++++++++++------------ src/files-regular/cat.js | 8 ++++---- src/files-regular/utils.js | 6 +++--- 5 files changed, 21 insertions(+), 22 deletions(-) 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({ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy