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

Commit cb22abe

Browse files
feat: Add bitswap comands
1 parent 9086663 commit cb22abe

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

src/api/bitswap.js

+15
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

+1
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

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.to.be.eql({
22+
BlocksReceived: 0,
23+
DupBlksReceived: 0,
24+
DupDataReceived: 0,
25+
Peers: null,
26+
ProvideBufLen: 0,
27+
Wantlist: null
28+
})
29+
done()
30+
})
31+
})
32+
33+
it('.unwant', (done) => {
34+
const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
35+
apiClients.a.bitswap.unwant(key, (err) => {
36+
expect(err).to.not.exist
37+
done()
38+
})
39+
})
40+
41+
describe('promise', () => {
42+
it('.wantlist', () => {
43+
return apiClients.a.bitswap.wantlist()
44+
.then((res) => {
45+
expect(res).to.have.to.be.eql({
46+
Keys: null
47+
})
48+
})
49+
})
50+
51+
it('.stat', () => {
52+
return apiClients.a.bitswap.stat()
53+
.then((res) => {
54+
expect(res).to.have.to.be.eql({
55+
BlocksReceived: 0,
56+
DupBlksReceived: 0,
57+
DupDataReceived: 0,
58+
Peers: null,
59+
ProvideBufLen: 0,
60+
Wantlist: null
61+
})
62+
})
63+
})
64+
65+
it('.unwant', () => {
66+
const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
67+
return apiClients.a.bitswap.unwant(key)
68+
})
69+
})
70+
})

0 commit comments

Comments
 (0)