Protect from peers without supported transports

# What

Trying to run compliance tests from the kad router module. I've tried to port the new swarm API but forgot to add a transport. The tests ended up blowing up instead of failing gracefully.

# How to test

```js
peerOne = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/8090')])
peerTwo = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/8091')])
swarm = new Swarm(peerZero)
swarm.dial(peerTwo, {}, function (err) {
  console.log(err);
});
```

This just work and display the error.
This commit is contained in:
Pau Ramon Revilla
2015-09-25 09:07:45 +02:00
parent cd53344441
commit 8dc46da80f
3 changed files with 32 additions and 8 deletions

View File

@ -13,17 +13,35 @@ var Swarm = require('../src')
var tcp = require('libp2p-tcp')
var Spdy = require('libp2p-spdy')
/* TODO
experiment('Basics', function () {
test('enforces creation with new', function (done) {done() })
})
*/
// because of Travis-CI
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err)
})
experiment('Basics', function () {
test('enforces creation with new', function (done) {
expect(function () {
Swarm()
}).to.throw()
done()
})
})
experiment('When dialing', function () {
experiment('if the swarm does add any of the peer transports', function () {
test('it returns an error', function (done) {
var peerOne = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/8090')])
var peerTwo = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/8091')])
var swarm = new Swarm(peerOne)
swarm.dial(peerTwo, {}, function (err) {
expect(err).to.exist()
done()
})
})
})
})
experiment('Without a Stream Muxer', function () {
experiment('tcp', function () {
test('add the transport', function (done) {