Skip to content

Commit

Permalink
Improve e2e test code
Browse files Browse the repository at this point in the history
  • Loading branch information
patitonar committed Jun 26, 2018
1 parent 2fcdeb4 commit 3c13889
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions e2e/test/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Web3 = require('web3')
const assert = require('assert')
const promiseRetry = require('promise-retry')
const { user } = require('../constants.json')
const { generateNewBlockWithTx } = require('../utils/utils')
const { generateNewBlock } = require('../utils/utils')

const abisDir = path.join(__dirname, '..', 'submodules/poa-bridge-contracts/build/contracts')

Expand Down Expand Up @@ -36,21 +36,23 @@ describe('transactions', () => {
value: '1000000000000000000'
})

// Send a Tx to generate a new block
await generateNewBlockWithTx(homeWeb3, user.address)
// Send a trivial transaction to generate a new block since the watcher
// is configured to wait 1 confirmation block
await generateNewBlock(homeWeb3, user.address)

// wait to send a Tx to generate a new block
// The bridge should create a new transaction with a CollectedSignatures
// event so we generate another trivial transaction
await promiseRetry(
async retry => {
const lastBlockNumber = await homeWeb3.eth.getBlockNumber()
if (lastBlockNumber === depositTx.blockNumber + 2) {
await generateNewBlockWithTx(homeWeb3, user.address)
if (lastBlockNumber >= depositTx.blockNumber + 2) {
await generateNewBlock(homeWeb3, user.address)
} else {
retry()
}
},
{
retries: 1000000,
forever: true,
factor: 1,
minTimeout: 500
}
Expand Down Expand Up @@ -79,8 +81,9 @@ describe('transactions', () => {
console.error(e)
})

// Send a second Tx to generate a new block
await generateNewBlockWithTx(foreignWeb3, user.address)
// Send a trivial transaction to generate a new block since the watcher
// is configured to wait 1 confirmation block
await generateNewBlock(foreignWeb3, user.address)

// check that balance increases
await promiseRetry(async retry => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function generateNewBlockWithTx(web3, address) {
function generateNewBlock(web3, address) {
return web3.eth.sendTransaction({
from: address,
to: '0x0000000000000000000000000000000000000000',
Expand All @@ -9,5 +9,5 @@ function generateNewBlockWithTx(web3, address) {
}

module.exports = {
generateNewBlockWithTx
generateNewBlock
}

0 comments on commit 3c13889

Please sign in to comment.