eth-to-bnc-bridge/tests/test/utils/bncController.js

23 lines
666 B
JavaScript
Raw Normal View History

2019-10-27 09:21:36 -07:00
const axios = require('axios')
2019-11-01 01:21:28 -07:00
const { retry } = require('./wait')
2019-10-27 09:21:36 -07:00
const { FOREIGN_URL, FOREIGN_ASSET } = process.env
const bnc = axios.create({
baseURL: FOREIGN_URL,
timeout: 15000
2019-10-27 09:21:36 -07:00
})
module.exports = {
getBalance: async function (address) {
2019-11-01 01:21:28 -07:00
const response = await retry(5, () => bnc.get(`/api/v1/account/${address}`))
const tokens = response.data.balances.find(x => x.symbol === FOREIGN_ASSET)
return response && tokens ? parseFloat(tokens.free) : 0
2019-10-27 09:21:36 -07:00
},
2019-11-01 01:21:28 -07:00
getSequence: async function (address) {
const response = await retry(5, () => bnc.get(`/api/v1/account/${address}/sequence`))
return response ? response.data.sequence : 0
2019-10-27 09:21:36 -07:00
}
}