Skip to content

Commit

Permalink
fix: add a test and correct the collateral check (#2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert authored Feb 1, 2021
1 parent e628351 commit 2396e4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/zoe/src/contracts/loan/borrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { assert, details } from '@agoric/assert';
import { E } from '@agoric/eventual-send';
import { makePromiseKit } from '@agoric/promise-kit';

import { assertProposalShape, trade, natSafeMath } from '../../contractSupport';
import { assertProposalShape, trade } from '../../contractSupport';

import { scheduleLiquidation } from './scheduleLiquidation';
import { calculateInterest, makeDebtCalculator } from './updateDebt';
Expand Down 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 2396e4d

Please sign in to comment.