Skip to content

Commit

Permalink
feat(contract): typedef improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Dec 30, 2023
1 parent 7e3d0ed commit f2d6dfc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
3 changes: 2 additions & 1 deletion contract/src/gameAssetContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ const bagValueSize = amt => {
return total;
};

/** @typedef {StandardTerms & { joinPrice: Amount<'nat'> }} GamePlacesTerms */
/**
* @param {ZCF<{joinPrice: Amount}>} zcf
* @param {ZCF<GamePlacesTerms>} zcf
*/
export const start = async zcf => {
const { joinPrice } = zcf.getTerms();
Expand Down
18 changes: 12 additions & 6 deletions contract/src/start-game1-proposal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @ts-check
import { E } from '@endo/far';
import { E } from '@endo/eventual-send';
import { makeMarshal } from '@endo/marshal';
import { AmountMath } from '@agoric/ertp/src/amountMath.js';
import '@agoric/zoe/exported.js';

console.warn('start-game1-proposal.js module evaluating');

Expand All @@ -26,6 +27,11 @@ const makeBoardAuxNode = async (chainStorage, boardId) => {
return E(boardAux).makeChildNode(boardId);
};

/**
* @param {ERef<StorageNode>} chainStorage
* @param {ERef<import('@agoric/vats/src/types').Board>} board
* @param {ERef<Brand>} brand
*/
const publishBrandInfo = async (chainStorage, board, brand) => {
const [id, displayInfo] = await Promise.all([
E(board).getId(brand),
Expand All @@ -38,28 +44,25 @@ const publishBrandInfo = async (chainStorage, board, brand) => {

/**
* Core eval script to start contract
*
* @param {BootstrapPowers} permittedPowers
* XXX FIXME File '~/agoric-sdk/packages/vats/src/core/types.js' is not a module
* @param {import('@agoric/vats/src/core/types').BootstrapPowers} permittedPowers
*/
export const startGameContract = async permittedPowers => {
console.error('startGameContract()...');
const {
consume: { board, chainStorage, startUpgradable, zoe },
brand: {
consume: { IST: istBrandP },
// @ts-expect-error dynamic extension to promise space
produce: { Place: producePlaceBrand },
},
issuer: {
consume: { IST: istIssuerP },
// @ts-expect-error dynamic extension to promise space
produce: { Place: producePlaceIssuer },
},
installation: {
consume: { game1: game1InstallationP },
},
instance: {
// @ts-expect-error dynamic extension to promise space
produce: { game1: produceInstance },
},
} = permittedPowers;
Expand Down Expand Up @@ -117,6 +120,9 @@ const gameManifest = {
};
harden(gameManifest);

/**
* @param {{restoreRef: (ref: unknown) => Promise<unknown> }} r
* @param {{ game1Ref: unknown }} g */
export const getManifestForGame1 = ({ restoreRef }, { game1Ref }) => {
return harden({
manifest: gameManifest,
Expand Down
2 changes: 1 addition & 1 deletion contract/test/mintStable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

// @ts-check
import { E } from '@endo/far';
import { E } from '@endo/eventual-send';
import { createRequire } from 'module';

const myRequire = createRequire(import.meta.url);
Expand Down
3 changes: 2 additions & 1 deletion contract/test/test-bundle-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { test } from './prepare-test-env-ava.js';

import { createRequire } from 'module';
import bundleSource from '@endo/bundle-source';
import { E, passStyleOf } from '@endo/far';
import { E } from '@endo/eventual-send';
import { passStyleOf } from '@endo/far';
import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';

const myRequire = createRequire(import.meta.url);
Expand Down
17 changes: 13 additions & 4 deletions contract/test/test-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import { test as anyTest } from './prepare-test-env-ava.js';

import { createRequire } from 'module';
import { E, Far } from '@endo/far';
import { E } from '@endo/eventual-send';
import { Far } from '@endo/far';
import { makePromiseKit } from '@endo/promise-kit';
import { makeCopyBag } from '@endo/patterns';
import { makeNodeBundleCache } from '@endo/bundle-source/cache.js';
Expand Down Expand Up @@ -78,8 +79,8 @@ test('Start the contract', async t => {
*
* @param {import('ava').ExecutionContext} t
* @param {ZoeService} zoe
* @param {ERef<import('@agoric/zoe/src/zoeService/utils').Instance<GameContractFn>} instance
* @param {Purse} purse
* @param {import('@agoric/zoe/src/zoeService/utils').Instance<GameContractFn>} instance
* @param {Purse<"nat">} purse
* @param {string[]} choices
*/
const alice = async (
Expand All @@ -90,7 +91,7 @@ const alice = async (
choices = ['Park Place', 'Boardwalk'],
) => {
const publicFacet = E(zoe).getPublicFacet(instance);
// @ts-expect-error Promise<Instance> seems to work
/** @type {import('../src/gameAssetContract.js').GamePlacesTerms} */
const terms = await E(zoe).getTerms(instance);
const { issuers, brands, joinPrice } = terms;

Expand Down Expand Up @@ -188,6 +189,14 @@ test('use the code that will go on chain to start the contract', async t => {
});

const { zoe } = t.context;
/**
* @param {{
* installation: ERef<Installation<GameContractFn>>;
* issuerKeywordRecord: IssuerKeywordRecord;
* label: string;
* terms: import('../src/gameAssetContract.js').GamePlacesTerms;
* }} opts
*/
const startUpgradable = async ({
installation,
issuerKeywordRecord,
Expand Down

0 comments on commit f2d6dfc

Please sign in to comment.