Skip to content

Commit

Permalink
feat(a3p-integration): add core eval in test (#8929)
Browse files Browse the repository at this point in the history
* feat(a3p-integration): add core eval in test

* fixup! feat(a3p-integration): add core eval in test

* Nudge

* test: reduce race sensitivity

---------

Co-authored-by: Turadg Aleahmad <turadg@agoric.com>
  • Loading branch information
mhofman and turadg committed Feb 18, 2024
1 parent 4a1ce12 commit 87e7a7a
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#! false node --ignore-this-line
/* global E */

/// <reference types="@agoric/vats/src/core/core-eval-env"/>
/// <reference types="@agoric/vats/src/core/types-ambient"/>

/**
* 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;
52 changes: 52 additions & 0 deletions a3p-integration/proposals/a:upgrade-14/core-eval.test.js
Original file line number Diff line number Diff line change
@@ -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<string, string>} 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);
});
2 changes: 1 addition & 1 deletion a3p-integration/proposals/a:upgrade-14/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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": {
Expand Down
12 changes: 12 additions & 0 deletions a3p-integration/proposals/a:upgrade-14/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"strict": false,
"strictNullChecks": true,
"noImplicitThis": true
}
}
10 changes: 5 additions & 5 deletions a3p-integration/proposals/a:upgrade-14/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ __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"
chalk: "npm:^5.3.0"
execa: "npm:^8.0.1"
bin:
synthetic-chain: dist/cli/cli.js
checksum: 10c0/0c8512eaedf05aa51a10e28c4db0970af1622cf70c0e51fa08768170f73326621125960fb5d8f300613203cdf1cf5ebb2950e6e691bb7204675c9062ff78293f
checksum: 10c0/dc30624063c619a5a7deb2e5a0a2ded19a03aad99465b3f5ffa8cf8a719ac99da3b4e3c4a42d65c69904a84a4aa9cebde3f33abcee7f5ddb88e469a1c55a997c
languageName: node
linkType: hard

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 87e7a7a

Please sign in to comment.