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

fix(bitswap.unwant) parse CID from arg just like block.add does #754

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/bitswap/unwant.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
'use strict'

const promisify = require('promisify-es6')
const CID = require('cids')

module.exports = (send) => {
return promisify((args, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

// Mirrors block.get's parsing of the CID
let cid
try {
if (CID.isCID(args)) {
cid = args
args = cid.toBaseEncodedString()
} else if (Buffer.isBuffer(args)) {
cid = new CID(args)
args = cid.toBaseEncodedString()
} else if (typeof args === 'string') {
cid = new CID(args)
} else {
return callback(new Error('invalid argument'))
}
} catch (err) {
return callback(err)
}

send({
path: 'bitswap/unwant',
args: args,
Expand Down
69 changes: 0 additions & 69 deletions test/bitswap.spec.js

This file was deleted.

32 changes: 32 additions & 0 deletions test/interface/bitswap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-env mocha */

'use strict'

const test = require('interface-ipfs-core')
const parallel = require('async/parallel')

const IPFSApi = require('../../src')
const f = require('../utils/factory')

const nodes = []
const common = {
setup: function (callback) {
callback(null, {
spawnNode: (cb) => {
f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => {
if (err) {
return cb(err)
}

nodes.push(_ipfsd)
cb(null, IPFSApi(_ipfsd.apiAddr))
})
}
})
},
teardown: function (callback) {
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
}
}

test.bitswap(common)