Fixed waiting for funds in sendTx, fixed correspondent tests.

This commit is contained in:
Kirill Fedoseev 2019-11-14 21:48:32 +03:00
parent 17cb9e760d
commit 73f7dc1612
8 changed files with 44 additions and 18 deletions

View File

@ -125,6 +125,14 @@ orbs:
docker logs ganache_home > ./artifacts/logs/ganache/home.log
docker logs ganache_side > ./artifacts/logs/ganache/side.log
when: always
- run:
name: "Save binance logs"
command: |
mkdir -p ./artifacts/logs/binance
docker logs binance-testnet_node_1 > ./artifacts/logs/binance/node.log
docker logs binance-testnet_api-server_1 > ./artifacts/logs/binance/api-server.log
docker logs binance-testnet_http-api_1 > ./artifacts/logs/binance/http-api.log
when: always
- store_artifacts:
path: ./artifacts
when: always
@ -151,7 +159,7 @@ jobs:
name: "Run dev environment, deploy contracts, prefund accounts"
command: |
BLOCK_TIME=3 ./demo/start-ethereum-environment.sh
cat ./tests/config.json | jq .users[].ethAddress | xargs -I {} ./src/test-services/ethereumSend/run.sh {} 300
cat ./tests/config.json | jq .users[].ethAddress | xargs -I {} ./src/test-services/ethereumSend/run.sh {} 1000
- run:
name: "Stop dev environment"
command: docker kill ganache_side ganache_home

View File

@ -126,7 +126,25 @@ async function handleBroadcast(req, res) {
tx: `0x${req.rawBody}`
}
})
res.send([response.data.result])
if (response.data.error) {
res.status(500).send({
code: 500,
failed_tx_index: 0,
message: 'RPC error -32603 - Internal error: Tx already exists in cache',
success_tx_results: []
})
} else if (response.data.result.code === 65546) {
res.status(400).send({
code: 400,
failed_tx_index: 0,
message: '3417218964BNB < 1000DEV-BA6',
success_tx_results: []
})
} else if (response.data.result) {
res.send([response.data.result])
} else {
res.status(400).end()
}
}
}

View File

@ -12,7 +12,7 @@ VALIDATOR_ADDRESS_3=0x6352e3e6038e05b9da00c84ae851308f9774f883
THRESHOLD=2
MIN_TX_LIMIT=10000000000000000
MAX_TX_LIMIT=100000000000000000000
MAX_TX_LIMIT=1000000000000000000000
BLOCKS_RANGE_SIZE=10

View File

@ -119,19 +119,19 @@ async function waitForAccountNonce(address, nonce) {
async function sendTx(tx) {
while (true) {
try {
return await httpClient
.post('/api/v1/broadcast?sync=true', tx, {
headers: {
'Content-Type': 'text/plain'
}
})
return await httpClient.post('/api/v1/broadcast?sync=true', tx, {
headers: {
'Content-Type': 'text/plain'
}
})
} catch (err) {
logger.trace('Error, response data %o', err.response.data)
if (err.response.data.message.includes('Tx already exists in cache')) {
logger.debug('Tx already exists in cache')
return true
}
if (err.response.data.message.includes(' < ')) {
logger.warn('Insufficient funds, waiting for funds to income')
logger.warn('Insufficient funds, waiting for funds')
await delay(60000)
} else {
logger.info('Something failed, restarting: %o', err.response)

View File

@ -22,7 +22,7 @@ echo "Starting binance test network"
./demo/start-binance-environment.sh
echo "Prefunding ethereum user accounts"
cat ./tests/config.json | jq .users[].ethAddress | xargs -I {} ./src/test-services/ethereumSend/run.sh {} 300
cat ./tests/config.json | jq .users[].ethAddress | xargs -I {} ./src/test-services/ethereumSend/run.sh {} 1000
echo "Prefunding binance user accounts"
cat ./tests/config.json | jq .users[].bncAddress | xargs -I {} ./src/test-services/binanceSend/run.sh {} 300 0.1

View File

@ -18,10 +18,10 @@ module.exports = (getUsers, newValidator) => {
initialInfo = await controller1.getInfo()
// eslint-disable-next-line prefer-destructuring
user = getUsers()[0]
bncBridgeSequence = await getBncSequence(info.foreignBridgeAddress)
bncBalance = await user.getBepBalance()
info = initialInfo
nextValidators = [...initialInfo.validators, newValidator]
bncBridgeSequence = await getBncSequence(info.foreignBridgeAddress)
nextValidators = [...info.validators, newValidator]
})
it('should start closing epoch process', async function () {

View File

@ -36,8 +36,8 @@ module.exports = (getUsers, amount = 5, getBncPrefundedUser = null) => {
}
})
if (bncPrefundedUser) {
it('should make exchange transaction on bnc side with waiting for enough funds on bnc side', async function () {
if (getBncPrefundedUser) {
it('should make exchange transaction on bnc side after already enough funds', async function () {
this.timeout(300000)
await delay(120000)
await bncPrefundedUser.transferBepBnb(info.foreignBridgeAddress, amount * 3 + 10, 0)

View File

@ -50,7 +50,7 @@ describe('bridge tests', function () {
const userEthBalance = await users[i].getEthBalance()
assert.ok(userEthBalance >= 0.1, `Insufficient ETH balance on ${users[i].ethAddress} in Ethereum network, expected 0.1 ETH, got ${userEthBalance}`)
const userErcBalance = await users[i].getErcBalance()
assert.ok(userErcBalance >= 200, `Insufficient ERC20 balance on ${users[i].ethAddress} in Ethereum network, expected 200 ERC20, got ${userErcBalance}`)
assert.ok(userErcBalance >= 1000, `Insufficient ERC20 balance on ${users[i].ethAddress} in Ethereum network, expected 1000 ERC20, got ${userErcBalance}`)
const userBnbBalance = await users[i].getBepBalance()
assert.ok(userBnbBalance >= 0.1, `Insufficient BNB balance on ${users[i].bncAddress} in Binance network, expected 0.1 BNB, got ${userBnbBalance}`)
const userBepBalance = await users[i].getBepBalance()
@ -84,7 +84,7 @@ describe('bridge tests', function () {
testRemoveValidator(validatorsConfig[1])
testEthToBnc(() => users)
testEthToBnc(() => users, 500, () => bncPrefundedUser)
testBncToEth(() => users)
testEthToBnc(() => users)
@ -99,5 +99,5 @@ describe('bridge tests', function () {
testEthToBnc(() => users)
testBncToEth(() => users)
testEthToBncWithRestart(() => users, 2)
testEthToBnc(() => users, 500, bncPrefundedUser)
testEthToBnc(() => users)
})