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

Commit 8be98df

Browse files
committed
fix(test) fix cli tests for both bitswap.unwant and bitswap.wantlist peerId
1 parent 371bb56 commit 8be98df

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

src/cli/commands/bitswap/stat.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
const CID = require('cids')
43
const print = require('../../utils').print
54

65
module.exports = {
@@ -17,11 +16,7 @@ module.exports = {
1716
}
1817

1918
stats.wantlist = stats.wantlist || []
20-
stats.wantlist = stats.wantlist.map((entry) => {
21-
const buf = Buffer.from(entry.cid.hash.data)
22-
const cid = new CID(entry.cid.version, entry.cid.codec, buf)
23-
return cid.toBaseEncodedString()
24-
})
19+
stats.wantlist = stats.wantlist.map(entry => entry['/'])
2520
stats.peers = stats.peers || []
2621

2722
print(`bitswap status

src/cli/commands/bitswap/wantlist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const print = require('../../utils').print
44

55
module.exports = {
6-
command: 'wantlist',
6+
command: 'wantlist [peer]',
77

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

src/cli/commands/block/get.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ module.exports = {
1919
}
2020

2121
if (block) {
22-
process.stdout.write(block.data)
22+
print(block.data)
2323
} else {
24-
process.stderr.write('Block was unwanted before it could be remotely retrieved')
24+
print('Block was unwanted before it could be remotely retrieved')
2525
}
2626
})
2727
}

src/http/api/resources/bitswap.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ exports = module.exports
99
exports.wantlist = {
1010
handler: (request, reply) => {
1111
const peerId = request.query.arg
12-
let list
1312
request.server.app.ipfs.bitswap.wantlist(peerId, (err, list) => {
1413
if (err) {
1514
return reply(boom.badRequest(err))

test/cli/bitswap.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33

44
const expect = require('chai').expect
55
const runOn = require('../utils/on-and-off').on
6+
const PeerId = require('peer-id')
67

78
describe('bitswap', () => runOn((thing) => {
89
let ipfs
10+
let peerId
911
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
1012

1113
before((done) => {
1214
ipfs = thing.ipfs
1315
ipfs('block get ' + key)
1416
.then(() => {})
1517
.catch(() => {})
16-
setTimeout(done, 250)
18+
PeerId.create((err, peer) => {
19+
expect(err).to.not.exist()
20+
peerId = peer.toB58String()
21+
setTimeout(done, 250)
22+
})
1723
})
1824

1925
it('wantlist', function () {
@@ -23,6 +29,13 @@ describe('bitswap', () => runOn((thing) => {
2329
})
2430
})
2531

32+
it('wantlist peerid', function () {
33+
this.timeout(20 * 1000)
34+
return ipfs('bitswap wantlist ' + peerId).then((out) => {
35+
expect(out).to.eql('')
36+
})
37+
})
38+
2639
it('stat', function () {
2740
this.timeout(20 * 1000)
2841

0 commit comments

Comments
 (0)