Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Added RLPX simulator tests to improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerd77 committed Feb 22, 2018
1 parent 36546f6 commit 7aa0616
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions test/integration/rlpx-simulator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const async = require('async')
const test = require('tape')
const util = require('./util.js')
const Peer = require('../../src/rlpx/peer.js')

function initTwoPeerSetup () {
const rlpxs = util.getTestRLPXs(2, [])
const peer = { address: util.localhost, udpPort: util.basePort + 1, tcpPort: util.basePort + 1 }
rlpxs[0]._dpt.addPeer(peer)
return rlpxs
}

function destroy (rlpxs) {
for (let rlpx of rlpxs) {
Expand All @@ -10,13 +19,38 @@ function destroy (rlpxs) {
}

test('RLPX: add working node', async (t) => {
const rlpxs = util.getTestRLPXs(2, [])

const peer = { address: util.localhost, udpPort: util.basePort + 1, tcpPort: util.basePort + 1 }
rlpxs[0]._dpt.addPeer(peer)
const rlpxs = initTwoPeerSetup()

rlpxs[0].on('peer:added', function (peer) {
t.equal(peer._port, 30306, 'should have added peer on peer:added after successful handshake')
t.equal(rlpxs[0]._getOpenSlots(), 24, 'should have maxPeers - 1 open slots left')
destroy(rlpxs)
t.end()
})
})

test('RLPX: remove node', async (t) => {
const rlpxs = initTwoPeerSetup()

async.series([
function (cb) {
rlpxs[0].on('peer:added', function (peer) {
rlpxs[0].disconnect(peer._remoteId)
cb(null)
})
},
function (cb) {
rlpxs[0].on('peer:removed', function (peer, reason, disconnectWe) {
t.equal(reason, Peer.DISCONNECT_REASONS.CLIENT_QUITTING, 'should close with CLIENT_QUITTING disconnect reason')
t.equal(rlpxs[0]._getOpenSlots(), 25, 'should have maxPeers open slots left')
cb(null)
})
}
],
function (err, results) {
if (err) {
t.fail('An unexpected error occured.')
}
destroy(rlpxs)
t.end()
})
Expand Down

0 comments on commit 7aa0616

Please sign in to comment.