-
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.
* chore: update ws rendezvous dep test(fix): fix tests with latest ws rendezvous server * fix: promisification of libp2p methods test: add tests to verify promisify support until async/await endeavor is complete * chore: fix linting
- Loading branch information
Showing
9 changed files
with
169 additions
and
108 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
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
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,87 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
/** | ||
* This test suite is intended to validate compatability of | ||
* the promisified api, until libp2p has been fully migrated to | ||
* async/await. Once the migration is complete and all tests | ||
* are using async/await, this file can be removed. | ||
*/ | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
const expect = chai.expect | ||
const promisify = require('promisify-es6') | ||
const createNode = promisify(require('./utils/create-node')) | ||
const { createPeerInfo } = require('./utils/create-node') | ||
const Node = require('./utils/bundle-nodejs') | ||
const pull = require('pull-stream') | ||
const Ping = require('libp2p-ping') | ||
|
||
/** | ||
* As libp2p is currently promisified, when extending libp2p, | ||
* method arguments must be passed to `super` to ensure the | ||
* promisify callbacks are properly resolved | ||
*/ | ||
class AsyncLibp2p extends Node { | ||
async start (...args) { | ||
await super.start(...args) | ||
} | ||
|
||
async stop (...args) { | ||
await super.start(...args) | ||
} | ||
} | ||
|
||
async function createAsyncNode () { | ||
const peerInfo = await promisify(createPeerInfo)() | ||
peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0') | ||
return new AsyncLibp2p({ peerInfo }) | ||
} | ||
|
||
describe('promisified libp2p', () => { | ||
let libp2p | ||
let otherNode | ||
const ECHO_PROTO = '/echo/1.0.0' | ||
|
||
before('Create and Start', async () => { | ||
[libp2p, otherNode] = await Promise.all([ | ||
createNode('/ip4/0.0.0.0/tcp/0'), | ||
createAsyncNode() | ||
]) | ||
|
||
return [libp2p, otherNode].map(node => { | ||
node.handle(ECHO_PROTO, (_, conn) => pull(conn, conn)) | ||
return node.start() | ||
}) | ||
}) | ||
|
||
after('Stop', () => { | ||
return [libp2p, otherNode].map(node => node.stop()) | ||
}) | ||
|
||
afterEach('Hang up', () => { | ||
return libp2p.hangUp(otherNode.peerInfo) | ||
}) | ||
|
||
it('dial', async () => { | ||
const stream = await libp2p.dial(otherNode.peerInfo) | ||
expect(stream).to.not.exist() | ||
expect(libp2p._switch.connection.getAll()).to.have.length(1) | ||
}) | ||
|
||
it('dialFSM', async () => { | ||
const connectionFSM = await libp2p.dialFSM(otherNode.peerInfo, ECHO_PROTO) | ||
expect(connectionFSM).to.exist() | ||
}) | ||
|
||
it('dialProtocol', async () => { | ||
const stream = await libp2p.dialProtocol(otherNode.peerInfo, ECHO_PROTO) | ||
expect(stream).to.exist() | ||
}) | ||
|
||
it('ping', async () => { | ||
const ping = await libp2p.ping(otherNode.peerInfo) | ||
expect(ping).to.be.an.instanceOf(Ping) | ||
}) | ||
}) |
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
Oops, something went wrong.