Skip to content

Commit

Permalink
test: update test-callSpread for playerPiano fakePriceAuthority
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Nov 6, 2020
1 parent 87422fb commit 68f55de
Showing 1 changed file with 48 additions and 15 deletions.
63 changes: 48 additions & 15 deletions packages/zoe/test/unitTests/contracts/test-callSpread.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import { makeFakePriceAuthority } from '../../../tools/fakePriceAuthority';
const callSpread = `${__dirname}/../../../src/contracts/callSpread`;
const simpleExchange = `${__dirname}/../../../src/contracts/simpleExchange`;

const makeTestPriceAuthority = (amountMaths, priceList, timer) =>
makeFakePriceAuthority({
mathIn: amountMaths.get('simoleans'),
mathOut: amountMaths.get('moola'),
priceList,
timer,
});

// Underlying is in Simoleans. Collateral, strikePrice and Payout are in bucks.
// Value is in Moola. The price oracle takes an amount in Underlying, and
// gives the value in Moola.
Expand All @@ -28,6 +36,7 @@ test('callSpread below Strike1', async t => {
bucks,
zoe,
amountMaths,
brands,
} = setup();
const installation = await installationPFromSource(zoe, callSpread);

Expand All @@ -42,8 +51,8 @@ test('callSpread below Strike1', async t => {
// Setup Carol
const carolBucksPurse = bucksIssuer.makeEmptyPurse();

const manualTimer = buildManualTimer(console.log, 1);
const priceAuthority = makeFakePriceAuthority(
const manualTimer = buildManualTimer(console.log, 0);
const priceAuthority = makeTestPriceAuthority(
amountMaths,
[54, 20, 35, 15, 28],
manualTimer,
Expand All @@ -64,7 +73,10 @@ test('callSpread below Strike1', async t => {
Underlying: simoleanIssuer,
Collateral: bucksIssuer,
Strike: moolaIssuer,
Quote: priceAuthority.getQuoteIssuer(),
Quote: await E(priceAuthority).getQuoteIssuer(
brands.get('simoleans'),
brands.get('moola'),
),
});
const { creatorInvitation } = await zoe.startInstance(
installation,
Expand Down Expand Up @@ -104,6 +116,7 @@ test('callSpread below Strike1', async t => {
bucks(300),
);

await E(manualTimer).tick();
await E(manualTimer).tick();
await E(manualTimer).tick();
await Promise.all([bobDeposit, carolDeposit]);
Expand All @@ -122,6 +135,7 @@ test('callSpread above Strike2', async t => {
bucks,
zoe,
amountMaths,
brands,
} = setup();
const installation = await installationPFromSource(zoe, callSpread);

Expand All @@ -136,8 +150,8 @@ test('callSpread above Strike2', async t => {
// Setup Carol
const carolBucksPurse = bucksIssuer.makeEmptyPurse();

const manualTimer = buildManualTimer(console.log, 1);
const priceAuthority = makeFakePriceAuthority(
const manualTimer = buildManualTimer(console.log, 0);
const priceAuthority = makeTestPriceAuthority(
amountMaths,
[20, 55],
manualTimer,
Expand All @@ -158,7 +172,10 @@ test('callSpread above Strike2', async t => {
Underlying: simoleanIssuer,
Collateral: bucksIssuer,
Strike: moolaIssuer,
Quote: priceAuthority.getQuoteIssuer(),
Quote: await E(priceAuthority).getQuoteIssuer(
brands.get('simoleans'),
brands.get('moola'),
),
});

const { creatorInvitation } = await zoe.startInstance(
Expand Down Expand Up @@ -204,6 +221,7 @@ test('callSpread above Strike2', async t => {
bucks(0),
);

await E(manualTimer).tick();
await E(manualTimer).tick();
await E(manualTimer).tick();
await Promise.all([bobDeposit, carolDeposit]);
Expand All @@ -222,6 +240,7 @@ test('callSpread, mid-strike', async t => {
bucks,
zoe,
amountMaths,
brands,
} = setup();
const installation = await installationPFromSource(zoe, callSpread);

Expand All @@ -236,8 +255,8 @@ test('callSpread, mid-strike', async t => {
// Setup Carol
const carolBucksPurse = bucksIssuer.makeEmptyPurse();

const manualTimer = buildManualTimer(console.log, 1);
const priceAuthority = makeFakePriceAuthority(
const manualTimer = buildManualTimer(console.log, 0);
const priceAuthority = makeTestPriceAuthority(
amountMaths,
[20, 45],
manualTimer,
Expand All @@ -257,7 +276,10 @@ test('callSpread, mid-strike', async t => {
Underlying: simoleanIssuer,
Collateral: bucksIssuer,
Strike: moolaIssuer,
Quote: priceAuthority.getQuoteIssuer(),
Quote: await E(priceAuthority).getQuoteIssuer(
brands.get('simoleans'),
brands.get('moola'),
),
});

const { creatorInvitation } = await zoe.startInstance(
Expand Down Expand Up @@ -303,6 +325,7 @@ test('callSpread, mid-strike', async t => {
bucks(75),
);

await E(manualTimer).tick();
await E(manualTimer).tick();
await E(manualTimer).tick();
await Promise.all([bobDeposit, carolDeposit]);
Expand All @@ -321,6 +344,7 @@ test('callSpread, late exercise', async t => {
bucks,
zoe,
amountMaths,
brands,
} = setup();
const installation = await installationPFromSource(zoe, callSpread);

Expand All @@ -335,8 +359,8 @@ test('callSpread, late exercise', async t => {
// Setup Carol
const carolBucksPurse = bucksIssuer.makeEmptyPurse();

const manualTimer = buildManualTimer(console.log, 1);
const priceAuthority = makeFakePriceAuthority(
const manualTimer = buildManualTimer(console.log, 0);
const priceAuthority = makeTestPriceAuthority(
amountMaths,
[20, 45],
manualTimer,
Expand All @@ -357,7 +381,10 @@ test('callSpread, late exercise', async t => {
Underlying: simoleanIssuer,
Collateral: bucksIssuer,
Strike: moolaIssuer,
Quote: priceAuthority.getQuoteIssuer(),
Quote: await E(priceAuthority).getQuoteIssuer(
brands.get('simoleans'),
brands.get('moola'),
),
});
const { creatorInvitation } = await zoe.startInstance(
installation,
Expand Down Expand Up @@ -395,6 +422,7 @@ test('callSpread, late exercise', async t => {
bucks(225),
);

await E(manualTimer).tick();
await E(manualTimer).tick();
await E(manualTimer).tick();

Expand All @@ -420,6 +448,7 @@ test('callSpread, sell options', async t => {
bucks,
zoe,
amountMaths,
brands,
} = setup();
const installation = await installationPFromSource(zoe, callSpread);
const invitationIssuer = await E(zoe).getInvitationIssuer();
Expand All @@ -438,8 +467,8 @@ test('callSpread, sell options', async t => {
const carolBucksPurse = bucksIssuer.makeEmptyPurse();
const carolBucksPayment = bucksMint.mintPayment(bucks(100));

const manualTimer = buildManualTimer(console.log, 1);
const priceAuthority = makeFakePriceAuthority(
const manualTimer = buildManualTimer(console.log, 0);
const priceAuthority = makeTestPriceAuthority(
amountMaths,
[20, 45],
manualTimer,
Expand All @@ -460,7 +489,10 @@ test('callSpread, sell options', async t => {
Underlying: simoleanIssuer,
Collateral: bucksIssuer,
Strike: moolaIssuer,
Quote: priceAuthority.getQuoteIssuer(),
Quote: await E(priceAuthority).getQuoteIssuer(
brands.get('simoleans'),
brands.get('moola'),
),
});
const { creatorInvitation } = await zoe.startInstance(
installation,
Expand Down Expand Up @@ -583,6 +615,7 @@ test('callSpread, sell options', async t => {
bucks(75),
);

await E(manualTimer).tick();
await E(manualTimer).tick();
await E(manualTimer).tick();
await Promise.all([aliceLong, aliceShort, bobDeposit, carolDeposit]);
Expand Down

0 comments on commit 68f55de

Please sign in to comment.