From dacb64adff85661bef3c99c109545b73daf14853 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 12 Dec 2019 16:21:04 +0000 Subject: [PATCH 1/3] fix: dedupe dag and add validation --- package.json | 2 +- src/dag/get.js | 55 ++++++++++++++++++++++++++++++++++------ test/dag.spec.js | 57 ------------------------------------------ test/interface.spec.js | 1 + 4 files changed, 50 insertions(+), 65 deletions(-) delete mode 100644 test/dag.spec.js diff --git a/package.json b/package.json index f0253c933..ef42ffb9d 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "cross-env": "^6.0.0", "detect-node": "^2.0.4", "go-ipfs-dep": "^0.4.22", - "interface-ipfs-core": "~0.125.0", + "interface-ipfs-core": "ipfs/interface-js-ipfs-core#fix/dedupe", "ipfsd-ctl": "^1.0.0", "ndjson": "^1.5.0", "nock": "^11.4.0", diff --git a/src/dag/get.js b/src/dag/get.js index 93847b2e6..827aa990d 100644 --- a/src/dag/get.js +++ b/src/dag/get.js @@ -1,5 +1,6 @@ 'use strict' - +const CID = require('cids') +const errCode = require('err-code') const dagPB = require('ipld-dag-pb') const dagCBOR = require('ipld-dag-cbor') const raw = require('ipld-raw') @@ -11,18 +12,58 @@ const resolvers = { raw: raw.resolver } +// TODO this function needs to be extracted and re-used by ipfs-http-client and ipfs +function parseArgs (cid, path, options) { + options = options || {} + + // Allow options in path position + if (path !== undefined && typeof path !== 'string') { + options = path + path = undefined + } + + if (typeof cid === 'string') { + if (cid.startsWith('/ipfs/')) { + cid = cid.substring(6) + } + + const split = cid.split('/') + + try { + cid = new CID(split[0]) + } catch (err) { + throw errCode(err, 'ERR_INVALID_CID') + } + + split.shift() + + if (split.length > 0) { + path = split.join('/') + } else { + path = path || '/' + } + } else if (Buffer.isBuffer(cid)) { + try { + cid = new CID(cid) + } catch (err) { + throw errCode(err, 'ERR_INVALID_CID') + } + } + + return [ + cid, + path, + options + ] +} + module.exports = config => { const getBlock = require('../block/get')(config) const dagResolve = require('./resolve')(config) return configure(({ ky }) => { return async (cid, path, options) => { - if (typeof path === 'object') { - options = path - path = null - } - - options = options || {} + [cid, path, options] = parseArgs(cid, path, options) const resolved = await dagResolve(cid, path, options) const block = await getBlock(resolved.cid, options) diff --git a/test/dag.spec.js b/test/dag.spec.js deleted file mode 100644 index de9217d13..000000000 --- a/test/dag.spec.js +++ /dev/null @@ -1,57 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ - -'use strict' - -const { expect } = require('interface-ipfs-core/src/utils/mocha') -const { DAGNode } = require('ipld-dag-pb') -const CID = require('cids') -const f = require('./utils/factory') - -let ipfs - -describe('.dag', function () { - this.timeout(20 * 1000) - before(async function () { - ipfs = (await f.spawn()).api - }) - - after(() => f.clean()) - - it('should be able to put and get a DAG node with format dag-pb', async () => { - const data = Buffer.from('some data') - const node = new DAGNode(data) - - let cid = await ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }) - cid = cid.toV0() - expect(cid.codec).to.equal('dag-pb') - cid = cid.toBaseEncodedString('base58btc') - // expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u') - expect(cid).to.equal('Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr') - - const result = await ipfs.dag.get(cid) - - expect(result.value.Data).to.deep.equal(data) - }) - - it('should be able to put and get a DAG node with format dag-cbor', async () => { - const cbor = { foo: 'dag-cbor-bar' } - let cid = await ipfs.dag.put(cbor, { format: 'dag-cbor', hashAlg: 'sha2-256' }) - - expect(cid.codec).to.equal('dag-cbor') - cid = cid.toBaseEncodedString('base32') - expect(cid).to.equal('bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce') - - const result = await ipfs.dag.get(cid) - - expect(result.value).to.deep.equal(cbor) - }) - - it('should callback with 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"') - }) -}) diff --git a/test/interface.spec.js b/test/interface.spec.js index 5435518cf..3db3ec797 100644 --- a/test/interface.spec.js +++ b/test/interface.spec.js @@ -55,6 +55,7 @@ describe('interface-ipfs-core tests', () => { }) tests.dag(commonFactory, { + only: true, skip: [ // dag.tree { From 85f4fddaae0c18720da8f06296bdf1cb8aacfdb3 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 12 Dec 2019 17:26:05 +0000 Subject: [PATCH 2/3] fix: remove files-mfs.spec.js --- package.json | 2 +- test/files-mfs.spec.js | 398 ----------------------------------------- test/interface.spec.js | 1 - 3 files changed, 1 insertion(+), 400 deletions(-) delete mode 100644 test/files-mfs.spec.js diff --git a/package.json b/package.json index ef42ffb9d..fa260f403 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "cross-env": "^6.0.0", "detect-node": "^2.0.4", "go-ipfs-dep": "^0.4.22", - "interface-ipfs-core": "ipfs/interface-js-ipfs-core#fix/dedupe", + "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#fix/dedupe", "ipfsd-ctl": "^1.0.0", "ndjson": "^1.5.0", "nock": "^11.4.0", diff --git a/test/files-mfs.spec.js b/test/files-mfs.spec.js deleted file mode 100644 index 0e3d6b1af..000000000 --- a/test/files-mfs.spec.js +++ /dev/null @@ -1,398 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const { expect } = require('interface-ipfs-core/src/utils/mocha') -const loadFixture = require('aegir/fixtures') -const mh = require('multihashes') -const CID = require('cids') -const values = require('pull-stream/sources/values') -const pull = require('pull-stream/pull') -const collect = require('pull-stream/sinks/collect') - -const f = require('./utils/factory') -const expectTimeout = require('./utils/expect-timeout') - -const testfile = loadFixture('test/fixtures/testfile.txt') - -// 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' -] - -describe('.files (the MFS API part)', function () { - this.timeout(20 * 1000) - - let ipfs - - const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - - before(async () => { - ipfs = (await f.spawn()).api - }) - - after(() => f.clean()) - - it('.add file for testing', async () => { - const res = await ipfs.add(testfile) - - expect(res).to.have.length(1) - expect(res[0].hash).to.equal(expectedMultihash) - expect(res[0].path).to.equal(expectedMultihash) - }) - - it('.add with Buffer module', async () => { - const { Buffer } = require('buffer') - - const expectedBufferMultihash = 'QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX' - const file = Buffer.from('hello') - - const res = await ipfs.add(file) - - expect(res).to.have.length(1) - expect(res[0].hash).to.equal(expectedBufferMultihash) - expect(res[0].path).to.equal(expectedBufferMultihash) - }) - - it('.add with 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) - expect(res[0].path).to.equal(expectedHash) - }) - - it('.add with cid-version=1 and raw-leaves=false', async () => { - const expectedCid = 'bafybeifogzovjqrcxvgt7g36y7g63hvwvoakledwk4b2fr2dl4wzawpnny' - const options = { cidVersion: 1, rawLeaves: false } - - const res = await ipfs.add(testfile, options) - - expect(res).to.have.length(1) - expect(res[0].hash).to.equal(expectedCid) - expect(res[0].path).to.equal(expectedCid) - }) - - it('.add with only-hash=true', async () => { - const content = String(Math.random() + Date.now()) - - const files = await ipfs.add(Buffer.from(content), { onlyHash: true }) - expect(files).to.have.length(1) - - // 'ipfs.object.get()' should timeout because content wasn't actually added - await expectTimeout(ipfs.object.get(files[0].hash), 4000) - }) - - it('.add with options', async () => { - const res = await ipfs.add(testfile, { pin: false }) - - expect(res).to.have.length(1) - expect(res[0].hash).to.equal(expectedMultihash) - expect(res[0].path).to.equal(expectedMultihash) - }) - - it('.add pins by default', async () => { - const newContent = Buffer.from(String(Math.random())) - - const initialPins = await ipfs.pin.ls() - - await ipfs.add(newContent) - - const pinsAfterAdd = await ipfs.pin.ls() - - expect(pinsAfterAdd.length).to.eql(initialPins.length + 1) - }) - - it('.add with pin=false', async () => { - const newContent = Buffer.from(String(Math.random())) - - const initialPins = await ipfs.pin.ls() - - await ipfs.add(newContent, { pin: false }) - - const pinsAfterAdd = await ipfs.pin.ls() - - expect(pinsAfterAdd.length).to.eql(initialPins.length) - }) - - HASH_ALGS.forEach((name) => { - it(`.add with hash=${name} and raw-leaves=false`, async () => { - const content = String(Math.random() + Date.now()) - const file = { - path: content + '.txt', - content: Buffer.from(content) - } - 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) - }) - }) - - it('.add file with progress option', async () => { - let progress - let progressCount = 0 - - const progressHandler = (p) => { - progressCount += 1 - progress = p - } - - const res = await ipfs.add(testfile, { progress: progressHandler }) - - expect(res).to.have.length(1) - expect(progress).to.be.equal(testfile.byteLength) - expect(progressCount).to.be.equal(1) - }) - - it('.add big file with progress option', async () => { - let progress = 0 - let progressCount = 0 - - const progressHandler = (p) => { - progressCount += 1 - progress = p - } - - // TODO: needs to be using a big file - const res = await ipfs.add(testfile, { progress: progressHandler }) - - expect(res).to.have.length(1) - expect(progress).to.be.equal(testfile.byteLength) - expect(progressCount).to.be.equal(1) - }) - - it('.add directory with progress option', async () => { - let progress = 0 - let progressCount = 0 - - const progressHandler = (p) => { - progressCount += 1 - progress = p - } - - // TODO: needs to be using a directory - const res = await ipfs.add(testfile, { progress: progressHandler }) - - expect(res).to.have.length(1) - expect(progress).to.be.equal(testfile.byteLength) - expect(progressCount).to.be.equal(1) - }) - - it('.add without progress options', async () => { - const res = await ipfs.add(testfile) - - expect(res).to.have.length(1) - }) - - HASH_ALGS.forEach((name) => { - it(`.add with hash=${name} and raw-leaves=false`, async () => { - const content = String(Math.random() + Date.now()) - const file = { - path: content + '.txt', - content: Buffer.from(content) - } - 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) - }) - }) - - it('.addPullStream with object chunks and pull stream content', (done) => { - const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm' - - pull( - values([{ content: values([Buffer.from('test')]) }]), - ipfs.addPullStream(), - collect((err, res) => { - expect(err).to.not.exist() - - expect(res).to.have.length(1) - expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 }) - done() - }) - ) - }) - - it('.add with pull stream', async () => { - const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm' - const res = await ipfs.add(values([Buffer.from('test')])) - - expect(res).to.have.length(1) - expect(res[0]).to.deep.equal({ path: expectedCid, hash: expectedCid, size: 12 }) - }) - - it('.add with array of objects with pull stream content', async () => { - const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm' - const res = await ipfs.add([{ content: values([Buffer.from('test')]) }]) - - expect(res).to.have.length(1) - expect(res[0]).to.eql({ path: expectedCid, hash: expectedCid, size: 12 }) - }) - - it('files.mkdir', async () => { - await ipfs.files.mkdir('/test-folder') - }) - - it('files.flush', async () => { - await ipfs.files.flush('/') - }) - - it('files.cp', async () => { - const folder = `/test-folder-${Math.random()}` - - await ipfs.files.mkdir(folder) - await ipfs.files.cp([ - '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - `${folder}/test-file-${Math.random()}` - ]) - }) - - it('files.cp with non-array arguments', async () => { - const folder = `/test-folder-${Math.random()}` - - await ipfs.files.mkdir(folder) - await ipfs.files.cp( - '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - `${folder}/test-file-${Math.random()}` - ) - }) - - it('files.mv', async () => { - const folder = `/test-folder-${Math.random()}` - const source = `${folder}/test-file-${Math.random()}` - const dest = `${folder}/test-file-${Math.random()}` - - await ipfs.files.mkdir(folder) - await ipfs.files.cp( - '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - source - ) - await ipfs.files.mv([ - source, - dest - ]) - }) - - it('files.mv with non-array arguments', async () => { - const folder = `/test-folder-${Math.random()}` - const source = `${folder}/test-file-${Math.random()}` - const dest = `${folder}/test-file-${Math.random()}` - - await ipfs.files.mkdir(folder) - await ipfs.files.cp( - '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - source - ) - await ipfs.files.mv( - source, - dest - ) - }) - - it('files.ls', async () => { - const folder = `/test-folder-${Math.random()}` - const file = `${folder}/test-file-${Math.random()}` - - await ipfs.files.mkdir(folder) - await ipfs.files.write(file, Buffer.from('Hello, world'), { - create: true - }) - const files = await ipfs.files.ls(folder) - - expect(files.length).to.equal(1) - }) - - it('files.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('files.write', async () => { - await ipfs.files.write('/test-folder/test-file-2.txt', Buffer.from('hello world'), { - create: true - }) - - const buf = await ipfs.files.read('/test-folder/test-file-2.txt') - - expect(buf.toString()).to.be.equal('hello world') - }) - - it('files.write without options', async () => { - await ipfs.files.write('/test-folder/test-file-2.txt', Buffer.from('hello world')) - - const buf = await ipfs.files.read('/test-folder/test-file-2.txt') - - expect(buf.toString()).to.be.equal('hello world') - }) - - it('files.stat', async () => { - const folder = `/test-folder-${Math.random()}` - const file = `${folder}/test-file-${Math.random()}` - - await ipfs.files.mkdir(folder) - await ipfs.files.write(file, testfile, { - create: true - }) - - const stats = await ipfs.files.stat(file) - - expect(stats).to.deep.equal({ - hash: 'QmQhouoDPAnzhVM148yCa9CbUXK65wSEAZBtgrLGHtmdmP', - size: 12, - cumulativeSize: 70, - blocks: 1, - type: 'file', - withLocality: false - }) - }) - - it('files.stat file that does not exist()', async () => { - await expect(ipfs.files.stat('/test-folder/does-not-exist()')).to.be.rejectedWith({ - code: 0, - type: 'error' - }) - }) - - it('files.read', async () => { - const folder = `/test-folder-${Math.random()}` - const file = `${folder}/test-file-${Math.random()}` - - await ipfs.files.mkdir(folder) - await ipfs.files.write(file, testfile, { - create: true - }) - const buf = await ipfs.files.read(file) - - expect(Buffer.from(buf)).to.deep.equal(testfile) - }) - - it('files.rm without options', async () => { - await ipfs.files.rm('/test-folder/test-file-2.txt') - }) - - it('files.rm', async () => { - await ipfs.files.rm('/test-folder', { recursive: true }) - }) -}) diff --git a/test/interface.spec.js b/test/interface.spec.js index 3db3ec797..5435518cf 100644 --- a/test/interface.spec.js +++ b/test/interface.spec.js @@ -55,7 +55,6 @@ describe('interface-ipfs-core tests', () => { }) tests.dag(commonFactory, { - only: true, skip: [ // dag.tree { From 2e30f994459a038fc4665890101a23beafcd0f71 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 12 Dec 2019 17:58:31 +0000 Subject: [PATCH 3/3] fix: remove test key, ping, repo, stats and tweak get --- test/get.spec.js | 28 +++----------- test/key.spec.js | 40 -------------------- test/ping.spec.js | 94 ---------------------------------------------- test/repo.spec.js | 37 ------------------ test/stats.spec.js | 53 -------------------------- 5 files changed, 5 insertions(+), 247 deletions(-) delete mode 100644 test/key.spec.js delete mode 100644 test/ping.spec.js delete mode 100644 test/repo.spec.js delete mode 100644 test/stats.spec.js diff --git a/test/get.spec.js b/test/get.spec.js index a6fb3aaa4..9a66592c7 100644 --- a/test/get.spec.js +++ b/test/get.spec.js @@ -11,13 +11,9 @@ const f = require('./utils/factory') describe('.get (specific go-ipfs features)', function () { this.timeout(60 * 1000) - function fixture (path) { - return loadFixture(path, 'interface-ipfs-core') - } - const smallFile = { cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - data: fixture('test/fixtures/testfile.txt') + data: loadFixture('test/fixtures/testfile.txt', 'interface-ipfs-core') } let ipfs @@ -29,13 +25,6 @@ describe('.get (specific go-ipfs features)', function () { after(() => f.clean()) - it('no compression args', async () => { - const files = await ipfs.get(smallFile.cid) - - expect(files).to.be.length(1) - expect(files[0].content.toString()).to.contain(smallFile.data.toString()) - }) - it('archive true', async () => { const files = await ipfs.get(smallFile.cid, { archive: true }) @@ -50,26 +39,19 @@ describe('.get (specific go-ipfs features)', function () { })).to.be.rejectedWith('compression level must be between 1 and 9') }) - // TODO Understand why this test started failing - it.skip('with compression level', async () => { + it('with compression level', async () => { await ipfs.get(smallFile.cid, { compress: true, 'compression-level': 1 }) }) - it('add path containing "+"s (for testing get)', async () => { + it('get path containing "+"s', async () => { const filename = 'ti,c64x+mega++mod-pic.txt' const subdir = 'tmp/c++files' - const expectedCid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff' + const cid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff' const path = `${subdir}/${filename}` - const files = await ipfs.add([{ + await ipfs.add([{ path, content: Buffer.from(path) }]) - - expect(files[2].hash).to.equal(expectedCid) - }) - - it('get path containing "+"s', async () => { - const cid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff' const files = await ipfs.get(cid) expect(files).to.be.an('array').with.lengthOf(3) diff --git a/test/key.spec.js b/test/key.spec.js deleted file mode 100644 index 180cb795b..000000000 --- a/test/key.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const { expect } = require('interface-ipfs-core/src/utils/mocha') -const f = require('./utils/factory') - -describe('.key', function () { - this.timeout(50 * 1000) - - let ipfs - - before(async () => { - ipfs = (await f.spawn()).api - }) - - after(() => f.clean()) - - describe('.gen', () => { - it('create a new rsa key', async () => { - const res = await ipfs.key.gen('foobarsa', { type: 'rsa', size: 2048 }) - - expect(res).to.exist() - }) - - it('create a new ed25519 key', async () => { - const res = await ipfs.key.gen('bazed', { type: 'ed25519' }) - - expect(res).to.exist() - }) - }) - - describe('.list', () => { - it('both keys show up + self', async () => { - const res = await ipfs.key.list() - - expect(res).to.exist() - expect(res.length).to.equal(3) - }) - }) -}) diff --git a/test/ping.spec.js b/test/ping.spec.js deleted file mode 100644 index 01636ed60..000000000 --- a/test/ping.spec.js +++ /dev/null @@ -1,94 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const { expect } = require('interface-ipfs-core/src/utils/mocha') -const pull = require('pull-stream/pull') -const collect = require('pull-stream/sinks/collect') - -const f = require('./utils/factory') - -// Determine if a ping response object is a pong, or something else, like a status message -function isPong (pingResponse) { - return Boolean(pingResponse && pingResponse.success && !pingResponse.text) -} - -describe('.ping', function () { - this.timeout(20 * 1000) - - let ipfs - let other - let otherId - - before(async function () { - this.timeout(30 * 1000) // slow CI - - ipfs = (await f.spawn()).api - other = (await f.spawn()).api - - const ma = (await ipfs.id()).addresses[0] - await other.swarm.connect(ma) - - otherId = (await other.id()).id - }) - - after(() => f.clean()) - - it('.ping with default count', async () => { - const res = await ipfs.ping(otherId) - expect(res).to.be.an('array') - expect(res.filter(isPong)).to.have.lengthOf(10) - res.forEach(packet => { - expect(packet).to.have.keys('success', 'time', 'text') - expect(packet.time).to.be.a('number') - }) - const resultMsg = res.find(packet => packet.text.includes('Average latency')) - expect(resultMsg).to.exist() - }) - - it('.ping with count = 2', async () => { - const res = await ipfs.ping(otherId, { count: 2 }) - expect(res).to.be.an('array') - expect(res.filter(isPong)).to.have.lengthOf(2) - res.forEach(packet => { - expect(packet).to.have.keys('success', 'time', 'text') - expect(packet.time).to.be.a('number') - }) - const resultMsg = res.find(packet => packet.text.includes('Average latency')) - expect(resultMsg).to.exist() - }) - - it('.pingPullStream', (done) => { - pull( - ipfs.pingPullStream(otherId, { count: 2 }), - collect((err, data) => { - expect(err).to.not.exist() - expect(data).to.be.an('array') - expect(data.filter(isPong)).to.have.lengthOf(2) - data.forEach(packet => { - expect(packet).to.have.keys('success', 'time', 'text') - expect(packet.time).to.be.a('number') - }) - const resultMsg = data.find(packet => packet.text.includes('Average latency')) - expect(resultMsg).to.exist() - done() - }) - ) - }) - - it('.pingReadableStream', (done) => { - let packetNum = 0 - ipfs.pingReadableStream(otherId, { count: 2 }) - .on('data', data => { - expect(data).to.be.an('object') - expect(data).to.have.keys('success', 'time', 'text') - if (isPong(data)) packetNum++ - }) - .on('error', err => { - expect(err).not.to.exist() - }) - .on('end', () => { - expect(packetNum).to.equal(2) - done() - }) - }) -}) diff --git a/test/repo.spec.js b/test/repo.spec.js deleted file mode 100644 index 21482135d..000000000 --- a/test/repo.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const { expect } = require('interface-ipfs-core/src/utils/mocha') -const f = require('./utils/factory') - -describe('.repo', function () { - this.timeout(50 * 1000) // slow CI - - let ipfs - - before(async () => { - ipfs = (await f.spawn()).api - }) - - after(() => f.clean()) - - it('.repo.gc', async () => { - const res = await ipfs.repo.gc() - - expect(res).to.exist() - }) - - it('.repo.stat', async () => { - const res = await ipfs.repo.stat() - - expect(res).to.exist() - expect(res).to.have.a.property('numObjects') - expect(res).to.have.a.property('repoSize') - }) - - it('.repo.version', async () => { - const res = await ipfs.repo.version() - - expect(res).to.exist() - }) -}) diff --git a/test/stats.spec.js b/test/stats.spec.js deleted file mode 100644 index d60aaa330..000000000 --- a/test/stats.spec.js +++ /dev/null @@ -1,53 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const { expect } = require('interface-ipfs-core/src/utils/mocha') -const f = require('./utils/factory') - -describe('stats', function () { - this.timeout(50 * 1000) // slow CI - - let ipfs - - before(async () => { - ipfs = (await f.spawn()).api - }) - - after(() => f.clean()) - - it('.stats.bitswap', async () => { - const res = await ipfs.stats.bitswap() - - expect(res).to.exist() - expect(res).to.have.a.property('provideBufLen') - expect(res).to.have.a.property('wantlist') - expect(res).to.have.a.property('peers') - expect(res).to.have.a.property('blocksReceived') - expect(res).to.have.a.property('dataReceived') - expect(res).to.have.a.property('blocksSent') - expect(res).to.have.a.property('dataSent') - expect(res).to.have.a.property('dupBlksReceived') - expect(res).to.have.a.property('dupDataReceived') - }) - - it('.stats.bw', async () => { - const res = await ipfs.stats.bw() - - expect(res).to.exist() - expect(res).to.have.a.property('totalIn') - expect(res).to.have.a.property('totalOut') - expect(res).to.have.a.property('rateIn') - expect(res).to.have.a.property('rateOut') - }) - - it('.stats.repo', async () => { - const res = await ipfs.stats.repo() - - expect(res).to.exist() - expect(res).to.have.a.property('numObjects') - expect(res).to.have.a.property('repoSize') - expect(res).to.have.a.property('repoPath') - expect(res).to.have.a.property('version') - expect(res).to.have.a.property('storageMax') - }) -})