2019-11-03 10:00:15 -08:00
|
|
|
const assert = require('assert')
|
|
|
|
|
2019-10-27 09:21:36 -07:00
|
|
|
const createUser = require('./utils/user')
|
2019-11-01 11:43:25 -07:00
|
|
|
const { waitPromise, seqMap } = require('./utils/wait')
|
2019-10-21 11:43:31 -07:00
|
|
|
|
2019-10-27 09:21:36 -07:00
|
|
|
const testEthToBnc = require('./ethToBnc')
|
2019-11-05 10:14:48 -08:00
|
|
|
const testEthToBncWithRestart = require('./ethToBncWithRestart')
|
2019-10-28 05:47:07 -07:00
|
|
|
const testBncToEth = require('./bncToEth')
|
2019-10-30 06:53:43 -07:00
|
|
|
const testRemoveValidator = require('./removeValidator')
|
|
|
|
const testAddValidator = require('./addValidator')
|
|
|
|
const testChangeThreshold = require('./changeThreshold')
|
2019-10-21 11:43:31 -07:00
|
|
|
|
2019-10-28 05:47:07 -07:00
|
|
|
const usersConfig = require('../config').users
|
2019-10-29 11:07:11 -07:00
|
|
|
const validatorsConfig = require('../config').validators
|
2019-10-27 09:21:36 -07:00
|
|
|
|
2019-11-03 10:00:15 -08:00
|
|
|
const {
|
|
|
|
HOME_PRIVATE_KEY, FOREIGN_PRIVATE_KEY, HOME_BRIDGE_ADDRESS, FOREIGN_ASSET
|
|
|
|
} = process.env
|
2019-10-27 09:21:36 -07:00
|
|
|
|
2019-10-30 06:53:43 -07:00
|
|
|
const { controller1 } = require('./utils/proxyController')
|
2019-10-27 09:21:36 -07:00
|
|
|
|
2019-10-28 05:47:07 -07:00
|
|
|
describe('bridge tests', function () {
|
|
|
|
let users
|
2019-10-27 09:21:36 -07:00
|
|
|
|
2019-10-29 11:07:11 -07:00
|
|
|
before(async function () {
|
2019-11-01 11:43:25 -07:00
|
|
|
users = await seqMap(usersConfig, (user) => createUser(user.privateKey))
|
2019-10-27 09:21:36 -07:00
|
|
|
})
|
|
|
|
|
2019-10-28 05:47:07 -07:00
|
|
|
describe('generation of initial epoch keys', function () {
|
2019-10-30 06:53:43 -07:00
|
|
|
let info
|
2019-11-03 10:00:15 -08:00
|
|
|
let ethPrefundedUser
|
|
|
|
let bncPrefundedUser
|
2019-10-30 06:53:43 -07:00
|
|
|
|
2019-10-28 05:47:07 -07:00
|
|
|
before(async function () {
|
2019-11-03 10:00:15 -08:00
|
|
|
ethPrefundedUser = await createUser(HOME_PRIVATE_KEY)
|
|
|
|
bncPrefundedUser = await createUser(FOREIGN_PRIVATE_KEY)
|
|
|
|
|
|
|
|
const bnbBalance = await bncPrefundedUser.getBnbBalance()
|
|
|
|
assert.ok(bnbBalance >= 0.5, `Insufficient BNB balance on ${bncPrefundedUser.ethAddress} in Binance network, expected 0.5 BNB, got ${bnbBalance}`)
|
|
|
|
const bepBalance = await bncPrefundedUser.getBepBalance()
|
|
|
|
assert.ok(bepBalance >= 500, `Insufficient BEP2 balance on ${bncPrefundedUser.ethAddress} in Binance network, expected 500 ${FOREIGN_ASSET}, got ${bepBalance}`)
|
|
|
|
|
|
|
|
const ethBalance = await ethPrefundedUser.getEthBalance()
|
|
|
|
assert.ok(ethBalance >= 0.5, `Insufficient ETH balance on ${ethPrefundedUser.ethAddress} in Ethereum network, expected 0.5 ETH, got ${ethBalance}`)
|
|
|
|
const ercBalance = await ethPrefundedUser.getErcBalance()
|
|
|
|
assert.ok(ercBalance >= 500, `Insufficient ERC20 balance on ${ethPrefundedUser.ethAddress} in Ethereum network, expected 500 ERC20, got ${ercBalance}`)
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 3; i += 1) {
|
|
|
|
const userEthBalance = await users[i].getEthBalance()
|
|
|
|
assert.ok(userEthBalance >= 0.2, `Insufficient ETH balance on ${users[i].ethAddress} in Ethereum network, expected 0.2 ETH, got ${userEthBalance}`)
|
|
|
|
const userErcBalance = await users[i].getErcBalance()
|
|
|
|
assert.ok(userErcBalance >= 50, `Insufficient ERC20 balance on ${users[i].ethAddress} in Ethereum network, expected 50 ERC20, got ${userErcBalance}`)
|
|
|
|
const userBnbBalance = await users[i].getBepBalance()
|
|
|
|
assert.ok(userBnbBalance >= 0.1, `Insufficient BNB balance on ${users[i].bncAddress} in Binance network, expected 0.1 BNB, got ${userBnbBalance}`)
|
|
|
|
const userBepBalance = await users[i].getBepBalance()
|
|
|
|
assert.ok(userErcBalance >= 50, `Insufficient BEP2 balance on ${users[i].bncAddress} in Binance network, expected 50 ${FOREIGN_ASSET}, got ${userBepBalance}`)
|
|
|
|
}
|
2019-10-28 05:47:07 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should generate keys', async function () {
|
|
|
|
this.timeout(120000)
|
2019-11-01 11:43:25 -07:00
|
|
|
info = await waitPromise(controller1.getInfo, (newInfo) => newInfo.epoch === 1)
|
2019-10-28 05:47:07 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
2019-11-03 10:00:15 -08:00
|
|
|
await bncPrefundedUser.transferBepBnb(info.foreignBridgeAddress, 100, 0.1)
|
|
|
|
await ethPrefundedUser.transferErc(HOME_BRIDGE_ADDRESS, 100)
|
2019-10-28 05:47:07 -07:00
|
|
|
})
|
2019-10-27 09:21:36 -07:00
|
|
|
})
|
|
|
|
|
2019-10-30 06:53:43 -07:00
|
|
|
testEthToBnc(() => users)
|
|
|
|
testBncToEth(() => users)
|
2019-11-05 12:24:47 -08:00
|
|
|
testEthToBnc(() => users)
|
2019-10-29 11:07:11 -07:00
|
|
|
|
2019-10-30 06:53:43 -07:00
|
|
|
testRemoveValidator(validatorsConfig[1])
|
2019-10-29 11:07:11 -07:00
|
|
|
|
2019-10-30 06:53:43 -07:00
|
|
|
testEthToBnc(() => users)
|
|
|
|
testBncToEth(() => users)
|
2019-11-05 12:24:47 -08:00
|
|
|
testEthToBnc(() => users)
|
2019-10-29 11:07:11 -07:00
|
|
|
|
2019-10-30 06:53:43 -07:00
|
|
|
testAddValidator(validatorsConfig[1])
|
2019-10-29 11:07:11 -07:00
|
|
|
|
2019-10-30 06:53:43 -07:00
|
|
|
testEthToBnc(() => users)
|
|
|
|
testBncToEth(() => users)
|
2019-11-05 10:14:48 -08:00
|
|
|
testEthToBncWithRestart(() => users, 99)
|
2019-10-29 11:07:11 -07:00
|
|
|
|
2019-11-04 01:53:58 -08:00
|
|
|
testChangeThreshold(3)
|
2019-10-29 11:07:11 -07:00
|
|
|
|
2019-10-30 06:53:43 -07:00
|
|
|
testEthToBnc(() => users)
|
|
|
|
testBncToEth(() => users)
|
2019-11-05 10:14:48 -08:00
|
|
|
testEthToBncWithRestart(() => users, 2)
|
2019-11-05 12:24:47 -08:00
|
|
|
testEthToBnc(() => users)
|
2019-10-21 11:43:31 -07:00
|
|
|
})
|