From 9488b95307be22c4c0e0f3404ea7ca36167ad17c Mon Sep 17 00:00:00 2001 From: jovonni Date: Thu, 5 Sep 2024 22:06:47 -0400 Subject: [PATCH 1/3] removed await, debugging keyword record, startArgs, privateArgs --- contract/src/offer-up-proposal.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/contract/src/offer-up-proposal.js b/contract/src/offer-up-proposal.js index 943e389..c3941af 100644 --- a/contract/src/offer-up-proposal.js +++ b/contract/src/offer-up-proposal.js @@ -69,21 +69,36 @@ export const startOfferUpContract = async permittedPowers => { const istIssuer = await istIssuerP; const istBrand = await istBrandP; - const timerService = await await chainTimerServiceP; + const timerService = await chainTimerServiceP; const terms = { subscriptionPrice: AmountMath.make(istBrand, 10000000n), timerService, }; + await console.log("permittedPowers: ", permittedPowers) + await console.log("chainTimerServiceP, ", chainTimerServiceP) + await console.log("timerService proposal: ", timerService) + + debugger; // agoricNames gets updated each time; the promise space only once XXXXXXX const installation = await offerUpInstallationP; const { instance } = await E(startUpgradable)({ installation, - issuerKeywordRecord: { Price: istIssuer }, + issuerKeywordRecord: { + Price: istIssuer, + // timerService: timerService + }, label: 'offerUp', terms, + startArgs: { + terms + }, + privateArgs: { + timerService, + terms + } }); console.log('CoreEval script: started contract', instance); const { From 520fbcb49fb1a6c653a0c0fad4853b19813d7104 Mon Sep 17 00:00:00 2001 From: jovonni Date: Thu, 5 Sep 2024 22:08:09 -0400 Subject: [PATCH 2/3] fix(offer-up-proposal.js): added privateArg to start --- contract/src/offer-up.contract.js | 52 ++++++++++++++++++------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/contract/src/offer-up.contract.js b/contract/src/offer-up.contract.js index 843610b..ec7fd67 100644 --- a/contract/src/offer-up.contract.js +++ b/contract/src/offer-up.contract.js @@ -45,9 +45,12 @@ import '@agoric/zoe/exported.js'; * * @param {ZCF} zcf */ -export const start = async zcf => { +export const start = async (zcf, privateArgs) => { + + await console.log("privateArgs in contract: ", privateArgs) + const { timerService } = privateArgs; const { - timerService, + // timerService, subscriptionPrice, subscriptionPeriod = 'MONTHLY', servicesToAvail = ['Netflix', 'Amazon', 'HboMax', 'Disney'], @@ -97,30 +100,35 @@ export const start = async zcf => { const userAddress = offerArgs.userAddress; // @ts-ignore const serviceType = offerArgs.serviceType; - const currentTimeRecord = await E(timerService).getCurrentTimestamp(); + await console.log("timerService::", timerService); - const amountObject = AmountMath.make( - brand, - makeCopyBag([[{ serviceStarted: currentTimeRecord, serviceType }, 1n]]), - ); - const want = { Items: amountObject }; - - const newSubscription = itemMint.mintGains(want); - - atomicRearrange( - zcf, - harden([ - // price from buyer to proceeds - [buyerSeat, proceeds, { Price: subscriptionPrice }], - // new items to buyer - [newSubscription, buyerSeat, want], - ]), - ); + debugger; + + // const currentTimeRecord = await E(timerService).getCurrentTimestamp(); + // console.log("currentTimeRecord::", currentTimeRecord); + + // const amountObject = AmountMath.make( + // brand, + // makeCopyBag([[{ serviceStarted: currentTimeRecord, serviceType }, 1n]]), + // ); + // const want = { Items: amountObject }; + + // const newSubscription = itemMint.mintGains(want); + + // atomicRearrange( + // zcf, + // harden([ + // // price from buyer to proceeds + // [buyerSeat, proceeds, { Price: subscriptionPrice }], + // // new items to buyer + // [newSubscription, buyerSeat, want], + // ]), + // ); - subscriptions.set(userAddress, want.Items); + // subscriptions.set(userAddress, want.Items); buyerSeat.exit(true); - newSubscription.exit(); + // newSubscription.exit(); return 'Subscription Granted'; }; From f329b8b06b63e050945620bd7e93162ebca7d23b Mon Sep 17 00:00:00 2001 From: jovonni Date: Thu, 5 Sep 2024 22:10:08 -0400 Subject: [PATCH 3/3] fix(test-contract.js): debugging privateArgs, keyword record, and timers used in alice --- contract/test/test-contract.js | 106 +++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 33 deletions(-) diff --git a/contract/test/test-contract.js b/contract/test/test-contract.js index f154e22..34422d5 100644 --- a/contract/test/test-contract.js +++ b/contract/test/test-contract.js @@ -63,16 +63,24 @@ test('Start the contract', async t => { const money = makeIssuerKit('PlayMoney'); const issuers = { Price: money.issuer }; const timer = buildZoeManualTimer(); + console.log("timer::66", timer) + + + debugger; const terms = { subscriptionPrice: AmountMath.make(money.brand, 10000000n), timerService: timer, }; - t.log('terms:', terms); + console.log('terms: 74', terms); + + const privateArgs = { + timerService: timer, + } /** @type {ERef>} */ const installation = E(zoe).install(bundle); - const { instance } = await E(zoe).startInstance(installation, issuers, terms); + const { instance } = await E(zoe).startInstance(installation, issuers, terms, privateArgs); t.log(instance); t.is(typeof instance, 'object'); }); @@ -84,14 +92,25 @@ test('Start the contract', async t => { * @param {ZoeService} zoe * @param {ERef>} instance * @param {Purse} purse + * @param {import('@agoric/time').TimerService} timer */ -const alice = async (t, zoe, instance, purse) => { +const alice = async (t, zoe, instance, purse, timer) => { const publicFacet = E(zoe).getPublicFacet(instance); // @ts-expect-error Promise seems to work const terms = await E(zoe).getTerms(instance); + + // issue is timerService isnt being resolve const { issuers, brands, subscriptionPrice, timerService } = terms; - const currentTimeRecord = await E(timerService).getCurrentTimestamp(); + await console.log("terms::99", terms) + await console.log("timerService 100", timerService) + await console.log("timer 106", timer) + debugger; + const currentTimeRecord = await E(timer).getCurrentTimestamp(); + // const currentTimeRecord = await E(terms.timerService).getCurrentTimestamp(); + // const currentTimeRecord = await timer.getCurrentTimestamp(); + t.is(1, 1) + console.log("currentTimeRecord:", currentTimeRecord) const serviceType = 'Netflix'; const choiceBag = makeCopyBag([ [{ serviceStarted: currentTimeRecord, serviceType }, 1n], @@ -128,28 +147,32 @@ const alice = async (t, zoe, instance, purse) => { t.deepEqual(actualMovies, subscriptionMovies); }; -test('Alice trades: give some play money, want subscription', async t => { - const { zoe, bundle } = t.context; - - const money = makeIssuerKit('PlayMoney'); - const issuers = { Price: money.issuer }; - const timer = buildZoeManualTimer(); - const terms = { - subscriptionPrice: AmountMath.make(money.brand, 10000000n), - timerService: timer, - }; - /** @type {ERef>} */ - const installation = E(zoe).install(bundle); - const { instance } = await E(zoe).startInstance(installation, issuers, terms); - t.log(instance); - t.is(typeof instance, 'object'); - - const alicePurse = money.issuer.makeEmptyPurse(); - const amountOfMoney = AmountMath.make(money.brand, 10000000n); - const moneyPayment = money.mint.mintPayment(amountOfMoney); - alicePurse.deposit(moneyPayment); - await alice(t, zoe, instance, alicePurse); -}); +// test('Alice trades: give some play money, want subscription', async t => { +// const { zoe, bundle } = t.context; + +// const money = makeIssuerKit('PlayMoney'); +// const issuers = { Price: money.issuer }; +// const timer = buildZoeManualTimer(); + +// console.log("timer 3: ", timer) +// debugger; +// const terms = { +// subscriptionPrice: AmountMath.make(money.brand, 10000000n), +// timerService: timer, +// }; +// /** @type {ERef>} */ +// const installation = E(zoe).install(bundle); +// const { instance } = await E(zoe).startInstance(installation, issuers, terms, { timerService: timer }); +// t.log(instance); +// t.is(typeof instance, 'object'); + +// const alicePurse = money.issuer.makeEmptyPurse(); +// const amountOfMoney = AmountMath.make(money.brand, 10000000n); +// const moneyPayment = money.mint.mintPayment(amountOfMoney); +// alicePurse.deposit(moneyPayment); +// await alice(t, zoe, instance, alicePurse, timer); + +// }); test('Trade in IST rather than play money', async t => { /** @@ -165,17 +188,31 @@ test('Trade in IST rather than play money', async t => { const feeBrand = await E(feeIssuer).getBrand(); const subscriptionPrice = AmountMath.make(feeBrand, 10000000n); const timer = buildZoeManualTimer(); + + console.log("timer 183", timer) + + return E(zoe).startInstance( installation, - { Price: feeIssuer }, - { subscriptionPrice, timerService: timer }, + { + Price: feeIssuer , + // timerService: timer + }, + { + subscriptionPrice, + timerService: timer + }, + { + timerService: timer + } ); }; + const timer = buildZoeManualTimer(); const { zoe, bundle, bundleCache, feeMintAccess } = t.context; const { instance } = await startContract({ zoe, bundle }); const { faucet } = makeStableFaucet({ bundleCache, feeMintAccess, zoe }); - await alice(t, zoe, instance, await faucet(10n * UNIT6)); + await alice(t, zoe, instance, await faucet(10n * UNIT6), timer); }); test('use the code that will go on chain to start the contract', async t => { @@ -205,20 +242,23 @@ test('use the code that will go on chain to start the contract', async t => { setValue: async () => {}, }); + const timer = buildZoeManualTimer(); + + const { zoe } = t.context; const startUpgradable = async ({ installation, issuerKeywordRecord, label, terms, - }) => - E(zoe).startInstance(installation, issuerKeywordRecord, terms, {}, label); + }) => E(zoe).startInstance(installation, issuerKeywordRecord, terms, { timerService: terms.timer }, label); + const feeIssuer = await E(zoe).getFeeIssuer(); const feeBrand = await E(feeIssuer).getBrand(); const pFor = x => Promise.resolve(x); const powers = { - consume: { zoe, chainStorage, startUpgradable, board }, + consume: { zoe, chainStorage, startUpgradable, board, timer }, brand: { consume: { IST: pFor(feeBrand) }, produce: { Item: sync.brand }, @@ -249,5 +289,5 @@ test('use the code that will go on chain to start the contract', async t => { // Now that we have the instance, resume testing as above. const { feeMintAccess, bundleCache } = t.context; const { faucet } = makeStableFaucet({ bundleCache, feeMintAccess, zoe }); - await alice(t, zoe, instance, await faucet(10n * UNIT6)); + await alice(t, zoe, instance, await faucet(10n * UNIT6), powers.consume.timer); });