Tests coverage for closing bridge
This commit is contained in:
parent
7f575238e1
commit
ec9c8e10c2
|
@ -22,3 +22,8 @@ docker start -a tests || true
|
|||
|
||||
echo "Saving test results"
|
||||
docker cp "tests:/tests/results.xml" "./tests/results.xml" > /dev/null 2>&1 || true
|
||||
|
||||
echo "Killing all remaining docker containers"
|
||||
docker kill $(docker ps | grep validator[1-3]_ | awk '{print $1}') > /dev/null 2>&1 || true
|
||||
docker kill ganache_home ganache_side > /dev/null 2>&1 || true
|
||||
docker kill $(docker ps | grep binance-testnet_ | awk '{print $1}') > /dev/null 2>&1 || true
|
||||
|
|
|
@ -17,27 +17,32 @@ module.exports = (newValidator) => {
|
|||
nextValidators = [...initialInfo.validators, newValidator]
|
||||
})
|
||||
|
||||
it('should start voting process', async function () {
|
||||
it('should start closing epoch process', async function () {
|
||||
await controller1.voteStartVoting()
|
||||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'ready', 'Should not change state after one vote')
|
||||
|
||||
await controller3.voteStartVoting()
|
||||
info = await waitPromise(controller1.getInfo, (newInfo) => newInfo.bridgeStatus === 'voting')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
info = await waitPromise(controller1.getInfo, (newInfo) => newInfo.bridgeStatus === 'closing_epoch')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, initialInfo.validators, 'Next validators are not set correctly')
|
||||
|
||||
await controller3.voteStartVoting()
|
||||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'voting', 'Should not do anything after duplicate vote')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.strictEqual(info.bridgeStatus, 'closing_epoch', 'Should not do anything after duplicate vote')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, initialInfo.validators, 'Incorrect set of next validators after third vote')
|
||||
})
|
||||
|
||||
it('should finish close epoch process and start voting process', async function () {
|
||||
this.timeout(120000)
|
||||
info = await waitPromise(controller1.getInfo, (newInfo) => newInfo.bridgeStatus === 'voting')
|
||||
})
|
||||
|
||||
it('should add validator', async function () {
|
||||
await controller1.voteAddValidator(newValidator)
|
||||
await delay(5000)
|
||||
|
@ -58,12 +63,43 @@ module.exports = (newValidator) => {
|
|||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'voting', 'Should not do anything after duplicate vote')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, nextValidators, 'Incorrect set of next validators after third vote')
|
||||
})
|
||||
|
||||
it('should change close epoch', async function () {
|
||||
await controller1.voteChangeCloseEpoch(false)
|
||||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'voting', 'Should not change state after one vote')
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, nextValidators, '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')
|
||||
|
||||
await controller3.voteChangeCloseEpoch(false)
|
||||
info = await waitPromise(
|
||||
controller1.getInfo,
|
||||
(newInfo) => !newInfo.nextCloseEpoch
|
||||
)
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, nextValidators, 'Next validators are not set correctly')
|
||||
assert.strictEqual(info.closeEpoch, true, 'Current close epoch is not set correctly')
|
||||
|
||||
await controller3.voteChangeCloseEpoch(false)
|
||||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'voting', 'Should not do anything after duplicate vote')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, nextValidators, 'Incorrect set of next validators after third vote')
|
||||
assert.strictEqual(info.closeEpoch, true, 'Current close epoch is not set correctly')
|
||||
assert.strictEqual(info.nextCloseEpoch, false, 'Next close epoch is not set correctly')
|
||||
})
|
||||
|
||||
it('should start keygen process', async function () {
|
||||
await controller1.voteStartKeygen()
|
||||
await delay(5000)
|
||||
|
@ -77,8 +113,8 @@ module.exports = (newValidator) => {
|
|||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'keygen', 'Should not do anything after duplicate vote')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, nextValidators, 'Incorrect set of next validators after third vote')
|
||||
})
|
||||
|
|
|
@ -22,17 +22,18 @@ module.exports = (newThreshold) => {
|
|||
assert.strictEqual(info.bridgeStatus, 'ready', 'Should not change state after one vote')
|
||||
|
||||
await controller2.voteStartVoting()
|
||||
info = await waitPromise(controller1.getInfo, (newInfo) => newInfo.bridgeStatus === 'voting')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
info = await waitPromise(controller1.getInfo, (newInfo) => newInfo.bridgeStatus === 'closingEpoch' || newInfo.bridgeStatus === 'voting')
|
||||
assert.strictEqual(info.bridgeStatus, 'voting', 'Should not started closing epoch after previous epoch')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, initialInfo.validators, 'Next validators are not set correctly')
|
||||
|
||||
await controller3.voteStartVoting()
|
||||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'voting', 'Should not do anything after third vote')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, initialInfo.validators, 'Incorrect set of next validators after third vote')
|
||||
})
|
||||
|
||||
|
@ -43,8 +44,8 @@ module.exports = (newThreshold) => {
|
|||
assert.strictEqual(info.bridgeStatus, 'voting', 'Should not change state after one vote')
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, initialInfo.validators, 'Next validators are not set correctly')
|
||||
assert.deepStrictEqual(info.threshold, initialInfo.threshold, 'Threshold not set correctly')
|
||||
assert.deepStrictEqual(info.nextThreshold, initialInfo.threshold, 'Next threshold is not set correctly')
|
||||
assert.strictEqual(info.threshold, initialInfo.threshold, 'Threshold not set correctly')
|
||||
assert.strictEqual(info.nextThreshold, initialInfo.threshold, 'Next threshold is not set correctly')
|
||||
|
||||
await controller2.voteChangeThreshold(newThreshold)
|
||||
info = await waitPromise(
|
||||
|
@ -53,18 +54,18 @@ module.exports = (newThreshold) => {
|
|||
)
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, initialInfo.validators, 'Next validators are not set correctly')
|
||||
assert.deepStrictEqual(info.threshold, initialInfo.threshold, 'Threshold not set correctly')
|
||||
assert.strictEqual(info.threshold, initialInfo.threshold, 'Threshold not set correctly')
|
||||
|
||||
await controller3.voteChangeThreshold(newThreshold)
|
||||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'voting', 'Should not do anything after third vote')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, initialInfo.validators, 'Incorrect set of next validators after third vote')
|
||||
assert.deepStrictEqual(info.threshold, initialInfo.threshold, 'Threshold not set correctly')
|
||||
assert.deepStrictEqual(info.nextThreshold, newThreshold, 'Next threshold is not set correctly')
|
||||
assert.strictEqual(info.threshold, initialInfo.threshold, 'Threshold not set correctly')
|
||||
assert.strictEqual(info.nextThreshold, newThreshold, 'Next threshold is not set correctly')
|
||||
})
|
||||
|
||||
it('should start keygen process', async function () {
|
||||
|
@ -80,12 +81,12 @@ module.exports = (newThreshold) => {
|
|||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'keygen', 'Should not do anything after third vote')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, initialInfo.validators, 'Incorrect set of next validators after third vote')
|
||||
assert.deepStrictEqual(info.threshold, initialInfo.threshold, 'Threshold not set correctly')
|
||||
assert.deepStrictEqual(info.nextThreshold, newThreshold, 'Next threshold is not set correctly')
|
||||
assert.strictEqual(info.threshold, initialInfo.threshold, 'Threshold not set correctly')
|
||||
assert.strictEqual(info.nextThreshold, newThreshold, 'Next threshold is not set correctly')
|
||||
})
|
||||
|
||||
it('should finish keygen process and start funds transfer', async function () {
|
||||
|
@ -102,8 +103,8 @@ module.exports = (newThreshold) => {
|
|||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Incorrect set of validators in new epoch')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Incorrect next epoch')
|
||||
assert.strictEqual(info.bridgeStatus, 'ready', 'Incorrect bridge state in new epoch')
|
||||
assert.deepStrictEqual(info.threshold, newThreshold, 'Threshold not set correctly')
|
||||
assert.deepStrictEqual(info.nextThreshold, newThreshold, 'Next threshold is not set correctly')
|
||||
assert.strictEqual(info.threshold, newThreshold, 'Threshold not set correctly')
|
||||
assert.strictEqual(info.nextThreshold, newThreshold, 'Next threshold is not set correctly')
|
||||
await delay(5000)
|
||||
const prevBalance = await getBepBalance(initialInfo.foreignBridgeAddress)
|
||||
const newBalance = await getBepBalance(info.foreignBridgeAddress)
|
||||
|
|
|
@ -36,7 +36,7 @@ describe('bridge tests', function () {
|
|||
bncPrefundedUser = await createUser(FOREIGN_PRIVATE_KEY, 'bnc')
|
||||
|
||||
const bnbBalance = await bncPrefundedUser.getBnbBalance()
|
||||
assert.ok(bnbBalance >= 1, `Insufficient BNB balance on ${bncPrefundedUser.ethAddress} in Binance network, expected 1 BNB, got ${bnbBalance}`)
|
||||
assert.ok(bnbBalance >= 10, `Insufficient BNB balance on ${bncPrefundedUser.ethAddress} in Binance network, expected 10 BNB, got ${bnbBalance}`)
|
||||
const bepBalance = await bncPrefundedUser.getBepBalance()
|
||||
assert.ok(bepBalance >= 2000, `Insufficient BEP2 balance on ${bncPrefundedUser.ethAddress} in Binance network, expected 2000 ${FOREIGN_ASSET}, got ${bepBalance}`)
|
||||
|
||||
|
@ -63,8 +63,17 @@ describe('bridge tests', function () {
|
|||
info = await waitPromise(controller1.getInfo, (newInfo) => newInfo.epoch === 1)
|
||||
})
|
||||
|
||||
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 () {
|
||||
await bncPrefundedUser.transferBepBnb(info.foreignBridgeAddress, 1000, 0.1)
|
||||
await bncPrefundedUser.transferBepBnb(info.foreignBridgeAddress, 1000, 5)
|
||||
await ethPrefundedUser.transferErc(HOME_BRIDGE_ADDRESS, 1000)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -17,27 +17,32 @@ module.exports = (oldValidator) => {
|
|||
nextValidators = initialInfo.validators.filter((validator) => validator !== oldValidator)
|
||||
})
|
||||
|
||||
it('should start voting process', async function () {
|
||||
it('should start closing epoch process', async function () {
|
||||
await controller1.voteStartVoting()
|
||||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'ready', 'Should not change state after one vote')
|
||||
|
||||
await controller2.voteStartVoting()
|
||||
info = await waitPromise(controller1.getInfo, (newInfo) => newInfo.bridgeStatus === 'voting')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
info = await waitPromise(controller1.getInfo, (newInfo) => newInfo.bridgeStatus === 'closing_epoch')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, initialInfo.validators, 'Next validators are not set correctly')
|
||||
|
||||
await controller3.voteStartVoting()
|
||||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'voting', 'Should not do anything after third vote')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.strictEqual(info.bridgeStatus, 'closing_epoch', 'Should not do anything after third vote')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, initialInfo.validators, 'Incorrect set of next validators after third vote')
|
||||
})
|
||||
|
||||
it('should finish close epoch process and start voting process', async function () {
|
||||
this.timeout(120000)
|
||||
info = await waitPromise(controller1.getInfo, (newInfo) => newInfo.bridgeStatus === 'voting')
|
||||
})
|
||||
|
||||
it('should remove validator', async function () {
|
||||
await controller1.voteRemoveValidator(oldValidator)
|
||||
await delay(5000)
|
||||
|
@ -58,8 +63,8 @@ module.exports = (oldValidator) => {
|
|||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'voting', 'Should not do anything after third vote')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, nextValidators, 'Incorrect set of next validators after third vote')
|
||||
})
|
||||
|
@ -77,8 +82,8 @@ module.exports = (oldValidator) => {
|
|||
await delay(5000)
|
||||
info = await controller1.getInfo()
|
||||
assert.strictEqual(info.bridgeStatus, 'keygen', 'Should not do anything after third vote')
|
||||
assert.deepStrictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.strictEqual(info.epoch, initialInfo.epoch, 'Current epoch is not set correctly')
|
||||
assert.strictEqual(info.nextEpoch, initialInfo.epoch + 1, 'Next epoch is not set correctly')
|
||||
assert.deepStrictEqual(info.validators, initialInfo.validators, 'Validators are not set correctly')
|
||||
assert.deepStrictEqual(info.nextValidators, nextValidators, 'Incorrect set of next validators after third vote')
|
||||
})
|
||||
|
|
|
@ -28,6 +28,9 @@ function createController(validatorId) {
|
|||
},
|
||||
async voteChangeThreshold(threshold) {
|
||||
return (await retry(() => proxy.get(`/vote/changeThreshold/${threshold}`))).data
|
||||
},
|
||||
async voteChangeCloseEpoch(closeEpoch) {
|
||||
return (await retry(() => proxy.get(`/vote/changeCloseEpoch/${closeEpoch}`))).data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue