From cb22abe0f8be9532ef4b344c81bb20c832e8629d Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Fri, 6 May 2016 16:42:06 +0200 Subject: [PATCH 1/2] feat: Add bitswap comands --- src/api/bitswap.js | 15 +++++++++ src/load-commands.js | 1 + test/api/bitswap.spec.js | 70 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 src/api/bitswap.js create mode 100644 test/api/bitswap.spec.js diff --git a/src/api/bitswap.js b/src/api/bitswap.js new file mode 100644 index 000000000..c2f9749b4 --- /dev/null +++ b/src/api/bitswap.js @@ -0,0 +1,15 @@ +'use strict' + +const argCommand = require('../cmd-helpers').argCommand + +module.exports = (send) => { + return { + wantlist (cb) { + return send('bitswap/wantlist', {}, null, null, cb) + }, + stat (cb) { + return send('bitswap/stat', {}, null, null, cb) + }, + unwant: argCommand(send, 'bitswap/unwant') + } +} diff --git a/src/load-commands.js b/src/load-commands.js index fea6ff39d..fc5ee614b 100644 --- a/src/load-commands.js +++ b/src/load-commands.js @@ -3,6 +3,7 @@ function requireCommands () { return { add: require('./api/add'), + bitswap: require('./api/bitswap'), block: require('./api/block'), cat: require('./api/cat'), commands: require('./api/commands'), diff --git a/test/api/bitswap.spec.js b/test/api/bitswap.spec.js new file mode 100644 index 000000000..86660a0d2 --- /dev/null +++ b/test/api/bitswap.spec.js @@ -0,0 +1,70 @@ +/* eslint-env mocha */ +/* globals apiClients */ +'use strict' + +const expect = require('chai').expect + +describe('.bitswap', () => { + it('.wantlist', (done) => { + apiClients.a.bitswap.wantlist((err, res) => { + expect(err).to.not.exist + expect(res).to.have.to.be.eql({ + Keys: null + }) + done() + }) + }) + + it('.stat', (done) => { + apiClients.a.bitswap.stat((err, res) => { + expect(err).to.not.exist + expect(res).to.have.to.be.eql({ + BlocksReceived: 0, + DupBlksReceived: 0, + DupDataReceived: 0, + Peers: null, + ProvideBufLen: 0, + Wantlist: null + }) + done() + }) + }) + + it('.unwant', (done) => { + const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' + apiClients.a.bitswap.unwant(key, (err) => { + expect(err).to.not.exist + done() + }) + }) + + describe('promise', () => { + it('.wantlist', () => { + return apiClients.a.bitswap.wantlist() + .then((res) => { + expect(res).to.have.to.be.eql({ + Keys: null + }) + }) + }) + + it('.stat', () => { + return apiClients.a.bitswap.stat() + .then((res) => { + expect(res).to.have.to.be.eql({ + BlocksReceived: 0, + DupBlksReceived: 0, + DupDataReceived: 0, + Peers: null, + ProvideBufLen: 0, + Wantlist: null + }) + }) + }) + + it('.unwant', () => { + const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' + return apiClients.a.bitswap.unwant(key) + }) + }) +}) From a3fe500c1dabcffde3a1c05911b7443caebacf35 Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Fri, 6 May 2016 16:51:03 +0200 Subject: [PATCH 2/2] fix --- test/api/bitswap.spec.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/test/api/bitswap.spec.js b/test/api/bitswap.spec.js index 86660a0d2..d3a8d4b81 100644 --- a/test/api/bitswap.spec.js +++ b/test/api/bitswap.spec.js @@ -18,14 +18,13 @@ describe('.bitswap', () => { it('.stat', (done) => { apiClients.a.bitswap.stat((err, res) => { expect(err).to.not.exist - expect(res).to.have.to.be.eql({ - BlocksReceived: 0, - DupBlksReceived: 0, - DupDataReceived: 0, - Peers: null, - ProvideBufLen: 0, - Wantlist: null - }) + expect(res).to.have.property('BlocksReceived') + expect(res).to.have.property('DupBlksReceived') + expect(res).to.have.property('DupDataReceived') + expect(res).to.have.property('Peers') + expect(res).to.have.property('ProvideBufLen') + expect(res).to.have.property('Wantlist') + done() }) }) @@ -51,14 +50,12 @@ describe('.bitswap', () => { it('.stat', () => { return apiClients.a.bitswap.stat() .then((res) => { - expect(res).to.have.to.be.eql({ - BlocksReceived: 0, - DupBlksReceived: 0, - DupDataReceived: 0, - Peers: null, - ProvideBufLen: 0, - Wantlist: null - }) + expect(res).to.have.property('BlocksReceived') + expect(res).to.have.property('DupBlksReceived') + expect(res).to.have.property('DupDataReceived') + expect(res).to.have.property('Peers') + expect(res).to.have.property('ProvideBufLen') + expect(res).to.have.property('Wantlist') }) })