From 5e1e35303e23dbfdb6b209d786f09da4c5df9377 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Thu, 16 Nov 2023 19:29:58 -0600 Subject: [PATCH] feat(gimix): publish displayInfo for oracle brand --- .../zoe/src/contracts/gimix/start-gimix.js | 47 ++++++++++++++++++- .../unitTests/contracts/gimix/test-gimix.js | 33 ++++++++++--- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/packages/zoe/src/contracts/gimix/start-gimix.js b/packages/zoe/src/contracts/gimix/start-gimix.js index ffd9e57763f..b6c81bc3b82 100644 --- a/packages/zoe/src/contracts/gimix/start-gimix.js +++ b/packages/zoe/src/contracts/gimix/start-gimix.js @@ -11,6 +11,32 @@ import { E, Far } from '@endo/far'; +// vstorage paths under published.* +const BOARD_AUX = 'boardAux'; + +/** + * Smallcaps marshalling for plain data (no caps/slots). + * Re-implemented to avoid linking @endo/marshal in + * in a core-eval script. + * + * Note unit test in test-gimix.js to confirm correctness. + * + * @param {*} data - PlainData + */ +const marshalPlainData = data => + JSON.stringify({ + body: `#${JSON.stringify(data)}`, + slots: [], + }); + +export const oracleBrandAux = { + allegedName: 'GimixOracle', + /** @type {DisplayInfo} */ + displayInfo: { assetKind: 'copyBag' }, +}; + +export const oracleBrandAuxValue = marshalPlainData(oracleBrandAux); + const trace = (...args) => console.log('start-gimix', ...args); const fail = msg => { @@ -21,7 +47,6 @@ const fail = msg => { * ref https://github.com/Agoric/agoric-sdk/issues/8408#issuecomment-1741445458 * * @param {ERef} namesByAddressAdmin - * @param namesByAddressAdminP */ const fixHub = async namesByAddressAdmin => { /** @type {import('@agoric/vats').NameHub} */ @@ -42,6 +67,17 @@ const fixHub = async namesByAddressAdmin => { return hub; }; +/** + * Make a storage node for auxilliary data for a value on the board. + * + * @param {ERef} chainStorage + * @param {string} boardId + */ +const makeBoardAuxNode = async (chainStorage, boardId) => { + const boardAux = E(chainStorage).makeChildNode(BOARD_AUX); + return E(boardAux).makeChildNode(boardId); +}; + /** * @param {BootstrapPowers} powers * @param {{ options?: { GiMiX: { @@ -55,6 +91,7 @@ export const startGiMiX = async (powers, config = {}) => { agoricNames, board, chainTimerService, + chainStorage, namesByAddressAdmin, zoe, }, @@ -102,6 +139,13 @@ export const startGiMiX = async (powers, config = {}) => { produceIssuer.resolve(issuers.GimixOracle); produceBrand.resolve(brands.GimixOracle); + /** @type {ERef} */ + // @ts-expect-error only null in testing + const storage = chainStorage; + const boardId = await E(board).getId(brands.GimixOracle); + const node = await makeBoardAuxNode(storage, boardId); + await E(node).setValue(oracleBrandAuxValue); + trace('gimix started!'); }; @@ -110,6 +154,7 @@ export const manifest = /** @type {const} */ ({ consume: { agoricNames: true, board: true, + chainStorage: true, chainTimerService: true, namesByAddress: true, namesByAddressAdmin: true, diff --git a/packages/zoe/test/unitTests/contracts/gimix/test-gimix.js b/packages/zoe/test/unitTests/contracts/gimix/test-gimix.js index 4e970f2ef6c..5d3eb172ae2 100644 --- a/packages/zoe/test/unitTests/contracts/gimix/test-gimix.js +++ b/packages/zoe/test/unitTests/contracts/gimix/test-gimix.js @@ -10,22 +10,27 @@ import { makePromiseKit } from '@endo/promise-kit'; import { unsafeMakeBundleCache } from '@agoric/swingset-vat/tools/bundleTool.js'; import { AmountMath } from '@agoric/ertp/src/amountMath.js'; -// import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js'; +import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js'; import { makeNameHubKit, makePromiseSpace } from '@agoric/vats'; import { makeWellKnownSpaces } from '@agoric/vats/src/core/utils.js'; import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js'; import { TimeMath } from '@agoric/time'; import { deeplyFulfilledObject } from '@agoric/internal'; -import buildManualTimer from '../../../../tools/manualTimer.js'; -import { makeZoeKitForTest } from '../../../../tools/setup-zoe.js'; -import { startGiMiX } from '../../../../src/contracts/gimix/start-gimix.js'; +import { makeMarshal } from '@endo/marshal'; import { mintStablePayment } from './mintStable.js'; +import { + oracleBrandAuxValue, + startGiMiX, +} from '../../../../src/contracts/gimix/start-gimix.js'; +import { makeZoeKitForTest } from '../../../../tools/setup-zoe.js'; +import buildManualTimer from '../../../../tools/manualTimer.js'; const DAY = 24 * 60 * 60 * 1000; const UNIT6 = 1_000_000n; const { entries } = Object; +const { Fail } = assert; /** @type {(x: T | null | undefined) => T} */ const NonNullish = x => { @@ -116,11 +121,13 @@ const makeTestContext = async t => { spaces.installation.produce.centralSupply.resolve(centralSupply); const board = makeFakeBoard(); + const { rootNode, data: _todo } = makeFakeStorageKit('published'); const { produce, consume } = makePromiseSpace(); produce.agoricNames.resolve(agoricNames); produce.board.resolve(board); produce.chainTimerService.resolve(chainTimerService); + produce.chainStorage.resolve(rootNode); produce.feeMintAccess.resolve(feeMintAccess); produce.namesByAddress.resolve(namesByAddress); produce.namesByAddressAdmin.resolve(namesByAddressAdmin); @@ -619,8 +626,6 @@ test('execute work agreement', async t => { t.deepEqual(amts, want); }; - // const { rootNode, data } = makeFakeStorageKit('X'); - const gitHub = Promise.resolve(makeGitHub(t.log)); const { faucet, @@ -669,4 +674,20 @@ test('execute work agreement', async t => { t.pass(); }); +test('GimixOracle brandAux marshal re-implementation', t => { + const smallcaps = /** @type {const} */ ({ + serializeBodyFormat: 'smallcaps', + }); + const marshalData = makeMarshal( + _val => Fail`data only`, + undefined, + smallcaps, + ); + const displayInfo = { assetKind: 'copyBag' }; + const allegedName = 'GimixOracle'; + const capData = marshalData.toCapData(harden({ displayInfo, allegedName })); + + t.is(JSON.stringify(capData), oracleBrandAuxValue); +}); + test.todo('make work agreement at wallet bridge / vstorage level');