2019-10-27 09:21:36 -07:00
|
|
|
const assert = require('assert')
|
|
|
|
const { getSequence } = require('./utils/bncController')
|
2019-10-29 13:46:18 -07:00
|
|
|
const { waitPromise, delay } = require('./utils/wait')
|
2019-10-27 09:21:36 -07:00
|
|
|
|
|
|
|
const { HOME_BRIDGE_ADDRESS } = process.env
|
|
|
|
|
2019-10-28 05:47:07 -07:00
|
|
|
module.exports = (usersFunc, foreignBridgeAddressFunc) => {
|
|
|
|
describe('exchange of tokens in eth => bnc direction', function () {
|
|
|
|
let users
|
|
|
|
let foreignBridgeAddress
|
2019-10-27 09:21:36 -07:00
|
|
|
let ethBalances
|
|
|
|
let bncBalances
|
|
|
|
let bncBridgeSequence
|
|
|
|
|
|
|
|
before(async function () {
|
2019-10-28 05:47:07 -07:00
|
|
|
users = usersFunc()
|
|
|
|
foreignBridgeAddress = foreignBridgeAddressFunc()
|
2019-10-27 09:21:36 -07:00
|
|
|
ethBalances = await Promise.all(users.map(user => user.getEthBalance()))
|
|
|
|
bncBalances = await users.seqMap(user => user.getBncBalance())
|
|
|
|
|
2019-10-28 05:47:07 -07:00
|
|
|
bncBridgeSequence = await getSequence(foreignBridgeAddress)
|
2019-10-27 09:21:36 -07:00
|
|
|
await Promise.all(users.map((user, i) => user.approveEth(HOME_BRIDGE_ADDRESS, 5 + i)))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should accept exchange requests', async function () {
|
|
|
|
await Promise.all(users.map((user, i) => user.exchangeEth(5 + i)))
|
|
|
|
const newEthBalances = await Promise.all(users.map(user => user.getEthBalance()))
|
|
|
|
for (let i = 0; i < 3; i++) {
|
2019-10-29 11:07:11 -07:00
|
|
|
assert.strictEqual(newEthBalances[i], ethBalances[i] - 5 - i, `Balance of ${users[i].ethAddress} did not updated as expected`)
|
2019-10-27 09:21:36 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should make exchange transaction on bnc side', async function () {
|
|
|
|
this.timeout(300000)
|
2019-10-28 05:47:07 -07:00
|
|
|
await waitPromise(() => getSequence(foreignBridgeAddress), sequence => sequence === bncBridgeSequence + 1)
|
2019-10-27 09:21:36 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should make correct exchange transaction', async function () {
|
2019-10-29 13:46:18 -07:00
|
|
|
await delay(10000)
|
2019-10-27 09:21:36 -07:00
|
|
|
const newBncBalances = await Promise.all(users.map(user => user.getBncBalance()))
|
|
|
|
for (let i = 0; i < 3; i++) {
|
2019-10-29 11:07:11 -07:00
|
|
|
assert.strictEqual(newBncBalances[i], bncBalances[i] + 5 + i, `Balance of ${users[i].bncAddress} did not updated as expected`)
|
2019-10-27 09:21:36 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|