eth-to-bnc-bridge/tests/test/index.js

104 lines
4.4 KiB
JavaScript
Raw Normal View History

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-27 09:21:36 -07:00
const testEthToBnc = require('./ethToBnc')
2019-11-05 10:14:48 -08:00
const testEthToBncWithRestart = require('./ethToBncWithRestart')
const testBncToEth = require('./bncToEth')
const testRemoveValidator = require('./removeValidator')
const testAddValidator = require('./addValidator')
const testChangeThreshold = require('./changeThreshold')
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
const { controller1 } = require('./utils/proxyController')
2019-10-27 09:21:36 -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
})
describe('generation of initial epoch keys', function () {
let info
2019-11-03 10:00:15 -08:00
let ethPrefundedUser
let bncPrefundedUser
before(async function () {
2019-11-11 08:43:28 -08:00
ethPrefundedUser = await createUser(HOME_PRIVATE_KEY, 'eth')
bncPrefundedUser = await createUser(FOREIGN_PRIVATE_KEY, 'bnc')
2019-11-03 10:00:15 -08:00
const bnbBalance = await bncPrefundedUser.getBnbBalance()
2019-11-14 02:30:23 -08:00
assert.ok(bnbBalance >= 10, `Insufficient BNB balance on ${bncPrefundedUser.ethAddress} in Binance network, expected 10 BNB, got ${bnbBalance}`)
2019-11-03 10:00:15 -08:00
const bepBalance = await bncPrefundedUser.getBepBalance()
assert.ok(bepBalance >= 2000, `Insufficient BEP2 balance on ${bncPrefundedUser.ethAddress} in Binance network, expected 2000 ${FOREIGN_ASSET}, got ${bepBalance}`)
2019-11-03 10:00:15 -08:00
const ethBalance = await ethPrefundedUser.getEthBalance()
assert.ok(ethBalance >= 1, `Insufficient ETH balance on ${ethPrefundedUser.ethAddress} in Ethereum network, expected 1 ETH, got ${ethBalance}`)
2019-11-03 10:00:15 -08:00
const ercBalance = await ethPrefundedUser.getErcBalance()
assert.ok(ercBalance >= 2000, `Insufficient ERC20 balance on ${ethPrefundedUser.ethAddress} in Ethereum network, expected 2000 ERC20, got ${ercBalance}`)
2019-11-03 10:00:15 -08:00
for (let i = 0; i < 3; i += 1) {
const userEthBalance = await users[i].getEthBalance()
assert.ok(userEthBalance >= 0.1, `Insufficient ETH balance on ${users[i].ethAddress} in Ethereum network, expected 0.1 ETH, got ${userEthBalance}`)
2019-11-03 10:00:15 -08:00
const userErcBalance = await users[i].getErcBalance()
assert.ok(userErcBalance >= 200, `Insufficient ERC20 balance on ${users[i].ethAddress} in Ethereum network, expected 200 ERC20, got ${userErcBalance}`)
2019-11-03 10:00:15 -08:00
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}`)
2019-11-03 10:00:15 -08:00
const userBepBalance = await users[i].getBepBalance()
assert.ok(userErcBalance >= 200, `Insufficient BEP2 balance on ${users[i].bncAddress} in Binance network, expected 200 ${FOREIGN_ASSET}, got ${userBepBalance}`)
2019-11-03 10:00:15 -08: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-11-14 02:30:23 -08:00
it('should start correct epoch', async function () {
assert.deepStrictEqual(info.validators, validatorsConfig, 'Validators are not set correctly')
assert.deepStrictEqual(info.nextValidators, validatorsConfig, 'Next validators are not set correctly')
assert.strictEqual(info.closeEpoch, true, 'Current close epoch is not set correctly')
assert.strictEqual(info.nextCloseEpoch, true, 'Next close epoch is not set correctly')
assert.strictEqual(info.threshold, 2, 'Threshold not set correctly')
assert.strictEqual(info.nextThreshold, 2, 'Next threshold is not set correctly')
})
after(async function () {
2019-11-14 02:30:23 -08:00
await bncPrefundedUser.transferBepBnb(info.foreignBridgeAddress, 1000, 5)
await ethPrefundedUser.transferErc(HOME_BRIDGE_ADDRESS, 1000)
})
2019-10-27 09:21:36 -07:00
})
testEthToBnc(() => users)
testBncToEth(() => users)
2019-11-05 12:24:47 -08:00
testEthToBnc(() => users)
2019-10-29 11:07:11 -07:00
testRemoveValidator(validatorsConfig[1])
2019-10-29 11:07:11 -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-11-14 06:18:56 -08:00
testAddValidator(() => users, validatorsConfig[1])
2019-10-29 11:07:11 -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
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)
})