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

Commit

Permalink
Merge pull request #264 from ipfs/feat/bitswap
Browse files Browse the repository at this point in the history
feat: Add bitswap comands
  • Loading branch information
dignifiedquire committed May 6, 2016
2 parents 9086663 + a3fe500 commit 51b06b2
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
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)
})
})
})

0 comments on commit 51b06b2

Please sign in to comment.