Skip to content

Commit

Permalink
refactoring(channels): require node above or equal to 5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Apr 28, 2021
1 parent bb7ec47 commit ebb36f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/node.js
Expand Up @@ -121,7 +121,7 @@ const Node = AsyncInit.compose({
}
})

const NODE_GE_VERSION = '5.0.1'
const NODE_GE_VERSION = '5.2.0'
const NODE_LT_VERSION = '6.0.0'

export default Node
53 changes: 13 additions & 40 deletions test/integration/channel.js
Expand Up @@ -54,8 +54,6 @@ describe('Channel', function () {
let contractAddress
let contractEncodeCall
let callerNonce
let majorVersion
let minorVersion
const initiatorSign = sinon.spy((tag, tx) => initiator.signTransaction(tx))
const responderSign = sinon.spy((tag, tx) => {
if (typeof responderShouldRejectUpdate === 'number') {
Expand Down Expand Up @@ -87,9 +85,6 @@ describe('Channel', function () {
sharedParams.initiatorId = await initiator.address()
sharedParams.responderId = await responder.address()
await initiator.spend(BigNumber('500e18').toString(), await responder.address())
const version = initiator.getNodeInfo().version.split(/[.-]/).map(i => parseInt(i, 10))
majorVersion = version[0]
minorVersion = version[1]
})

after(() => {
Expand Down Expand Up @@ -686,15 +681,11 @@ describe('Channel', function () {
})

it('can reestablish a channel', async () => {
const existingChannelIdKey =
majorVersion > 5 || (majorVersion === 5 && minorVersion >= 2)
? 'existingFsmId'
: 'existingChannelId'
initiatorCh = await Channel({
...sharedParams,
role: 'initiator',
port: 3002,
[existingChannelIdKey]: existingChannelId,
existingFsmId: existingChannelId,
offchainTx,
sign: initiatorSign
})
Expand Down Expand Up @@ -1074,36 +1065,18 @@ describe('Channel', function () {
)
result.accepted.should.be.true
const channelId = await initiatorCh.id()
const round = initiatorCh.round()
let ch
if (majorVersion > 5 || (majorVersion === 5 && minorVersion >= 2)) {
const fsmId = initiatorCh.fsmId()
initiatorCh.disconnect()
ch = await Channel({
url: sharedParams.url,
host: sharedParams.host,
port: 3006,
role: 'initiator',
existingChannelId: channelId,
existingFsmId: fsmId
})
await waitForChannel(ch)
ch.fsmId().should.equal(fsmId)
} else {
initiatorCh.disconnect()
ch = await Channel.reconnect({
...sharedParams,
role: 'initiator',
port: 3006,
sign: initiatorSign
}, {
channelId,
round,
role: 'initiator',
pubkey: await initiator.address()
})
await waitForChannel(ch)
}
const fsmId = initiatorCh.fsmId()
initiatorCh.disconnect()
const ch = await Channel({
url: sharedParams.url,
host: sharedParams.host,
port: 3006,
role: 'initiator',
existingChannelId: channelId,
existingFsmId: fsmId
})
await waitForChannel(ch)
ch.fsmId().should.equal(fsmId)
// TODO: why node doesn't return signed_tx when channel is reestablished?
// await new Promise((resolve) => {
// const checkRound = () => {
Expand Down

0 comments on commit ebb36f0

Please sign in to comment.