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

Porting upgrade tests to Javascript #8145

Merged
merged 1 commit into from
Aug 17, 2023
Merged

Porting upgrade tests to Javascript #8145

merged 1 commit into from
Aug 17, 2023

Conversation

iomekam
Copy link
Contributor

@iomekam iomekam commented Aug 4, 2023

refs: #8137

Description

Refactoring our bash scripts to look and feel more like Javascript. To accomplish portions of the scripts shelling out, we've leveraged. We intend to port all the upgrade tests, but started this endeavor with agoric-upgrade-10

To discuss a few of the changes:

  • pre_test.sh, actions.sh, and test.sh have been moved. respectfully, to pre.test.js, actions.test.js, and post.test.js.
  • We are now using AVA as the test runner. To run the upgrade tests, you can run yarn upgrade-test within the upgrade-test-scripts folder
  • We've added a few helper files to make writing tests a little less cumbersome. These helpers have replaced the functionality of env_setup.sh

@iomekam iomekam changed the title Bash -> Execa Moving our upgrade tests to Javascript Aug 15, 2023
@iomekam iomekam changed the title Moving our upgrade tests to Javascript Porting upgrade tests to Javascript Aug 15, 2023
@iomekam iomekam marked this pull request as ready for review August 16, 2023 19:34
if (run === 1) {
try {
const params = ['ec', 'committee', '--send-from', account];
await executeCommand(agopsLocation, params, {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be doing almost the same thing as line 47. Why is the syntax so different?

Was there a missed opportunity to turn line 39 into the agops.ec() form, or is this intended to demonstrate the two styles of call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good callout. At one point, there was a reason why I had to do it this way (to pass in custom options to execa), but I moved away from that approach, so I can converge this to look like the call below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, on second thought, the reason I did this was to pass in the timeout option to execa

}
} else {
try {
await agops.ec('committee', '--send-from', account, '--voter', voter);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like if we're going to add helpers for agops subcommands, we could turn them into actual javascript calls rather than requiring the user to mimic the CLI version. It seems like the flags could be omitted, so the call here could be agops.ec(account, voter);. [I don't know whether 'committee' is a flag or not. If the user has to specify the committee name, for instance, then that could be an extra parameter, and the javascript function's signature would help the caller know what arguments to provide.

Comment on lines 94 to 105
return agops.auctioneer(
'proposeParamChange',
'--charterAcceptOfferId',
charterAcceptOfferId,
'--start-frequency',
startFequency,
'--clock-step',
clockStep,
'--price-lock-period',
priceLockPeriod,
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem like an improvement over the shell syntax. Can we convert to JS style call? Would more work in the agops commands make this easier to support?

FASTER_AUCTIONS_OFFER=$(mktemp -t agops.XXX)
agops auctioneer proposeParamChange --charterAcceptOfferId "$(agops ec find-continuing-id --for "charter member invitation" --from "$GOV1ADDR")" --start-frequency $START_FREQUENCY --clock-step $CLOCK_STEP --price-lock-period $PRICE_LOCK_PERIOD >|"$FASTER_AUCTIONS_OFFER"
agoric wallet print --file "$FASTER_AUCTIONS_OFFER"
agops perf satisfaction --from "$GOV1ADDR" --executeOffer "$FASTER_AUCTIONS_OFFER" --keyring-backend=test

@dckc
Copy link
Member

dckc commented Aug 16, 2023

before I get into detailed feedback...

Getting all this working in ci is great work!

Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

Love it!

I left some comments and requests. Happy to hop on a call to go over them.

packages/deployment/upgrade-test/Dockerfile Show resolved Hide resolved
@@ -0,0 +1,348 @@
/* eslint-disable @jessie.js/safe-await-separator */
Copy link
Member

Choose a reason for hiding this comment

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

remark: we should eventually update our configs so this suppression isn't necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the blurb explaining why it was setup in the first case. Is this no longer relevant?

Copy link
Member

Choose a reason for hiding this comment

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

It's necessary for contract code. It's not a risk for deployment upgrade test code.

let voter = 0;
for (const account of govAccounts) {
const runs = [1, 2];
for (const run of runs) {
Copy link
Member

Choose a reason for hiding this comment

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

a little funny to have a loop where most of the lines are conditional on the index.

import: refactor to a sequence of calls.
suggestion: helper function for doing whatever is in common

Comment on lines 71 to 73
const offerFunction = async () => {
return agops.oracle('accept', '--offerId', oracle.id);
};
Copy link
Member

Choose a reason for hiding this comment

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

the function is returning a promise but it's not async.

Suggested change
const offerFunction = async () => {
return agops.oracle('accept', '--offerId', oracle.id);
};
const offerFunction = () => agops.oracle('accept', '--offerId', oracle.id);

await submitDeliverInbound('user1');

const oracles = [];
const oraclesAddresses = [GOV1ADDR, GOV2ADDR];
Copy link
Member

Choose a reason for hiding this comment

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

important: hoist

);

const govParams = await agoric.follow('-lF', ':published.auction.governance');
t.is(govParams.current.ClockStep.value.relValue, CLOCK_STEP.toString());
Copy link
Member

Choose a reason for hiding this comment

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

that relvalue is a string makes me think the unmarshaler needs work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should file an issue to get this into the backlog?

Copy link
Member

Choose a reason for hiding this comment

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

pretty sure it's a byproduct of the open coded unmarshaller

import { GOV1ADDR, GOV2ADDR, GOV3ADDR, USER1ADDR } from '../constants.mjs';
import { calculateWalletState } from './upgradeHelpers.mjs';

test.serial(
Copy link
Member

Choose a reason for hiding this comment

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

in post.test.js the tests needn't be serial because they're not supposed to affect the chain

important: remove serial in test that don't depend on it

cwd: '/usr/src/agoric-sdk',
})`yarn bin agops`;

export const agops = {
Copy link
Member

Choose a reason for hiding this comment

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

remark: I worry we're creating more work for ourselves by going from JS to shell and shell back to JS. This test is of upgrade . We don't need to integrate with Commander.js. We might better off importing the modules from agoric-cli directly. We'd get type checking that way!

Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

just flushing a pending comment that I didn't mean to make pending
I don't understand what github is doing here

@@ -0,0 +1,20 @@
{
"type": "module",
Copy link
Member

Choose a reason for hiding this comment

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

Since we've got type module here, we use .js instead of .mjs?

const deadline = toSec(Date.now()) + voteDurSec;

const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]);
const fromSmallCapsEntries = txt => {
Copy link
Member

Choose a reason for hiding this comment

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

all the smallcaps manipulations in the JS thingy I wrote are to avoid using anything outside the node standard library. Since we've now crossed over into using package.json and such, this should switch to using @endo/marshal in the normal way.

await waitForBlock();
};

export const ensureNewAuctionParams = async (
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this more like implementNewAuctionParams? The test that calls does the ensure part, I think.

(all the other verbs I can think of are too overloaded: you "pass" a resolution. Maybe 'enact'?)

address,
);

return paramChangeOfferGeneration(charterAcceptOfferId, 30, 123000000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the new value should be a parameter. That way the test 'Ensure debt ceiling raised' could verify that the passed value matches the proposal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This may be refactored entirely, as stated here

@iomekam iomekam requested a review from turadg August 17, 2023 19:30
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

There's more work to do before closing out #8137 but this is definite progress that I think is worth landing.

We have an urgent need to write new tests and this will allow us to write them in JS. We can always improve the code quality and DX incrementally.

);

const govParams = await agoric.follow('-lF', ':published.auction.governance');
t.is(govParams.current.ClockStep.value.relValue, CLOCK_STEP.toString());
Copy link
Member

Choose a reason for hiding this comment

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

pretty sure it's a byproduct of the open coded unmarshaller

@iomekam iomekam added this pull request to the merge queue Aug 17, 2023
Merged via the queue into master with commit a3d49e5 Aug 17, 2023
@iomekam iomekam deleted the execa-proto branch August 17, 2023 22:28
mhofman pushed a commit that referenced this pull request Nov 8, 2023
Porting upgrade tests to Javascript
mhofman pushed a commit that referenced this pull request Nov 10, 2023
Porting upgrade tests to Javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants