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

Commit

Permalink
feat(tests) move some bitswap tests to interface
Browse files Browse the repository at this point in the history
Will require including the version of interface-ipfs-core that
they are moved to
  • Loading branch information
wraithgar committed Apr 26, 2018
1 parent 5a46bdb commit c582097
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 71 deletions.
71 changes: 0 additions & 71 deletions test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,75 +247,4 @@ skipOnWindows('bitswap', function () {
})
})
})

describe('api', () => {
let node

before(function (done) {
this.timeout(40 * 1000)

node = new IPFS({
repo: createTempRepo(),
start: false,
config: {
Addresses: {
Swarm: []
},
Discovery: {
MDNS: {
Enabled: false
}
}
}
})
node.on('ready', () => done())
})

describe('while offline', () => {
it('.wantlist throws if offline', () => {
expect(() => node.bitswap.wantlist()).to.throw(/online/)
})

it('.stat gives error while offline', () => {
node.bitswap.stat((err, stats) => {
expect(err).to.exist()
expect(stats).to.not.exist()
})
})

it('.unwant throws if offline', () => {
expect(() => node.bitswap.unwant('my key')).to.throw(/online/)
})
})

describe('while online', () => {
before(function (done) {
this.timeout(80 * 1000)

node.start(() => done())
})

it('.wantlist returns an array of wanted blocks', () => {
expect(node.bitswap.wantlist()).to.eql([])
})

it('returns the stats', (done) => {
node.bitswap.stat((err, stats) => {
expect(err).to.not.exist()
expect(stats).to.have.keys([
'blocksReceived',
'blocksSent',
'dataReceived',
'dataSent',
'wantlist',
'peers',
'provideBufLen',
'dupDataReceived',
'dupBlksReceived'
])
done()
})
})
})
})
})
35 changes: 35 additions & 0 deletions test/core/interface/bitswap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-env mocha */
'use strict'

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

const IPFS = require('../../../src')

const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })

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

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

test.bitswap(common)

0 comments on commit c582097

Please sign in to comment.