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

fix bitswap tests #645

Closed
wants to merge 2 commits 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
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
},
"homepage": "https://github.com/ipfs/js-ipfs#readme",
"devDependencies": {
"aegir": "^9.1.2",
"aegir": "^9.2.0",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"detect-node": "^2.0.3",
"eslint-plugin-react": "^6.7.1",
"eslint-plugin-react": "^6.8.0",
"execa": "^0.5.0",
"expose-loader": "^0.7.1",
"form-data": "^2.1.2",
Expand All @@ -77,22 +77,22 @@
"debug": "^2.3.3",
"fs-pull-blob-store": "^0.3.0",
"glob": "^7.1.1",
"hapi": "^16.0.0",
"hapi": "^16.0.1",
"hapi-set-header": "^1.0.2",
"idb-pull-blob-store": "^0.5.1",
"ipfs-api": "^12.0.0",
"ipfs-bitswap": "^0.8.1",
"ipfs-block": "^0.5.0",
"ipfs-block-service": "^0.7.0",
"ipfs-api": "^12.0.3",
"ipfs-bitswap": "^0.8.2",
"ipfs-block": "^0.5.1",
"ipfs-block-service": "^0.7.1",
"ipfs-multipart": "^0.1.0",
"ipfs-repo": "^0.11.1",
"ipfs-unixfs": "^0.1.8",
"ipfs-unixfs-engine": "^0.14.0",
"ipfs-unixfs-engine": "^0.14.1",
"ipld-resolver": "^0.4.0",
"isstream": "^0.1.2",
"joi": "^10.0.1",
"libp2p-ipfs-nodejs": "^0.16.1",
"libp2p-ipfs-browser": "^0.17.0",
"joi": "^10.0.5",
"libp2p-ipfs-nodejs": "^0.16.4",
"libp2p-ipfs-browser": "^0.17.1",
"lodash.flatmap": "^4.5.0",
"lodash.get": "^4.4.2",
"lodash.has": "^4.5.2",
Expand All @@ -119,9 +119,9 @@
"stream-to-pull-stream": "^1.7.2",
"tar-stream": "^1.5.2",
"temp": "^0.8.3",
"through2": "^2.0.2",
"update-notifier": "^1.0.2",
"yargs": "^6.4.0"
"through2": "^2.0.3",
"update-notifier": "^1.0.3",
"yargs": "^6.5.0"
},
"contributors": [
"Andrew de Andrade <[email protected]>",
Expand Down Expand Up @@ -149,4 +149,4 @@
"nginnever <[email protected]>",
"npmcdn-to-unpkg-bot <[email protected]>"
]
}
}
39 changes: 27 additions & 12 deletions test/core/both/test-bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ const isNode = require('detect-node')

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

function makeBlock (cb) {
return cb(null, new Block(`IPFS is awesome ${Math.random()}`))
function makeBlock (callback) {
const block = new Block(new Buffer(`IPFS is awesome ${Math.random()}`))
callback(null, block)
}

describe('bitswap', () => {
describe.only('bitswap', () => {
let inProcNode // Node spawned inside this process
let swarmAddrsBak

Expand Down Expand Up @@ -68,8 +69,7 @@ describe('bitswap', () => {
targetAddr = addr.encapsulate(multiaddr(`/ipfs/${identity.id}`)).toString()
targetAddr = targetAddr.replace('0.0.0.0', '127.0.0.1')
} else {
// Note: the browser doesn't have
// a websockets listening addr
// Note: the browser doesn't have a websockets listening addr

// TODO, what we really need is a way to dial to
// a peerId only and another to dial to peerInfo
Expand Down Expand Up @@ -129,19 +129,34 @@ describe('bitswap', () => {
remoteNode = res[1]
cb()
},
(cb) => remoteNode.block.put(block, cb),
(res, cb) => block.key('sha2-256', cb),
(key, cb) => inProcNode.block.get(key, cb),
(cb) => {
remoteNode.block.put(block, (err, _block) => {
expect(err).to.not.exist
expect(block.data).to.eql(_block.data)
cb()
})
},
(cb) => block.key('sha2-256', cb),
(key, cb) => {
console.log('----> 1')
inProcNode.swarm.peers((err, peers) => {
expect(err).to.not.exist
console.log('Got %d peers', peers.length)
})

// remoteNode.block.get(key, cb) // for testing
inProcNode.block.get(key, cb)
},
(b, cb) => {
expect(b.data).to.be.eql(block.data)
console.log('----> 2')

expect(b.data).to.eql(block.data)
cb()
}
], done)
})

it('3 peers', function (done) {
this.timeout(60 * 1000)

it('3 peers', (done) => {
let blocks
let keys
const remoteNodes = []
Expand Down