-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from libp2p/chore/enable-browser-tests
chore: enable browser tests
- Loading branch information
Showing
10 changed files
with
186 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use strict' | ||
|
||
const pull = require('pull-stream') | ||
const parallel = require('async/parallel') | ||
const WebSocketStarRendezvous = require('libp2p-websocket-star-rendezvous') | ||
|
||
const Node = require('./test/utils/nodejs-bundle.js') | ||
const { | ||
getPeerRelay, | ||
WS_RENDEZVOUS_MULTIADDR | ||
} = require('./test/utils/constants.js') | ||
|
||
let wsRendezvous | ||
let node | ||
|
||
const before = (done) => { | ||
parallel([ | ||
(cb) => { | ||
WebSocketStarRendezvous.start({ | ||
port: WS_RENDEZVOUS_MULTIADDR.nodeAddress().port, | ||
refreshPeerListIntervalMS: 1000, | ||
strictMultiaddr: false, | ||
cryptoChallenge: true | ||
}, (err, _server) => { | ||
if (err) { | ||
return cb(err) | ||
} | ||
wsRendezvous = _server | ||
cb() | ||
}) | ||
}, | ||
(cb) => { | ||
getPeerRelay((err, peerInfo) => { | ||
if (err) { | ||
return done(err) | ||
} | ||
|
||
node = new Node({ | ||
peerInfo, | ||
config: { | ||
relay: { | ||
enabled: true, | ||
hop: { | ||
enabled: true, | ||
active: true | ||
} | ||
} | ||
} | ||
}) | ||
|
||
node.handle('/echo/1.0.0', (_, conn) => pull(conn, conn)) | ||
node.start(cb) | ||
}) | ||
} | ||
], done) | ||
} | ||
|
||
const after = (done) => { | ||
setTimeout(() => | ||
parallel( | ||
[node, wsRendezvous].map((s) => (cb) => s.stop(cb)), | ||
done), | ||
2000) | ||
} | ||
|
||
module.exports = { | ||
hooks: { | ||
pre: before, | ||
post: after | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": "Qmex1SSsueWFsUfjdkugJ5zhcnjddAt8TxcnDLUXKD9Sx7", | ||
"privKey": "CAASqAkwggSkAgEAAoIBAQCXzV127CvVHOGMzvsn/U+/32JM58KA6k0FSCCeNFzNowiDS/vV5eezGN5AFoxsF6icWLoaczz7l9RdVD+I/t6PEt9X7XUdrDCtSS8WmAcCgvZWSSf7yAd3jT4GSZDUIgIEeRZsERDt/yVqTLwsZ1G9dMIeh8sbf2zwjTXZIWaRM6o4lq3DYFfzLvJUXlJodxPogU7l7nLkITPUv+yQAMcVHizbNwJvwiETKYeUj73/m/wEPAlnFESexDstxNiIwE/FH8Ao50QPZRO6E6Jb0hhYSI/4CLRdrzDFm/Vzplei3Wr2DokSROaNyeG37VAueyA+pDqn84um+L9uXLwbv5FbAgMBAAECggEAdBUzV/GaQ0nmoQrWvOnUxmFIho7kCjkh1NwnNVPNc+Msa1r7pcI9wJNPwap8j1w4L/cZuYhOJgcg+o2mWFiuULKZ4F9Ro/M89gZ038457g2/2pPu43c/Xoi/2YcAHXg0Gr+OCe2zCIyITBWKAFqyAzL6DubAxrJW2Ezj1LrZ+EZgMyzbh/go/eEGSJaaGkINeAkY144DqDWWWvzyhKhryipsGkZGEkVy9xJgMEI3ipVvuPez2XAvoyyeuinBBLe+Z2vY5G50XXzbIMhIQGLncHf9MwTv6wt1ilyOSLOXK0BoQbB76J3R3is5dSULXXP9r8VocjLBEkmBuf4FXAKzoQ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ZDUIgIEeRZsERDt/yVqTLwsZ1G9dMIeh8sbf2zwjTXZIWaRM6o4lq3DYFfzLvJUXlJodxPogU7l7nLkITPUv+yQAMcVHizbNwJvwiETKYeUj73/m/wEPAlnFESexDstxNiIwE/FH8Ao50QPZRO6E6Jb0hhYSI/4CLRdrzDFm/Vzplei3Wr2DokSROaNyeG37VAueyA+pDqn84um+L9uXLwbv5FbAgMBAAE=" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const WebSocketStar = require('libp2p-websocket-star') | ||
const spdy = require('libp2p-spdy') | ||
const secio = require('libp2p-secio') | ||
const libp2p = require('libp2p') | ||
|
||
const { WS_STAR_MULTIADDR } = require('./constants') | ||
|
||
class Node extends libp2p { | ||
constructor ({ peerInfo, peerBook }) { | ||
const starOpts = { id: peerInfo.id } | ||
const wsStar = new WebSocketStar(starOpts) | ||
|
||
peerInfo.multiaddrs.add(WS_STAR_MULTIADDR) | ||
|
||
const modules = { | ||
transport: [wsStar], | ||
streamMuxer: [spdy], | ||
connEncryption: [secio] | ||
} | ||
|
||
super({ | ||
modules, | ||
peerInfo, | ||
peerBook | ||
}) | ||
} | ||
} | ||
|
||
module.exports = Node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_STAR_MULTIADDR = multiaddr('/ip4/127.0.0.1/tcp/14444/ws/p2p-websocket-star/') | ||
module.exports.WS_RENDEZVOUS_MULTIADDR = multiaddr('/ip4/127.0.0.1/tcp/14444/wss') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters