Use 3 validators in oracle e2e tests (#264)

This commit is contained in:
Gerardo Nardelli 2020-01-20 17:00:04 -03:00 committed by Alexander Kolotov
parent 612f130544
commit edc51c78e2
17 changed files with 223 additions and 21 deletions

@ -7,10 +7,26 @@
"address": "0xcca2fb44C8C36E51f743269d6F484Fd027B9F9Aa", "address": "0xcca2fb44C8C36E51f743269d6F484Fd027B9F9Aa",
"privateKey": "0xcf954e07e6a439faf392eb474e95ddb444c2ca444847f2ad6ecc79e1a585e2b8" "privateKey": "0xcf954e07e6a439faf392eb474e95ddb444c2ca444847f2ad6ecc79e1a585e2b8"
}, },
"thirdUser": {
"address": "0x441cc8537aB6cE63d060b63F3A44eE021d62e6cF",
"privateKey": "0xd3915199f27691d7784cb01ab0c7220308053b229f95d592e97493326314a8d0"
},
"fourthUser": {
"address": "0x3CC5baAB679eC0732C175760079Bf48F564ad26B",
"privateKey": "0xedb53ee050631b7914d5f1a66c2f0d2df3ec85a9ed2a9616b16a7b1b7a10b8d1"
},
"validator": { "validator": {
"address": "0xaaB52d66283F7A1D5978bcFcB55721ACB467384b", "address": "0xaaB52d66283F7A1D5978bcFcB55721ACB467384b",
"privateKey": "0x8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9" "privateKey": "0x8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9"
}, },
"secondValidator": {
"address": "0xdCC784657C78054aa61FbcFFd2605F32374816A4",
"privateKey": "0x5a5c3645d0f04e9eb4f27f94ed4c244a225587405b8838e7456f7781ce3a9513"
},
"thirdValidator": {
"address": "0xDcef88209a20D52165230104B245803C3269454d",
"privateKey": "0xf877f62a1c19f852cff1d29f0fb1ecac18821c0080d4cc0520c60c098293dca1"
},
"blockGenerator": { "blockGenerator": {
"address": "0xB4579fd5AfEaB60B03Db3F408AAdD315035943f7", "address": "0xB4579fd5AfEaB60B03Db3F408AAdD315035943f7",
"privateKey": "0xd6143d390d8b28c33601bb0fe29392fb1c35c24ccfe8722c09c2bdd6ada2699f" "privateKey": "0xd6143d390d8b28c33601bb0fe29392fb1c35c24ccfe8722c09c2bdd6ada2699f"

@ -22,4 +22,4 @@ FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS=1
FOREIGN_GAS_PRICE=10000000000 FOREIGN_GAS_PRICE=10000000000
REQUIRED_NUMBER_OF_VALIDATORS=1 REQUIRED_NUMBER_OF_VALIDATORS=1
VALIDATORS=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b VALIDATORS="0xaaB52d66283F7A1D5978bcFcB55721ACB467384b 0xdCC784657C78054aa61FbcFFd2605F32374816A4 0xDcef88209a20D52165230104B245803C3269454d"

@ -34,8 +34,7 @@ FOREIGN_REWARDABLE=false
ERC20_TOKEN_ADDRESS=0x3C665A31199694Bf723fD08844AD290207B5797f ERC20_TOKEN_ADDRESS=0x3C665A31199694Bf723fD08844AD290207B5797f
REQUIRED_NUMBER_OF_VALIDATORS=1 REQUIRED_NUMBER_OF_VALIDATORS=1
VALIDATORS="0xaaB52d66283F7A1D5978bcFcB55721ACB467384b" VALIDATORS="0xaaB52d66283F7A1D5978bcFcB55721ACB467384b 0xdCC784657C78054aa61FbcFFd2605F32374816A4 0xDcef88209a20D52165230104B245803C3269454d"
VALIDATORS_REWARD_ACCOUNTS=0x0000000000000000000000000000000000000000
BLOCK_REWARD_ADDRESS=0x0000000000000000000000000000000000000000 BLOCK_REWARD_ADDRESS=0x0000000000000000000000000000000000000000
DPOS_STAKING_ADDRESS=0x0000000000000000000000000000000000000000 DPOS_STAKING_ADDRESS=0x0000000000000000000000000000000000000000
ERC20_EXTENDED_BY_ERC677=false ERC20_EXTENDED_BY_ERC677=false

@ -35,5 +35,4 @@ BLOCK_REWARD_ADDRESS=0xF9698Eb93702dfdd0e2d802088d4c21822a8A977
ERC20_TOKEN_ADDRESS=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359 ERC20_TOKEN_ADDRESS=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359
REQUIRED_NUMBER_OF_VALIDATORS=1 REQUIRED_NUMBER_OF_VALIDATORS=1
VALIDATORS="0xaaB52d66283F7A1D5978bcFcB55721ACB467384b" VALIDATORS="0xaaB52d66283F7A1D5978bcFcB55721ACB467384b 0xdCC784657C78054aa61FbcFFd2605F32374816A4 0xDcef88209a20D52165230104B245803C3269454d"
VALIDATORS_REWARD_ACCOUNTS=0x0000000000000000000000000000000000000000

@ -34,6 +34,5 @@ FOREIGN_GAS_PRICE=10000000000
FOREIGN_REWARDABLE=false FOREIGN_REWARDABLE=false
REQUIRED_NUMBER_OF_VALIDATORS=1 REQUIRED_NUMBER_OF_VALIDATORS=1
VALIDATORS="0xaaB52d66283F7A1D5978bcFcB55721ACB467384b" VALIDATORS="0xaaB52d66283F7A1D5978bcFcB55721ACB467384b 0xdCC784657C78054aa61FbcFFd2605F32374816A4 0xDcef88209a20D52165230104B245803C3269454d"
VALIDATORS_REWARD_ACCOUNTS=0x0000000000000000000000000000000000000000
BLOCK_REWARD_ADDRESS=0x0000000000000000000000000000000000000000 BLOCK_REWARD_ADDRESS=0x0000000000000000000000000000000000000000

@ -24,8 +24,6 @@ services:
- ultimate - ultimate
rabbit: rabbit:
image: "rabbitmq:3-management" image: "rabbitmq:3-management"
ports:
- "15672:15672"
networks: networks:
- ultimate - ultimate
oracle: oracle:

@ -5,4 +5,6 @@ if [ $CI ]; then exit $rc; fi
ps | grep node | grep -v grep | awk '{print "kill " $1}' | /bin/bash ps | grep node | grep -v grep | awk '{print "kill " $1}' | /bin/bash
docker-compose down docker-compose down
docker-compose -p validator2 down
docker-compose -p validator3 down
docker network rm ultimate || true docker network rm ultimate || true

@ -7,6 +7,29 @@ docker-compose build
docker network create --driver bridge ultimate || true docker network create --driver bridge ultimate || true
docker-compose up -d parity1 parity2 e2e docker-compose up -d parity1 parity2 e2e
startValidator () {
docker-compose $1 run -d --name $4 redis
docker-compose $1 run -d --name $5 rabbit
docker-compose $1 run $2 $3 -d oracle yarn watcher:signature-request
docker-compose $1 run $2 $3 -d oracle yarn watcher:collected-signatures
docker-compose $1 run $2 $3 -d oracle yarn watcher:affirmation-request
docker-compose $1 run $2 $3 -d oracle-erc20 yarn watcher:signature-request
docker-compose $1 run $2 $3 -d oracle-erc20 yarn watcher:collected-signatures
docker-compose $1 run $2 $3 -d oracle-erc20 yarn watcher:affirmation-request
docker-compose $1 run $2 $3 -d oracle-erc20 yarn watcher:transfer
docker-compose $1 run $2 $3 -d oracle-erc20-native yarn watcher:signature-request
docker-compose $1 run $2 $3 -d oracle-erc20-native yarn watcher:collected-signatures
docker-compose $1 run $2 $3 -d oracle-erc20-native yarn watcher:affirmation-request
docker-compose $1 run $2 $3 -d oracle-erc20-native yarn watcher:transfer
docker-compose $1 run $2 $3 -d oracle-erc20-native yarn watcher:half-duplex-transfer
docker-compose $1 run $2 $3 -d oracle-erc20-native yarn worker:swap-tokens
docker-compose $1 run $2 $3 -d oracle-amb yarn watcher:signature-request
docker-compose $1 run $2 $3 -d oracle-amb yarn watcher:collected-signatures
docker-compose $1 run $2 $3 -d oracle-amb yarn watcher:affirmation-request
docker-compose $1 run $2 $3 -d oracle-erc20-native yarn sender:home
docker-compose $1 run $2 $3 -d oracle-erc20-native yarn sender:foreign
}
while [ "$1" != "" ]; do while [ "$1" != "" ]; do
if [ "$1" == "oracle" ]; then if [ "$1" == "oracle" ]; then
docker-compose up -d redis rabbit oracle oracle-erc20 oracle-erc20-native oracle-amb docker-compose up -d redis rabbit oracle oracle-erc20 oracle-erc20-native oracle-amb
@ -31,6 +54,20 @@ while [ "$1" != "" ]; do
docker-compose run -d oracle yarn sender:foreign docker-compose run -d oracle yarn sender:foreign
fi fi
if [ "$1" == "oracle-validator-2" ]; then
oracle2name="-p validator2"
oracle2Values="-e ORACLE_VALIDATOR_ADDRESS=0xdCC784657C78054aa61FbcFFd2605F32374816A4 -e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=5a5c3645d0f04e9eb4f27f94ed4c244a225587405b8838e7456f7781ce3a9513"
oracle2comp="-e ORACLE_QUEUE_URL=amqp://rabbit2 -e ORACLE_REDIS_URL=redis://redis2"
startValidator "$oracle2name" "$oracle2Values" "$oracle2comp" "redis2" "rabbit2"
fi
if [ "$1" == "oracle-validator-3" ]; then
oracle3name="-p validator3"
oracle3Values="-e ORACLE_VALIDATOR_ADDRESS=0xDcef88209a20D52165230104B245803C3269454d -e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=f877f62a1c19f852cff1d29f0fb1ecac18821c0080d4cc0520c60c098293dca1"
oracle3comp="-e ORACLE_QUEUE_URL=amqp://rabbit3 -e ORACLE_REDIS_URL=redis://redis3"
startValidator "$oracle3name" "$oracle3Values" "$oracle3comp" "redis3" "rabbit3"
fi
if [ "$1" == "ui" ]; then if [ "$1" == "ui" ]; then
docker-compose up -d ui ui-erc20 ui-erc20-native docker-compose up -d ui ui-erc20 ui-erc20-native

@ -1,6 +1,6 @@
cd $(dirname $0) cd $(dirname $0)
../e2e-commons/up.sh deploy oracle ../e2e-commons/up.sh deploy 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,22 +1,53 @@
const Web3 = require('web3') const Web3 = require('web3')
const assert = require('assert') const assert = require('assert')
const promiseRetry = require('promise-retry') const promiseRetry = require('promise-retry')
const { user, homeRPC, foreignRPC, amb } = require('../../e2e-commons/constants.json') const { user, homeRPC, foreignRPC, amb, validator } = require('../../e2e-commons/constants.json')
const { generateNewBlock } = require('../../e2e-commons/utils') const { generateNewBlock } = require('../../e2e-commons/utils')
const { BOX_ABI } = require('../../commons') const { BOX_ABI, HOME_AMB_ABI, FOREIGN_AMB_ABI } = require('../../commons')
const { setRequiredSignatures } = require('./utils')
const { toBN } = Web3.utils const { toBN } = Web3.utils
const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL)) const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL))
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL)) const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL))
const COMMON_HOME_BRIDGE_ADDRESS = amb.home
const COMMON_FOREIGN_BRIDGE_ADDRESS = amb.foreign
homeWeb3.eth.accounts.wallet.add(user.privateKey) homeWeb3.eth.accounts.wallet.add(user.privateKey)
homeWeb3.eth.accounts.wallet.add(validator.privateKey)
foreignWeb3.eth.accounts.wallet.add(user.privateKey) foreignWeb3.eth.accounts.wallet.add(user.privateKey)
foreignWeb3.eth.accounts.wallet.add(validator.privateKey)
const homeBox = new homeWeb3.eth.Contract(BOX_ABI, amb.homeBox) const homeBox = new homeWeb3.eth.Contract(BOX_ABI, amb.homeBox)
const foreignBox = new foreignWeb3.eth.Contract(BOX_ABI, amb.foreignBox) const foreignBox = new foreignWeb3.eth.Contract(BOX_ABI, amb.foreignBox)
const homeBridge = new homeWeb3.eth.Contract(HOME_AMB_ABI, COMMON_HOME_BRIDGE_ADDRESS)
const foreignBridge = new foreignWeb3.eth.Contract(FOREIGN_AMB_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
describe('arbitrary message bridging', () => { describe('arbitrary message bridging', () => {
before(async () => {
// Set 2 required signatures for home bridge
await setRequiredSignatures({
bridgeContract: homeBridge,
web3: homeWeb3,
requiredSignatures: 2,
options: {
from: validator.address,
gas: '4000000'
}
})
// Set 2 required signatures for foreign bridge
await setRequiredSignatures({
bridgeContract: foreignBridge,
web3: foreignWeb3,
requiredSignatures: 2,
options: {
from: validator.address,
gas: '4000000'
}
})
})
describe('Home to Foreign', () => { describe('Home to Foreign', () => {
describe('Subsidized Mode', () => { describe('Subsidized Mode', () => {
it('should bridge message', async () => { it('should bridge message', async () => {
@ -59,6 +90,7 @@ describe('arbitrary message bridging', () => {
// check that value changed and balance decreased // check that value changed and balance decreased
await promiseRetry(async retry => { await promiseRetry(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()

@ -1,9 +1,10 @@
const Web3 = require('web3') const Web3 = require('web3')
const assert = require('assert') const assert = require('assert')
const promiseRetry = require('promise-retry') const promiseRetry = require('promise-retry')
const { user, secondUser, ercToErcBridge, homeRPC, foreignRPC } = 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 } = 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 { generateNewBlock } = require('../../e2e-commons/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))
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL)) const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL))
@ -14,13 +15,39 @@ const COMMON_FOREIGN_BRIDGE_ADDRESS = ercToErcBridge.foreign
const { toBN } = foreignWeb3.utils const { toBN } = foreignWeb3.utils
homeWeb3.eth.accounts.wallet.add(user.privateKey) homeWeb3.eth.accounts.wallet.add(user.privateKey)
homeWeb3.eth.accounts.wallet.add(validator.privateKey)
foreignWeb3.eth.accounts.wallet.add(user.privateKey) foreignWeb3.eth.accounts.wallet.add(user.privateKey)
foreignWeb3.eth.accounts.wallet.add(validator.privateKey)
const erc20Token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToErcBridge.foreignToken) const erc20Token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToErcBridge.foreignToken)
const foreignBridge = new foreignWeb3.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS) const foreignBridge = new foreignWeb3.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
const erc677Token = new homeWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToErcBridge.homeToken) const erc677Token = new homeWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToErcBridge.homeToken)
const homeBridge = new homeWeb3.eth.Contract(HOME_ERC_TO_ERC_ABI, COMMON_HOME_BRIDGE_ADDRESS)
describe('erc to erc', () => { describe('erc to erc', () => {
before(async () => {
// Set 2 required signatures for home bridge
await setRequiredSignatures({
bridgeContract: homeBridge,
web3: homeWeb3,
requiredSignatures: 2,
options: {
from: validator.address,
gas: '4000000'
}
})
// Set 2 required signatures for foreign bridge
await setRequiredSignatures({
bridgeContract: foreignBridge,
web3: foreignWeb3,
requiredSignatures: 2,
options: {
from: validator.address,
gas: '4000000'
}
})
})
it('should convert tokens in foreign to tokens in home', async () => { it('should convert tokens in foreign to tokens in home', async () => {
const balance = await erc20Token.methods.balanceOf(user.address).call() const balance = await erc20Token.methods.balanceOf(user.address).call()
assert(!toBN(balance).isZero(), 'Account should have tokens') assert(!toBN(balance).isZero(), 'Account should have tokens')
@ -132,6 +159,7 @@ describe('erc to erc', () => {
// check that balance increases // check that balance increases
await promiseRetry(async retry => { await promiseRetry(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()

@ -9,8 +9,9 @@ const {
homeRPC, homeRPC,
foreignRPC foreignRPC
} = require('../../e2e-commons/constants.json') } = require('../../e2e-commons/constants.json')
const { ERC677_BRIDGE_TOKEN_ABI, FOREIGN_ERC_TO_NATIVE_ABI, SAI_TOP } = 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 { generateNewBlock } = require('../../e2e-commons/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))
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL)) const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL))
@ -21,11 +22,13 @@ const COMMON_FOREIGN_BRIDGE_ADDRESS = ercToNativeBridge.foreign
const { toBN } = foreignWeb3.utils const { toBN } = foreignWeb3.utils
homeWeb3.eth.accounts.wallet.add(user.privateKey) homeWeb3.eth.accounts.wallet.add(user.privateKey)
homeWeb3.eth.accounts.wallet.add(validator.privateKey)
foreignWeb3.eth.accounts.wallet.add(user.privateKey) foreignWeb3.eth.accounts.wallet.add(user.privateKey)
foreignWeb3.eth.accounts.wallet.add(validator.privateKey) foreignWeb3.eth.accounts.wallet.add(validator.privateKey)
const erc20Token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToNativeBridge.foreignToken) const erc20Token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToNativeBridge.foreignToken)
const foreignBridge = new foreignWeb3.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS) const foreignBridge = new foreignWeb3.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
const homeBridge = new homeWeb3.eth.Contract(HOME_ERC_TO_NATIVE_ABI, COMMON_HOME_BRIDGE_ADDRESS)
describe('erc to native', () => { describe('erc to native', () => {
let halfDuplexTokenAddress let halfDuplexTokenAddress
@ -33,6 +36,28 @@ describe('erc to native', () => {
before(async () => { before(async () => {
halfDuplexTokenAddress = await foreignBridge.methods.halfDuplexErc20token().call() halfDuplexTokenAddress = await foreignBridge.methods.halfDuplexErc20token().call()
halfDuplexToken = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, halfDuplexTokenAddress) halfDuplexToken = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, halfDuplexTokenAddress)
// Set 2 required signatures for home bridge
await setRequiredSignatures({
bridgeContract: homeBridge,
web3: homeWeb3,
requiredSignatures: 2,
options: {
from: validator.address,
gas: '4000000'
}
})
// Set 2 required signatures for foreign bridge
await setRequiredSignatures({
bridgeContract: foreignBridge,
web3: foreignWeb3,
requiredSignatures: 2,
options: {
from: validator.address,
gas: '4000000'
}
})
}) })
it('should continue working after migration', async () => { it('should continue working after migration', async () => {
const originalBalanceOnHome = await homeWeb3.eth.getBalance(user.address) const originalBalanceOnHome = await homeWeb3.eth.getBalance(user.address)
@ -81,7 +106,7 @@ describe('erc to native', () => {
}) })
// update min threshold for swap // update min threshold for swap
await foreignBridge.methods.setMinHDTokenBalance(foreignWeb3.utils.toWei('1', 'ether')).send({ await foreignBridge.methods.setMinHDTokenBalance(foreignWeb3.utils.toWei('2', 'ether')).send({
from: validator.address, from: validator.address,
gas: '1000000' gas: '1000000'
}) })
@ -494,6 +519,7 @@ describe('erc to native', () => {
// check that balance increases // check that balance increases
await promiseRetry(async retry => { await promiseRetry(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 +1 @@
--timeout 30000 --timeout 120000

@ -4,13 +4,18 @@ const promiseRetry = require('promise-retry')
const { const {
user, user,
validator, validator,
secondValidator,
thirdValidator,
nativeToErcBridge, nativeToErcBridge,
secondUser, secondUser,
thirdUser,
fourthUser,
homeRPC, homeRPC,
foreignRPC foreignRPC
} = require('../../e2e-commons/constants.json') } = require('../../e2e-commons/constants.json')
const { ERC677_BRIDGE_TOKEN_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 { generateNewBlock } = require('../../e2e-commons/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))
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL)) const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL))
@ -22,15 +27,48 @@ const COMMON_FOREIGN_BRIDGE_ADDRESS = nativeToErcBridge.foreign
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)
homeWeb3.eth.accounts.wallet.add(secondValidator.privateKey)
homeWeb3.eth.accounts.wallet.add(thirdValidator.privateKey)
homeWeb3.eth.accounts.wallet.add(thirdUser.privateKey)
homeWeb3.eth.accounts.wallet.add(fourthUser.privateKey)
foreignWeb3.eth.accounts.wallet.add(user.privateKey) foreignWeb3.eth.accounts.wallet.add(user.privateKey)
foreignWeb3.eth.accounts.wallet.add(validator.privateKey) foreignWeb3.eth.accounts.wallet.add(validator.privateKey)
foreignWeb3.eth.accounts.wallet.add(secondUser.privateKey) foreignWeb3.eth.accounts.wallet.add(secondUser.privateKey)
foreignWeb3.eth.accounts.wallet.add(secondValidator.privateKey)
foreignWeb3.eth.accounts.wallet.add(thirdValidator.privateKey)
foreignWeb3.eth.accounts.wallet.add(thirdUser.privateKey)
foreignWeb3.eth.accounts.wallet.add(fourthUser.privateKey)
const token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, nativeToErcBridge.foreignToken) const token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, nativeToErcBridge.foreignToken)
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 sleep = timeout => new Promise(res => setTimeout(res, timeout)) const sleep = timeout => new Promise(res => setTimeout(res, timeout))
describe('native to erc', () => { describe('native to erc', () => {
before(async () => {
// Set 2 required signatures for home bridge
await setRequiredSignatures({
bridgeContract: homeBridge,
web3: homeWeb3,
requiredSignatures: 2,
options: {
from: validator.address,
gas: '4000000'
}
})
// Set 2 required signatures for foreign bridge
await setRequiredSignatures({
bridgeContract: foreignBridge,
web3: foreignWeb3,
requiredSignatures: 2,
options: {
from: validator.address,
gas: '4000000'
}
})
})
it('should convert eth in home to tokens in foreign', async () => { it('should convert eth in home to tokens in foreign', async () => {
// check that account has zero tokens in the foreign chain // check that account has zero tokens in the foreign chain
const balance = await token.methods.balanceOf(user.address).call() const balance = await token.methods.balanceOf(user.address).call()
@ -109,6 +147,8 @@ describe('native to erc', () => {
// empty validator funds // empty validator funds
await sendAllBalance(homeWeb3, validator.address, secondUser.address) await sendAllBalance(homeWeb3, validator.address, secondUser.address)
await sendAllBalance(homeWeb3, secondValidator.address, thirdUser.address)
await sendAllBalance(homeWeb3, thirdValidator.address, fourthUser.address)
// send transaction to home chain // send transaction to home chain
const depositTx = await homeWeb3.eth.sendTransaction({ const depositTx = await homeWeb3.eth.sendTransaction({
@ -130,14 +170,16 @@ describe('native to erc', () => {
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
const sendBalanceBackTx = await sendAllBalance(homeWeb3, secondUser.address, validator.address) await sendAllBalance(homeWeb3, secondUser.address, validator.address)
await sendAllBalance(homeWeb3, thirdUser.address, secondValidator.address)
const sendBalanceBackTx = await sendAllBalance(homeWeb3, fourthUser.address, thirdValidator.address)
// expect Deposit event to be processed // expect Deposit event to be processed
await promiseRetry( await promiseRetry(
async retry => { async retry => {
const lastBlockNumber = await homeWeb3.eth.getBlockNumber() const lastBlockNumber = await homeWeb3.eth.getBlockNumber()
// check that a new block was created since the last transaction // check that a new block was created since the last transaction
if (lastBlockNumber === sendBalanceBackTx.blockNumber + 1) { if (lastBlockNumber >= sendBalanceBackTx.blockNumber + 1) {
await generateNewBlock(homeWeb3, user.address) await generateNewBlock(homeWeb3, user.address)
} else { } else {
retry() retry()
@ -165,6 +207,8 @@ describe('native to erc', () => {
// empty foreign validator funds // empty foreign validator funds
await sendAllBalance(foreignWeb3, validator.address, secondUser.address) await sendAllBalance(foreignWeb3, validator.address, secondUser.address)
await sendAllBalance(foreignWeb3, secondValidator.address, thirdUser.address)
await sendAllBalance(foreignWeb3, thirdValidator.address, fourthUser.address)
const foreignBlockNumber = await foreignWeb3.eth.getBlockNumber() const foreignBlockNumber = await foreignWeb3.eth.getBlockNumber()
// send transaction to home chain // send transaction to home chain
@ -183,7 +227,7 @@ describe('native to erc', () => {
await promiseRetry( await promiseRetry(
async retry => { async retry => {
const lastBlockNumber = await homeWeb3.eth.getBlockNumber() const lastBlockNumber = await homeWeb3.eth.getBlockNumber()
if (lastBlockNumber === lastHomeTx.blockNumber + 1) { if (lastBlockNumber >= lastHomeTx.blockNumber + 1) {
await generateNewBlock(homeWeb3, user.address) await generateNewBlock(homeWeb3, user.address)
} else { } else {
retry() retry()
@ -203,6 +247,8 @@ describe('native to erc', () => {
// send funds back to validator // send funds back to validator
await sendAllBalance(foreignWeb3, secondUser.address, validator.address) await sendAllBalance(foreignWeb3, secondUser.address, validator.address)
await sendAllBalance(foreignWeb3, thirdUser.address, secondValidator.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 promiseRetry(async retry => {

12
oracle-e2e/test/utils.js Normal file

@ -0,0 +1,12 @@
const { BRIDGE_VALIDATORS_ABI } = require('../../commons')
const setRequiredSignatures = async ({ bridgeContract, web3, requiredSignatures, options }) => {
const validatorAddress = await bridgeContract.methods.validatorContract().call()
const validatorContract = new web3.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorAddress)
return validatorContract.methods.setRequiredSignatures(requiredSignatures).send(options)
}
module.exports = {
setRequiredSignatures
}

@ -79,6 +79,12 @@
"aaB52d66283F7A1D5978bcFcB55721ACB467384b": { "aaB52d66283F7A1D5978bcFcB55721ACB467384b": {
"balance": "1606938044258990275541962092341162602522202993782792835301376" "balance": "1606938044258990275541962092341162602522202993782792835301376"
}, },
"dCC784657C78054aa61FbcFFd2605F32374816A4": {
"balance": "1606938044258990275541962092341162602522202993782792835301376"
},
"Dcef88209a20D52165230104B245803C3269454d": {
"balance": "1606938044258990275541962092341162602522202993782792835301376"
},
"bb140FbA6242a1c3887A7823F7750a73101383e3": { "bb140FbA6242a1c3887A7823F7750a73101383e3": {
"balance": "1606938044258990275541962092341162602522202993782792835301376" "balance": "1606938044258990275541962092341162602522202993782792835301376"
}, },

File diff suppressed because one or more lines are too long