Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEBUG Attempt] subscription service contract debug notes #100

Draft
wants to merge 3 commits into
base: subscription-service-contract
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions contract/src/offer-up-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
52 changes: 30 additions & 22 deletions contract/src/offer-up.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ import '@agoric/zoe/exported.js';
*
* @param {ZCF<SubscriptionServiceTerms>} 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'],
Expand Down Expand Up @@ -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';
};

Expand Down
106 changes: 73 additions & 33 deletions contract/test/test-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Installation<AssetContractFn>>} */
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');
});
Expand All @@ -84,14 +92,25 @@ test('Start the contract', async t => {
* @param {ZoeService} zoe
* @param {ERef<import('@agoric/zoe/src/zoeService/utils').Instance<AssetContractFn>>} 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<Instance> 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],
Expand Down Expand Up @@ -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<Installation<AssetContractFn>>} */
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<Installation<AssetContractFn>>} */
// 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 => {
/**
Expand All @@ -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 => {
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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);
});