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

Commit c582097

Browse files
committed
feat(tests) move some bitswap tests to interface
Will require including the version of interface-ipfs-core that they are moved to
1 parent 5a46bdb commit c582097

File tree

2 files changed

+35
-71
lines changed

2 files changed

+35
-71
lines changed

test/core/bitswap.spec.js

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -247,75 +247,4 @@ skipOnWindows('bitswap', function () {
247247
})
248248
})
249249
})
250-
251-
describe('api', () => {
252-
let node
253-
254-
before(function (done) {
255-
this.timeout(40 * 1000)
256-
257-
node = new IPFS({
258-
repo: createTempRepo(),
259-
start: false,
260-
config: {
261-
Addresses: {
262-
Swarm: []
263-
},
264-
Discovery: {
265-
MDNS: {
266-
Enabled: false
267-
}
268-
}
269-
}
270-
})
271-
node.on('ready', () => done())
272-
})
273-
274-
describe('while offline', () => {
275-
it('.wantlist throws if offline', () => {
276-
expect(() => node.bitswap.wantlist()).to.throw(/online/)
277-
})
278-
279-
it('.stat gives error while offline', () => {
280-
node.bitswap.stat((err, stats) => {
281-
expect(err).to.exist()
282-
expect(stats).to.not.exist()
283-
})
284-
})
285-
286-
it('.unwant throws if offline', () => {
287-
expect(() => node.bitswap.unwant('my key')).to.throw(/online/)
288-
})
289-
})
290-
291-
describe('while online', () => {
292-
before(function (done) {
293-
this.timeout(80 * 1000)
294-
295-
node.start(() => done())
296-
})
297-
298-
it('.wantlist returns an array of wanted blocks', () => {
299-
expect(node.bitswap.wantlist()).to.eql([])
300-
})
301-
302-
it('returns the stats', (done) => {
303-
node.bitswap.stat((err, stats) => {
304-
expect(err).to.not.exist()
305-
expect(stats).to.have.keys([
306-
'blocksReceived',
307-
'blocksSent',
308-
'dataReceived',
309-
'dataSent',
310-
'wantlist',
311-
'peers',
312-
'provideBufLen',
313-
'dupDataReceived',
314-
'dupBlksReceived'
315-
])
316-
done()
317-
})
318-
})
319-
})
320-
})
321250
})

test/core/interface/bitswap.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
6+
7+
const IPFS = require('../../../src')
8+
9+
const DaemonFactory = require('ipfsd-ctl')
10+
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })
11+
12+
const nodes = []
13+
const common = {
14+
setup: function (callback) {
15+
callback(null, {
16+
spawnNode: (cb) => {
17+
df.spawn({
18+
initOptions: { bits: 512 }
19+
}, (err, _ipfsd) => {
20+
if (err) {
21+
return cb(err)
22+
}
23+
24+
nodes.push(_ipfsd)
25+
cb(null, _ipfsd.api)
26+
})
27+
}
28+
})
29+
},
30+
teardown: function (callback) {
31+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
32+
}
33+
}
34+
35+
test.bitswap(common)

0 commit comments

Comments
 (0)