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-14 23:02:46 -08:00
|
|
|
const { HOME_PRIVATE_KEY, FOREIGN_PRIVATE_KEY, HOME_BRIDGE_ADDRESS } = 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-11-14 06:44:08 -08:00
|
|
|
let bncPrefundedUser
|
2019-11-14 23:02:46 -08:00
|
|
|
let ethPrefundedUser
|
2019-10-27 09:21:36 -07:00
|
|
|
|
2019-10-29 11:07:11 -07:00
|
|
|
before(async function () {
|
2019-11-14 23:02:46 -08:00
|
|
|
ethPrefundedUser = await createUser(HOME_PRIVATE_KEY, 'eth')
|
|
|
|
bncPrefundedUser = await createUser(FOREIGN_PRIVATE_KEY, 'bnc')
|
|
|
|
|
|
|
|
for (let i = 0; i < 3; i += 1) {
|
|
|
|
// user eth balance is already prefunded with 100 eth in genesis block
|
|
|
|
await ethPrefundedUser.transferErc(usersConfig[i].ethAddress, 10000)
|
|
|
|
await bncPrefundedUser.transferBepBnb(usersConfig[i].bncAddress, 10000, 100)
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
})
|
|
|
|
|
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')
|
|
|
|
})
|
|
|
|
|
2019-10-28 05:47:07 -07:00
|
|
|
after(async function () {
|
2019-11-14 23:02:46 -08:00
|
|
|
await bncPrefundedUser.transferBepBnb(info.foreignBridgeAddress, 1000, 50)
|
2019-11-05 13:27:11 -08:00
|
|
|
await ethPrefundedUser.transferErc(HOME_BRIDGE_ADDRESS, 1000)
|
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-11-14 10:48:32 -08:00
|
|
|
testEthToBnc(() => users, 500, () => bncPrefundedUser)
|
2019-10-30 06:53:43 -07:00
|
|
|
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
|
|
|
|
2019-10-30 06:53:43 -07:00
|
|
|
testEthToBnc(() => users)
|
|
|
|
testBncToEth(() => users)
|
2019-11-26 05:53:35 -08:00
|
|
|
testEthToBncWithRestart(() => users)
|
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-26 05:53:35 -08:00
|
|
|
testEthToBncWithRestart(() => users)
|
2019-11-14 10:48:32 -08:00
|
|
|
testEthToBnc(() => users)
|
2019-10-21 11:43:31 -07:00
|
|
|
})
|