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

Commit 51b06b2

Browse files
Merge pull request #264 from ipfs/feat/bitswap
feat: Add bitswap comands
2 parents 9086663 + a3fe500 commit 51b06b2

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

src/api/bitswap.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
const argCommand = require('../cmd-helpers').argCommand
4+
5+
module.exports = (send) => {
6+
return {
7+
wantlist (cb) {
8+
return send('bitswap/wantlist', {}, null, null, cb)
9+
},
10+
stat (cb) {
11+
return send('bitswap/stat', {}, null, null, cb)
12+
},
13+
unwant: argCommand(send, 'bitswap/unwant')
14+
}
15+
}

src/load-commands.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
function requireCommands () {
44
return {
55
add: require('./api/add'),
6+
bitswap: require('./api/bitswap'),
67
block: require('./api/block'),
78
cat: require('./api/cat'),
89
commands: require('./api/commands'),

test/api/bitswap.spec.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* eslint-env mocha */
2+
/* globals apiClients */
3+
'use strict'
4+
5+
const expect = require('chai').expect
6+
7+
describe('.bitswap', () => {
8+
it('.wantlist', (done) => {
9+
apiClients.a.bitswap.wantlist((err, res) => {
10+
expect(err).to.not.exist
11+
expect(res).to.have.to.be.eql({
12+
Keys: null
13+
})
14+
done()
15+
})
16+
})
17+
18+
it('.stat', (done) => {
19+
apiClients.a.bitswap.stat((err, res) => {
20+
expect(err).to.not.exist
21+
expect(res).to.have.property('BlocksReceived')
22+
expect(res).to.have.property('DupBlksReceived')
23+
expect(res).to.have.property('DupDataReceived')
24+
expect(res).to.have.property('Peers')
25+
expect(res).to.have.property('ProvideBufLen')
26+
expect(res).to.have.property('Wantlist')
27+
28+
done()
29+
})
30+
})
31+
32+
it('.unwant', (done) => {
33+
const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
34+
apiClients.a.bitswap.unwant(key, (err) => {
35+
expect(err).to.not.exist
36+
done()
37+
})
38+
})
39+
40+
describe('promise', () => {
41+
it('.wantlist', () => {
42+
return apiClients.a.bitswap.wantlist()
43+
.then((res) => {
44+
expect(res).to.have.to.be.eql({
45+
Keys: null
46+
})
47+
})
48+
})
49+
50+
it('.stat', () => {
51+
return apiClients.a.bitswap.stat()
52+
.then((res) => {
53+
expect(res).to.have.property('BlocksReceived')
54+
expect(res).to.have.property('DupBlksReceived')
55+
expect(res).to.have.property('DupDataReceived')
56+
expect(res).to.have.property('Peers')
57+
expect(res).to.have.property('ProvideBufLen')
58+
expect(res).to.have.property('Wantlist')
59+
})
60+
})
61+
62+
it('.unwant', () => {
63+
const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
64+
return apiClients.a.bitswap.unwant(key)
65+
})
66+
})
67+
})

0 commit comments

Comments
 (0)