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

Commit

Permalink
feat: add bitswap.unwant javascript spec
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored and alanshaw committed Jun 18, 2018
1 parent c291ca9 commit d75a361
Showing 1 changed file with 36 additions and 15 deletions.
51 changes: 36 additions & 15 deletions js/src/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const series = require('async/series')
const expect = chai.expect
const statsTests = require('./utils/stats')
const spawn = require('./utils/spawn')
Expand All @@ -10,7 +11,8 @@ const CID = require('cids')

module.exports = (common) => {
describe('.bitswap online', () => {
let ipfs
let ipfsA
let ipfsB
let withGo
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'

Expand All @@ -21,44 +23,63 @@ module.exports = (common) => {

common.setup((err, factory) => {
expect(err).to.not.exist()
spawn.spawnNodeWithId(factory, (err, node) => {
expect(err).to.not.exist()
ipfs = node
withGo = node.peerId.agentVersion.startsWith('go-ipfs')
ipfs.block.get(key)
.then(() => {})
.catch(() => {})
done()
})
series([
(cb) => spawn.spawnNodeWithId(factory, (err, node) => {
expect(err).to.not.exist()
ipfsA = node
withGo = node.peerId.agentVersion.startsWith('go-ipfs')
cb()
//ipfsA.block.get(key)
//.then(() => {})
//.catch(() => {})
//cb()
}),
(cb) => spawn.spawnNodeWithId(factory, (err, node) => {
expect(err).to.not.exist()
ipfsB = node
ipfsB.block.get(new CID(key))
.then(() => {})
.catch(() => {})
ipfsA.swarm.connect(node.peerId.addresses[0], cb)
})
], done)
})
})

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

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

ipfs.bitswap.stat((err, stats) => {
ipfsA.bitswap.stat((err, stats) => {
expect(err).to.not.exist()
statsTests.expectIsBitswap(err, stats)
done()
})
})

it('.wantlist', (done) => {
ipfs.bitswap.wantlist((err, list) => {
ipfsA.bitswap.wantlist((err, list) => {
expect(err).to.not.exist()
expect(list.Keys).to.have.length(1);
expect(list.Keys[0]['/']).to.equal(key)
done()
})
})

it('.wantlist peerid', (done) => {
ipfsA.bitswap.wantlist(ipfsBId, (err, list) => {
expect(err).to.not.exist()
expect(list.Keys[0]['/']).to.equal(key)
done()
})
})

it('.unwant', function (done) {
if (withGo) {
this.skip()
}
ipfs.bitswap.unwant(key, (err) => {
ipfsA.bitswap.unwant(key, (err) => {
expect(err).to.not.exist();
ipfs.bitswap.wantlist((err, list) => {
ipfsA.bitswap.wantlist((err, list) => {
expect(err).to.not.exist();
expect(list.Keys).to.be.empty()
done()
Expand Down

0 comments on commit d75a361

Please sign in to comment.