From e2cdb04beab9847e561eb5b8dcd541f6036e10c0 Mon Sep 17 00:00:00 2001 From: Mathieu Hofman Date: Thu, 15 Feb 2024 00:20:03 +0000 Subject: [PATCH 1/4] feat(a3p-integration): add core eval in test --- .../core-eval-test-submission/README.md | 6 +++ .../send-script-permit.json | 1 + .../core-eval-test-submission/send-script.tjs | 27 +++++++++++++ .../a:upgrade-next/core-eval.test.js | 40 +++++++++++++++++++ .../proposals/a:upgrade-next/jsconfig.json | 14 +++++++ .../proposals/a:upgrade-next/package.json | 2 +- .../proposals/a:upgrade-next/yarn.lock | 10 ++--- 7 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/README.md create mode 100644 a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/send-script-permit.json create mode 100644 a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/send-script.tjs create mode 100644 a3p-integration/proposals/a:upgrade-next/core-eval.test.js create mode 100644 a3p-integration/proposals/a:upgrade-next/jsconfig.json 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..aeb250b50e4 --- /dev/null +++ b/a3p-integration/proposals/a:upgrade-next/core-eval-test-submission/send-script.tjs @@ -0,0 +1,27 @@ +// @ts-nocheck +/* 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..4d39ade7af0 --- /dev/null +++ b/a3p-integration/proposals/a:upgrade-next/core-eval.test.js @@ -0,0 +1,40 @@ +import test from 'ava'; +import { readFile, writeFile } from 'node:fs/promises'; + +import { agoric, 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); +}; + +test(`core eval works`, async t => { + const nodePath = 'foo.bar'; + const nodeValue = 'baz'; + + 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 ? + const chainStorageValue = await agoric.follow( + '-lF', + `:${nodePath}`, + '-o', + 'text', + ); + + t.is(chainStorageValue, nodeValue); +}); diff --git a/a3p-integration/proposals/a:upgrade-next/jsconfig.json b/a3p-integration/proposals/a:upgrade-next/jsconfig.json new file mode 100644 index 00000000000..3d11fd9cc82 --- /dev/null +++ b/a3p-integration/proposals/a:upgrade-next/jsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "moduleResolution": "node", + "allowJs": true, + "checkJs": true, + "strict": false, + "downlevelIteration": true, + "strictNullChecks": true, + "noImplicitThis": true, + "noEmit": true + } +} 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/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 From 4481434e08807e4893424bd33ccd945bbf6acb6e Mon Sep 17 00:00:00 2001 From: Mathieu Hofman Date: Thu, 15 Feb 2024 23:21:18 +0000 Subject: [PATCH 2/4] fixup! feat(a3p-integration): add core eval in test --- .../a:upgrade-next/core-eval-test-submission/send-script.tjs | 5 ++++- a3p-integration/proposals/a:upgrade-next/jsconfig.json | 5 +---- 2 files changed, 5 insertions(+), 5 deletions(-) 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 index aeb250b50e4..5ae5192335c 100644 --- 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 @@ -1,6 +1,9 @@ -// @ts-nocheck +#! false node --ignore-this-line /* global E */ +/// +/// + /** * Write a value to chain storage * diff --git a/a3p-integration/proposals/a:upgrade-next/jsconfig.json b/a3p-integration/proposals/a:upgrade-next/jsconfig.json index 3d11fd9cc82..9306844e383 100644 --- a/a3p-integration/proposals/a:upgrade-next/jsconfig.json +++ b/a3p-integration/proposals/a:upgrade-next/jsconfig.json @@ -3,12 +3,9 @@ "target": "esnext", "module": "esnext", "moduleResolution": "node", - "allowJs": true, "checkJs": true, "strict": false, - "downlevelIteration": true, "strictNullChecks": true, - "noImplicitThis": true, - "noEmit": true + "noImplicitThis": true } } From 4dea35de276d53e3c5d0d3ef143d313ecc5c1d7f Mon Sep 17 00:00:00 2001 From: Mathieu Hofman Date: Fri, 16 Feb 2024 01:26:29 +0000 Subject: [PATCH 3/4] Nudge --- .../proposals/a:upgrade-next/{jsconfig.json => tsconfig.json} | 1 + 1 file changed, 1 insertion(+) rename a3p-integration/proposals/a:upgrade-next/{jsconfig.json => tsconfig.json} (90%) diff --git a/a3p-integration/proposals/a:upgrade-next/jsconfig.json b/a3p-integration/proposals/a:upgrade-next/tsconfig.json similarity index 90% rename from a3p-integration/proposals/a:upgrade-next/jsconfig.json rename to a3p-integration/proposals/a:upgrade-next/tsconfig.json index 9306844e383..98fa6f26c3b 100644 --- a/a3p-integration/proposals/a:upgrade-next/jsconfig.json +++ b/a3p-integration/proposals/a:upgrade-next/tsconfig.json @@ -3,6 +3,7 @@ "target": "esnext", "module": "esnext", "moduleResolution": "node", + "allowJs": true, "checkJs": true, "strict": false, "strictNullChecks": true, From 0cd9160db314ee2334d6c213bc2d1e6319dfdd60 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 15 Feb 2024 16:46:38 -0800 Subject: [PATCH 4/4] test: reduce race sensitivity --- .../a:upgrade-next/core-eval.test.js | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/a3p-integration/proposals/a:upgrade-next/core-eval.test.js b/a3p-integration/proposals/a:upgrade-next/core-eval.test.js index 4d39ade7af0..ab94ec5ac3f 100644 --- a/a3p-integration/proposals/a:upgrade-next/core-eval.test.js +++ b/a3p-integration/proposals/a:upgrade-next/core-eval.test.js @@ -1,7 +1,8 @@ +/* eslint-disable @jessie.js/safe-await-separator */ import test from 'ava'; import { readFile, writeFile } from 'node:fs/promises'; -import { agoric, evalBundles, waitForBlock } from '@agoric/synthetic-chain'; +import { agd, evalBundles, waitForBlock } from '@agoric/synthetic-chain'; const SUBMISSION_DIR = 'core-eval-test-submission'; @@ -17,10 +18,27 @@ const replaceTemplateValuesInFile = async (fileName, replacements) => { 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, @@ -29,12 +47,6 @@ test(`core eval works`, async t => { await evalBundles(SUBMISSION_DIR); await waitForBlock(2); // enough time for core eval to execute ? - const chainStorageValue = await agoric.follow( - '-lF', - `:${nodePath}`, - '-o', - 'text', - ); - t.is(chainStorageValue, nodeValue); + t.is(await readPublished(nodePath), nodeValue); });