Skip to content

Commit

Permalink
feat(gimix): publish displayInfo for oracle brand
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Nov 17, 2023
1 parent b9e5743 commit 5e1e353
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 7 deletions.
47 changes: 46 additions & 1 deletion packages/zoe/src/contracts/gimix/start-gimix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -21,7 +47,6 @@ const fail = msg => {
* ref https://github.com/Agoric/agoric-sdk/issues/8408#issuecomment-1741445458
*
* @param {ERef<import('@agoric/vats').NameAdmin>} namesByAddressAdmin
* @param namesByAddressAdminP
*/
const fixHub = async namesByAddressAdmin => {
/** @type {import('@agoric/vats').NameHub} */
Expand All @@ -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<StorageNode>} 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: {
Expand All @@ -55,6 +91,7 @@ export const startGiMiX = async (powers, config = {}) => {
agoricNames,
board,
chainTimerService,
chainStorage,
namesByAddressAdmin,
zoe,
},
Expand Down Expand Up @@ -102,6 +139,13 @@ export const startGiMiX = async (powers, config = {}) => {
produceIssuer.resolve(issuers.GimixOracle);
produceBrand.resolve(brands.GimixOracle);

/** @type {ERef<StorageNode>} */
// @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!');
};

Expand All @@ -110,6 +154,7 @@ export const manifest = /** @type {const} */ ({
consume: {
agoricNames: true,
board: true,
chainStorage: true,
chainTimerService: true,
namesByAddress: true,
namesByAddressAdmin: true,
Expand Down
33 changes: 27 additions & 6 deletions packages/zoe/test/unitTests/contracts/gimix/test-gimix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {<T>(x: T | null | undefined) => T} */
const NonNullish = x => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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');

0 comments on commit 5e1e353

Please sign in to comment.