mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-06-24 21:41:40 +00:00
fix(connection): dont require remoteAddr on creation (#20)
This commit is contained in:
48
test/connection/index.spec.js
Normal file
48
test/connection/index.spec.js
Normal file
@ -0,0 +1,48 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const { Connection } = require('../../src/connection')
|
||||
const peers = require('../../src/utils/peers')
|
||||
const PeerId = require('peer-id')
|
||||
const pair = require('it-pair')
|
||||
|
||||
describe('connection tests', () => {
|
||||
it('should not require local or remote addrs', async () => {
|
||||
const [localPeer, remotePeer] = await Promise.all([
|
||||
PeerId.createFromJSON(peers[0]),
|
||||
PeerId.createFromJSON(peers[1])
|
||||
])
|
||||
const openStreams = []
|
||||
let streamId = 0
|
||||
|
||||
return new Connection({
|
||||
localPeer,
|
||||
remotePeer,
|
||||
stat: {
|
||||
timeline: {
|
||||
open: Date.now() - 10,
|
||||
upgraded: Date.now()
|
||||
},
|
||||
direction: 'outbound',
|
||||
encryption: '/secio/1.0.0',
|
||||
multiplexer: '/mplex/6.7.0'
|
||||
},
|
||||
newStream: (protocols) => {
|
||||
const id = streamId++
|
||||
const stream = pair()
|
||||
|
||||
stream.close = () => stream.sink([])
|
||||
stream.id = id
|
||||
|
||||
openStreams.push(stream)
|
||||
|
||||
return {
|
||||
stream,
|
||||
protocol: protocols[0]
|
||||
}
|
||||
},
|
||||
close: () => {},
|
||||
getStreams: () => openStreams
|
||||
})
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user