diff --git a/a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/README.md b/a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/README.md new file mode 100644 index 00000000000..dd60f098b11 --- /dev/null +++ b/a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/README.md @@ -0,0 +1,6 @@ +These files enable a test of core-eval in an upgraded chain. + +send-script is a test submission, which is transmitted in ../core-eval.test.js. +Some template values in the `.tjs` file are replaced before submitting the +core-eval. The test then verifies that the core-eval written the expected +values to vstorage. diff --git a/a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/send-script-permit.json b/a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/send-script-permit.json new file mode 100644 index 00000000000..27ba77ddaf6 --- /dev/null +++ b/a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/send-script-permit.json @@ -0,0 +1 @@ +true diff --git a/a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/send-script.tjs b/a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/send-script.tjs new file mode 100644 index 00000000000..5ae5192335c --- /dev/null +++ b/a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/send-script.tjs @@ -0,0 +1,30 @@ +#! false node --ignore-this-line +/* global E */ + +/// +/// + +/** + * Write a value to chain storage + * + * see ../core-eval.test.js + * + * @param {BootstrapPowers} powers + */ +const writeIt = async powers => { + const nodePath = '{{NODE_PATH}}'; + const nodeValue = '{{NODE_VALUE}}'; + const { + consume: { chainStorage }, + } = powers; + + let node = chainStorage; + + for (const nodeName of nodePath.split('.')) { + node = E(node).makeChildNode(nodeName); + } + + await E(node).setValue(nodeValue); +}; + +writeIt; diff --git a/a3p-integration/proposals/a:upgrade-next/core-eval.test.js b/a3p-integration/proposals/a:upgrade-next/core-eval.test.js new file mode 100644 index 00000000000..ab94ec5ac3f --- /dev/null +++ b/a3p-integration/proposals/a:upgrade-next/core-eval.test.js @@ -0,0 +1,52 @@ +/* eslint-disable @jessie.js/safe-await-separator */ +import test from 'ava'; +import { readFile, writeFile } from 'node:fs/promises'; + +import { agd, evalBundles, waitForBlock } from '@agoric/synthetic-chain'; + +const SUBMISSION_DIR = 'core-eval-test-submission'; + +/** + * @param {string} fileName base file name without .tjs extension + * @param {Record} replacements + */ +const replaceTemplateValuesInFile = async (fileName, replacements) => { + let script = await readFile(`${fileName}.tjs`, 'utf-8'); + for (const [template, value] of Object.entries(replacements)) { + script = script.replaceAll(`{{${template}}}`, value); + } + await writeFile(`${fileName}.js`, script); +}; + +const readPublished = async path => { + const { value } = await agd.query( + 'vstorage', + 'data', + '--output', + 'json', + `published.${path}`, + ); + if (value === '') { + return undefined; + } + const obj = JSON.parse(value); + return obj.values[0]; +}; + +test(`core eval works`, async t => { + const nodePath = 'foo.bar'; + const nodeValue = 'baz'; + + t.falsy(await readPublished(nodePath)); + + await replaceTemplateValuesInFile(`${SUBMISSION_DIR}/send-script`, { + NODE_PATH: nodePath, + NODE_VALUE: nodeValue, + }); + + await evalBundles(SUBMISSION_DIR); + + await waitForBlock(2); // enough time for core eval to execute ? + + t.is(await readPublished(nodePath), nodeValue); +}); diff --git a/a3p-integration/proposals/a:upgrade-next/package.json b/a3p-integration/proposals/a:upgrade-next/package.json index 88cdbd9a141..b25466ff0db 100644 --- a/a3p-integration/proposals/a:upgrade-next/package.json +++ b/a3p-integration/proposals/a:upgrade-next/package.json @@ -13,7 +13,7 @@ "type": "module", "license": "Apache-2.0", "dependencies": { - "@agoric/synthetic-chain": "^0.0.6-4", + "@agoric/synthetic-chain": "^0.0.7-1", "ava": "^5.3.1" }, "scripts": { diff --git a/a3p-integration/proposals/a:upgrade-next/tsconfig.json b/a3p-integration/proposals/a:upgrade-next/tsconfig.json new file mode 100644 index 00000000000..98fa6f26c3b --- /dev/null +++ b/a3p-integration/proposals/a:upgrade-next/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "moduleResolution": "node", + "allowJs": true, + "checkJs": true, + "strict": false, + "strictNullChecks": true, + "noImplicitThis": true + } +} diff --git a/a3p-integration/proposals/a:upgrade-next/yarn.lock b/a3p-integration/proposals/a:upgrade-next/yarn.lock index fa80388d723..d20dc303d87 100644 --- a/a3p-integration/proposals/a:upgrade-next/yarn.lock +++ b/a3p-integration/proposals/a:upgrade-next/yarn.lock @@ -5,9 +5,9 @@ __metadata: version: 8 cacheKey: 10c0 -"@agoric/synthetic-chain@npm:^0.0.6-4": - version: 0.0.6-4 - resolution: "@agoric/synthetic-chain@npm:0.0.6-4" +"@agoric/synthetic-chain@npm:^0.0.7-1": + version: 0.0.7-1 + resolution: "@agoric/synthetic-chain@npm:0.0.7-1" dependencies: "@endo/zip": "npm:^1.0.1" better-sqlite3: "npm:^9.4.0" @@ -15,7 +15,7 @@ __metadata: execa: "npm:^8.0.1" bin: synthetic-chain: dist/cli/cli.js - checksum: 10c0/0c8512eaedf05aa51a10e28c4db0970af1622cf70c0e51fa08768170f73326621125960fb5d8f300613203cdf1cf5ebb2950e6e691bb7204675c9062ff78293f + checksum: 10c0/dc30624063c619a5a7deb2e5a0a2ded19a03aad99465b3f5ffa8cf8a719ac99da3b4e3c4a42d65c69904a84a4aa9cebde3f33abcee7f5ddb88e469a1c55a997c languageName: node linkType: hard @@ -1820,7 +1820,7 @@ __metadata: version: 0.0.0-use.local resolution: "root-workspace-0b6124@workspace:." dependencies: - "@agoric/synthetic-chain": "npm:^0.0.6-4" + "@agoric/synthetic-chain": "npm:^0.0.7-1" ava: "npm:^5.3.1" languageName: unknown linkType: soft