Skip to content

Commit

Permalink
fix: update swingset runner demos for latest zoe incarnation
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed Oct 1, 2020
1 parent 6a65984 commit c169ffd
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 13 deletions.
2 changes: 2 additions & 0 deletions packages/swingset-runner/demo/zoeTests/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import simpleExchangeBundle from './bundle-simpleExchange';
import autoswapBundle from './bundle-autoswap';
import sellItemsBundle from './bundle-sellItems';
import mintAndSellNFTBundle from './bundle-mintAndSellNFT';
import otcDeskBundle from './bundle-otcDesk';
/* eslint-enable import/no-unresolved, import/extensions */

const setupBasicMints = () => {
Expand Down Expand Up @@ -106,6 +107,7 @@ export function buildRootObject(_vatPowers, vatParameters) {
autoswap: await E(zoe).install(autoswapBundle.bundle),
sellItems: await E(zoe).install(sellItemsBundle.bundle),
mintAndSellNFT: await E(zoe).install(mintAndSellNFTBundle.bundle),
otcDesk: await E(zoe).install(otcDeskBundle.bundle),
};

const testName = vatParameters.argv[0] || 'simpleExchangeOk';
Expand Down
1 change: 1 addition & 0 deletions packages/swingset-runner/demo/zoeTests/prepareContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const CONTRACT_FILES = [
'simpleExchange',
'sellItems',
'mintAndSellNFT',
'otcDesk',
];

const generateBundlesP = Promise.all(
Expand Down
1 change: 1 addition & 0 deletions packages/swingset-runner/demo/zoeTests/sampleArgs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ simpleExchangeOk
simpleExchangeNotifier
autoswapOk
sellTicketsOk
otcDeskOk
4 changes: 4 additions & 0 deletions packages/swingset-runner/demo/zoeTests/swingset.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"sellTicketsOk": [
[ 0, 0, 0 ],
[ 22, 0, 0 ]
],
"otcDeskOk": [
[10000, 10000, 10000],
[10000, 10000, 10000]
]
}
}
Expand Down
74 changes: 71 additions & 3 deletions packages/swingset-runner/demo/zoeTests/vat-alice.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { showPurseBalance, setupIssuers } from './helpers';
import { makePrintLog } from './printLog';

const build = async (log, zoe, issuers, payments, installations, timer) => {
const { moola, simoleans, purses } = await setupIssuers(zoe, issuers);
const { moola, simoleans, bucks, purses } = await setupIssuers(zoe, issuers);
const [moolaPurseP, simoleanPurseP] = purses;
const [moolaPayment, simoleanPayment] = payments;
const [moolaIssuer, simoleanIssuer] = issuers;
const [moolaPayment, simoleanPayment, bucksPayment] = payments;
const [moolaIssuer, simoleanIssuer, bucksIssuer] = issuers;

const doAutomaticRefund = async bobP => {
log(`=> alice.doCreateAutomaticRefund called`);
Expand Down Expand Up @@ -418,6 +418,71 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
log('alice earned: ', currentPurseBalance);
};

const doOTCDesk = async bobP => {
const { creatorFacet } = await E(zoe).startInstance(
installations.otcDesk,
undefined,
{ coveredCallInstallation: installations.coveredCall },
);

// Add inventory
const addInventoryInvitation = await E(
creatorFacet,
).makeAddInventoryInvitation({
Moola: moolaIssuer,
Simolean: simoleanIssuer,
Buck: bucksIssuer,
});
const addInventoryProposal = harden({
give: {
Moola: moola(10000),
Simolean: simoleans(10000),
Buck: bucks(10000),
},
});
const addInventoryPayments = {
Moola: moolaPayment,
Simolean: simoleanPayment,
Buck: bucksPayment,
};

const addInventorySeat = await E(zoe).offer(
addInventoryInvitation,
addInventoryProposal,
addInventoryPayments,
);
const addInventoryOfferResult = await E(addInventorySeat).getOfferResult();
log(addInventoryOfferResult);
const bobInvitation = await E(creatorFacet).makeQuote(
{ Simolean: simoleans(4) },
{ Moola: moola(3) },
timer,
1,
);

await E(bobP).doOTCDesk(bobInvitation);

// Remove Inventory
const removeInventoryInvitation = await E(
creatorFacet,
).makeRemoveInventoryInvitation();
// Intentionally do not remove it all
const removeInventoryProposal = harden({
want: { Simolean: simoleans(2) },
});
const removeInventorySeat = await E(zoe).offer(
removeInventoryInvitation,
removeInventoryProposal,
);
const removeInventoryOfferResult = await E(
removeInventorySeat,
).getOfferResult();
log(removeInventoryOfferResult);
const simoleanPayout = await E(removeInventorySeat).getPayout('Simolean');

log(await E(simoleanIssuer).getAmountOf(simoleanPayout));
};

return harden({
startTest: async (testName, bobP, carolP, daveP) => {
switch (testName) {
Expand Down Expand Up @@ -448,6 +513,9 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
case 'sellTicketsOk': {
return doSellTickets(bobP, carolP, daveP);
}
case 'otcDeskOk': {
return doOTCDesk(bobP);
}
default: {
throw new Error(`testName ${testName} not recognized`);
}
Expand Down
50 changes: 45 additions & 5 deletions packages/swingset-runner/demo/zoeTests/vat-bob.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,17 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
optionValue[0].description === 'exerciseOption',
details`wrong invitation`,
);
assert(moolaAmountMath.isEqual(optionValue[0].underlyingAsset, moola(3)));
assert(
simoleanAmountMath.isEqual(optionValue[0].strikePrice, simoleans(7)),
moolaAmountMath.isEqual(
optionValue[0].underlyingAssets.UnderlyingAsset,
moola(3),
),
);
assert(
simoleanAmountMath.isEqual(
optionValue[0].strikePrice.StrikePrice,
simoleans(7),
),
);
assert(
optionValue[0].expirationDate === 1,
Expand Down Expand Up @@ -162,11 +170,17 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
details`wrong invitation`,
);
assert(
moolaAmountMath.isEqual(optionValue[0].underlyingAsset, moola(3)),
moolaAmountMath.isEqual(
optionValue[0].underlyingAssets.UnderlyingAsset,
moola(3),
),
details`wrong underlying asset`,
);
assert(
simoleanAmountMath.isEqual(optionValue[0].strikePrice, simoleans(7)),
simoleanAmountMath.isEqual(
optionValue[0].strikePrice.StrikePrice,
simoleans(7),
),
details`wrong strike price`,
);
assert(
Expand Down Expand Up @@ -257,7 +271,6 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
proposal,
paymentKeywordRecord,
);

log(`Bob: ${await E(secondPriceAuctionSeatP).getOfferResult()}`);
},
doSecondPriceAuctionGetPayout: async () => {
Expand Down Expand Up @@ -539,6 +552,33 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
);
log('boughtTicketAmount: ', boughtTicketAmount);
},

doOTCDesk: async untrustedInvitation => {
const invitation = await E(invitationIssuer).claim(untrustedInvitation);
const invitationValue = await E(zoe).getInvitationDetails(invitation);
assert(invitationValue.installation === installations.coveredCall);

// Bob can use whatever keywords he wants
const proposal = harden({
give: { Whatever1: simoleans(4) },
want: { Whatever2: moola(3) },
exit: { onDemand: null },
});
await E(simoleanPurseP).deposit(simoleanPayment);
const simoleanPayment1 = await E(simoleanPurseP).withdraw(simoleans(4));

const seat = await E(zoe).offer(invitation, proposal, {
Whatever1: simoleanPayment1,
});

log(await E(seat).getOfferResult());

const moolaPayout = await E(seat).getPayout('Whatever2');
const simoleansPayout = await E(seat).getPayout('Whatever1');

log(await E(moolaIssuer).getAmountOf(moolaPayout));
log(await E(simoleanIssuer).getAmountOf(simoleansPayout));
},
});
};

Expand Down
1 change: 0 additions & 1 deletion packages/swingset-runner/demo/zoeTests/vat-carol.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const build = async (log, zoe, issuers, payments, installations) => {
proposal,
paymentKeywordRecord,
);

log(`Carol: ${await E(secondPriceAuctionSeatP).getOfferResult()}`);
},
doSecondPriceAuctionGetPayout: async () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/swingset-runner/demo/zoeTests/vat-dave.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,17 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
details`wrong invitation`,
);
assert(
moolaAmountMath.isEqual(optionValue[0].underlyingAsset, moola(3)),
moolaAmountMath.isEqual(
optionValue[0].underlyingAssets.UnderlyingAsset,
moola(3),
),
details`wrong underlying asset`,
);
assert(
simoleanAmountMath.isEqual(optionValue[0].strikePrice, simoleans(7)),
simoleanAmountMath.isEqual(
optionValue[0].strikePrice.StrikePrice,
simoleans(7),
),
details`wrong strike price`,
);
assert(
Expand Down
5 changes: 3 additions & 2 deletions packages/swingset-runner/trun
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ function runone {
fi
cmdline="$cmd $cmdargs $@"
echo "$cmdline > rlog-${runct}"
echo "$cmdline > rlog-${runct}" > rlog-${runct}
if [ "$dryrun" != "1" ]; then
if [ $dotime ]; then
(time $cmdline) >& rlog-${runct}
(time $cmdline) >> rlog-${runct} 2>&1
else
$cmdline > rlog-${runct}
$cmdline >> rlog-${runct} 2>&1
fi
fi
((runct=runct+1))
Expand Down

0 comments on commit c169ffd

Please sign in to comment.