Skip to content

Commit

Permalink
Merge pull request #12 from Jorge-Lopes/jorge/unit-tests
Browse files Browse the repository at this point in the history
Extend liquidation visibility unit tests
  • Loading branch information
Jorge-Lopes authored Feb 8, 2024
2 parents 728d695 + cdb3c19 commit 60b2245
Show file tree
Hide file tree
Showing 10 changed files with 2,550 additions and 80 deletions.
21 changes: 8 additions & 13 deletions packages/inter-protocol/src/vaultFactory/vaultManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
NotifierShape,
RatioShape,
} from '@agoric/ertp';
import { makeTracer } from '@agoric/internal';
import { allValuesSettled, makeTracer } from '@agoric/internal';
import { makeStoredNotifier, observeNotifier } from '@agoric/notifier';
import { appendToStoredArray } from '@agoric/store/src/stores/store-utils.js';
import {
Expand Down Expand Up @@ -1385,21 +1385,16 @@ export const prepareVaultManagerKit = (
// we don't want those failures to prevent liquidation process from going forward.
// We don't handle the case where 'makeDeposit' rejects as liquidation depends on
// 'makeDeposit' being fulfilled.
await null;
const [
{ userSeatPromise, deposited },
const {
makeDeposit: { userSeatPromise, deposited },
liquidationVisibilityWriters,
auctionSchedule,
] = (
await Promise.allSettled([
makeDeposit,
} = await allValuesSettled({
makeDeposit,
liquidationVisibilityWriters:
helper.makeLiquidationVisibilityWriters(timestamp),
schedulesP,
])
)
.filter(result => result.status === 'fulfilled')
// @ts-expect-error
.map(result => result.value);
auctionSchedule: schedulesP,
});

void helper.writeLiqVisibility(liquidationVisibilityWriters, [
['writePreAuction', vaultData],
Expand Down
22 changes: 16 additions & 6 deletions packages/inter-protocol/test/liquidationVisibility/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@ export const assertVaultCurrentDebt = async (t, vault, debt) => {
);
};

export const assertVaultCollateral = async (t, vault, collateralValue) => {
export const assertVaultCollateral = async (
t,
vault,
collateralValue,
asset,
) => {
const collateralAmount = await E(vault).getCollateralAmount();

t.deepEqual(collateralAmount, t.context.aeth.make(collateralValue));
t.deepEqual(collateralAmount, asset.make(collateralValue));
};

export const assertMintedAmount = async (t, vaultSeat, wantMinted) => {
Expand All @@ -94,11 +99,16 @@ export const assertMintedProceeds = async (t, vaultSeat, wantMinted) => {
);
};

export const assertVaultLocked = async (t, vaultNotifier, lockedValue) => {
export const assertVaultLocked = async (
t,
vaultNotifier,
lockedValue,
asset,
) => {
const notification = await E(vaultNotifier).getUpdateSince();
const lockedAmount = notification.value.locked;

t.deepEqual(lockedAmount, t.context.aeth.make(lockedValue));
t.deepEqual(lockedAmount, asset.make(lockedValue));
};

export const assertVaultDebtSnapshot = async (t, vaultNotifier, wantMinted) => {
Expand Down Expand Up @@ -139,15 +149,15 @@ export const assertVaultFactoryRewardAllocation = async (
});
};

export const assertCollateralProceeds = async (t, seat, colWanted) => {
export const assertCollateralProceeds = async (t, seat, colWanted, issuer) => {
const { Collateral: withdrawnCol } = await E(seat).getFinalAllocation();
const proceeds4 = await E(seat).getPayouts();
t.deepEqual(withdrawnCol, colWanted);

const collateralWithdrawn = await proceeds4.Collateral;
t.truthy(
AmountMath.isEqual(
await E(t.context.aeth.issuer).getAmountOf(collateralWithdrawn),
await E(issuer).getAmountOf(collateralWithdrawn),
colWanted,
),
);
Expand Down
Loading

0 comments on commit 60b2245

Please sign in to comment.