Skip to content

Commit

Permalink
refactor(launch-it): move creatorCathy to market-actors
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Jan 14, 2024
1 parent 95f2dbf commit 28f316e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 71 deletions.
50 changes: 50 additions & 0 deletions contract/test/market-actors.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,53 @@ export const starterSam = async (t, mine, wellKnown) => {
t.deepEqual([...todo.keys()], []);
return done;
};

/**
* @param {import('ava').ExecutionContext} t
* @param {{wallet: import('./wallet-tools.js').MockWallet}} mine
* @param {*} wellKnown
*/
export const creatorCathy = async (t, { wallet }, wellKnown) => {
const instance = await wellKnown.instance.launchIt;
const { timerService: timer } = wellKnown;
const timerBrand = await wellKnown.brand.timer;
const MNYbrand = await wellKnown.brand.MNY;

{
const deadline = harden({ timerBrand, absValue: 10n });

/** @type {import('@agoric/smart-wallet').OfferSpec} */
const launchOfferSpec = {
id: 'mint-1',
invitationSpec: {
source: 'contract',
instance,
publicInvitationMaker: 'makeLaunchInvitation',
},
proposal: {
give: {},
want: { Deposit: AmountMath.makeEmpty(MNYbrand) },
exit: { afterDeadline: { timer, deadline } },
},
offerArgs: { name: 'CDOG', supplyQty: 1_000_000n },
};

t.log('1,000,000 CDOG tokens are minted');
const updates = await E(wallet.offers).executeOffer(launchOfferSpec);

const expected = [
{ id: launchOfferSpec.id },
{ result: 0 },
// { status: { numWantsSatisfied: 1 } },
// { status: { payouts: '@@' } },
];
for await (const selector of expected) {
const {
value: { status },
} = await updates.next();
t.log('expecting ##NN', selector);
// t.log('update ##NN', value);
t.like(status, selector);
}
}
};
98 changes: 27 additions & 71 deletions contract/test/test-launchIt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
import { AmountMath } from '@agoric/ertp/src/amountMath.js';
import { makeIssuerKit } from '@agoric/ertp';
import { startLaunchIt, contractName } from '../src/start-launchIt.js';
import { creatorCathy } from './market-actors.js';

const nodeRequire = createRequire(import.meta.url);

Expand Down Expand Up @@ -42,79 +43,30 @@ test.serial('start contract', async t => {
Object.assign(t.context.shared, { powers, MNY });
});

test.serial('launch a token', async t => {
t.log('Creator Cathy chooses to launch a new token, CDOG, paired with MNY');

/**
*
* @param {*} wellKnown
* @param {import('./wallet-tools.js').MockWallet} wallet
*/
const cathy = async (wellKnown, wallet) => {
const instance = await wellKnown.instance[contractName];
const { timerService: timer } = wellKnown;
const timerBrand = await wellKnown.brand.timer;
const MNYbrand = await wellKnown.brand.MNY;

{
const deadline = harden({ timerBrand, absValue: 10n });

/** @type {import('@agoric/smart-wallet').OfferSpec} */
const launchOfferSpec = {
id: 'mint-1',
invitationSpec: {
source: 'contract',
instance,
publicInvitationMaker: 'makeLaunchInvitation',
const albert = async (wellKnown, wallet) => {
const instance = await wellKnown.instance[contractName];
/** @type {import('@agoric/smart-wallet').OfferSpec} */
const offerSpec = {
id: 'contribute-2',
invitationSpec: {
source: 'contract',
instance,
publicInvitationMaker: 'createSubscribeInvitation',
invitationArgs: [
{
name: 'CDOG',
supplyQty: 1_000_000n,
deadline,
},
proposal: {
give: {},
want: { Deposit: AmountMath.makeEmpty(MNYbrand) },
exit: { afterDeadline: { timer, deadline } },
},
offerArgs: { name: 'CDOG', supplyQty: 1_000_000n },
};

t.log('1,000,000 CDOG tokens are minted');
const updates = await E(wallet.offers).executeOffer(launchOfferSpec);

const expected = [
{ id: launchOfferSpec.id },
{ result: 0 },
// { status: { numWantsSatisfied: 1 } },
// { status: { payouts: '@@' } },
];
for await (const selector of expected) {
const {
value: { status },
} = await updates.next();
t.log('expecting ##NN', selector);
// t.log('update ##NN', value);
t.like(status, selector);
}
}
],
},
proposal: { give: {} },
};
};

test.serial('launch a token', async t => {
t.log('Creator Cathy chooses to launch a new token, CDOG, paired with MNY');

const albert = async (wellKnown, wallet) => {
const instance = await wellKnown.instance[contractName];
/** @type {import('@agoric/smart-wallet').OfferSpec} */
const offerSpec = {
id: 'contribute-2',
invitationSpec: {
source: 'contract',
instance,
publicInvitationMaker: 'createSubscribeInvitation',
invitationArgs: [
{
name: 'CDOG',
supplyQty: 1_000_000n,
deadline,
},
],
},
proposal: { give: {} },
};
};
const { powers, MNY } = t.context.shared;

powers.brand.produce.MNY.resolve(MNY.brand);
Expand All @@ -136,7 +88,11 @@ test.serial('launch a token', async t => {
{ Invitation: invitationIssuer },
);
assert(await wellKnown.brand.timer, 'no timer brand???');
await cathy(wellKnown, await walletFactory.makeSmartWallet('agoric1cathy'));
await creatorCathy(
t,
{ wallet: await walletFactory.makeSmartWallet('agoric1cathy') },
wellKnown,
);
t.log('TODO: pool is open for contributions');
t.log('TODO: boostrap time is up. swap contributions');
t.log('TODO Cathy withdraws proceeds');
Expand Down

0 comments on commit 28f316e

Please sign in to comment.