2019-10-21 15:57:28 +03:00
|
|
|
const Web3 = require('web3')
|
|
|
|
const assert = require('assert')
|
2020-01-20 23:00:04 +03:00
|
|
|
const { user, homeRPC, foreignRPC, amb, validator } = require('../../e2e-commons/constants.json')
|
2020-02-11 20:50:34 +03:00
|
|
|
const { uniformRetry } = require('../../e2e-commons/utils')
|
2020-01-20 23:00:04 +03:00
|
|
|
const { BOX_ABI, HOME_AMB_ABI, FOREIGN_AMB_ABI } = require('../../commons')
|
|
|
|
const { setRequiredSignatures } = require('./utils')
|
2019-10-21 15:57:28 +03:00
|
|
|
|
|
|
|
const { toBN } = Web3.utils
|
|
|
|
|
|
|
|
const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL))
|
|
|
|
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL))
|
|
|
|
|
2020-01-20 23:00:04 +03:00
|
|
|
const COMMON_HOME_BRIDGE_ADDRESS = amb.home
|
|
|
|
const COMMON_FOREIGN_BRIDGE_ADDRESS = amb.foreign
|
|
|
|
|
2019-10-21 15:57:28 +03:00
|
|
|
homeWeb3.eth.accounts.wallet.add(user.privateKey)
|
2020-01-20 23:00:04 +03:00
|
|
|
homeWeb3.eth.accounts.wallet.add(validator.privateKey)
|
2019-10-21 15:57:28 +03:00
|
|
|
foreignWeb3.eth.accounts.wallet.add(user.privateKey)
|
2020-01-20 23:00:04 +03:00
|
|
|
foreignWeb3.eth.accounts.wallet.add(validator.privateKey)
|
2019-10-21 15:57:28 +03:00
|
|
|
|
|
|
|
const homeBox = new homeWeb3.eth.Contract(BOX_ABI, amb.homeBox)
|
|
|
|
const foreignBox = new foreignWeb3.eth.Contract(BOX_ABI, amb.foreignBox)
|
2020-01-20 23:00:04 +03:00
|
|
|
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)
|
2019-10-21 15:57:28 +03:00
|
|
|
|
|
|
|
describe('arbitrary message bridging', () => {
|
2020-01-20 23:00:04 +03:00
|
|
|
before(async () => {
|
2020-02-03 19:39:21 +03:00
|
|
|
// Only 1 validator is used in ultimate tests
|
|
|
|
if (process.env.ULTIMATE !== 'true') {
|
|
|
|
// Set 2 required signatures for home bridge
|
|
|
|
await setRequiredSignatures({
|
|
|
|
bridgeContract: homeBridge,
|
|
|
|
web3: homeWeb3,
|
|
|
|
requiredSignatures: 2,
|
|
|
|
options: {
|
|
|
|
from: validator.address,
|
|
|
|
gas: '4000000'
|
|
|
|
}
|
|
|
|
})
|
2020-01-20 23:00:04 +03:00
|
|
|
|
2020-02-03 19:39:21 +03:00
|
|
|
// Set 2 required signatures for foreign bridge
|
|
|
|
await setRequiredSignatures({
|
|
|
|
bridgeContract: foreignBridge,
|
|
|
|
web3: foreignWeb3,
|
|
|
|
requiredSignatures: 2,
|
|
|
|
options: {
|
|
|
|
from: validator.address,
|
|
|
|
gas: '4000000'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-01-20 23:00:04 +03:00
|
|
|
})
|
2019-10-21 15:57:28 +03:00
|
|
|
describe('Home to Foreign', () => {
|
|
|
|
describe('Subsidized Mode', () => {
|
|
|
|
it('should bridge message', async () => {
|
|
|
|
const newValue = 3
|
|
|
|
|
|
|
|
const initialValue = await foreignBox.methods.value().call()
|
|
|
|
assert(!toBN(initialValue).eq(toBN(newValue)), 'initial value should be different from new value')
|
|
|
|
|
2020-02-11 20:50:34 +03:00
|
|
|
await homeBox.methods
|
2019-10-21 15:57:28 +03:00
|
|
|
.setValueOnOtherNetwork(newValue, amb.home, amb.foreignBox)
|
|
|
|
.send({
|
|
|
|
from: user.address,
|
|
|
|
gas: '400000'
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.error(e)
|
|
|
|
})
|
|
|
|
|
|
|
|
// check that value changed and balance decreased
|
2020-02-11 20:50:34 +03:00
|
|
|
await uniformRetry(async retry => {
|
2019-10-21 15:57:28 +03:00
|
|
|
const value = await foreignBox.methods.value().call()
|
|
|
|
if (!toBN(value).eq(toBN(newValue))) {
|
|
|
|
retry()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
describe('Foreign to Home', () => {
|
|
|
|
describe('Subsidized Mode', () => {
|
|
|
|
it('should bridge message', async () => {
|
|
|
|
const newValue = 7
|
|
|
|
|
|
|
|
const initialValue = await homeBox.methods.value().call()
|
|
|
|
assert(!toBN(initialValue).eq(toBN(newValue)), 'initial value should be different from new value')
|
|
|
|
|
|
|
|
await foreignBox.methods
|
|
|
|
.setValueOnOtherNetwork(newValue, amb.foreign, amb.homeBox)
|
|
|
|
.send({
|
|
|
|
from: user.address,
|
|
|
|
gas: '400000'
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.error(e)
|
|
|
|
})
|
|
|
|
|
|
|
|
// check that value changed and balance decreased
|
2020-02-11 20:50:34 +03:00
|
|
|
await uniformRetry(async retry => {
|
2019-10-21 15:57:28 +03:00
|
|
|
const value = await homeBox.methods.value().call()
|
|
|
|
if (!toBN(value).eq(toBN(newValue))) {
|
|
|
|
retry()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|