From 3647b6ccf2e94ad58f6c08556cd2cc1aba42f3dc Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 12 Dec 2019 16:13:14 +0000 Subject: [PATCH 1/5] fix: add new tests for dag.get --- src/dag/get.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/dag/get.js b/src/dag/get.js index 67a25cda..7df74326 100644 --- a/src/dag/get.js +++ b/src/dag/get.js @@ -210,5 +210,29 @@ module.exports = (common, options) => { const result = await ipfs.dag.get(cid) expect(result.value).to.deep.equal(buf) }) + + // This should be skipped in js-ipfs because it loads all the formats + it('should error when missing DAG resolver for multicodec from requested CID', async () => { + const block = await ipfs.block.put(Buffer.from([0, 1, 2, 3]), { + cid: new CID('z8mWaJ1dZ9fH5EetPuRsj8jj26pXsgpsr') + }) + await expect(ipfs.dag.get(block.cid)).to.be.rejectedWith('Missing IPLD format "git-raw"') + }) + + it('should error for invalid string CID input', async () => { + try { + await expect(ipfs.dag.get('INVALID CID')).to.be.rejected() + } catch (err) { + expect(err.code).to.equal('ERR_INVALID_CID') + } + }) + + it('should error for invalid buffer CID input', async () => { + try { + await expect(ipfs.dag.get(Buffer.from('INVALID CID'))).to.be.rejected() + } catch (err) { + expect(err.code).to.equal('ERR_INVALID_CID') + } + }) }) } From b1d0968d0d77eedcbc21c7c4bc1722e9f655960e Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 12 Dec 2019 17:19:52 +0000 Subject: [PATCH 2/5] fix: dedupe from http-client files tests --- src/files-mfs/ls.js | 9 ++++++ src/files-regular/add.js | 69 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/files-mfs/ls.js b/src/files-mfs/ls.js index 5497f49a..522bfca0 100644 --- a/src/files-mfs/ls.js +++ b/src/files-mfs/ls.js @@ -23,6 +23,15 @@ module.exports = (common, options) => { after(() => common.clean()) + it('should ls mfs root by default', async () => { + const folder = `test-folder-${Math.random()}` + + await ipfs.files.mkdir(`/${folder}`) + const files = await ipfs.files.ls() + + expect(files.find(file => file.name === folder)).to.be.ok() + }) + it('should not ls not found file/dir, expect error', () => { const testDir = `/test-${hat()}` diff --git a/src/files-regular/add.js b/src/files-regular/add.js index c1fbaaa7..13bf1652 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -4,6 +4,8 @@ const { fixtures } = require('./utils') const Readable = require('readable-stream').Readable const pull = require('pull-stream') +const mh = require('multihashes') +const CID = require('cids') const expectTimeout = require('../utils/expect-timeout') const { getDescribe, getIt, expect } = require('../utils/mocha') const { supportsFileReader } = require('ipfs-utils/src/supports') @@ -299,5 +301,72 @@ module.exports = (common, options) => { await expectTimeout(ipfs.object.get(files[0].hash), 4000) }) + + it('should add empty path and buffer content', async () => { + const expectedHash = 'QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX' + const content = Buffer.from('hello') + + const res = await ipfs.add([{ path: '', content }]) + + expect(res).to.have.length(1) + expect(res[0].hash).to.equal(expectedHash) + }) + + it('should add with cid-version=1 and raw-leaves=false', async () => { + const expectedCid = 'bafybeifj7nuqlszk47q4jvdvaurqlb7ihbqfjxofg4hfcy53oc2s5tlg5m' + const options = { cidVersion: 1, rawLeaves: false } + + const res = await ipfs.add('.add with cid-version=1 and raw-leaves=false', options) + + expect(res).to.have.length(1) + expect(res[0].hash).to.equal(expectedCid) + }) + + it('should pin by default', async () => { + const initialPins = await ipfs.pin.ls() + + await ipfs.add('should add pins by default') + + const pinsAfterAdd = await ipfs.pin.ls() + + expect(pinsAfterAdd.length).to.eql(initialPins.length + 1) + }) + + it('should not pin with pin=false', async () => { + const initialPins = await ipfs.pin.ls() + + await ipfs.add('should not pin with pin=false', { pin: false }) + + const pinsAfterAdd = await ipfs.pin.ls() + + expect(pinsAfterAdd.length).to.eql(initialPins.length) + }) + + // TODO: Test against all algorithms Object.keys(mh.names) + // This subset is known to work with both go-ipfs and js-ipfs as of 2017-09-05 + const HASH_ALGS = [ + 'sha1', + 'sha2-256', + 'sha2-512', + // 'keccak-224', // go throws + 'keccak-256', + // 'keccak-384', // go throws + 'keccak-512' + ] + HASH_ALGS.forEach((name) => { + it(`should add with hash=${name} and raw-leaves=false`, async () => { + const file = { + path: `${name}.txt`, + content: `should add with hash=${name} and raw-leaves=false` + } + const options = { hashAlg: name, rawLeaves: false } + + const res = await ipfs.add([file], options) + + expect(res).to.have.length(1) + const cid = new CID(res[0].hash) + expect(mh.decode(cid.multihash).name).to.equal(name) + }) + }) }) } From 679126cb69bea4b8234c337fba6b18a70e16aeb9 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 12 Dec 2019 17:44:38 +0000 Subject: [PATCH 3/5] fix: add a new ping test --- src/ping/ping.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ping/ping.js b/src/ping/ping.js index 00e42b6c..bd8ace16 100644 --- a/src/ping/ping.js +++ b/src/ping/ping.js @@ -27,6 +27,14 @@ module.exports = (common, options) => { after(() => common.clean()) + it('should send the default number of packets', async () => { + const responses = await ipfsA.ping(ipfsB.peerId.id) + responses.forEach(expectIsPingResponse) + + const pongs = responses.filter(isPong) + expect(pongs.length).to.equal(10) + }) + it('should send the specified number of packets', async () => { const count = 3 const responses = await ipfsA.ping(ipfsB.peerId.id, { count }) From 80337bdfc90a1d8c47d01b6a01adcd1d9f14c344 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 13 Dec 2019 11:13:14 +0000 Subject: [PATCH 4/5] fix: add cidv1 tests --- src/files-regular/add.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/files-regular/add.js b/src/files-regular/add.js index 13bf1652..bbc653f9 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -312,6 +312,16 @@ module.exports = (common, options) => { expect(res[0].hash).to.equal(expectedHash) }) + it('should add with cid-version=1', async () => { + const expectedCid = 'bafkreiaoumr4mhytmxmaav7qbe2vpsmsxkdvyelbws5orak5u6bjrekuz4' + const options = { cidVersion: 1 } + + const res = await ipfs.add('should add with cid-version=1', options) + + expect(res).to.have.length(1) + expect(res[0].hash).to.equal(expectedCid) + }) + it('should add with cid-version=1 and raw-leaves=false', async () => { const expectedCid = 'bafybeifj7nuqlszk47q4jvdvaurqlb7ihbqfjxofg4hfcy53oc2s5tlg5m' const options = { cidVersion: 1, rawLeaves: false } From 177c24fa95742c7ae1aff4d3236bc2863db44b43 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 13 Dec 2019 20:40:25 +0000 Subject: [PATCH 5/5] fix: add test for dag.get --- src/dag/get.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/dag/get.js b/src/dag/get.js index 7df74326..cc8f7997 100644 --- a/src/dag/get.js +++ b/src/dag/get.js @@ -56,6 +56,11 @@ module.exports = (common, options) => { })) }) + it('should get dag node with options as the second param and cid with path', async function () { + const result = await ipfs.dag.get(`/ipfs/${cidCbor}/pb`, { localResolve: true }) + expect(result.value._data).to.be.deep.eq(nodePb._data) + }) + it('should get a dag-pb node', async () => { const cid = await ipfs.dag.put(pbNode, { format: 'dag-pb',