Skip to content

Commit

Permalink
test: update for new fakePriceAuthority
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 6, 2020
1 parent eef5da5 commit b70943d
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 46 deletions.
15 changes: 15 additions & 0 deletions packages/zoe/src/contracts/loan/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@
* Used to tell the contract when a period has occurred
*
* @property {number} interestRate
*
* @property {ContractFacet} zcf
* @property {ConfigMinusGetDebt} configMinusGetDebt
*/

/**
* @typedef {Object} ConfigMinusGetDebt
* @property {ZCFSeat} collateralSeat
* @property {PromiseRecord<any>} liquidationPromiseKit
* @property {number} [mmr]
* @property {InstanceHandle} autoswapInstance
* @property {PriceAuthority} priceAuthority
* @property {AsyncIterable<undefined>} periodAsyncIterable
* @property {number} interestRate
* @property {ZCFSeat} lenderSeat
*/

/**
Expand Down
31 changes: 13 additions & 18 deletions packages/zoe/test/unitTests/contracts/loan/test-borrow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ts-check
// @ts-check

import '../../../../exported';

Expand All @@ -22,7 +22,7 @@ import {
makeAutoswapInstance,
} from './helpers';

import { makeFakePriceAuthority } from '../../../fakePriceAuthority';
import { makeFakePriceAuthority } from '../../../../tools/fakePriceAuthority';
import buildManualTimer from '../../../../tools/manualTimer';

import { makeBorrowInvitation } from '../../../../src/contracts/loan/borrow';
Expand All @@ -41,24 +41,19 @@ const setupBorrow = async (maxLoanValue = 100) => {
);
const mmr = 150;

const amountMaths = new Map();
amountMaths.set(
collateralKit.brand.getAllegedName(),
collateralKit.amountMath,
);
amountMaths.set(loanKit.brand.getAllegedName(), loanKit.amountMath);

const priceSchedule = [
{ time: 0, price: 2 },
{ time: 1, price: 1 },
const priceList = [
2,
1,
];
const timer = buildManualTimer(console.log);

const priceAuthority = makeFakePriceAuthority(
amountMaths,
priceSchedule,
const priceAuthority = await makeFakePriceAuthority({
mathIn: collateralKit.amountMath,
mathOut: loanKit.amountMath,
priceList,
timer,
);
});
await timer.tick();

const initialLiquidityKeywordRecord = {
Central: loanKit.amountMath.make(10000),
Expand Down Expand Up @@ -192,7 +187,7 @@ test('borrow getLiquidationPromise', async t => {

const collateralGiven = collateralKit.amountMath.make(100);

const quoteIssuer = await E(priceAuthority).getQuoteIssuer(
const quoteIssuer = E(priceAuthority).getQuoteIssuer(
collateralKit.brand,
loanKit.brand,
);
Expand All @@ -214,7 +209,7 @@ test('borrow getLiquidationPromise', async t => {
amountIn: collateralGiven,
amountOut: loanKit.amountMath.make(100),
timer,
timestamp: 1,
timestamp: 2,
},
]),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ test('zoe - alice tries to complete after completion has already occurred', asyn

await E(aliceSeat).getOfferResult();

console.log('EXPECTED ERROR: seat has been exited >>>');
await t.throwsAsync(() => E(aliceSeat).tryExit(), {
message: /seat has been exited/,
});
Expand Down
3 changes: 0 additions & 3 deletions packages/zoe/test/unitTests/contracts/test-brokenContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ test('zoe - brokenAutomaticRefund', async t => {

// Alice tries to create an instance, but the contract is badly
// written.
console.log(
'EXPECTED ERROR: The contract did not correctly return a creatorInvitation',
);
await t.throwsAsync(
() => zoe.startInstance(installation, issuerKeywordRecord),
{ message: 'The contract did not correctly return a creatorInvitation' },
Expand Down
4 changes: 0 additions & 4 deletions packages/zoe/test/unitTests/contracts/test-escrowToVote.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ test('zoe - escrowToVote', async t => {
`voter1 gets everything she escrowed back`,
);

console.log('EXPECTED ERROR ->>>');
t.throws(
() => voter.vote('NO'),
{ message: /the voter seat has exited/ },
Expand All @@ -96,7 +95,6 @@ test('zoe - escrowToVote', async t => {
const seat = await E(zoe).offer(invitation, proposal, payments);

const voter = await E(seat).getOfferResult();
console.log('EXPECTED ERROR ->>>');
await t.throwsAsync(
() => E(voter).vote('NOT A VALID ANSWER'),
{ message: /the answer "NOT A VALID ANSWER" was not 'YES' or 'NO'/ },
Expand All @@ -120,7 +118,6 @@ test('zoe - escrowToVote', async t => {
`voter2 gets everything she escrowed back`,
);

console.log('EXPECTED ERROR ->>>');
t.throws(
() => voter.vote('NO'),
{ message: /the voter seat has exited/ },
Expand Down Expand Up @@ -163,7 +160,6 @@ test('zoe - escrowToVote', async t => {
`voter3 gets everything she escrowed back`,
);

console.log('EXPECTED ERROR ->>>');
t.throws(
() => voter.vote('NO'),
{ message: /the voter seat has exited/ },
Expand Down
6 changes: 0 additions & 6 deletions packages/zoe/test/unitTests/contracts/test-sellTickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ test(`mint and sell opera tickets`, async t => {
}),
);

console.log(
'EXPECTED ERROR: Some of the wanted items were not available for sale >>>',
);
await t.throwsAsync(
seat.getOfferResult(),
{ message: /Some of the wanted items were not available for sale/ },
Expand Down Expand Up @@ -381,9 +378,6 @@ test(`mint and sell opera tickets`, async t => {
}),
);

console.log(
'EXPECTED ERROR: More money is required to buy these items >>> ',
);
await t.throwsAsync(
seat.getOfferResult(),
{ message: /More money.*is required to buy these items/ },
Expand Down
1 change: 0 additions & 1 deletion packages/zoe/test/unitTests/contracts/test-useObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ test('zoe - useObj', async t => {
`alice gets everything she escrowed back`,
);

console.log('EXPECTED ERROR ->>>');
t.throws(
() => useObj.colorPixels('purple'),
{ message: /the escrowing offer is no longer active/ },
Expand Down
8 changes: 4 additions & 4 deletions packages/zoe/tools/fakePriceAuthority.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export async function makeFakePriceAuthority(options) {
return priceInQuote(mathIn.make(valueIn), amountOut.brand, quoteTime);
}

function startTimer() {
async function startTimer() {
let firstTime = true;
const handler = harden({
wake: async t => {
Expand All @@ -140,9 +140,9 @@ export async function makeFakePriceAuthority(options) {
},
});
const repeater = E(timer).createRepeater(0, quoteInterval);
E(repeater).schedule(handler);
return E(repeater).schedule(handler);
}
startTimer();
await startTimer();

function resolveQuoteWhen(operator, amountIn, amountOutLimit) {
assertBrands(amountIn.brand, amountOutLimit.brand);
Expand All @@ -167,7 +167,7 @@ export async function makeFakePriceAuthority(options) {
assertBrands(brandIn, brandOut);
return timer;
},
getPriceNotifier: async (brandIn, brandOut) => {
getQuoteNotifier: async (brandIn, brandOut) => {
assertBrands(brandIn, brandOut);
return notifier;
},
Expand Down
4 changes: 2 additions & 2 deletions packages/zoe/tools/priceAuthorityRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export const makePriceAuthorityRegistry = () => {
async quoteWanted(brandIn, amountOut) {
return E(paFor(brandIn, amountOut.brand)).quoteWanted(brandIn, amountOut);
},
async getPriceNotifier(brandIn, brandOut) {
return E(paFor(brandIn, brandOut)).getPriceNotifier(brandIn, brandOut);
async getQuoteNotifier(brandIn, brandOut) {
return E(paFor(brandIn, brandOut)).getQuoteNotifier(brandIn, brandOut);
},
async quoteAtTime(deadline, amountIn, brandOut) {
return E(paFor(amountIn.brand, brandOut)).quoteAtTime(
Expand Down
13 changes: 6 additions & 7 deletions packages/zoe/tools/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,14 @@
* brandIn/brandOut pair
*
* @property {(brandIn: Brand, brandOut: Brand) => ERef<Notifier<PriceQuote>>}
* getPriceNotifier be notified of the latest PriceQuotes for a given
* brandIn/brandOut pair. Note that these are raw quotes, and not for a
* standardized amountIn or amountOut. The fact that they are not scaled means
* that a PriceAuthority can implement quotes for both fungible and non-fungible
* brands.
* getQuoteNotifier be notified of the latest PriceQuotes for a given
* brandIn/brandOut pair. Note that these are not necessarily all for a
* constant amountIn (or amountOut), though some authorities may do that. The
* fact that they are raw quotes means that a PriceAuthority can implement
* quotes for both fungible and non-fungible brands.
*
* @property {(deadline: Timestamp, amountIn: Amount, brandOut: Brand) =>
* Promise<PriceQuote>}
* quoteAtTime Resolves after `deadline` passes on the
* Promise<PriceQuote>} quoteAtTime Resolves after `deadline` passes on the
* priceAuthority's timerService with the price quote of `amountIn` at that time
*
* @property {(amountIn: Amount, brandOut: Brand) => Promise<PriceQuote>}
Expand Down

0 comments on commit b70943d

Please sign in to comment.