Skip to content

Commit c169ffd

Browse files
committed
fix: update swingset runner demos for latest zoe incarnation
1 parent 6a65984 commit c169ffd

File tree

9 files changed

+135
-13
lines changed

9 files changed

+135
-13
lines changed

packages/swingset-runner/demo/zoeTests/bootstrap.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import simpleExchangeBundle from './bundle-simpleExchange';
1313
import autoswapBundle from './bundle-autoswap';
1414
import sellItemsBundle from './bundle-sellItems';
1515
import mintAndSellNFTBundle from './bundle-mintAndSellNFT';
16+
import otcDeskBundle from './bundle-otcDesk';
1617
/* eslint-enable import/no-unresolved, import/extensions */
1718

1819
const setupBasicMints = () => {
@@ -106,6 +107,7 @@ export function buildRootObject(_vatPowers, vatParameters) {
106107
autoswap: await E(zoe).install(autoswapBundle.bundle),
107108
sellItems: await E(zoe).install(sellItemsBundle.bundle),
108109
mintAndSellNFT: await E(zoe).install(mintAndSellNFTBundle.bundle),
110+
otcDesk: await E(zoe).install(otcDeskBundle.bundle),
109111
};
110112

111113
const testName = vatParameters.argv[0] || 'simpleExchangeOk';

packages/swingset-runner/demo/zoeTests/prepareContracts.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const CONTRACT_FILES = [
1414
'simpleExchange',
1515
'sellItems',
1616
'mintAndSellNFT',
17+
'otcDesk',
1718
];
1819

1920
const generateBundlesP = Promise.all(

packages/swingset-runner/demo/zoeTests/sampleArgs

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ simpleExchangeOk
1010
simpleExchangeNotifier
1111
autoswapOk
1212
sellTicketsOk
13+
otcDeskOk

packages/swingset-runner/demo/zoeTests/swingset.json

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
"sellTicketsOk": [
6868
[ 0, 0, 0 ],
6969
[ 22, 0, 0 ]
70+
],
71+
"otcDeskOk": [
72+
[10000, 10000, 10000],
73+
[10000, 10000, 10000]
7074
]
7175
}
7276
}

packages/swingset-runner/demo/zoeTests/vat-alice.js

+71-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { showPurseBalance, setupIssuers } from './helpers';
55
import { makePrintLog } from './printLog';
66

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

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

421+
const doOTCDesk = async bobP => {
422+
const { creatorFacet } = await E(zoe).startInstance(
423+
installations.otcDesk,
424+
undefined,
425+
{ coveredCallInstallation: installations.coveredCall },
426+
);
427+
428+
// Add inventory
429+
const addInventoryInvitation = await E(
430+
creatorFacet,
431+
).makeAddInventoryInvitation({
432+
Moola: moolaIssuer,
433+
Simolean: simoleanIssuer,
434+
Buck: bucksIssuer,
435+
});
436+
const addInventoryProposal = harden({
437+
give: {
438+
Moola: moola(10000),
439+
Simolean: simoleans(10000),
440+
Buck: bucks(10000),
441+
},
442+
});
443+
const addInventoryPayments = {
444+
Moola: moolaPayment,
445+
Simolean: simoleanPayment,
446+
Buck: bucksPayment,
447+
};
448+
449+
const addInventorySeat = await E(zoe).offer(
450+
addInventoryInvitation,
451+
addInventoryProposal,
452+
addInventoryPayments,
453+
);
454+
const addInventoryOfferResult = await E(addInventorySeat).getOfferResult();
455+
log(addInventoryOfferResult);
456+
const bobInvitation = await E(creatorFacet).makeQuote(
457+
{ Simolean: simoleans(4) },
458+
{ Moola: moola(3) },
459+
timer,
460+
1,
461+
);
462+
463+
await E(bobP).doOTCDesk(bobInvitation);
464+
465+
// Remove Inventory
466+
const removeInventoryInvitation = await E(
467+
creatorFacet,
468+
).makeRemoveInventoryInvitation();
469+
// Intentionally do not remove it all
470+
const removeInventoryProposal = harden({
471+
want: { Simolean: simoleans(2) },
472+
});
473+
const removeInventorySeat = await E(zoe).offer(
474+
removeInventoryInvitation,
475+
removeInventoryProposal,
476+
);
477+
const removeInventoryOfferResult = await E(
478+
removeInventorySeat,
479+
).getOfferResult();
480+
log(removeInventoryOfferResult);
481+
const simoleanPayout = await E(removeInventorySeat).getPayout('Simolean');
482+
483+
log(await E(simoleanIssuer).getAmountOf(simoleanPayout));
484+
};
485+
421486
return harden({
422487
startTest: async (testName, bobP, carolP, daveP) => {
423488
switch (testName) {
@@ -448,6 +513,9 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
448513
case 'sellTicketsOk': {
449514
return doSellTickets(bobP, carolP, daveP);
450515
}
516+
case 'otcDeskOk': {
517+
return doOTCDesk(bobP);
518+
}
451519
default: {
452520
throw new Error(`testName ${testName} not recognized`);
453521
}

packages/swingset-runner/demo/zoeTests/vat-bob.js

+45-5
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,17 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
9797
optionValue[0].description === 'exerciseOption',
9898
details`wrong invitation`,
9999
);
100-
assert(moolaAmountMath.isEqual(optionValue[0].underlyingAsset, moola(3)));
101100
assert(
102-
simoleanAmountMath.isEqual(optionValue[0].strikePrice, simoleans(7)),
101+
moolaAmountMath.isEqual(
102+
optionValue[0].underlyingAssets.UnderlyingAsset,
103+
moola(3),
104+
),
105+
);
106+
assert(
107+
simoleanAmountMath.isEqual(
108+
optionValue[0].strikePrice.StrikePrice,
109+
simoleans(7),
110+
),
103111
);
104112
assert(
105113
optionValue[0].expirationDate === 1,
@@ -162,11 +170,17 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
162170
details`wrong invitation`,
163171
);
164172
assert(
165-
moolaAmountMath.isEqual(optionValue[0].underlyingAsset, moola(3)),
173+
moolaAmountMath.isEqual(
174+
optionValue[0].underlyingAssets.UnderlyingAsset,
175+
moola(3),
176+
),
166177
details`wrong underlying asset`,
167178
);
168179
assert(
169-
simoleanAmountMath.isEqual(optionValue[0].strikePrice, simoleans(7)),
180+
simoleanAmountMath.isEqual(
181+
optionValue[0].strikePrice.StrikePrice,
182+
simoleans(7),
183+
),
170184
details`wrong strike price`,
171185
);
172186
assert(
@@ -257,7 +271,6 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
257271
proposal,
258272
paymentKeywordRecord,
259273
);
260-
261274
log(`Bob: ${await E(secondPriceAuctionSeatP).getOfferResult()}`);
262275
},
263276
doSecondPriceAuctionGetPayout: async () => {
@@ -539,6 +552,33 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
539552
);
540553
log('boughtTicketAmount: ', boughtTicketAmount);
541554
},
555+
556+
doOTCDesk: async untrustedInvitation => {
557+
const invitation = await E(invitationIssuer).claim(untrustedInvitation);
558+
const invitationValue = await E(zoe).getInvitationDetails(invitation);
559+
assert(invitationValue.installation === installations.coveredCall);
560+
561+
// Bob can use whatever keywords he wants
562+
const proposal = harden({
563+
give: { Whatever1: simoleans(4) },
564+
want: { Whatever2: moola(3) },
565+
exit: { onDemand: null },
566+
});
567+
await E(simoleanPurseP).deposit(simoleanPayment);
568+
const simoleanPayment1 = await E(simoleanPurseP).withdraw(simoleans(4));
569+
570+
const seat = await E(zoe).offer(invitation, proposal, {
571+
Whatever1: simoleanPayment1,
572+
});
573+
574+
log(await E(seat).getOfferResult());
575+
576+
const moolaPayout = await E(seat).getPayout('Whatever2');
577+
const simoleansPayout = await E(seat).getPayout('Whatever1');
578+
579+
log(await E(moolaIssuer).getAmountOf(moolaPayout));
580+
log(await E(simoleanIssuer).getAmountOf(simoleansPayout));
581+
},
542582
});
543583
};
544584

packages/swingset-runner/demo/zoeTests/vat-carol.js

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const build = async (log, zoe, issuers, payments, installations) => {
5050
proposal,
5151
paymentKeywordRecord,
5252
);
53-
5453
log(`Carol: ${await E(secondPriceAuctionSeatP).getOfferResult()}`);
5554
},
5655
doSecondPriceAuctionGetPayout: async () => {

packages/swingset-runner/demo/zoeTests/vat-dave.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,17 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
122122
details`wrong invitation`,
123123
);
124124
assert(
125-
moolaAmountMath.isEqual(optionValue[0].underlyingAsset, moola(3)),
125+
moolaAmountMath.isEqual(
126+
optionValue[0].underlyingAssets.UnderlyingAsset,
127+
moola(3),
128+
),
126129
details`wrong underlying asset`,
127130
);
128131
assert(
129-
simoleanAmountMath.isEqual(optionValue[0].strikePrice, simoleans(7)),
132+
simoleanAmountMath.isEqual(
133+
optionValue[0].strikePrice.StrikePrice,
134+
simoleans(7),
135+
),
130136
details`wrong strike price`,
131137
);
132138
assert(

packages/swingset-runner/trun

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ function runone {
4545
fi
4646
cmdline="$cmd $cmdargs $@"
4747
echo "$cmdline > rlog-${runct}"
48+
echo "$cmdline > rlog-${runct}" > rlog-${runct}
4849
if [ "$dryrun" != "1" ]; then
4950
if [ $dotime ]; then
50-
(time $cmdline) >& rlog-${runct}
51+
(time $cmdline) >> rlog-${runct} 2>&1
5152
else
52-
$cmdline > rlog-${runct}
53+
$cmdline >> rlog-${runct} 2>&1
5354
fi
5455
fi
5556
((runct=runct+1))

0 commit comments

Comments
 (0)