-
Notifications
You must be signed in to change notification settings - Fork 206
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
a3p-integration/proposals/a:upgrade-next/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-next/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-next/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; |
52 changes: 52 additions & 0 deletions
52
a3p-integration/proposals/a:upgrade-next/core-eval.test.js
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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