Skip to content

Commit

Permalink
Make tests more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymx95 committed Apr 30, 2024
1 parent f5e008a commit 97e6998
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions test/trinity/StabilityPoolTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const mv = testHelpers.MoneyValues
const timeValues = testHelpers.TimeValues

var contracts
var validCollateral
var snapshotId
var initialSnapshotId
var validCollateral
var unsortedCollaterals

const openVessel = async params => th.openVessel(contracts.core, params)
const deploy = async (treasury, distributor, mintingAccounts) => {
Expand All @@ -33,7 +34,7 @@ const deploy = async (treasury, distributor, mintingAccounts) => {
longTimelock = contracts.core.longTimelock

validCollateral = await adminContract.getValidCollateral()

unsortedCollaterals = validCollateral.slice(0)
// getDepositorGains() expects a sorted collateral array
validCollateral = validCollateral.slice(0).sort((a, b) => toBN(a.toLowerCase()).sub(toBN(b.toLowerCase())))

Expand Down Expand Up @@ -1132,7 +1133,7 @@ contract("StabilityPool", async accounts => {
// Expect alice to be entitled to 1000/200000 of the liquidated coll

const aliceExpectedGainERC20 = liquidatedCollERC20.mul(toBN(dec(1000, 18))).div(toBN(dec(200_000, 18)))
const idx = validCollateral.indexOf(erc20.address)
const idx = unsortedCollaterals.indexOf(erc20.address)
const aliceGainERC20 = (await stabilityPool.getDepositorGains(alice, validCollateral))[1][idx]
assert.isTrue(aliceExpectedGainERC20.eq(aliceGainERC20))

Expand Down
5 changes: 3 additions & 2 deletions test/trinity/VesselManagerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var contracts
var snapshotId
var initialSnapshotId
var validCollateral
var unsortedCollaterals

const deploy = async (treasury, distributor, mintingAccounts) => {
contracts = await deploymentHelper.deployTestContracts(treasury, distributor, mintingAccounts)
Expand All @@ -42,7 +43,7 @@ const deploy = async (treasury, distributor, mintingAccounts) => {
longTimelock = contracts.core.longTimelock

validCollateral = await adminContract.getValidCollateral()

unsortedCollaterals = validCollateral.slice(0)
// getDepositorGains() expects a sorted collateral array
validCollateral = validCollateral.slice(0).sort((a, b) => toBN(a.toLowerCase()).sub(toBN(b.toLowerCase())))

Expand Down Expand Up @@ -1169,7 +1170,7 @@ contract("VesselManager", async accounts => {
// Check Bob' SP deposit has absorbed Carol's debt, and he has received her liquidated ETH

const bob_Deposit_Before_Asset = await stabilityPool.getCompoundedDebtTokenDeposits(bob)
const idx = validCollateral.indexOf(erc20.address)
const idx = unsortedCollaterals.indexOf(erc20.address)
const bob_ETHGain_Before_Asset = (await stabilityPool.getDepositorGains(bob, validCollateral))[1][idx]

assert.isAtMost(th.getDifference(bob_Deposit_Before_Asset, B_spDeposit.sub(C_debt_Asset)), 1000000)
Expand Down

0 comments on commit 97e6998

Please sign in to comment.