diff --git a/package.json b/package.json index fda509b7e..3b720b0fe 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "eslint-plugin-react": "^7.9.1", "go-ipfs-dep": "~0.4.15", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.67.0", + "interface-ipfs-core": "~0.68.1", "ipfsd-ctl": "~0.37.3", "pull-stream": "^3.6.8", "socket.io": "^2.1.1", diff --git a/src/bitswap/unwant.js b/src/bitswap/unwant.js index 267568ee1..865fbc27b 100644 --- a/src/bitswap/unwant.js +++ b/src/bitswap/unwant.js @@ -1,16 +1,24 @@ 'use strict' const promisify = require('promisify-es6') +const CID = require('cids') module.exports = (send) => { - return promisify((args, opts, callback) => { + return promisify((cid, opts, callback) => { if (typeof (opts) === 'function') { callback = opts opts = {} } + + try { + cid = new CID(cid) + } catch (err) { + return callback(err) + } + send({ path: 'bitswap/unwant', - args: args, + args: cid.toBaseEncodedString(), qs: opts }, callback) }) diff --git a/src/bitswap/wantlist.js b/src/bitswap/wantlist.js index c96aaaaac..6cd1e3868 100644 --- a/src/bitswap/wantlist.js +++ b/src/bitswap/wantlist.js @@ -1,11 +1,30 @@ 'use strict' const promisify = require('promisify-es6') +const CID = require('cids') module.exports = (send) => { - return promisify((callback) => { + return promisify((peerId, opts, callback) => { + if (typeof (peerId) === 'function') { + callback = peerId + opts = {} + peerId = null + } else if (typeof (opts) === 'function') { + callback = opts + opts = {} + } + + if (peerId) { + try { + opts.peer = new CID(peerId).toBaseEncodedString() + } catch (err) { + return callback(err) + } + } + send({ - path: 'bitswap/wantlist' + path: 'bitswap/wantlist', + qs: opts }, callback) }) } 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)