Fix some of the possibles failure reasons in e2e tests (#294)
This commit is contained in:
parent
52ed4e85e2
commit
e6052f162a
@ -245,7 +245,7 @@ jobs:
|
|||||||
- tokenbridge-orb/yarn-install-cached-on-machine
|
- tokenbridge-orb/yarn-install-cached-on-machine
|
||||||
- run:
|
- run:
|
||||||
name: Prepare the infrastructure
|
name: Prepare the infrastructure
|
||||||
command: e2e-commons/up.sh deploy << parameters.scenario-name >>
|
command: e2e-commons/up.sh deploy << parameters.scenario-name >> blocks
|
||||||
no_output_timeout: 50m
|
no_output_timeout: 50m
|
||||||
- tokenbridge-orb/wait-for-oracle:
|
- tokenbridge-orb/wait-for-oracle:
|
||||||
redis-key: << parameters.redis-key >>
|
redis-key: << parameters.redis-key >>
|
||||||
@ -256,7 +256,6 @@ jobs:
|
|||||||
name: Run the ui-e2e tests
|
name: Run the ui-e2e tests
|
||||||
command: |
|
command: |
|
||||||
nvm use default;
|
nvm use default;
|
||||||
node ./e2e-commons/scripts/blocks.js &
|
|
||||||
cd ui-e2e; yarn mocha -g "<< parameters.ui-e2e-grep >>" -b ./test.js
|
cd ui-e2e; yarn mocha -g "<< parameters.ui-e2e-grep >>" -b ./test.js
|
||||||
- when:
|
- when:
|
||||||
condition: << parameters.oracle-e2e-script >>
|
condition: << parameters.oracle-e2e-script >>
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 7e17921ffc56287678eb54eadd325a7406821ed9
|
Subproject commit efbbdfade1d2eae6a6c6f12f1a59aa936470ad6f
|
@ -144,3 +144,10 @@ services:
|
|||||||
command: "true"
|
command: "true"
|
||||||
networks:
|
networks:
|
||||||
- ultimate
|
- ultimate
|
||||||
|
blocks:
|
||||||
|
build:
|
||||||
|
context: ..
|
||||||
|
dockerfile: Dockerfile.e2e
|
||||||
|
entrypoint: node e2e-commons/scripts/blocks.js
|
||||||
|
networks:
|
||||||
|
- ultimate
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const { generateNewBlock } = require('../utils')
|
|
||||||
|
|
||||||
const homeWeb3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8541'))
|
const homeWeb3 = new Web3(new Web3.providers.HttpProvider('http://parity1:8545'))
|
||||||
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8542'))
|
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider('http://parity2:8545'))
|
||||||
const {user, blockGenerator} = require('../constants.json');
|
const {user, blockGenerator} = require('../constants.json');
|
||||||
|
|
||||||
homeWeb3.eth.accounts.wallet.add(user.privateKey)
|
homeWeb3.eth.accounts.wallet.add(user.privateKey)
|
||||||
@ -10,10 +9,24 @@ foreignWeb3.eth.accounts.wallet.add(user.privateKey)
|
|||||||
homeWeb3.eth.accounts.wallet.add(blockGenerator.privateKey)
|
homeWeb3.eth.accounts.wallet.add(blockGenerator.privateKey)
|
||||||
foreignWeb3.eth.accounts.wallet.add(blockGenerator.privateKey)
|
foreignWeb3.eth.accounts.wallet.add(blockGenerator.privateKey)
|
||||||
|
|
||||||
|
function generateNewBlock(web3, address) {
|
||||||
|
return web3.eth.sendTransaction({
|
||||||
|
from: address,
|
||||||
|
to: '0x0000000000000000000000000000000000000000',
|
||||||
|
gasPrice: '1',
|
||||||
|
gas: '21000',
|
||||||
|
value: '1'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
generateNewBlock(homeWeb3, blockGenerator.address)
|
try {
|
||||||
generateNewBlock(foreignWeb3, blockGenerator.address)
|
generateNewBlock(homeWeb3, blockGenerator.address)
|
||||||
|
} catch {} // in case of Transaction with the same hash was already imported.
|
||||||
|
try {
|
||||||
|
generateNewBlock(foreignWeb3, blockGenerator.address)
|
||||||
|
} catch {} // in case of Transaction with the same hash was already imported.
|
||||||
main()
|
main()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,9 @@ CONTRACTS_PATH="../../contracts"
|
|||||||
DEPLOY_PATH="$CONTRACTS_PATH/deploy"
|
DEPLOY_PATH="$CONTRACTS_PATH/deploy"
|
||||||
ENVS_PATH="../contracts-envs"
|
ENVS_PATH="../contracts-envs"
|
||||||
|
|
||||||
|
# mock bridge validators contract with the one with deterministic isValidatorDuty
|
||||||
|
mv "$CONTRACTS_PATH/build/contracts/BridgeValidatorsDeterministic.json" "$CONTRACTS_PATH/build/contracts/BridgeValidators.json"
|
||||||
|
|
||||||
echo -e "\n\n############ Deploying native-to-erc ############\n"
|
echo -e "\n\n############ Deploying native-to-erc ############\n"
|
||||||
cp "$ENVS_PATH/native-to-erc.env" "$DEPLOY_PATH/.env"
|
cp "$ENVS_PATH/native-to-erc.env" "$DEPLOY_PATH/.env"
|
||||||
cd "$DEPLOY_PATH"
|
cd "$DEPLOY_PATH"
|
||||||
|
@ -81,7 +81,7 @@ while [ "$1" != "" ]; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" == "blocks" ]; then
|
if [ "$1" == "blocks" ]; then
|
||||||
node ./scripts/blocks.js &
|
docker-compose up -d blocks
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" == "monitor" ]; then
|
if [ "$1" == "monitor" ]; then
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
function generateNewBlock(web3, address) {
|
const promiseRetry = require('promise-retry')
|
||||||
return web3.eth.sendTransaction({
|
|
||||||
from: address,
|
async function uniformRetry(f) {
|
||||||
to: '0x0000000000000000000000000000000000000000',
|
return promiseRetry(f, {
|
||||||
gasPrice: '1',
|
forever: true,
|
||||||
gas: '21000',
|
factor: 1,
|
||||||
value: '1'
|
minTimeout: 500
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
async function sleep(timeout) {
|
||||||
generateNewBlock
|
return new Promise(res => setTimeout(res, timeout))
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
uniformRetry,
|
||||||
|
sleep
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
cd $(dirname $0)
|
cd $(dirname $0)
|
||||||
|
|
||||||
../e2e-commons/up.sh deploy monitor
|
../e2e-commons/up.sh deploy blocks monitor
|
||||||
|
|
||||||
./wait-for-monitor.sh
|
./wait-for-monitor.sh
|
||||||
nohup ./periodically-check-all.sh < /dev/null > /dev/null 2>&1 &
|
nohup ./periodically-check-all.sh < /dev/null > /dev/null 2>&1 &
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
cd $(dirname $0)
|
cd $(dirname $0)
|
||||||
|
|
||||||
../e2e-commons/up.sh deploy oracle oracle-validator-2 oracle-validator-3
|
../e2e-commons/up.sh deploy blocks oracle oracle-validator-2 oracle-validator-3
|
||||||
|
|
||||||
docker-compose -f ../e2e-commons/docker-compose.yml run e2e yarn workspace oracle-e2e run start
|
docker-compose -f ../e2e-commons/docker-compose.yml run e2e yarn workspace oracle-e2e run start
|
||||||
rc=$?
|
rc=$?
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const promiseRetry = require('promise-retry')
|
|
||||||
const { user, homeRPC, foreignRPC, amb, validator } = require('../../e2e-commons/constants.json')
|
const { user, homeRPC, foreignRPC, amb, validator } = require('../../e2e-commons/constants.json')
|
||||||
const { generateNewBlock } = require('../../e2e-commons/utils')
|
const { uniformRetry } = require('../../e2e-commons/utils')
|
||||||
const { BOX_ABI, HOME_AMB_ABI, FOREIGN_AMB_ABI } = require('../../commons')
|
const { BOX_ABI, HOME_AMB_ABI, FOREIGN_AMB_ABI } = require('../../commons')
|
||||||
const { setRequiredSignatures } = require('./utils')
|
const { setRequiredSignatures } = require('./utils')
|
||||||
|
|
||||||
@ -59,7 +58,7 @@ describe('arbitrary message bridging', () => {
|
|||||||
const initialValue = await foreignBox.methods.value().call()
|
const initialValue = await foreignBox.methods.value().call()
|
||||||
assert(!toBN(initialValue).eq(toBN(newValue)), 'initial value should be different from new value')
|
assert(!toBN(initialValue).eq(toBN(newValue)), 'initial value should be different from new value')
|
||||||
|
|
||||||
const setValueTx = await homeBox.methods
|
await homeBox.methods
|
||||||
.setValueOnOtherNetwork(newValue, amb.home, amb.foreignBox)
|
.setValueOnOtherNetwork(newValue, amb.home, amb.foreignBox)
|
||||||
.send({
|
.send({
|
||||||
from: user.address,
|
from: user.address,
|
||||||
@ -69,31 +68,8 @@ describe('arbitrary message bridging', () => {
|
|||||||
console.error(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(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 >= setValueTx.blockNumber + 2) {
|
|
||||||
await generateNewBlock(homeWeb3, user.address)
|
|
||||||
} else {
|
|
||||||
retry()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
forever: true,
|
|
||||||
factor: 1,
|
|
||||||
minTimeout: 500
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// check that value changed and balance decreased
|
// check that value changed and balance decreased
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
await generateNewBlock(homeWeb3, user.address)
|
|
||||||
const value = await foreignBox.methods.value().call()
|
const value = await foreignBox.methods.value().call()
|
||||||
if (!toBN(value).eq(toBN(newValue))) {
|
if (!toBN(value).eq(toBN(newValue))) {
|
||||||
retry()
|
retry()
|
||||||
@ -120,12 +96,8 @@ describe('arbitrary message bridging', () => {
|
|||||||
console.error(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 value changed and balance decreased
|
// check that value changed and balance decreased
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const value = await homeBox.methods.value().call()
|
const value = await homeBox.methods.value().call()
|
||||||
if (!toBN(value).eq(toBN(newValue))) {
|
if (!toBN(value).eq(toBN(newValue))) {
|
||||||
retry()
|
retry()
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const promiseRetry = require('promise-retry')
|
|
||||||
const { user, secondUser, ercToErcBridge, homeRPC, foreignRPC, validator } = require('../../e2e-commons/constants.json')
|
const { user, secondUser, ercToErcBridge, homeRPC, foreignRPC, validator } = require('../../e2e-commons/constants.json')
|
||||||
const { ERC677_BRIDGE_TOKEN_ABI, FOREIGN_ERC_TO_NATIVE_ABI, HOME_ERC_TO_ERC_ABI } = require('../../commons')
|
const { ERC677_BRIDGE_TOKEN_ABI, FOREIGN_ERC_TO_NATIVE_ABI, HOME_ERC_TO_ERC_ABI } = require('../../commons')
|
||||||
const { generateNewBlock } = require('../../e2e-commons/utils')
|
const { uniformRetry } = require('../../e2e-commons/utils')
|
||||||
const { setRequiredSignatures } = require('./utils')
|
const { setRequiredSignatures } = require('./utils')
|
||||||
|
|
||||||
const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL))
|
const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL))
|
||||||
@ -76,12 +75,8 @@ describe('erc to erc', () => {
|
|||||||
console.error(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
|
// check that balance increases
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const balance = await erc677Token.methods.balanceOf(user.address).call()
|
const balance = await erc677Token.methods.balanceOf(user.address).call()
|
||||||
const recipientBalance = await erc677Token.methods.balanceOf(secondUser.address).call()
|
const recipientBalance = await erc677Token.methods.balanceOf(secondUser.address).call()
|
||||||
assert(toBN(balance).isZero(), 'User balance should be the same')
|
assert(toBN(balance).isZero(), 'User balance should be the same')
|
||||||
@ -103,12 +98,8 @@ describe('erc to erc', () => {
|
|||||||
console.error(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
|
// check that balance increases
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const balance = await erc677Token.methods.balanceOf(user.address).call()
|
const balance = await erc677Token.methods.balanceOf(user.address).call()
|
||||||
if (toBN(balance).isZero()) {
|
if (toBN(balance).isZero()) {
|
||||||
retry()
|
retry()
|
||||||
@ -125,7 +116,7 @@ describe('erc to erc', () => {
|
|||||||
assert(!toBN(balance).isZero(), 'Account should have tokens')
|
assert(!toBN(balance).isZero(), 'Account should have tokens')
|
||||||
|
|
||||||
// send transaction to home bridge
|
// send transaction to home bridge
|
||||||
const depositTx = await erc677Token.methods
|
await erc677Token.methods
|
||||||
.transferAndCall(COMMON_HOME_BRIDGE_ADDRESS, homeWeb3.utils.toWei('0.01'), '0x')
|
.transferAndCall(COMMON_HOME_BRIDGE_ADDRESS, homeWeb3.utils.toWei('0.01'), '0x')
|
||||||
.send({
|
.send({
|
||||||
from: user.address,
|
from: user.address,
|
||||||
@ -135,31 +126,8 @@ describe('erc to erc', () => {
|
|||||||
console.error(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(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 balance increases
|
// check that balance increases
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
await generateNewBlock(homeWeb3, user.address)
|
|
||||||
const balance = await erc20Token.methods.balanceOf(user.address).call()
|
const balance = await erc20Token.methods.balanceOf(user.address).call()
|
||||||
if (toBN(balance).lte(toBN(originalBalance))) {
|
if (toBN(balance).lte(toBN(originalBalance))) {
|
||||||
retry()
|
retry()
|
||||||
|
@ -10,7 +10,7 @@ const {
|
|||||||
foreignRPC
|
foreignRPC
|
||||||
} = require('../../e2e-commons/constants.json')
|
} = require('../../e2e-commons/constants.json')
|
||||||
const { ERC677_BRIDGE_TOKEN_ABI, FOREIGN_ERC_TO_NATIVE_ABI, SAI_TOP, HOME_ERC_TO_NATIVE_ABI } = require('../../commons')
|
const { ERC677_BRIDGE_TOKEN_ABI, FOREIGN_ERC_TO_NATIVE_ABI, SAI_TOP, HOME_ERC_TO_NATIVE_ABI } = require('../../commons')
|
||||||
const { generateNewBlock } = require('../../e2e-commons/utils')
|
const { uniformRetry, sleep } = require('../../e2e-commons/utils')
|
||||||
const { setRequiredSignatures } = require('./utils')
|
const { setRequiredSignatures } = require('./utils')
|
||||||
|
|
||||||
const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL))
|
const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL))
|
||||||
@ -80,14 +80,9 @@ describe('erc to native', () => {
|
|||||||
console.error(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
|
// check that balance increases
|
||||||
await promiseRetry(async (retry, number) => {
|
await promiseRetry(async (retry, number) => {
|
||||||
const balance = await homeWeb3.eth.getBalance(user.address)
|
const balance = await homeWeb3.eth.getBalance(user.address)
|
||||||
await generateNewBlock(foreignWeb3, user.address)
|
|
||||||
// retry at least 4 times to check transfer is not double processed by the two watchers
|
// retry at least 4 times to check transfer is not double processed by the two watchers
|
||||||
if (toBN(balance).lte(toBN(originalBalanceOnHome)) || number < 4) {
|
if (toBN(balance).lte(toBN(originalBalanceOnHome)) || number < 4) {
|
||||||
retry()
|
retry()
|
||||||
@ -124,14 +119,9 @@ describe('erc to native', () => {
|
|||||||
console.error(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
|
// check that balance increases
|
||||||
await promiseRetry(async (retry, number) => {
|
await promiseRetry(async (retry, number) => {
|
||||||
const balance = await homeWeb3.eth.getBalance(user.address)
|
const balance = await homeWeb3.eth.getBalance(user.address)
|
||||||
await generateNewBlock(foreignWeb3, user.address)
|
|
||||||
// retry at least 4 times to check transfer is not double processed by the two watchers
|
// retry at least 4 times to check transfer is not double processed by the two watchers
|
||||||
if (toBN(balance).lte(toBN(AfterMigrateBalance)) || number < 4) {
|
if (toBN(balance).lte(toBN(AfterMigrateBalance)) || number < 4) {
|
||||||
retry()
|
retry()
|
||||||
@ -156,14 +146,9 @@ describe('erc to native', () => {
|
|||||||
console.error(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
|
// check that balance increases
|
||||||
await promiseRetry(async (retry, number) => {
|
await promiseRetry(async (retry, number) => {
|
||||||
const balance = await homeWeb3.eth.getBalance(user.address)
|
const balance = await homeWeb3.eth.getBalance(user.address)
|
||||||
await generateNewBlock(foreignWeb3, user.address)
|
|
||||||
// retry at least 4 times to check transfer is not double processed by the two watchers
|
// retry at least 4 times to check transfer is not double processed by the two watchers
|
||||||
if (toBN(balance).lte(toBN(afterMigrateAndTransferBalance)) || number < 4) {
|
if (toBN(balance).lte(toBN(afterMigrateAndTransferBalance)) || number < 4) {
|
||||||
retry()
|
retry()
|
||||||
@ -203,12 +188,8 @@ describe('erc to native', () => {
|
|||||||
console.error(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
|
// check that balance increases
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const balance = await homeWeb3.eth.getBalance(user.address)
|
const balance = await homeWeb3.eth.getBalance(user.address)
|
||||||
const secondUserbalance = await homeWeb3.eth.getBalance(secondUser.address)
|
const secondUserbalance = await homeWeb3.eth.getBalance(secondUser.address)
|
||||||
assert(toBN(balance).lte(toBN(originalBalanceOnHome)), 'User balance should be the same')
|
assert(toBN(balance).lte(toBN(originalBalanceOnHome)), 'User balance should be the same')
|
||||||
@ -230,12 +211,8 @@ describe('erc to native', () => {
|
|||||||
console.error(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
|
// check that balance increases
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const balance = await homeWeb3.eth.getBalance(user.address)
|
const balance = await homeWeb3.eth.getBalance(user.address)
|
||||||
if (toBN(balance).lte(toBN(originalBalanceOnHome))) {
|
if (toBN(balance).lte(toBN(originalBalanceOnHome))) {
|
||||||
retry()
|
retry()
|
||||||
@ -260,12 +237,8 @@ describe('erc to native', () => {
|
|||||||
gas: '1000000'
|
gas: '1000000'
|
||||||
})
|
})
|
||||||
|
|
||||||
// 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
|
// check that balance increases
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const balance = await homeWeb3.eth.getBalance(user.address)
|
const balance = await homeWeb3.eth.getBalance(user.address)
|
||||||
if (toBN(balance).lte(toBN(originalBalanceOnHome))) {
|
if (toBN(balance).lte(toBN(originalBalanceOnHome))) {
|
||||||
retry()
|
retry()
|
||||||
@ -290,9 +263,9 @@ describe('erc to native', () => {
|
|||||||
gas: '1000000'
|
gas: '1000000'
|
||||||
})
|
})
|
||||||
|
|
||||||
await generateNewBlock(foreignWeb3, user.address)
|
await sleep(2000)
|
||||||
|
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const userBalance = await homeWeb3.eth.getBalance(user.address)
|
const userBalance = await homeWeb3.eth.getBalance(user.address)
|
||||||
const updatedBridgeErc20TokenBalance = await erc20Token.methods.balanceOf(COMMON_FOREIGN_BRIDGE_ADDRESS).call()
|
const updatedBridgeErc20TokenBalance = await erc20Token.methods.balanceOf(COMMON_FOREIGN_BRIDGE_ADDRESS).call()
|
||||||
|
|
||||||
@ -351,12 +324,8 @@ describe('erc to native', () => {
|
|||||||
console.error(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
|
// check that balance increases
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const secondUserbalance = await homeWeb3.eth.getBalance(secondUser.address)
|
const secondUserbalance = await homeWeb3.eth.getBalance(secondUser.address)
|
||||||
const updatedBridgeErc20TokenBalance = await erc20Token.methods.balanceOf(COMMON_FOREIGN_BRIDGE_ADDRESS).call()
|
const updatedBridgeErc20TokenBalance = await erc20Token.methods.balanceOf(COMMON_FOREIGN_BRIDGE_ADDRESS).call()
|
||||||
const userbalance = await homeWeb3.eth.getBalance(user.address)
|
const userbalance = await homeWeb3.eth.getBalance(user.address)
|
||||||
@ -401,7 +370,7 @@ describe('erc to native', () => {
|
|||||||
|
|
||||||
const valueToTransfer = foreignWeb3.utils.toWei('1', 'ether')
|
const valueToTransfer = foreignWeb3.utils.toWei('1', 'ether')
|
||||||
|
|
||||||
await generateNewBlock(foreignWeb3, user.address)
|
await sleep(2000)
|
||||||
|
|
||||||
// this transfer won't trigger a call to swap tokens
|
// this transfer won't trigger a call to swap tokens
|
||||||
await halfDuplexToken.methods.transfer(COMMON_FOREIGN_BRIDGE_ADDRESS, valueToTransfer).send({
|
await halfDuplexToken.methods.transfer(COMMON_FOREIGN_BRIDGE_ADDRESS, valueToTransfer).send({
|
||||||
@ -409,10 +378,6 @@ describe('erc to native', () => {
|
|||||||
gas: '1000000'
|
gas: '1000000'
|
||||||
})
|
})
|
||||||
|
|
||||||
// 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 transfer and swap are not processed in the next blocks.
|
// check that transfer and swap are not processed in the next blocks.
|
||||||
await promiseRetry(async (retry, number) => {
|
await promiseRetry(async (retry, number) => {
|
||||||
const balanceOnHome = await homeWeb3.eth.getBalance(user.address)
|
const balanceOnHome = await homeWeb3.eth.getBalance(user.address)
|
||||||
@ -428,9 +393,6 @@ describe('erc to native', () => {
|
|||||||
)
|
)
|
||||||
assert(toBN(currentBridgeErc20TokenBalance).eq(toBN(bridgeErc20TokenBalance)), 'erc20 balance should not change')
|
assert(toBN(currentBridgeErc20TokenBalance).eq(toBN(bridgeErc20TokenBalance)), 'erc20 balance should not change')
|
||||||
|
|
||||||
// generate new blocks
|
|
||||||
await generateNewBlock(foreignWeb3, user.address)
|
|
||||||
|
|
||||||
// after several retries, the state is corrects
|
// after several retries, the state is corrects
|
||||||
if (number < 4) {
|
if (number < 4) {
|
||||||
retry()
|
retry()
|
||||||
@ -450,9 +412,9 @@ describe('erc to native', () => {
|
|||||||
gas: '1000000'
|
gas: '1000000'
|
||||||
})
|
})
|
||||||
|
|
||||||
await generateNewBlock(foreignWeb3, user.address)
|
await sleep(2000)
|
||||||
|
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const userBalance = await homeWeb3.eth.getBalance(user.address)
|
const userBalance = await homeWeb3.eth.getBalance(user.address)
|
||||||
const updatedBridgeErc20TokenBalance = await erc20Token.methods.balanceOf(COMMON_FOREIGN_BRIDGE_ADDRESS).call()
|
const updatedBridgeErc20TokenBalance = await erc20Token.methods.balanceOf(COMMON_FOREIGN_BRIDGE_ADDRESS).call()
|
||||||
|
|
||||||
@ -487,7 +449,7 @@ describe('erc to native', () => {
|
|||||||
assert(!toBN(balance).isZero(), 'Account should have tokens')
|
assert(!toBN(balance).isZero(), 'Account should have tokens')
|
||||||
|
|
||||||
// send transaction to home bridge
|
// send transaction to home bridge
|
||||||
const depositTx = await homeWeb3.eth.sendTransaction({
|
await homeWeb3.eth.sendTransaction({
|
||||||
from: user.address,
|
from: user.address,
|
||||||
to: COMMON_HOME_BRIDGE_ADDRESS,
|
to: COMMON_HOME_BRIDGE_ADDRESS,
|
||||||
gasPrice: '1',
|
gasPrice: '1',
|
||||||
@ -495,31 +457,8 @@ describe('erc to native', () => {
|
|||||||
value: homeWeb3.utils.toWei('0.01')
|
value: homeWeb3.utils.toWei('0.01')
|
||||||
})
|
})
|
||||||
|
|
||||||
// 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 balance increases
|
// check that balance increases
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
await generateNewBlock(homeWeb3, user.address)
|
|
||||||
const balance = await erc20Token.methods.balanceOf(user.address).call()
|
const balance = await erc20Token.methods.balanceOf(user.address).call()
|
||||||
if (toBN(balance).lte(toBN(originalBalance))) {
|
if (toBN(balance).lte(toBN(originalBalance))) {
|
||||||
retry()
|
retry()
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const promiseRetry = require('promise-retry')
|
|
||||||
const {
|
const {
|
||||||
user,
|
user,
|
||||||
validator,
|
validator,
|
||||||
@ -14,7 +13,7 @@ const {
|
|||||||
foreignRPC
|
foreignRPC
|
||||||
} = require('../../e2e-commons/constants.json')
|
} = require('../../e2e-commons/constants.json')
|
||||||
const { ERC677_BRIDGE_TOKEN_ABI, HOME_NATIVE_TO_ERC_ABI, FOREIGN_NATIVE_TO_ERC_ABI } = require('../../commons')
|
const { ERC677_BRIDGE_TOKEN_ABI, HOME_NATIVE_TO_ERC_ABI, FOREIGN_NATIVE_TO_ERC_ABI } = require('../../commons')
|
||||||
const { generateNewBlock } = require('../../e2e-commons/utils')
|
const { uniformRetry, sleep } = require('../../e2e-commons/utils')
|
||||||
const { setRequiredSignatures } = require('./utils')
|
const { setRequiredSignatures } = require('./utils')
|
||||||
|
|
||||||
const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL))
|
const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL))
|
||||||
@ -24,6 +23,8 @@ const { toBN } = foreignWeb3.utils
|
|||||||
const COMMON_HOME_BRIDGE_ADDRESS = nativeToErcBridge.home
|
const COMMON_HOME_BRIDGE_ADDRESS = nativeToErcBridge.home
|
||||||
const COMMON_FOREIGN_BRIDGE_ADDRESS = nativeToErcBridge.foreign
|
const COMMON_FOREIGN_BRIDGE_ADDRESS = nativeToErcBridge.foreign
|
||||||
|
|
||||||
|
const validatorAddresses = [validator.address, secondValidator.address, thirdValidator.address]
|
||||||
|
|
||||||
homeWeb3.eth.accounts.wallet.add(user.privateKey)
|
homeWeb3.eth.accounts.wallet.add(user.privateKey)
|
||||||
homeWeb3.eth.accounts.wallet.add(validator.privateKey)
|
homeWeb3.eth.accounts.wallet.add(validator.privateKey)
|
||||||
homeWeb3.eth.accounts.wallet.add(secondUser.privateKey)
|
homeWeb3.eth.accounts.wallet.add(secondUser.privateKey)
|
||||||
@ -43,8 +44,6 @@ const token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, nativeToErcB
|
|||||||
const homeBridge = new homeWeb3.eth.Contract(HOME_NATIVE_TO_ERC_ABI, COMMON_HOME_BRIDGE_ADDRESS)
|
const homeBridge = new homeWeb3.eth.Contract(HOME_NATIVE_TO_ERC_ABI, COMMON_HOME_BRIDGE_ADDRESS)
|
||||||
const foreignBridge = new foreignWeb3.eth.Contract(FOREIGN_NATIVE_TO_ERC_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
const foreignBridge = new foreignWeb3.eth.Contract(FOREIGN_NATIVE_TO_ERC_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
||||||
|
|
||||||
const sleep = timeout => new Promise(res => setTimeout(res, timeout))
|
|
||||||
|
|
||||||
describe('native to erc', () => {
|
describe('native to erc', () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
// Set 2 required signatures for home bridge
|
// Set 2 required signatures for home bridge
|
||||||
@ -75,7 +74,7 @@ describe('native to erc', () => {
|
|||||||
assert(toBN(balance).isZero(), 'Account should not have tokens yet')
|
assert(toBN(balance).isZero(), 'Account should not have tokens yet')
|
||||||
|
|
||||||
// send transaction to home chain
|
// send transaction to home chain
|
||||||
const depositTx = await homeWeb3.eth.sendTransaction({
|
await homeWeb3.eth.sendTransaction({
|
||||||
from: user.address,
|
from: user.address,
|
||||||
to: COMMON_HOME_BRIDGE_ADDRESS,
|
to: COMMON_HOME_BRIDGE_ADDRESS,
|
||||||
gasPrice: '1',
|
gasPrice: '1',
|
||||||
@ -83,30 +82,8 @@ describe('native to erc', () => {
|
|||||||
value: '1000000000000000000'
|
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
|
// check that account has tokens in the foreign chain
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const balance = await token.methods.balanceOf(user.address).call()
|
const balance = await token.methods.balanceOf(user.address).call()
|
||||||
if (toBN(balance).isZero()) {
|
if (toBN(balance).isZero()) {
|
||||||
retry()
|
retry()
|
||||||
@ -128,12 +105,8 @@ describe('native to erc', () => {
|
|||||||
console.error(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
|
// check that balance increases
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const balance = await homeWeb3.eth.getBalance(user.address)
|
const balance = await homeWeb3.eth.getBalance(user.address)
|
||||||
if (toBN(balance).lte(toBN(originalBalance))) {
|
if (toBN(balance).lte(toBN(originalBalance))) {
|
||||||
retry()
|
retry()
|
||||||
@ -150,8 +123,9 @@ describe('native to erc', () => {
|
|||||||
await sendAllBalance(homeWeb3, secondValidator.address, thirdUser.address)
|
await sendAllBalance(homeWeb3, secondValidator.address, thirdUser.address)
|
||||||
await sendAllBalance(homeWeb3, thirdValidator.address, fourthUser.address)
|
await sendAllBalance(homeWeb3, thirdValidator.address, fourthUser.address)
|
||||||
|
|
||||||
|
const nonces = await Promise.all(validatorAddresses.map(homeWeb3.eth.getTransactionCount))
|
||||||
// send transaction to home chain
|
// send transaction to home chain
|
||||||
const depositTx = await homeWeb3.eth.sendTransaction({
|
await homeWeb3.eth.sendTransaction({
|
||||||
from: user.address,
|
from: user.address,
|
||||||
to: COMMON_HOME_BRIDGE_ADDRESS,
|
to: COMMON_HOME_BRIDGE_ADDRESS,
|
||||||
gasPrice: '1',
|
gasPrice: '1',
|
||||||
@ -159,41 +133,20 @@ describe('native to erc', () => {
|
|||||||
value: '1000000000000000000'
|
value: '1000000000000000000'
|
||||||
})
|
})
|
||||||
|
|
||||||
// Send a Tx to generate a new block
|
|
||||||
await generateNewBlock(homeWeb3, user.address)
|
|
||||||
|
|
||||||
// wait two seconds, no new blocks should have been generated
|
// wait two seconds, no new blocks should have been generated
|
||||||
await sleep(2000)
|
await sleep(2000)
|
||||||
const lastBlockNumber = await homeWeb3.eth.getBlockNumber()
|
const newNonces = await Promise.all(validatorAddresses.map(homeWeb3.eth.getTransactionCount))
|
||||||
const balance = toBN(await token.methods.balanceOf(user.address).call())
|
const balance = toBN(await token.methods.balanceOf(user.address).call())
|
||||||
assert(lastBlockNumber === depositTx.blockNumber + 1, "Shouldn't have emitted a new block")
|
assert.deepStrictEqual(nonces, newNonces, "Shouldn't sent new tx")
|
||||||
assert(originalBalance.eq(balance), "Token balance shouldn't have changed")
|
assert(originalBalance.eq(balance), "Token balance shouldn't have changed")
|
||||||
|
|
||||||
// send funds back to validator
|
// send funds back to validator
|
||||||
await sendAllBalance(homeWeb3, secondUser.address, validator.address)
|
await sendAllBalance(homeWeb3, secondUser.address, validator.address)
|
||||||
await sendAllBalance(homeWeb3, thirdUser.address, secondValidator.address)
|
await sendAllBalance(homeWeb3, thirdUser.address, secondValidator.address)
|
||||||
const sendBalanceBackTx = await sendAllBalance(homeWeb3, fourthUser.address, thirdValidator.address)
|
await sendAllBalance(homeWeb3, fourthUser.address, thirdValidator.address)
|
||||||
|
|
||||||
// expect Deposit event to be processed
|
|
||||||
await promiseRetry(
|
|
||||||
async retry => {
|
|
||||||
const lastBlockNumber = await homeWeb3.eth.getBlockNumber()
|
|
||||||
// check that a new block was created since the last transaction
|
|
||||||
if (lastBlockNumber >= sendBalanceBackTx.blockNumber + 1) {
|
|
||||||
await generateNewBlock(homeWeb3, user.address)
|
|
||||||
} else {
|
|
||||||
retry()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
forever: true,
|
|
||||||
factor: 1,
|
|
||||||
minTimeout: 500
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// check that token balance was incremented in foreign chain
|
// check that token balance was incremented in foreign chain
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const balance = toBN(await token.methods.balanceOf(user.address).call())
|
const balance = toBN(await token.methods.balanceOf(user.address).call())
|
||||||
if (!balance.gt(originalBalance)) {
|
if (!balance.gt(originalBalance)) {
|
||||||
retry()
|
retry()
|
||||||
@ -209,7 +162,7 @@ describe('native to erc', () => {
|
|||||||
await sendAllBalance(foreignWeb3, validator.address, secondUser.address)
|
await sendAllBalance(foreignWeb3, validator.address, secondUser.address)
|
||||||
await sendAllBalance(foreignWeb3, secondValidator.address, thirdUser.address)
|
await sendAllBalance(foreignWeb3, secondValidator.address, thirdUser.address)
|
||||||
await sendAllBalance(foreignWeb3, thirdValidator.address, fourthUser.address)
|
await sendAllBalance(foreignWeb3, thirdValidator.address, fourthUser.address)
|
||||||
const foreignBlockNumber = await foreignWeb3.eth.getBlockNumber()
|
const nonces = await Promise.all(validatorAddresses.map(foreignWeb3.eth.getTransactionCount))
|
||||||
|
|
||||||
// send transaction to home chain
|
// send transaction to home chain
|
||||||
await homeWeb3.eth.sendTransaction({
|
await homeWeb3.eth.sendTransaction({
|
||||||
@ -220,30 +173,10 @@ describe('native to erc', () => {
|
|||||||
value: '1000000000000000000'
|
value: '1000000000000000000'
|
||||||
})
|
})
|
||||||
|
|
||||||
// Send a Tx to generate a new block
|
|
||||||
const lastHomeTx = await generateNewBlock(homeWeb3, user.address)
|
|
||||||
|
|
||||||
// wait for the deposit to be processed
|
|
||||||
await promiseRetry(
|
|
||||||
async retry => {
|
|
||||||
const lastBlockNumber = await homeWeb3.eth.getBlockNumber()
|
|
||||||
if (lastBlockNumber >= lastHomeTx.blockNumber + 1) {
|
|
||||||
await generateNewBlock(homeWeb3, user.address)
|
|
||||||
} else {
|
|
||||||
retry()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
forever: true,
|
|
||||||
factor: 1,
|
|
||||||
minTimeout: 500
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// tokens shouldn't be generated in the foreign chain because the validator doesn't have funds
|
// tokens shouldn't be generated in the foreign chain because the validator doesn't have funds
|
||||||
await sleep(2000)
|
await sleep(2000)
|
||||||
const lastForeignBlockNumber = await foreignWeb3.eth.getBlockNumber()
|
const newNonces = await Promise.all(validatorAddresses.map(foreignWeb3.eth.getTransactionCount))
|
||||||
assert(lastForeignBlockNumber === foreignBlockNumber, "Shouldn't have emitted a new block")
|
assert.deepStrictEqual(nonces, newNonces, "Shouldn't sent new tx")
|
||||||
|
|
||||||
// send funds back to validator
|
// send funds back to validator
|
||||||
await sendAllBalance(foreignWeb3, secondUser.address, validator.address)
|
await sendAllBalance(foreignWeb3, secondUser.address, validator.address)
|
||||||
@ -251,7 +184,7 @@ describe('native to erc', () => {
|
|||||||
await sendAllBalance(foreignWeb3, fourthUser.address, thirdValidator.address)
|
await sendAllBalance(foreignWeb3, fourthUser.address, thirdValidator.address)
|
||||||
|
|
||||||
// check that account has tokens in the foreign chain
|
// check that account has tokens in the foreign chain
|
||||||
await promiseRetry(async retry => {
|
await uniformRetry(async retry => {
|
||||||
const balance = toBN(await token.methods.balanceOf(user.address).call())
|
const balance = toBN(await token.methods.balanceOf(user.address).call())
|
||||||
if (balance.eq(originalBalance)) {
|
if (balance.eq(originalBalance)) {
|
||||||
retry()
|
retry()
|
||||||
|
Loading…
Reference in New Issue
Block a user