Waiting for funds on bnc side, if not enough for making exchange transaction
This commit is contained in:
parent
6665e0e0a5
commit
17cb9e760d
|
@ -116,23 +116,29 @@ async function waitForAccountNonce(address, nonce) {
|
||||||
return !cancelled
|
return !cancelled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendTx(tx) {
|
||||||
function sendTx(tx) {
|
while (true) {
|
||||||
return httpClient
|
try {
|
||||||
.post('/api/v1/broadcast?sync=true', tx, {
|
return await httpClient
|
||||||
headers: {
|
.post('/api/v1/broadcast?sync=true', tx, {
|
||||||
'Content-Type': 'text/plain'
|
headers: {
|
||||||
}
|
'Content-Type': 'text/plain'
|
||||||
})
|
}
|
||||||
.catch(async (err) => {
|
})
|
||||||
|
} catch (err) {
|
||||||
if (err.response.data.message.includes('Tx already exists in cache')) {
|
if (err.response.data.message.includes('Tx already exists in cache')) {
|
||||||
logger.debug('Tx already exists in cache')
|
logger.debug('Tx already exists in cache')
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
logger.info('Something failed, restarting: %o', err.response)
|
if (err.response.data.message.includes(' < ')) {
|
||||||
await delay(1000)
|
logger.warn('Insufficient funds, waiting for funds to income')
|
||||||
return await sendTx(tx)
|
await delay(60000)
|
||||||
})
|
} else {
|
||||||
|
logger.info('Something failed, restarting: %o', err.response)
|
||||||
|
await delay(10000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sign(keysFile, hash, tx, publicKey, signerAddress) {
|
function sign(keysFile, hash, tx, publicKey, signerAddress) {
|
||||||
|
|
|
@ -7,45 +7,60 @@ const { HOME_BRIDGE_ADDRESS } = process.env
|
||||||
|
|
||||||
const { controller1 } = require('./utils/proxyController')
|
const { controller1 } = require('./utils/proxyController')
|
||||||
|
|
||||||
module.exports = (getUsers) => {
|
module.exports = (getUsers, amount = 5, getBncPrefundedUser = null) => {
|
||||||
describe('exchange of tokens in eth => bnc direction', function () {
|
describe('exchange of tokens in eth => bnc direction', function () {
|
||||||
let info
|
let info
|
||||||
let users
|
let users
|
||||||
let ethBalances
|
let ethBalances
|
||||||
let bncBalances
|
let bncBalances
|
||||||
let bncBridgeSequence
|
let bncBridgeSequence
|
||||||
|
let bncPrefundedUser
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
users = getUsers()
|
users = getUsers()
|
||||||
info = await controller1.getInfo()
|
info = await controller1.getInfo()
|
||||||
ethBalances = await Promise.all(users.map((user) => user.getErcBalance()))
|
ethBalances = await Promise.all(users.map((user) => user.getErcBalance()))
|
||||||
bncBalances = await seqMap(users, (user) => user.getBepBalance())
|
bncBalances = await seqMap(users, (user) => user.getBepBalance())
|
||||||
|
if (getBncPrefundedUser) {
|
||||||
|
bncPrefundedUser = getBncPrefundedUser()
|
||||||
|
}
|
||||||
bncBridgeSequence = await getBncSequence(info.foreignBridgeAddress)
|
bncBridgeSequence = await getBncSequence(info.foreignBridgeAddress)
|
||||||
await Promise.all(users.map((user, i) => user.approveErc(HOME_BRIDGE_ADDRESS, 5 + i)))
|
await Promise.all(users.map((user, i) => user.approveErc(HOME_BRIDGE_ADDRESS, amount + i)))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should accept exchange requests', async function () {
|
it('should accept exchange requests', async function () {
|
||||||
await Promise.all(users.map((user, i) => user.exchangeErc(5 + i)))
|
await Promise.all(users.map((user, i) => user.exchangeErc(amount + i)))
|
||||||
const newEthBalances = await Promise.all(users.map((user) => user.getErcBalance()))
|
const newEthBalances = await Promise.all(users.map((user) => user.getErcBalance()))
|
||||||
for (let i = 0; i < 3; i += 1) {
|
for (let i = 0; i < 3; i += 1) {
|
||||||
assert.strictEqual(newEthBalances[i], ethBalances[i] - 5 - i, `Balance of ${users[i].ethAddress} did not updated as expected`)
|
assert.strictEqual(newEthBalances[i], ethBalances[i] - amount - i, `Balance of ${users[i].ethAddress} did not updated as expected`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should make exchange transaction on bnc side', async function () {
|
if (bncPrefundedUser) {
|
||||||
this.timeout(300000)
|
it('should make exchange transaction on bnc side with waiting for enough funds on bnc side', async function () {
|
||||||
await waitPromise(
|
this.timeout(300000)
|
||||||
() => getBncSequence(info.foreignBridgeAddress),
|
await delay(120000)
|
||||||
(sequence) => sequence === bncBridgeSequence + 1
|
await bncPrefundedUser.transferBepBnb(info.foreignBridgeAddress, amount * 3 + 10, 0)
|
||||||
)
|
await waitPromise(
|
||||||
})
|
() => getBncSequence(info.foreignBridgeAddress),
|
||||||
|
(sequence) => sequence === bncBridgeSequence + 1
|
||||||
|
)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
it('should make exchange transaction on bnc side', async function () {
|
||||||
|
this.timeout(300000)
|
||||||
|
await waitPromise(
|
||||||
|
() => getBncSequence(info.foreignBridgeAddress),
|
||||||
|
(sequence) => sequence === bncBridgeSequence + 1
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
it('should make correct exchange transaction', async function () {
|
it('should make correct exchange transaction', async function () {
|
||||||
await delay(10000)
|
await delay(10000)
|
||||||
const newBncBalances = await Promise.all(users.map((user) => user.getBepBalance()))
|
const newBncBalances = await Promise.all(users.map((user) => user.getBepBalance()))
|
||||||
for (let i = 0; i < 3; i += 1) {
|
for (let i = 0; i < 3; i += 1) {
|
||||||
assert.strictEqual(newBncBalances[i], bncBalances[i] + 5 + i, `Balance of ${users[i].bncAddress} did not updated as expected`)
|
assert.strictEqual(newBncBalances[i], bncBalances[i] + amount + i, `Balance of ${users[i].bncAddress} did not updated as expected`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -21,6 +21,7 @@ const { controller1 } = require('./utils/proxyController')
|
||||||
|
|
||||||
describe('bridge tests', function () {
|
describe('bridge tests', function () {
|
||||||
let users
|
let users
|
||||||
|
let bncPrefundedUser
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
users = await seqMap(usersConfig, (user) => createUser(user.privateKey))
|
users = await seqMap(usersConfig, (user) => createUser(user.privateKey))
|
||||||
|
@ -29,7 +30,6 @@ describe('bridge tests', function () {
|
||||||
describe('generation of initial epoch keys', function () {
|
describe('generation of initial epoch keys', function () {
|
||||||
let info
|
let info
|
||||||
let ethPrefundedUser
|
let ethPrefundedUser
|
||||||
let bncPrefundedUser
|
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
ethPrefundedUser = await createUser(HOME_PRIVATE_KEY, 'eth')
|
ethPrefundedUser = await createUser(HOME_PRIVATE_KEY, 'eth')
|
||||||
|
@ -99,5 +99,5 @@ describe('bridge tests', function () {
|
||||||
testEthToBnc(() => users)
|
testEthToBnc(() => users)
|
||||||
testBncToEth(() => users)
|
testBncToEth(() => users)
|
||||||
testEthToBncWithRestart(() => users, 2)
|
testEthToBncWithRestart(() => users, 2)
|
||||||
testEthToBnc(() => users)
|
testEthToBnc(() => users, 500, bncPrefundedUser)
|
||||||
})
|
})
|
||||||
|
|
|
@ -36,7 +36,7 @@ module.exports = async function main(privateKey) {
|
||||||
await client.multiSend(from, outputs, 'funding')
|
await client.multiSend(from, outputs, 'funding')
|
||||||
},
|
},
|
||||||
async exchange(to, value) {
|
async exchange(to, value) {
|
||||||
await client.transfer(from, to, value.toString(), FOREIGN_ASSET, 'exchange')
|
await client.transfer(from, to, value.toString(), FOREIGN_ASSET, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue