2019-08-27 17:26:49 +03:00
|
|
|
const assert = require('assert')
|
|
|
|
const axios = require('axios')
|
|
|
|
const { ercToNativeBridge, user, foreignRPC, validator } = require('../../e2e-commons/constants.json')
|
2020-02-18 19:17:01 +03:00
|
|
|
const {
|
|
|
|
waitUntil,
|
|
|
|
sendTokens,
|
|
|
|
addValidator,
|
|
|
|
initializeChaiToken,
|
|
|
|
convertDaiToChai,
|
2020-04-24 21:01:07 +03:00
|
|
|
setMinDaiTokenBalance
|
2020-02-18 19:17:01 +03:00
|
|
|
} = require('../utils')
|
2019-08-27 17:26:49 +03:00
|
|
|
|
|
|
|
const baseUrl = ercToNativeBridge.monitor
|
|
|
|
|
|
|
|
describe('ERC TO NATIVE', () => {
|
|
|
|
let data
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
;({ data } = await axios.get(`${baseUrl}`))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('balance', () => assert(parseInt(data.foreign.erc20Balance, 10) >= 0))
|
|
|
|
it('should contain totalSupply', () => assert(data.home.totalSupply === '0'))
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('ERC TO NATIVE with changing state of contracts', () => {
|
|
|
|
let data
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
assert((await axios.get(`${baseUrl}`)).data.balanceDiff === 0)
|
|
|
|
assert((await axios.get(`${baseUrl}/validators`)).data.validatorsMatch === true)
|
|
|
|
})
|
|
|
|
|
2020-02-18 19:17:01 +03:00
|
|
|
it('should change balanceDiff', async function() {
|
|
|
|
this.timeout(60000)
|
2020-04-24 21:01:07 +03:00
|
|
|
await sendTokens(foreignRPC.URL, user, ercToNativeBridge.foreignToken, ercToNativeBridge.foreign)
|
2020-02-18 19:17:01 +03:00
|
|
|
|
|
|
|
await waitUntil(async () => {
|
|
|
|
;({ data } = await axios.get(`${baseUrl}`))
|
2020-09-02 17:43:48 +03:00
|
|
|
if (!data.foreign) {
|
|
|
|
return false
|
|
|
|
}
|
2020-04-24 21:01:07 +03:00
|
|
|
const { erc20Balance, investedErc20Balance } = data.foreign
|
|
|
|
return data.balanceDiff === 0.01 && erc20Balance === '0.01' && investedErc20Balance === undefined
|
2019-08-27 17:26:49 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should change validatorsMatch', async () => {
|
|
|
|
await addValidator(foreignRPC.URL, validator, ercToNativeBridge.foreign)
|
|
|
|
await waitUntil(async () => {
|
|
|
|
;({ data } = await axios.get(`${baseUrl}/validators`))
|
|
|
|
return data.validatorsMatch === false
|
|
|
|
})
|
|
|
|
})
|
2020-02-18 19:17:01 +03:00
|
|
|
|
|
|
|
it('should consider chai token balance', async function() {
|
2020-11-04 22:16:43 +03:00
|
|
|
this.timeout(120000)
|
2020-02-18 19:17:01 +03:00
|
|
|
await initializeChaiToken(foreignRPC.URL, ercToNativeBridge.foreign)
|
|
|
|
await sendTokens(foreignRPC.URL, user, ercToNativeBridge.foreignToken, ercToNativeBridge.foreign)
|
|
|
|
|
|
|
|
await waitUntil(async () => {
|
|
|
|
;({ data } = await axios.get(`${baseUrl}`))
|
2020-09-02 17:43:48 +03:00
|
|
|
if (!data.foreign) {
|
|
|
|
return false
|
|
|
|
}
|
2020-11-04 22:16:43 +03:00
|
|
|
const { erc20Balance, investedErc20Balance, accumulatedInterest } = data.foreign
|
2020-02-18 19:17:01 +03:00
|
|
|
return (
|
2020-04-24 21:01:07 +03:00
|
|
|
data.balanceDiff === 0.02 &&
|
2020-02-18 19:17:01 +03:00
|
|
|
erc20Balance === '0.02' &&
|
|
|
|
investedErc20Balance === '0' &&
|
|
|
|
accumulatedInterest === '0.001' // value of dsrBalance() is initially defined in genesis block as 0.001
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
await setMinDaiTokenBalance(foreignRPC.URL, ercToNativeBridge.foreign, '0.01')
|
|
|
|
await convertDaiToChai(foreignRPC.URL, ercToNativeBridge.foreign)
|
|
|
|
|
|
|
|
await waitUntil(async () => {
|
|
|
|
;({ data } = await axios.get(`${baseUrl}`))
|
2020-09-02 17:43:48 +03:00
|
|
|
if (!data.foreign) {
|
|
|
|
return false
|
|
|
|
}
|
2020-11-04 22:16:43 +03:00
|
|
|
const { erc20Balance, investedErc20Balance, accumulatedInterest } = data.foreign
|
2020-02-18 19:17:01 +03:00
|
|
|
return (
|
2020-04-24 21:01:07 +03:00
|
|
|
data.balanceDiff === 0.02 &&
|
2020-02-18 19:17:01 +03:00
|
|
|
erc20Balance === '0.01' &&
|
|
|
|
investedErc20Balance === '0.01' &&
|
|
|
|
accumulatedInterest === '0.001'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
await setMinDaiTokenBalance(foreignRPC.URL, ercToNativeBridge.foreign, '0.005')
|
|
|
|
await convertDaiToChai(foreignRPC.URL, ercToNativeBridge.foreign)
|
|
|
|
|
|
|
|
await waitUntil(async () => {
|
|
|
|
;({ data } = await axios.get(`${baseUrl}`))
|
2020-09-02 17:43:48 +03:00
|
|
|
if (!data.foreign) {
|
|
|
|
return false
|
|
|
|
}
|
2020-11-04 22:16:43 +03:00
|
|
|
const { erc20Balance, investedErc20Balance, accumulatedInterest } = data.foreign
|
2020-02-18 19:17:01 +03:00
|
|
|
return (
|
2020-04-24 21:01:07 +03:00
|
|
|
data.balanceDiff === 0.02 &&
|
2020-02-18 19:17:01 +03:00
|
|
|
erc20Balance === '0.005' &&
|
|
|
|
investedErc20Balance === '0.015' &&
|
|
|
|
accumulatedInterest === '0.001'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2019-08-27 17:26:49 +03:00
|
|
|
})
|