Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(a3p-integration): add core eval in test #8929

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-next/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);
};
Comment on lines +13 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be handy for Agoric/agoric-3-proposals#82


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-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 12 additions & 0 deletions a3p-integration/proposals/a:upgrade-next/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-next/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
Loading