Skip to content

Commit

Permalink
chore(tests): Add test for connecting Go to JS peer with Secp256k1 keys
Browse files Browse the repository at this point in the history
  • Loading branch information
aknuds1 committed Jul 12, 2019
1 parent 30e7d26 commit d84821e
Showing 1 changed file with 71 additions and 31 deletions.
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)
})
})
})

0 comments on commit d84821e

Please sign in to comment.