Skip to content

Commit

Permalink
Merge pull request #38 from poanetwork/fix-e2e-block-confirmation
Browse files Browse the repository at this point in the history
Update e2e test for block confirmations
  • Loading branch information
rstormsf authored Jun 27, 2018
2 parents 76e9e6e + 3c13889 commit 2a00eee
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
3 changes: 3 additions & 0 deletions e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ services:
- REDIS_LOCK_TTL=1000
- GAS_PRICE_SPEED_TYPE=standard
- GAS_PRICE_FALLBACK=1
- HOME_POLLING_INTERVAL=500
- FOREIGN_POLLING_INTERVAL=500
- ALLOW_HTTP=yes
command: "true"
e2e:
build: .
Expand Down
33 changes: 30 additions & 3 deletions e2e/test/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Web3 = require('web3')
const assert = require('assert')
const promiseRetry = require('promise-retry')
const { user } = require('../constants.json')
const { generateNewBlock } = require('../utils/utils')

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

Expand All @@ -27,14 +28,36 @@ describe('transactions', () => {
assert(toBN(balance).isZero(), 'Account should not have tokens yet')

// send transaction to home chain
await homeWeb3.eth.sendTransaction({
const depositTx = await homeWeb3.eth.sendTransaction({
from: user.address,
to: HOME_BRIDGE_ADDRESS,
gasPrice: '1',
gasLimit: '50000',
gas: '50000',
value: '1000000000000000000'
})

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

// 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 generateNewBlock(homeWeb3, user.address)
} else {
retry()
}
},
{
forever: true,
factor: 1,
minTimeout: 500
}
)

// check that account has tokens in the foreign chain
await promiseRetry(async retry => {
const balance = await token.methods.balanceOf(user.address).call()
Expand All @@ -52,12 +75,16 @@ describe('transactions', () => {
.transferAndCall(FOREIGN_BRIDGE_ADDRESS, homeWeb3.utils.toWei('0.01'), '0x')
.send({
from: user.address,
gasLimit: '1000000'
gas: '1000000'
})
.catch(e => {
console.error(e)
})

// 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 => {
const balance = await homeWeb3.eth.getBalance(user.address)
Expand Down
13 changes: 13 additions & 0 deletions e2e/utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function generateNewBlock(web3, address) {
return web3.eth.sendTransaction({
from: address,
to: '0x0000000000000000000000000000000000000000',
gasPrice: '1',
gas: '21000',
value: '1'
})
}

module.exports = {
generateNewBlock
}

0 comments on commit 2a00eee

Please sign in to comment.