Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test connecting Go to JS peer with Secp256k1 keys #24

Merged
merged 2 commits into from
Jul 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 71 additions & 31 deletions test/connect/go2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,86 @@ const expect = chai.expect

const spawnDaemons = require('../utils/spawnDaemons')

describe('connect', () => {
let daemons
const beforeConnect = (ctx, keyType) => {
ctx.timeout(20 * 1000)

// Start Daemons
before(async function () {
this.timeout(20 * 1000)
return spawnDaemons(2, [{ type: 'go', keyType }, { type: 'js', keyType }])
}

daemons = await spawnDaemons(2, ['go', 'js'])
})
const afterConnect = async (daemons) => {
if (daemons == null) {
return
}

// Stop daemons
after(async function () {
await Promise.all(
daemons.map((daemon) => daemon.stop())
)
})
await Promise.all(
daemons.map(async (daemon) => {
// Ignore errors
try {
await daemon.stop()
} catch (_) {
}
})
)
}

const performTest = async (ctx, daemons) => {
ctx.timeout(10 * 1000)

const identifyGo = await daemons[0].client.identify()
const goId = identifyGo.peerId.toB58String()
const identifyJs = await daemons[1].client.identify()
const jsId = identifyJs.peerId.toB58String()

// verify connected peers
const knownPeersBeforeConnectGo = await daemons[0].client.listPeers()
expect(knownPeersBeforeConnectGo).to.have.lengthOf(0)

const knownPeersBeforeConnectJs = await daemons[1].client.listPeers()
expect(knownPeersBeforeConnectJs).to.have.lengthOf(0)

it('go peer to js peer', async function () {
this.timeout(10 * 1000)
// connect peers
await daemons[0].client.connect(identifyJs.peerId, identifyJs.addrs)

const identifyJs = await daemons[0].client.identify()
const identifyGo = await daemons[1].client.identify()
// verify connected peers
const knownPeersAfterConnectGo = await daemons[0].client.listPeers()
expect(knownPeersAfterConnectGo).to.have.lengthOf(1)
expect(knownPeersAfterConnectGo[0].toB58String()).to.equal(jsId)

// verify connected peers
const knownPeersBeforeConnectJs = await daemons[0].client.listPeers()
expect(knownPeersBeforeConnectJs).to.have.lengthOf(0)
const knownPeersAfterConnectJs = await daemons[1].client.listPeers()
expect(knownPeersAfterConnectJs).to.have.lengthOf(1)
expect(knownPeersAfterConnectJs[0].toB58String()).to.equal(goId)
}

describe('connecting go peer to js peer', () => {
describe('with RSA keys', () => {
let daemons

before(async function () {
daemons = await beforeConnect(this, 'rsa')
})

after(async () => {
await afterConnect(daemons)
})

it('should work', async function () {
await performTest(this, daemons)
})
})

const knownPeersBeforeConnectGo = await daemons[1].client.listPeers()
expect(knownPeersBeforeConnectGo).to.have.lengthOf(0)
describe('with SECP256k1 keys', () => {
let daemons

// connect peers
await daemons[1].client.connect(identifyJs.peerId, identifyJs.addrs)
before(async function () {
daemons = await beforeConnect(this, 'secp256k1')
})

// verify connected peers
const knownPeersAfterConnectGo = await daemons[1].client.listPeers()
expect(knownPeersAfterConnectGo).to.have.lengthOf(1)
expect(knownPeersAfterConnectGo[0].toB58String()).to.equal(identifyJs.peerId.toB58String())
after(async () => {
await afterConnect(daemons)
})

const knownPeersAfterConnectJs = await daemons[0].client.listPeers()
expect(knownPeersAfterConnectJs).to.have.lengthOf(1)
expect(knownPeersAfterConnectJs[0].toB58String()).to.equal(identifyGo.peerId.toB58String())
it('should work', async function () {
await performTest(this, daemons)
})
})
})