Asserting that maintainer receives eth refund
@@ -29,6 +29,7 @@ const bnChai = require('bn-chai')
chai.use(bnChai(BN))
import { AssertBalanceHelpers } from './helpers/assert_balance'
+import { getTxCost } from './helpers/tx_cost'
const TEST_DEPOSIT_DEPLOY = [
{ name: 'BytesLib', contract: BytesLib },
@@ -84,7 +85,7 @@ contract('DepositLiquidation', (accounts) => {
await uniswapExchange.mockLiquidity(tbtcSupply, { from: accounts[0], value: ethSupply })
}
- describe.only('#attemptToLiquidateOnchain', () => {
+ describe('#attemptToLiquidateOnchain', () => {
let deployed
let deposit
let tbtc
@@ -119,12 +120,10 @@ contract('DepositLiquidation', (accounts) => {
await uniswapExchange.mockLiquidity(tbtcSupply, { from: accounts[0], value: keepBondAmount })
})
- it('returns false when exchange = 0x0', async () => {
-
+ it('returns false when exchange = 0x0 (todo)', async () => {
})
- it('returns false if buy under MIN_TBTC threshold', async () => {
-
+ it('returns false if buy under MIN_TBTC threshold (todo)', async () => {
})
it('liquidates eth for 1.005 tbtc (MIN_TBTC)', async () => {
@@ -280,6 +279,9 @@ contract('DepositLiquidation', (accounts) => {
})
it('#startSignerFraudLiquidation', async () => {
+ const maintainer = accounts[5]
+ const maintainerBalance = new BN(await web3.eth.getBalance(maintainer))
+
await uniswapExchange.setPrices(
new BN(keepBondAmount).sub(remainingEthAfterLiquidation),
tbtcPrice
@@ -292,19 +294,18 @@ contract('DepositLiquidation', (accounts) => {
0, 0, DIGEST
)
- const maintainer = accounts[5]
- const maintainerBalance1 = new BN(await web3.eth.getBalance(maintainer))
- await deposit.startSignerFraudLiquidation({ from: maintainer })
+ const tx = await deposit.startSignerFraudLiquidation({ from: maintainer })
+ const txCostEth = await getTxCost(tx)
const depositState = await deposit.getState.call()
expect(depositState, 'Deposit state should be LIQUIDATED').to.eq.BN(utils.states.LIQUIDATED)
- const maintainerBalance2 = new BN(await web3.eth.getBalance(maintainer))
-
- expect(
- maintainerBalance2.sub(maintainerBalance1)
- ).to.eq.BN(remainingEthAfterLiquidation)
+ // check remaining eth sent to maintainer
+ await assertBalance.eth(deposit.address, '0')
+ const maintainerBalanceExpected = maintainerBalance.sub(txCostEth).add(remainingEthAfterLiquidation)
+ const maintainerBalance2 = await web3.eth.getBalance(maintainer)
+ expect(maintainerBalance2).to.eq.BN(maintainerBalanceExpected)
})
it('#startSignerAbortLiquidation', async () => {
@@ -322,6 +323,8 @@ contract('DepositLiquidation', (accounts) => {
await deposit.startSignerAbortLiquidation({ from: maintainer })
+ // check remaining eth sent to keep group
+ await assertBalance.eth(deposit.address, '0')
const keepGroupTotalEth = await keep.keepGroupTotalEth.call()
expect(keepGroupTotalEth).to.equal(remainingEthAfterLiquidation.toString())
})
