-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add js integration test for solidity test runner #634
Conversation
|
8a35c3c
to
3944a9e
Compare
Thanks for the PR and the detailed write up! I've tried the tests and LGTM, except for changing the default build behavior in
I feel this is too risky. It's an easy mistake to use |
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.
One question, but otherwise LGTM!
I don't have the same concern about using a non-default, dedicated target/script for publishable builds. This is a common pattern in the industry: making the default development workflow the standard and using an alternative target for CI/CD scripts when publishing.
"lint:fix": "pnpm run prettier --write", | ||
"prebenchmark": "cd ../../../edr_napi/ && pnpm build", | ||
"presoltests": "cd ../../../edr_napi/ && pnpm build", | ||
"prebenchmark": "cd ../../../.. && pnpm build && cd crates/edr_napi && pnpm build:publish", |
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.
Why do we need to build twice?
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.
Because the build
script builds with a non-publish profile, but we want to benchmark with the super-optimized profile.
Counterpoint: in the |
To clarify, I'm not stating that no one uses the default build target for publishing. I'm just saying that it's not uncommon for projects to have a non-default publish/final build profile that does additional optimisations and/or build steps for publishing. As such, in my mind, the risk of misconfiguration of CD exists either way. Thus, I don't have the same sense of increased risk one way or another. |
@Wodann that's a valid point, but I went ahead and reverted the change anyway (c72eec9). The reason is that the negative impact of publishing a non-completely-optimized version would be very high, and so anything that reduces that risk seems worth it (I guess it's debatable whether this change actually reduces risk, but I think it does). The trade-off here is that, during local development, one might accidentally use a publish build, but that's easy to notice because it's so fucking slow. The proper solution, of course, would be to run the benchmarks before publishing. But that's way harder to do, and we can't do it for all builds. |
This PR is mainly about adding a minimal typescript integration test for the solidity test runner, but that triggered an avalanche of changes. I'll explain them (mostly) in causality order.
edr-helpers
The integration test has to use the
runSolidityTests
function, which has a low-level, callback-based interface. It's easy to create a wrapper around it, but we are already doing things like that in other parts of the codebase (the benchmarks, the v2 plugin). Similarly, building the input for that function from Hardhat's compilation output is done in a similar way in multiple places.To deduplicate that code, I created an internal
@nomicfoundation/edr-helpers
package (the name doesn't really matter because it won't be published) underjs/helpers
. This has two functions:runAllSolidityTests
, which returns a promise with all the test results (but also accepts a progress callback), andbuildSolidityTestsInput
, which builds the input and has an optional predicate callback to figure out which artifacts correspond to test contracts.These helpers are now used in the benchmark package, in the Hardhat v2 plugin, and in the integration test that this PR adds.
The tests in
edr_napi
still have a somewhat duplicated logic. The reason for this is that the helpers depend on that package, so using the helpers there would create a circular dependency. Circular dependencies are, I think, doable in this case, but I got a problem, didn't look into it, and just duplicated the function. I also think that it makes sense for these tests to use the function more directly. You could argue that the proper solution is for the helpers to live underedr_napi
, but this opens a different can of worms, and I don't love the idea of adding public API for internal reasons.Root
build
scriptEDIT: outdated section. Some of this description is still valid, but see the rest of the discussion below to see what changed.
Adding the helpers and using them in other packages means that the helpers need to be compiled before they are used. (I think it's technically possible to import typescript files directly, since they are not going to be used by javascript code anyway, but to be honest I don't know how to properly do that.)
I could've just expanded every relevant
prebuild
script (or whatever) tocd
into the helpers directory and build them, but that seemed too much work and brittle. Instead, I added abuild
script in the rootpackage.json
which runs thebuild
scripts in all the packages. This is done by pnpm in topological order, meaning that the dependencies are built before the dependents. I then modifiedpre-
scripts likepretest
andprebenchmark
to justcd
into the root and build everything. And I made sure that all the compilations are done incrementally, so that all this building is not unnecessarily slow. This is the same approach we had in Hardhat; I think it works well enough.One caveat here is that
hardhat-tests
needsedr_napi
to be built because of thepnpm override
, but it's not an explicit dependency so there are no guarantees that it will be built before it. To make sure that was the case, I added it as an explicit dependency, even if it's not really used by the tests code.Another impact of this change is that I changed the
build
scripts inedr_napi
. Thebuild
script was the slow one used before publishing, and that didn't play well with this approach. So I added abuild:publish
script, used it in the release workflows, and changedbuild
to be the normal one used for development. This is the riskiest change in the PR, please pay special attention to it.Other changes
Some other related changes:
build
script. This is perhaps redundant, but it doesn't hurt.--silent
flag. That was a problem when trying to figure out why something wasn't working. I removed the ones that were not necessary, and replaced-s
with the longer--silent
because I had no idea what-s
meant.Javascript packages are all over the place
We now have these javascript packages:
hardhat-tests
hardhat-solidity-tests
crates/tools/js/benchmark
js/helpers
andjs/integration-tests/*
This is not great. I think we should move all of them under the root's
js
directory that this PR adds. But we should wait until we don't have any major divergent feature branches, otherwise moving that much code around can cause some annoying merge conflicts.