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

Commit 86d2600

Browse files
committed
feat: add bitswap.unwant javascript spec
1 parent 2df22b0 commit 86d2600

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed

SPEC/BITSWAP.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@
44
* [bitswap.unwant](#bitswapunwant)
55
* [bitswap.stat](#bitswapstat)
66

7-
#### `bitswap.wantlist`
7+
#### `unwant`
8+
9+
> Removes a given block from your wantlist
10+
11+
##### `Go` **WIP**
12+
13+
##### `JavaScript` - ipfs.bitswap.unwant(cid)
14+
15+
`cid` is a [cid][cid] which can be passed as:
16+
17+
- CID, a CID instance
18+
- String, the base58 encoded version of the multihash
19+
20+
### `bitswap.wantlist`
821

922
(not spec'ed yet)
1023

js/src/bitswap.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
'use strict'
2+
3+
const chai = require('chai')
4+
const dirtyChai = require('dirty-chai')
5+
const expect = chai.expect
6+
const statsTests = require('./utils/stats')
7+
chai.use(dirtyChai)
8+
const CID = require('cids')
9+
10+
module.exports = (common) => {
11+
describe('.bitswap online', () => {
12+
let ipfs
13+
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
14+
15+
before(function (done) {
16+
// CI takes longer to instantiate the daemon, so we need to increase the
17+
// timeout for the before step
18+
this.timeout(60 * 1000)
19+
20+
common.setup((err, factory) => {
21+
expect(err).to.not.exist()
22+
factory.spawnNode((err, node) => {
23+
expect(err).to.not.exist()
24+
ipfs = node
25+
ipfs.block.get(key)
26+
.then(() => {})
27+
.catch(() => {})
28+
setTimeout(done, 250)
29+
})
30+
})
31+
})
32+
33+
after((done) => common.teardown(done))
34+
35+
it('.stat', (done) => {
36+
37+
ipfs.bitswap.stat((err, stats) => {
38+
statsTests.expectIsBitswap(err, stats)
39+
done()
40+
})
41+
})
42+
43+
it('.wantlist', (done) => {
44+
ipfs.bitswap.wantlist((err, list) => {
45+
expect(err).to.not.exist()
46+
expect(list.Keys).to.have.length(1);
47+
expect(list.Keys[0]['/']).to.equal(key)
48+
done()
49+
})
50+
})
51+
52+
it('.unwant', (done) => {
53+
ipfs.bitswap.unwant(key, (err) => {
54+
expect(err).to.not.exist();
55+
ipfs.bitswap.wantlist((err, list) => {
56+
expect(err).to.not.exist();
57+
expect(list.Keys).to.be.empty()
58+
done()
59+
})
60+
})
61+
})
62+
})
63+
64+
describe('.bitswap offline', () => {
65+
let ipfs
66+
67+
before(function (done) {
68+
// CI takes longer to instantiate the daemon, so we need to increase the
69+
// timeout for the before step
70+
this.timeout(60 * 1000)
71+
72+
common.setup((err, factory) => {
73+
expect(err).to.not.exist()
74+
factory.spawnNode((err, node) => {
75+
expect(err).to.not.exist()
76+
ipfs = node
77+
ipfs.id((err, id) => {
78+
expect(err).to.not.exist()
79+
ipfs.stop((err) => {
80+
// TODO: go-ipfs returns an error, https://github.com/ipfs/go-ipfs/issues/4078
81+
if (!id.agentVersion.startsWith('go-ipfs')) {
82+
expect(err).to.not.exist()
83+
}
84+
done()
85+
})
86+
})
87+
})
88+
})
89+
})
90+
91+
it('.stat gives error while offline', () => {
92+
ipfs.bitswap.stat((err, stats) => {
93+
expect(err).to.match(/online mode/)
94+
expect(stats).to.not.exist()
95+
})
96+
})
97+
98+
it('.wantlist gives error if offline', () => {
99+
ipfs.bitswap.wantlist((err, list) => {
100+
expect(err).to.match(/online mode/)
101+
expect(list).to.not.exist()
102+
})
103+
})
104+
105+
it('.unwant gives error if offline', () => {
106+
expect(() => ipfs.bitswap.unwant(key, (err) => {
107+
expect(err).to.match(/online mode/)
108+
}))
109+
})
110+
})
111+
}

js/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ exports.repo = require('./repo')
1919
exports.bootstrap = require('./bootstrap')
2020
exports.types = require('./types')
2121
exports.util = require('./util')
22+
exports.bitswap = require('./bitswap')

0 commit comments

Comments
 (0)