Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix(test) fix cli tests for both bitswap.unwant and bitswap.wantlist …
Browse files Browse the repository at this point in the history
…peerId
  • Loading branch information
wraithgar committed Jun 14, 2018
1 parent 371bb56 commit 2733a12
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
7 changes: 1 addition & 6 deletions src/cli/commands/bitswap/stat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const CID = require('cids')
const print = require('../../utils').print

module.exports = {
Expand All @@ -17,11 +16,7 @@ module.exports = {
}

stats.wantlist = stats.wantlist || []
stats.wantlist = stats.wantlist.map((entry) => {
const buf = Buffer.from(entry.cid.hash.data)
const cid = new CID(entry.cid.version, entry.cid.codec, buf)
return cid.toBaseEncodedString()
})
stats.wantlist = stats.wantlist.map(entry => entry['/'])
stats.peers = stats.peers || []

print(`bitswap status
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/bitswap/wantlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const print = require('../../utils').print

module.exports = {
command: 'wantlist',
command: 'wantlist [peer]',

describe: 'Print out all blocks currently on the bitswap wantlist for the local peer.',

Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/block/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ module.exports = {
}

if (block) {
process.stdout.write(block.data)
print(block.data)
} else {
process.stderr.write('Block was unwanted before it could be remotely retrieved')
print('Block was unwanted before it could be remotely retrieved')
}
})
}
Expand Down
1 change: 0 additions & 1 deletion src/http/api/resources/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ exports = module.exports
exports.wantlist = {
handler: (request, reply) => {
const peerId = request.query.arg
let list
request.server.app.ipfs.bitswap.wantlist(peerId, (err, list) => {
if (err) {
return reply(boom.badRequest(err))
Expand Down
15 changes: 14 additions & 1 deletion test/cli/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@

const expect = require('chai').expect
const runOn = require('../utils/on-and-off').on
const PeerId = require('peer-id')

describe('bitswap', () => runOn((thing) => {
let ipfs
let peerId
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'

before((done) => {
ipfs = thing.ipfs
ipfs('block get ' + key)
.then(() => {})
.catch(() => {})
setTimeout(done, 250)
PeerId.create((err, peer) => {
expect(err).to.not.exist()
peerId = peer.toB58String()
setTimeout(done, 250)
})
})

it('wantlist', function () {
Expand All @@ -23,6 +29,13 @@ describe('bitswap', () => runOn((thing) => {
})
})

it('wantlist peerid', function () {
this.timeout(20 * 1000)
return ipfs('bitswap wantlist ' + peerId).then((out) => {
expect(out).to.eql('')
})
})

it('stat', function () {
this.timeout(20 * 1000)

Expand Down

0 comments on commit 2733a12

Please sign in to comment.