Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Mar 17, 2016
1 parent 7e044a2 commit e73023b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libp2p-ipfs",
"version": "0.1.0",
"version": "0.1.1",
"description": "The libp2p build (module) used by js-ipfs on Node.js",
"main": "src/index.js",
"scripts": {
Expand Down
45 changes: 15 additions & 30 deletions tests/test-libp2p-ipfs.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,43 @@
/* globals describe, it */
/* eslint-env mocha */

const expect = require('chai').expect
const libp2p = require('../src')
const libp2p = require('../src').Node
const Id = require('peer-id')
const Peer = require('peer-info')
const multiaddr = require('multiaddr')

describe('libp2p-ipfs', () => {
const idA = Id.create()
const idB = Id.create()
const peerA = new Peer(idA, [])
const peerB = new Peer(idB, [])
const peerA = new Peer(idA)
const peerB = new Peer(idB)

var nodeA
var nodeB

it('prepare node A', (done) => {
const options = {
peer: peerA,
multiaddrs: {
tcp: multiaddr('/ip4/127.0.0.1/tcp/8010')
}
}

nodeA = libp2p(options)
nodeA.listen((err) => {
expect(err).to.not.exist
done()
})
peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/8010'))

nodeA = libp2p(peerA)
nodeA.start(done)
})

it('prepare node B', (done) => {
const options = {
peer: peerB,
multiaddrs: {
tcp: multiaddr('/ip4/127.0.0.1/tcp/8020')
}
}

nodeB = libp2p(options)
nodeB.listen((err) => {
expect(err).to.not.exist
done()
})
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/8020'))

nodeB = libp2p(peerB)
nodeB.start(done)
})

it('B handle /echo/1.0.0', (done) => {
nodeB.swarm.handleProtocol('/echo/1.0.0', (conn) => {
nodeB.swarm.handle('/echo/1.0.0', (conn) => {
conn.pipe(conn)
})
done()
})

it('A dial B to speak /echo/1.0.0', (done) => {
nodeA.swarm.dial(peerB, {}, '/echo/1.0.0', (err, conn) => {
nodeA.swarm.dial(peerB, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist
done()
})
Expand Down

0 comments on commit e73023b

Please sign in to comment.