Skip to content

Commit

Permalink
refactor: convert to new setupBasicMints in Zoe tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Apr 15, 2020
1 parent c142b7a commit 223cb12
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { test } from 'tape-promise/tape';
import harden from '@agoric/harden';

import { setup } from '../setupBasicMints2';
import { setup } from '../setupBasicMints';

import {
makeZoeHelpers,
Expand Down
11 changes: 8 additions & 3 deletions packages/zoe/test/unitTests/contracts/test-atomicSwap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ const atomicSwapRoot = `${__dirname}/../../../src/contracts/atomicSwap`;

test('zoe - atomicSwap', async t => {
t.plan(11);
const { issuers, mints, moola, simoleans } = setup();
const {
moolaIssuer,
simoleanIssuer,
moolaMint,
simoleanMint,
moola,
simoleans,
} = setup();
const zoe = makeZoe({ require });
const inviteIssuer = zoe.getInviteIssuer();
const [moolaIssuer, simoleanIssuer] = issuers;
const [moolaMint, simoleanMint] = mints;

// pack the contract
const { source, moduleFormat } = await bundleSource(atomicSwapRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import harden from '@agoric/harden';

import { makeZoe } from '../../../src/zoe';
// TODO: Remove setupBasicMints and rename setupBasicMints2
import { setup } from '../setupBasicMints2';
import { setup } from '../setupBasicMints';
import { makeGetInstanceHandle } from '../../../src/clientSupport';
import { setupNonFungible } from '../setupNonFungibleMints';

Expand Down
58 changes: 36 additions & 22 deletions packages/zoe/test/unitTests/contracts/test-autoswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,34 @@ import bundleSource from '@agoric/bundle-source';
import harden from '@agoric/harden';

import { makeZoe } from '../../../src/zoe';
import { setup } from '../setupBasicMints2';
import { setup } from '../setupBasicMints';
import { makeGetInstanceHandle } from '../../../src/clientSupport';

const autoswapRoot = `${__dirname}/../../../src/contracts/autoswap`;

test('autoSwap with valid offers', async t => {
t.plan(19);
try {
const { moolaR, simoleanR, moola, simoleans } = setup();
const {
moolaIssuer,
simoleanIssuer,
moolaMint,
simoleanMint,
moola,
simoleans,
} = setup();
const zoe = makeZoe({ require });
const inviteIssuer = zoe.getInviteIssuer();
const getInstanceHandle = makeGetInstanceHandle(inviteIssuer);

// Setup Alice
const aliceMoolaPayment = moolaR.mint.mintPayment(moola(10));
const aliceMoolaPayment = moolaMint.mintPayment(moola(10));
// Let's assume that simoleans are worth 2x as much as moola
const aliceSimoleanPayment = simoleanR.mint.mintPayment(simoleans(5));
const aliceSimoleanPayment = simoleanMint.mintPayment(simoleans(5));

// Setup Bob
const bobMoolaPayment = moolaR.mint.mintPayment(moola(3));
const bobSimoleanPayment = simoleanR.mint.mintPayment(simoleans(3));
const bobMoolaPayment = moolaMint.mintPayment(moola(3));
const bobSimoleanPayment = simoleanMint.mintPayment(simoleans(3));

// Alice creates an autoswap instance

Expand All @@ -35,8 +42,8 @@ test('autoSwap with valid offers', async t => {

const installationHandle = zoe.install(source, moduleFormat);
const issuerKeywordRecord = harden({
TokenA: moolaR.issuer,
TokenB: simoleanR.issuer,
TokenA: moolaIssuer,
TokenB: simoleanIssuer,
});
const aliceInvite = await zoe.makeInstance(
installationHandle,
Expand Down Expand Up @@ -117,9 +124,9 @@ test('autoSwap with valid offers', async t => {
const bobMoolaPayout1 = await bobPayout.TokenA;
const bobSimoleanPayout1 = await bobPayout.TokenB;

t.deepEqual(await moolaR.issuer.getAmountOf(bobMoolaPayout1), moola(0));
t.deepEqual(await moolaIssuer.getAmountOf(bobMoolaPayout1), moola(0));
t.deepEqual(
await simoleanR.issuer.getAmountOf(bobSimoleanPayout1),
await simoleanIssuer.getAmountOf(bobSimoleanPayout1),
simoleans(1),
);
t.deepEquals(bobAutoswap.getPoolAllocation(), {
Expand Down Expand Up @@ -155,9 +162,9 @@ test('autoSwap with valid offers', async t => {
const bobMoolaPayout2 = await bobSimsForMoolaPayout.TokenA;
const bobSimoleanPayout2 = await bobSimsForMoolaPayout.TokenB;

t.deepEqual(await moolaR.issuer.getAmountOf(bobMoolaPayout2), moola(5));
t.deepEqual(await moolaIssuer.getAmountOf(bobMoolaPayout2), moola(5));
t.deepEqual(
await simoleanR.issuer.getAmountOf(bobSimoleanPayout2),
await simoleanIssuer.getAmountOf(bobSimoleanPayout2),
simoleans(0),
);
t.deepEqual(bobAutoswap.getPoolAllocation(), {
Expand Down Expand Up @@ -190,9 +197,9 @@ test('autoSwap with valid offers', async t => {
const aliceSimoleanPayout = await aliceRemoveLiquidityPayout.TokenB;
const aliceLiquidityPayout = await aliceRemoveLiquidityPayout.Liquidity;

t.deepEquals(await moolaR.issuer.getAmountOf(aliceMoolaPayout), moola(8));
t.deepEquals(await moolaIssuer.getAmountOf(aliceMoolaPayout), moola(8));
t.deepEquals(
await simoleanR.issuer.getAmountOf(aliceSimoleanPayout),
await simoleanIssuer.getAmountOf(aliceSimoleanPayout),
simoleans(7),
);
t.deepEquals(
Expand All @@ -213,17 +220,24 @@ test('autoSwap with valid offers', async t => {
test('autoSwap - test fee', async t => {
t.plan(9);
try {
const { moolaR, simoleanR, moola, simoleans } = setup();
const {
moolaIssuer,
simoleanIssuer,
moolaMint,
simoleanMint,
moola,
simoleans,
} = setup();
const zoe = makeZoe({ require });
const inviteIssuer = zoe.getInviteIssuer();
const getInstanceHandle = makeGetInstanceHandle(inviteIssuer);

// Setup Alice
const aliceMoolaPayment = moolaR.mint.mintPayment(moola(10000));
const aliceSimoleanPayment = simoleanR.mint.mintPayment(simoleans(10000));
const aliceMoolaPayment = moolaMint.mintPayment(moola(10000));
const aliceSimoleanPayment = simoleanMint.mintPayment(simoleans(10000));

// Setup Bob
const bobMoolaPayment = moolaR.mint.mintPayment(moola(1000));
const bobMoolaPayment = moolaMint.mintPayment(moola(1000));

// Alice creates an autoswap instance

Expand All @@ -232,8 +246,8 @@ test('autoSwap - test fee', async t => {

const installationHandle = zoe.install(source, moduleFormat);
const issuerKeywordRecord = harden({
TokenA: moolaR.issuer,
TokenB: simoleanR.issuer,
TokenA: moolaIssuer,
TokenB: simoleanIssuer,
});
const aliceAddLiquidityInvite = await zoe.makeInstance(
installationHandle,
Expand Down Expand Up @@ -315,9 +329,9 @@ test('autoSwap - test fee', async t => {
const bobMoolaPayout = await bobPayout.TokenA;
const bobSimoleanPayout = await bobPayout.TokenB;

t.deepEqual(await moolaR.issuer.getAmountOf(bobMoolaPayout), moola(0));
t.deepEqual(await moolaIssuer.getAmountOf(bobMoolaPayout), moola(0));
t.deepEqual(
await simoleanR.issuer.getAmountOf(bobSimoleanPayout),
await simoleanIssuer.getAmountOf(bobSimoleanPayout),
simoleans(906),
);
t.deepEquals(bobAutoswap.getPoolAllocation(), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import harden from '@agoric/harden';

import { makeZoe } from '../../../src/zoe';
// TODO: Remove setupBasicMints and rename setupBasicMints2
import { setup } from '../setupBasicMints2';
import { setup } from '../setupBasicMints';

const automaticRefundRoot = `${__dirname}/brokenAutoRefund`;

Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/test/unitTests/contracts/test-coveredCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { sameStructure } from '@agoric/same-structure';

import buildManualTimer from '../../../tools/manualTimer';
import { makeZoe } from '../../../src/zoe';
import { setup } from '../setupBasicMints2';
import { setup } from '../setupBasicMints';
import { setupNonFungible } from '../setupNonFungibleMints';

const coveredCallRoot = `${__dirname}/../../../src/contracts/coveredCall`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import bundleSource from '@agoric/bundle-source';
import harden from '@agoric/harden';

import { makeZoe } from '../../../src/zoe';
import { setup } from '../setupBasicMints2';
import { setup } from '../setupBasicMints';
import { setupMixed } from '../setupMixedMints';
import { makeGetInstanceHandle } from '../../../src/clientSupport';

Expand Down
37 changes: 24 additions & 13 deletions packages/zoe/test/unitTests/contracts/test-simpleExchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ const simpleExchange = `${__dirname}/../../../src/contracts/simpleExchange`;

test('simpleExchange with valid offers', async t => {
t.plan(9);
const { issuers, mints, amountMaths, moola, simoleans } = setup();
const [moolaIssuer, simoleanIssuer] = issuers;
const [moolaMint, simoleanMint] = mints;
const {
moolaIssuer,
simoleanIssuer,
moolaMint,
simoleanMint,
amountMaths,
moola,
simoleans,
} = setup();
const zoe = makeZoe({ require });
const inviteIssuer = zoe.getInviteIssuer();
const getInstanceHandle = makeGetInstanceHandle(inviteIssuer);
Expand Down Expand Up @@ -120,10 +126,12 @@ test('simpleExchange with valid offers', async t => {

// Alice gets paid at least what she wanted
t.ok(
amountMaths[1].isGTE(
await simoleanIssuer.getAmountOf(aliceSimoleanPayout),
aliceSellOrderProposal.want.Price,
),
amountMaths
.get('simoleans')
.isGTE(
await simoleanIssuer.getAmountOf(aliceSimoleanPayout),
aliceSellOrderProposal.want.Price,
),
);

// Alice sold all of her moola
Expand All @@ -149,9 +157,14 @@ test('simpleExchange with valid offers', async t => {
test('simpleExchange with multiple sell offers', async t => {
t.plan(1);
try {
const { issuers, mints, moola, simoleans } = setup();
const [moolaIssuer, simoleanIssuer] = issuers;
const [moolaMint, simoleanMint] = mints;
const {
moolaIssuer,
simoleanIssuer,
moolaMint,
simoleanMint,
moola,
simoleans,
} = setup();
const zoe = makeZoe({ require });
const inviteIssuer = zoe.getInviteIssuer();
const getInstanceHandle = makeGetInstanceHandle(inviteIssuer);
Expand Down Expand Up @@ -242,9 +255,7 @@ test('simpleExchange with multiple sell offers', async t => {

test('simpleExchange showPayoutRules', async t => {
t.plan(1);
const { issuers, mints, moola, simoleans } = setup();
const [moolaIssuer, simoleanIssuer] = issuers;
const [moolaMint] = mints;
const { moolaIssuer, simoleanIssuer, moolaMint, moola, simoleans } = setup();
const zoe = makeZoe({ require });
const inviteIssuer = zoe.getInviteIssuer();
const getInstanceHandle = makeGetInstanceHandle(inviteIssuer);
Expand Down
42 changes: 26 additions & 16 deletions packages/zoe/test/unitTests/setupBasicMints.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@ import harden from '@agoric/harden';
import produceIssuer from '@agoric/ertp';

const setup = () => {
const moolaIssuerResults = produceIssuer('moola');
const simoleanIssuerResults = produceIssuer('simoleans');
const bucksIssuerResults = produceIssuer('bucks');
const moolaBundle = produceIssuer('moola');
const simoleanBundle = produceIssuer('simoleans');
const bucksBundle = produceIssuer('bucks');
const allBundles = {
moola: moolaBundle,
simoleans: simoleanBundle,
bucks: bucksBundle,
};
const amountMaths = new Map();
const brands = new Map();

const all = [moolaIssuerResults, simoleanIssuerResults, bucksIssuerResults];
const mints = all.map(objs => objs.mint);
const issuers = all.map(objs => objs.issuer);
const amountMaths = all.map(objs => objs.amountMath);
const brands = all.map(objs => objs.brand);
for (const k of Object.getOwnPropertyNames(allBundles)) {
amountMaths.set(k, allBundles[k].amountMath);
brands.set(k, allBundles[k].brand);
}

return harden({
mints,
issuers,
moolaIssuer: moolaBundle.issuer,
moolaMint: moolaBundle.mint,
moolaR: moolaBundle,
simoleanIssuer: simoleanBundle.issuer,
simoleanMint: simoleanBundle.mint,
simoleanR: simoleanBundle,
bucksIssuer: bucksBundle.issuer,
bucksMint: bucksBundle.mint,
bucksR: bucksBundle,
amountMaths,
brands,
moolaIssuerResults,
simoleanIssuerResults,
bucksIssuerResults,
moola: moolaIssuerResults.amountMath.make,
simoleans: simoleanIssuerResults.amountMath.make,
bucks: bucksIssuerResults.amountMath.make,
moola: moolaBundle.amountMath.make,
simoleans: simoleanBundle.amountMath.make,
bucks: bucksBundle.amountMath.make,
});
};
harden(setup);
Expand Down
20 changes: 0 additions & 20 deletions packages/zoe/test/unitTests/setupBasicMints2.js

This file was deleted.

Loading

0 comments on commit 223cb12

Please sign in to comment.