Add AMB monitor e2e tests (#231)

* Add amb monitor e2e tests
* Fix eventsStats endpoint monitor
This commit is contained in:
Gerardo Nardelli 2019-11-13 03:51:11 -03:00 committed by Alexander Kolotov
parent db89d1c12e
commit 5d770e8607
9 changed files with 180 additions and 8 deletions

@ -0,0 +1,18 @@
COMMON_HOME_RPC_URL=http://parity1:8545
COMMON_FOREIGN_RPC_URL=http://parity2:8545
COMMON_HOME_BRIDGE_ADDRESS=0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0
COMMON_FOREIGN_BRIDGE_ADDRESS=0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0
MONITOR_HOME_START_BLOCK=0
MONITOR_FOREIGN_START_BLOCK=0
MONITOR_VALIDATOR_HOME_TX_LIMIT=300000
COMMON_HOME_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/
COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard
COMMON_HOME_GAS_PRICE_FALLBACK=1000000000
COMMON_HOME_GAS_PRICE_FACTOR=1
MONITOR_VALIDATOR_FOREIGN_TX_LIMIT=300000
COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/
COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard
COMMON_FOREIGN_GAS_PRICE_FALLBACK=1000000000
COMMON_FOREIGN_GAS_PRICE_FACTOR=1
MONITOR_TX_NUMBER_THRESHOLD=100
MONITOR_PORT=3013

@ -41,7 +41,8 @@
"home": "0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0", "home": "0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0",
"foreign": "0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0", "foreign": "0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0",
"homeBox": "0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1", "homeBox": "0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1",
"foreignBox": "0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1" "foreignBox": "0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1",
"monitor": "http://monitor-amb:3013"
}, },
"homeRPC": { "homeRPC": {
"URL": "http://parity1:8545", "URL": "http://parity1:8545",

@ -132,6 +132,17 @@ services:
- "3012:3012" - "3012:3012"
networks: networks:
- ultimate - ultimate
monitor-amb:
build:
context: ..
dockerfile: monitor/Dockerfile
args:
DOT_ENV_PATH: e2e-commons/components-envs/monitor-amb.env
entrypoint: yarn check-and-start
ports:
- "3013:3013"
networks:
- ultimate
e2e: e2e:
build: build:
context: .. context: ..

@ -46,7 +46,7 @@ while [ "$1" != "" ]; do
fi fi
if [ "$1" == "monitor" ]; then if [ "$1" == "monitor" ]; then
docker-compose up -d monitor monitor-erc20 monitor-erc20-native docker-compose up -d monitor monitor-erc20 monitor-erc20-native monitor-amb
fi fi
if [ "$1" == "native-to-erc" ]; then if [ "$1" == "native-to-erc" ]; then

@ -3,4 +3,5 @@ while true; do
docker-compose -f ../e2e-commons/docker-compose.yml exec monitor yarn check-all docker-compose -f ../e2e-commons/docker-compose.yml exec monitor yarn check-all
docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-erc20 yarn check-all docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-erc20 yarn check-all
docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-erc20-native yarn check-all docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-erc20-native yarn check-all
docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-amb yarn check-all
done done

128
monitor-e2e/test/amb.js Normal file

@ -0,0 +1,128 @@
const assert = require('assert')
const axios = require('axios')
const { amb, user, foreignRPC, homeRPC, validator } = require('../../e2e-commons/constants.json')
const { waitUntil, sendAMBMessage, addValidator } = require('../utils')
const baseUrl = amb.monitor
describe('AMB', () => {
describe('balances', async () => {
let data
before(async () => {
;({ data } = await axios.get(`${baseUrl}`))
})
describe('home', async () => {
it('should contain toForeign:', () => assert(data.home.toForeign === 0))
it('should contain fromForeign', () => assert(data.home.fromForeign === 0))
})
describe('foreign', async () => {
it('should contain fromHome:', () => assert(data.foreign.fromHome === 0))
it('should contain toHome', () => assert(data.foreign.toHome === 0))
})
describe('general', async () => {
it('should contain fromHomeToForeignDiff', () => assert(data.fromHomeToForeignDiff === 0))
it('should contain fromForeignToHomeDiff', () => assert(data.fromForeignToHomeDiff === 0))
it('should contain lastChecked', () => assert(data.lastChecked >= 0))
it('should contain timeDiff', () => assert(data.timeDiff >= 0))
it('should contain lastChecked', () => assert(data.lastChecked >= 0))
})
})
describe('validators', async () => {
let data
before(async () => {
;({ data } = await axios.get(`${baseUrl}/validators`))
})
it('home', () => {
assert(typeof data.home.validators === 'object')
assert(data.home.validators[validator.address].balance > 0)
assert(data.home.validators[validator.address].leftTx > 0)
assert(data.home.validators[validator.address].gasPrice > 0)
})
it('foreign', () => {
assert(typeof data.foreign.validators === 'object')
assert(data.foreign.validators[validator.address].balance > 0)
assert(data.foreign.validators[validator.address].leftTx > 0)
assert(data.foreign.validators[validator.address].gasPrice > 0)
})
it('requiredSignaturesMatch', () => assert(data.requiredSignaturesMatch, 1))
it('validatorsMatch', () => assert(data.validatorsMatch))
it('lastChecked', () => assert(data.lastChecked >= 0))
it('timeDiff', () => assert(data.timeDiff >= 0))
it('homeOk', () => assert(data.homeOk))
it('foreignOk', () => assert(data.foreignOk))
it('ok', () => assert(data.ok))
})
describe('eventsStats', async () => {
let data
before(async () => {
;({ data } = await axios.get(`${baseUrl}/eventsStats`))
})
it('ok', () => assert(data.ok))
it('lastChecked', () => assert(data.lastChecked >= 0))
it('timeDiff', () => assert(data.timeDiff >= 0))
it('home-deliveredMsgNotProcessedInForeign', () =>
assert(typeof data.home.deliveredMsgNotProcessedInForeign === 'object'))
it('home-processedMsgNotDeliveredInForeign', () =>
assert(typeof data.home.processedMsgNotDeliveredInForeign === 'object'))
it('foreign-deliveredMsgNotProcessedInHome', () =>
assert(typeof data.foreign.deliveredMsgNotProcessedInHome === 'object'))
it('foreign-processedMsgNotDeliveredInHome', () =>
assert(typeof data.foreign.processedMsgNotDeliveredInHome === 'object'))
})
describe('alerts', async () => {
let data
before(async () => {
;({ data } = await axios.get(`${baseUrl}/alerts`))
})
it('ok', () => assert(data.ok))
it('lastChecked', () => assert(data.lastChecked >= 0))
it('timeDiff', () => assert(data.timeDiff >= 0))
it('executeSignatures', () => assert(typeof data.executeSignatures === 'object'))
it('executeAffirmations', () => assert(typeof data.executeAffirmations === 'object'))
})
describe('changing state of contracts', () => {
let data
before(async () => {
assert((await axios.get(`${baseUrl}/validators`)).data.validatorsMatch === true)
})
it('should change fromForeignToHomeDiff', async () => {
// send message
await sendAMBMessage(foreignRPC.URL, user, amb.foreignBox, amb.foreign, amb.homeBox)
await waitUntil(async () => {
;({ data } = await axios.get(`${baseUrl}`))
return data.fromForeignToHomeDiff !== 0
})
})
it('should change fromHomeToForeignDiff', async () => {
// send message
await sendAMBMessage(homeRPC.URL, user, amb.homeBox, amb.home, amb.foreignBox)
await waitUntil(async () => {
;({ data } = await axios.get(`${baseUrl}`))
return data.fromHomeToForeignDiff !== 0
})
})
it('should change validatorsMatch', async () => {
await addValidator(foreignRPC.URL, validator, amb.foreign)
await waitUntil(async () => {
;({ data } = await axios.get(`${baseUrl}/validators`))
return data.validatorsMatch === false
})
})
})
})

@ -1,5 +1,5 @@
const Web3 = require('web3') const Web3 = require('web3')
const { ERC677_BRIDGE_TOKEN_ABI, BRIDGE_VALIDATORS_ABI, FOREIGN_NATIVE_TO_ERC_ABI } = require('../commons') const { ERC677_BRIDGE_TOKEN_ABI, BRIDGE_VALIDATORS_ABI, FOREIGN_NATIVE_TO_ERC_ABI, BOX_ABI } = require('../commons')
const waitUntil = async (predicate, step = 100, timeout = 10000) => { const waitUntil = async (predicate, step = 100, timeout = 10000) => {
const stopTime = Date.now() + timeout const stopTime = Date.now() + timeout
@ -37,6 +37,17 @@ const sendTokens = async (rpcUrl, account, tokenAddress, recipientAddress) => {
}) })
} }
const sendAMBMessage = async (rpcUrl, account, boxAddress, bridgeAddress, boxOtherSideAddress) => {
const web3 = new Web3(new Web3.providers.HttpProvider(rpcUrl))
web3.eth.accounts.wallet.add(account.privateKey)
const homeBox = new web3.eth.Contract(BOX_ABI, boxAddress)
await homeBox.methods.setValueOnOtherNetwork(3, bridgeAddress, boxOtherSideAddress).send({
from: account.address,
gas: '400000'
})
}
const addValidator = async (rpcUrl, account, bridgeAddress) => { const addValidator = async (rpcUrl, account, bridgeAddress) => {
const web3 = new Web3(new Web3.providers.HttpProvider(rpcUrl)) const web3 = new Web3(new Web3.providers.HttpProvider(rpcUrl))
web3.eth.accounts.wallet.add(account.privateKey) web3.eth.accounts.wallet.add(account.privateKey)
@ -53,5 +64,6 @@ module.exports = {
waitUntil, waitUntil,
sendEther, sendEther,
sendTokens, sendTokens,
addValidator addValidator,
sendAMBMessage
} }

@ -7,6 +7,7 @@ check_files_exist() {
(docker-compose -f ../e2e-commons/docker-compose.yml exec monitor /bin/bash -c "$command") || rc=1 (docker-compose -f ../e2e-commons/docker-compose.yml exec monitor /bin/bash -c "$command") || rc=1
(docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-erc20 /bin/bash -c "$command") || rc=1 (docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-erc20 /bin/bash -c "$command") || rc=1
(docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-erc20-native /bin/bash -c "$command") || rc=1 (docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-erc20-native /bin/bash -c "$command") || rc=1
(docker-compose -f ../e2e-commons/docker-compose.yml exec monitor-amb /bin/bash -c "$command") || rc=1
done done
return $rc return $rc
} }

@ -77,10 +77,10 @@ app.get('/eventsStats', async (req, res, next) => {
try { try {
const results = await readFile('./responses/eventsStats.json') const results = await readFile('./responses/eventsStats.json')
results.ok = results.ok =
results.onlyInHomeDeposits.length === 0 && (results.onlyInHomeDeposits || results.home.deliveredMsgNotProcessedInForeign).length === 0 &&
results.onlyInForeignDeposits.length === 0 && (results.onlyInForeignDeposits || results.home.processedMsgNotDeliveredInForeign).length === 0 &&
results.onlyInHomeWithdrawals.length === 0 && (results.onlyInHomeWithdrawals || results.foreign.deliveredMsgNotProcessedInHome).length === 0 &&
results.onlyInForeignWithdrawals.length === 0 (results.onlyInForeignWithdrawals || results.foreign.processedMsgNotDeliveredInHome).length === 0
res.json(results) res.json(results)
} catch (e) { } catch (e) {
// this will eventually be handled by your error handling middleware // this will eventually be handled by your error handling middleware