From bd11c8a3a5b1751b9671f3e7ff010579398139bd Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Fri, 12 Jan 2024 23:01:20 -0600 Subject: [PATCH] chore: launcherLarry market actor --- contract/test/market-actors.js | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/contract/test/market-actors.js b/contract/test/market-actors.js index df5ce9b..53b4e46 100644 --- a/contract/test/market-actors.js +++ b/contract/test/market-actors.js @@ -1,7 +1,9 @@ // @ts-check import { E, getInterfaceOf } from '@endo/far'; +import { makePromiseKit } from '@endo/promise-kit'; import { AmountMath } from '@agoric/ertp/src/amountMath.js'; import { allValues, mapValues } from './wallet-tools.js'; +import { makeIssuerKit } from '@agoric/ertp'; const { entries, fromEntries, keys } = Object; const { Fail } = assert; @@ -258,3 +260,50 @@ export const starterSam = async (t, mine, wellKnown) => { t.deepEqual([...todo.keys()], []); return done; }; + +const seatLike = updates => { + const sync = { + result: makePromiseKit(), + payouts: makePromiseKit(), + }; + (async () => { + for await (const update of updates) { + if (update.updated !== 'offerStatus') continue; + const { result, payouts } = update.status; + if (result) sync.result.resolve(result); + if (payouts) sync.payouts.resolve(payouts); + } + })(); + return harden({ + getOfferResult: () => sync.result.promise, + getPayouts: () => sync.payouts.promise, + }); +}; +/** + * @param {import('ava').ExecutionContext} t + * @param {{ wallet: import('./wallet-tools.js').MockWallet }} mine + * @param { WellKnown & { terms: { arbAssetName: { price }}} } wellKnown + */ +export const launcherLarry = async (t, { wallet }, wellKnown) => { + const { price } = wellKnown.terms.arbAssetName; + const BRD = makeIssuerKit('BRD'); + const launched = { issuer: BRD.issuer, brand: BRD.brand }; + t.log('Larry launched', launched); + await E(wallet.offers).addIssuer(BRD.issuer); + const instance = await wellKnown.instance.arbAssetName; + t.log('Larry offers', price, 'to publish'); + const updates = await E(wallet.offers).executeOffer({ + id: 'larry-brd-publish-1', + invitationSpec: { + source: 'contract', + instance, + publicInvitationMaker: 'makePublishAssetInvitation', + }, + proposal: { give: { Pay: price } }, + offerArgs: launched, + }); + const seat = seatLike(updates); + const id = await E(seat).getOfferResult(); + t.log('Larry published as', id); + return { ...launched, id }; +};