diff --git a/src/bitswap/unwant.js b/src/bitswap/unwant.js index 267568ee1..aa3c575cf 100644 --- a/src/bitswap/unwant.js +++ b/src/bitswap/unwant.js @@ -1,6 +1,7 @@ 'use strict' const promisify = require('promisify-es6') +const CID = require('cids') module.exports = (send) => { return promisify((args, opts, callback) => { @@ -8,6 +9,25 @@ module.exports = (send) => { callback = opts opts = {} } + + // Mirrors block.get's parsing of the CID + let cid + try { + if (CID.isCID(args)) { + cid = args + args = cid.toBaseEncodedString() + } else if (Buffer.isBuffer(args)) { + cid = new CID(args) + args = cid.toBaseEncodedString() + } else if (typeof args === 'string') { + cid = new CID(args) + } else { + return callback(new Error('invalid argument')) + } + } catch (err) { + return callback(err) + } + send({ path: 'bitswap/unwant', args: args, diff --git a/test/bitswap.spec.js b/test/bitswap.spec.js deleted file mode 100644 index 2f7844289..000000000 --- a/test/bitswap.spec.js +++ /dev/null @@ -1,69 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - -const IPFSApi = require('../src') - -const f = require('./utils/factory') - -describe('.bitswap', function () { - this.timeout(20 * 1000) // slow CI - - let ipfs - let ipfsd = null - - before(function (done) { - this.timeout(20 * 1000) // slow CI - - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = IPFSApi(_ipfsd.apiAddr) - done() - }) - }) - - after((done) => { - if (!ipfsd) return done() - ipfsd.stop(done) - }) - - it('.wantlist', (done) => { - ipfs.bitswap.wantlist((err, res) => { - expect(err).to.not.exist() - expect(res).to.have.to.eql({ - Keys: [] - }) - done() - }) - }) - - it('.stat', (done) => { - ipfs.bitswap.stat((err, res) => { - expect(err).to.not.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') - - done() - }) - }) - - it('.unwant', (done) => { - const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - ipfs.bitswap.unwant(key, (err) => { - expect(err).to.not.exist() - done() - }) - }) -}) diff --git a/test/interface/bitswap.spec.js b/test/interface/bitswap.spec.js new file mode 100644 index 000000000..82eaacb6d --- /dev/null +++ b/test/interface/bitswap.spec.js @@ -0,0 +1,32 @@ +/* eslint-env mocha */ + +'use strict' + +const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + +const IPFSApi = require('../../src') +const f = require('../utils/factory') + +const nodes = [] +const common = { + setup: function (callback) { + callback(null, { + spawnNode: (cb) => { + f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) + } +} + +test.bitswap(common)