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

Commit

Permalink
fix: update stats API (#684)
Browse files Browse the repository at this point in the history
* implement stats

* update tests
  • Loading branch information
hacdias authored and daviddias committed Jan 30, 2018
1 parent 118456e commit 4f7999d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
18 changes: 16 additions & 2 deletions src/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, {
provideBufLen: res.ProvideBufLen,
wantlist: res.Wantlist,
peers: res.Peers,
blocksReceived: res.BlocksReceived,
dataReceived: res.DataReceived,
blocksSent: res.BlocksSent,
dataSent: res.DataSent,
dupBlksReceived: res.DupBlksReceived,
dupDataReceived: res.DupDataReceived
})
}

module.exports = (send) => {
return promisify((callback) => {
send({
send.andTransform({
path: 'bitswap/stat'
}, callback)
}, transform, callback)
})
}
15 changes: 9 additions & 6 deletions test/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ describe('.bitswap', function () {
it('.stat', (done) => {
ipfs.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')
expect(res).to.have.a.property('provideBufLen')
expect(res).to.have.a.property('wantlist')
expect(res).to.have.a.property('peers')
expect(res).to.have.a.property('blocksReceived')
expect(res).to.have.a.property('dataReceived')
expect(res).to.have.a.property('blocksSent')
expect(res).to.have.a.property('dataSent')
expect(res).to.have.a.property('dupBlksReceived')
expect(res).to.have.a.property('dupDataReceived')

done()
})
Expand Down

0 comments on commit 4f7999d

Please sign in to comment.