This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from ipfs/feat/bitswap
feat: Add bitswap comands
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
}) |