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

Commit ef0dc25

Browse files
committed
feat: add peerId param to bitswap.wantlist
1 parent 8c6181c commit ef0dc25

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

js/src/bitswap.js

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
const chai = require('chai')
44
const dirtyChai = require('dirty-chai')
5+
const series = require('async/series')
56
const expect = chai.expect
67
const statsTests = require('./utils/stats')
78
chai.use(dirtyChai)
89
const CID = require('cids')
910

1011
module.exports = (common) => {
1112
describe('.bitswap online', () => {
12-
let ipfs
13+
let ipfsA
14+
let ipfsB
15+
let ipfsBId
1316
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
1417

1518
before(function (done) {
@@ -19,38 +22,64 @@ module.exports = (common) => {
1922

2023
common.setup((err, factory) => {
2124
expect(err).to.not.exist()
22-
factory.spawnNode((err, node) => {
23-
expect(err).to.not.exist()
24-
ipfs = node
25-
ipfs.block.get(new CID(key))
26-
.then(() => {})
27-
.catch(() => {})
28-
setTimeout(done, 250)
29-
})
25+
series([
26+
(cb) => factory.spawnNode((err, node) => {
27+
expect(err).to.not.exist()
28+
ipfsA = node
29+
cb()
30+
}),
31+
(cb) => factory.spawnNode((err, node) => {
32+
expect(err).to.not.exist()
33+
ipfsB = node
34+
cb()
35+
}),
36+
(cb) => {
37+
ipfsB.id((err, id) => {
38+
expect(err).to.not.exist()
39+
const ipfsBAddr = id.addresses[0]
40+
ipfsBId = id.id
41+
ipfsA.swarm.connect(ipfsBAddr, cb)
42+
})
43+
},
44+
(cb) => {
45+
ipfsB.block.get(new CID(key))
46+
.then(() => {})
47+
.catch(() => {})
48+
setTimeout(cb, 500)
49+
}
50+
], done)
3051
})
3152
})
3253

3354
after((done) => common.teardown(done))
3455

3556
it('.stat', (done) => {
3657

37-
ipfs.bitswap.stat((err, stats) => {
58+
ipfsA.bitswap.stat((err, stats) => {
3859
statsTests.expectIsBitswap(err, stats)
3960
done()
4061
})
4162
})
4263

4364
it('.wantlist', (done) => {
44-
ipfs.bitswap.wantlist((err, list) => {
65+
ipfsB.bitswap.wantlist((err, list) => {
66+
expect(err).to.not.exist()
67+
expect(list[0].cid.toBaseEncodedString()).to.equal(key)
68+
done()
69+
})
70+
})
71+
72+
it('.wantlist peerid', (done) => {
73+
ipfsA.bitswap.wantlist(ipfsBId, (err, list) => {
4574
expect(err).to.not.exist()
4675
expect(list[0].cid.toBaseEncodedString()).to.equal(key)
4776
done()
4877
})
4978
})
5079

5180
it('.unwant', (done) => {
52-
ipfs.bitswap.unwant(new CID(key), (err) => {
53-
ipfs.bitswap.wantlist((err, list) => {
81+
ipfsA.bitswap.unwant(new CID(key), (err) => {
82+
ipfsA.bitswap.wantlist((err, list) => {
5483
expect(list).to.be.empty()
5584
done()
5685
})

0 commit comments

Comments
 (0)