Skip to content

Commit

Permalink
feat: upgrade v7-board and test it
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Nov 18, 2024
1 parent c27cc4f commit d4640fa
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 1 deletion.
3 changes: 2 additions & 1 deletion a3p-integration/proposals/p:upgrade-19/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"agoricProposal": {
"type": "/agoric.swingset.CoreEvalProposal",
"sdk-generate": [
"testing/replace-feeDistributor-short.js replaceFeeDistributor"
"testing/replace-feeDistributor-short.js replaceFeeDistributor",
"testing/test-upgraded-board.js"
]
},
"type": "module",
Expand Down
1 change: 1 addition & 0 deletions a3p-integration/proposals/p:upgrade-19/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash

yarn ava replaceFeeDistributor.test.js
yarn ava upgradedBoard.test.js
14 changes: 14 additions & 0 deletions a3p-integration/proposals/p:upgrade-19/upgradedBoard.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-env node */
// @ts-check

/** @file test that the upgraded board can store and retrieve values. */

import '@endo/init/legacy.js';
import test from 'ava';
import { evalBundles } from '@agoric/synthetic-chain';

test('test upgraded board', async t => {
await evalBundles('submission');

t.pass();
});
3 changes: 3 additions & 0 deletions golang/cosmos/app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ func unreleasedUpgradeHandler(app *GaiaApp, targetUpgrade string) func(sdk.Conte
vm.CoreProposalStepForModules(
"@agoric/builders/scripts/inter-protocol/replace-feeDistributor.js",
),
vm.CoreProposalStepForModules(
"@agoric/builders/scripts/vats/upgrade-board.js",
),
)
}

Expand Down
15 changes: 15 additions & 0 deletions packages/builders/scripts/testing/test-upgraded-board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { makeHelpers } from '@agoric/deploy-script-support';
import { getManifestForTestUpgradedBoard } from '@agoric/vats/src/proposals/testUpgradedBoard.js';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder} */
export const defaultProposalBuilder = async () =>
harden({
sourceSpec: '@agoric/vats/src/proposals/testUpgradedBoard.js',
getManifestCall: [getManifestForTestUpgradedBoard.name],
});

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreEval } = await makeHelpers(homeP, endowments);
await writeCoreEval('testUpgradedBoard', defaultProposalBuilder);
};
20 changes: 20 additions & 0 deletions packages/builders/scripts/vats/upgrade-board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { makeHelpers } from '@agoric/deploy-script-support';
import { getManifestForUpgradingBoard } from '@agoric/vats/src/proposals/upgrade-board-proposal.js';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder} */
export const defaultProposalBuilder = async ({ publishRef, install }) =>
harden({
sourceSpec: '@agoric/vats/src/proposals/upgrade-board-proposal.js',
getManifestCall: [
getManifestForUpgradingBoard.name,
{
boardRef: publishRef(install('@agoric/vats/src/vat-board.js')),
},
],
});

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreEval } = await makeHelpers(homeP, endowments);
await writeCoreEval('upgrade-board', defaultProposalBuilder);
};
35 changes: 35 additions & 0 deletions packages/vats/src/proposals/testUpgradedBoard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { E, Far } from '@endo/far';
import { Stable } from '@agoric/internal/src/tokens.js';

export const testUpgradedBoard = async ({
consume: { board },
brand: {
consume: { [Stable.symbol]: stableBrandP },
},
}) => {
// /////// can we store something and get it back? ////////
const thing1 = Far('thing1', {});
const thing1Id = await E(board).getId(thing1);
assert(thing1Id.match(/^board0[0-9]+$/));

// /////// can we retrieve something stored long ago? ////////
const marshaller = await E(board).getReadonlyMarshaller();
assert(marshaller, 'expected a marshaller');

const stableBrand = await stableBrandP;
// /////// can we retrieve a well-known object via its ID? ////////
const stableID = await E(board).getId(stableBrand);
const stableBrandRetrieved = await E(board).getValue(stableID);
assert(stableBrandRetrieved === stableBrand, 'retrieved matching brand');
};

export const getManifestForTestUpgradedBoard = () => ({
manifest: {
[testUpgradedBoard.name]: {
consume: { board: true },
brand: {
consume: { [Stable.symbol]: true },
},
},
},
});
41 changes: 41 additions & 0 deletions packages/vats/src/proposals/upgrade-board-proposal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { E } from '@endo/far';

/**
* @param {BootstrapPowers & {
* consume: {
* vatAdminSvc: VatAdminSvc;
* vatStore: MapStore<
* string,
* import('@agoric/swingset-vat').CreateVatResults
* >;
* };
* }} powers
* @param {object} options
* @param {{ boardRef: VatSourceRef }} options.options
*/
export const upgradeBoard = async (
{ consume: { vatAdminSvc, vatStore } },
options,
) => {
const { boardRef } = options.options;

assert(boardRef.bundleID);
const boardBundleCap = await E(vatAdminSvc).getBundleCap(boardRef.bundleID);
console.log(`Board BUNDLE ID: `, boardRef.bundleID);

const { adminNode } = await E(vatStore).get('board');

await E(adminNode).upgrade(boardBundleCap, {});
};

export const getManifestForUpgradingBoard = (_powers, { boardRef }) => ({
manifest: {
[upgradeBoard.name]: {
consume: {
vatAdminSvc: 'vatAdminSvc',
vatStore: 'vatStore',
},
},
},
options: { boardRef },
});

0 comments on commit d4640fa

Please sign in to comment.