mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-13 01:01:23 +00:00
test: add circuit browser test (#326)
This commit is contained in:
40
test/utils/constants.js
Normal file
40
test/utils/constants.js
Normal file
@ -0,0 +1,40 @@
|
||||
'use strict'
|
||||
|
||||
const PeerId = require('peer-id')
|
||||
const PeerInfo = require('peer-info')
|
||||
const nextTick = require('async/nextTick')
|
||||
const peerJSON = require('../fixtures/test-peer')
|
||||
const multiaddr = require('multiaddr')
|
||||
|
||||
let peerRelay = null
|
||||
|
||||
/**
|
||||
* Creates a `PeerInfo` that can be used across testing. Once the
|
||||
* relay `PeerInfo` has been requested, it will be reused for each
|
||||
* additional request.
|
||||
*
|
||||
* This is currently being used to create a relay on test bootstrapping
|
||||
* so that it can be used by browser nodes during their test suite. This
|
||||
* is necessary for running a TCP node during browser tests.
|
||||
* @private
|
||||
* @param {function(error, PeerInfo)} callback
|
||||
* @returns {void}
|
||||
*/
|
||||
module.exports.getPeerRelay = (callback) => {
|
||||
if (peerRelay) return nextTick(callback, null, peerRelay)
|
||||
|
||||
PeerId.createFromJSON(peerJSON, (err, peerId) => {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
peerRelay = new PeerInfo(peerId)
|
||||
|
||||
peerRelay.multiaddrs.add('/ip4/127.0.0.1/tcp/9200/ws')
|
||||
peerRelay.multiaddrs.add('/ip4/127.0.0.1/tcp/9245')
|
||||
|
||||
callback(null, peerRelay)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.WS_RENDEZVOUS_MULTIADDR = multiaddr('/ip4/127.0.0.1/tcp/14444/wss')
|
||||
module.exports.WRTC_RENDEZVOUS_MULTIADDR = multiaddr('/ip4/127.0.0.1/tcp/15555/wss')
|
@ -8,3 +8,4 @@ function echo (protocol, conn) {
|
||||
}
|
||||
|
||||
module.exports = echo
|
||||
module.exports.multicodec = '/echo/1.0.0'
|
||||
|
Reference in New Issue
Block a user