-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(a3p-integration): add core eval in test (#8929)
* 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
Showing
7 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
a3p-integration/proposals/a:upgrade-14/core-eval-test-submission/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
1 change: 1 addition & 0 deletions
1
a3p-integration/proposals/a:upgrade-14/core-eval-test-submission/send-script-permit.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
true |
30 changes: 30 additions & 0 deletions
30
a3p-integration/proposals/a:upgrade-14/core-eval-test-submission/send-script.tjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters