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

Some fixes regarding the Stats API #684

Merged
merged 2 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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