Skip to content

Commit

Permalink
fix: add a test and correct the collateral check
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Jan 29, 2021
1 parent 07e763d commit f692a00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 1 addition & 3 deletions packages/zoe/src/contracts/loan/borrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ export const makeBorrowInvitation = (zcf, config) => {
// Assert the required collateral was escrowed.
assert(
loanMath.isGTE(
loanMath.make(
natSafeMath.multiply(collateralPriceInLoanBrand.value, 100),
),
loanMath.make(collateralPriceInLoanBrand.value),
mmr.scale(loanWanted),
),
details`The required margin is approximately ${approxForMsg.value}% but collateral only had value of ${collateralPriceInLoanBrand.value}`,
Expand Down
13 changes: 13 additions & 0 deletions packages/zoe/test/unitTests/contracts/loan/test-borrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,19 @@ test('getDebtNotifier with interest', async t => {
});
});

test('borrow collateral just too low', async t => {
const { borrowSeat: borrowSeatGood } = await setupBorrowFacet(75);
const offerResult = await E(borrowSeatGood).getOfferResult();
const collateralAmount = await E(offerResult).getRecentCollateralAmount();
t.is(collateralAmount.value, 75);

const { borrowSeat: borrowSeatBad } = await setupBorrowFacet(74);
await t.throwsAsync(() => E(borrowSeatBad).getOfferResult(), {
message:
'The required margin is approximately (a number)% but collateral only had value of (a number)',
});
});

test.todo('borrow bad proposal');

test.todo('schedule a liquidation that fails, giving collateral to the lender');

0 comments on commit f692a00

Please sign in to comment.