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

Commit 2f0bb01

Browse files
committed
fix(bitswap.unwant) Parse CID from arg
CID parsing is done just like block.add does This also removes the local tests and moves reliance on testing to the tests that are being added to interface-ipfs-core
1 parent 5e7b7c4 commit 2f0bb01

File tree

3 files changed

+52
-69
lines changed

3 files changed

+52
-69
lines changed

src/bitswap/unwant.js

+20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4+
const CID = require('cids')
45

56
module.exports = (send) => {
67
return promisify((args, opts, callback) => {
78
if (typeof (opts) === 'function') {
89
callback = opts
910
opts = {}
1011
}
12+
13+
// Mirrors block.get's parsing of the CID
14+
let cid
15+
try {
16+
if (CID.isCID(args)) {
17+
cid = args
18+
args = cid.toBaseEncodedString()
19+
} else if (Buffer.isBuffer(args)) {
20+
cid = new CID(args)
21+
args = cid.toBaseEncodedString()
22+
} else if (typeof args === 'string') {
23+
cid = new CID(args)
24+
} else {
25+
return callback(new Error('invalid argument'))
26+
}
27+
} catch (err) {
28+
return callback(err)
29+
}
30+
1131
send({
1232
path: 'bitswap/unwant',
1333
args: args,

test/bitswap.spec.js

-69
This file was deleted.

test/interface/bitswap.spec.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-env mocha */
2+
3+
'use strict'
4+
5+
const test = require('interface-ipfs-core')
6+
const parallel = require('async/parallel')
7+
8+
const IPFSApi = require('../../src')
9+
const f = require('../utils/factory')
10+
11+
const nodes = []
12+
const common = {
13+
setup: function (callback) {
14+
callback(null, {
15+
spawnNode: (cb) => {
16+
f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => {
17+
if (err) {
18+
return cb(err)
19+
}
20+
21+
nodes.push(_ipfsd)
22+
cb(null, IPFSApi(_ipfsd.apiAddr))
23+
})
24+
}
25+
})
26+
},
27+
teardown: function (callback) {
28+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
29+
}
30+
}
31+
32+
test.bitswap(common)

0 commit comments

Comments
 (0)