Fixed extra votes processing. Added delay before getting binance balance.

This commit is contained in:
Kirill Fedoseev 2019-10-30 11:51:22 +03:00
parent 5359ac8b3c
commit e44b3915d1
3 changed files with 12 additions and 8 deletions

View File

@ -222,7 +222,8 @@ function parseError (message) {
async function sendVote (query, req, res, waitFlag = false) {
try {
let { txHash, gasLimit } = await homeSendQuery(query)
const sentQuery = await homeSendQuery(query)
let { txHash, gasLimit } = sentQuery
if (txHash) {
while (waitFlag) {
const { status, gasUsed } = await waitForReceipt(HOME_RPC_URL, txHash)
@ -232,14 +233,16 @@ async function sendVote (query, req, res, waitFlag = false) {
}
if (gasLimit === gasUsed) {
logger.info('Sending vote failed due to out of gas revert, retrying with more gas')
const nexTx = await homeSendQuery(query)
txHash = nexTx.txHash
gasLimit = nexTx.gasLimit
const nextTx = await homeSendQuery(query)
txHash = nextTx.txHash
gasLimit = nextTx.gasLimit
} else {
logger.warn(`Vote tx was reverted, txHash ${txHash}`)
break
}
}
}
if (sentQuery) {
res.send('Voted\n')
logger.info('Voted successfully')
} else {
@ -300,8 +303,7 @@ function decodeStatus (status) {
}
}
function boundX(x) {
function boundX (x) {
try {
return x.toNumber()
} catch (e) {

View File

@ -50,7 +50,7 @@ async function createSender (url, privateKey) {
if (estimate.error) {
logger.debug('Gas estimate failed %o', estimate.error)
return false
return true
}
const gasLimit = BN.min(new BN(estimate.result, 16).multipliedBy(GAS_LIMIT_FACTOR), MAX_GAS_LIMIT)
tx.gasLimit = `0x${new BN(gasLimit).toString(16)}`

View File

@ -47,7 +47,8 @@ describe('bridge tests', function () {
testBncToEth(() => users, () => info.foreignBridgeAddress)
describe('remove validator', function () {
before(function () {
before(async function () {
info = await controller1.getInfo()
prevForeignBridgeBalance = info.foreignBalanceTokens
prevForeignBridgeAddress = info.foreignBridgeAddress
})
@ -126,6 +127,7 @@ describe('bridge tests', function () {
assert.deepStrictEqual(info.validators, [ validatorsConfig[0], validatorsConfig[2] ], 'Incorrect set of validators in epoch 2')
assert.strictEqual(info.nextEpoch, 2, 'Incorrect next epoch')
assert.strictEqual(info.bridgeStatus, 'ready', 'Incorrect bridge state in new epoch')
await delay(5000)
const prevBalance = await getBalance(prevForeignBridgeAddress)
const newBalance = await getBalance(info.foreignBridgeAddress)
assert.strictEqual(prevBalance, 0, "Did not transfer all funds")