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 366e4ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions test/trinity/StabilityPoolTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ const mv = testHelpers.MoneyValues
const timeValues = testHelpers.TimeValues

var contracts
var validCollateral
var snapshotId
var initialSnapshotId

const openVessel = async params => th.openVessel(contracts.core, params)
const deploy = async (treasury, distributor, mintingAccounts) => {
let validCollateral
let unsortedCollaterals
contracts = await deploymentHelper.deployTestContracts(treasury, distributor, mintingAccounts)

activePool = contracts.core.activePool
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
7 changes: 4 additions & 3 deletions test/trinity/VesselManagerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const f = v => ethers.utils.formatEther(v.toString())
var contracts
var snapshotId
var initialSnapshotId
var validCollateral

const deploy = async (treasury, distributor, mintingAccounts) => {
let validCollateral
let unsortedCollaterals
contracts = await deploymentHelper.deployTestContracts(treasury, distributor, mintingAccounts)

activePool = contracts.core.activePool
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 366e4ec

Please sign in to comment.