Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feat: Add bitswap comands #264

Merged
merged 2 commits into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/api/bitswap.js
Original file line number Diff line number Diff line change
@@ -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')
}
}
1 change: 1 addition & 0 deletions src/load-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
67 changes: 67 additions & 0 deletions test/api/bitswap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* 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.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()
})
})

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.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')
})
})

it('.unwant', () => {
const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
return apiClients.a.bitswap.unwant(key)
})
})
})