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: define solidity test sources in config #5870

Open
wants to merge 7 commits into
base: v-next
Choose a base branch
from

Conversation

galargh
Copy link
Member

@galargh galargh commented Oct 28, 2024

  • Because this PR includes a bug fix, relevant tests have been included.
  • Because this PR includes a new feature, the change was previously discussed on an Issue or with someone from the team.
  • I didn't do anything of this.

This PR:

  • adds a solidity key to the paths.tests user config (defaults to paths.sources.solidity value)
  • removes the dependency on the compile task from the test:solidity task
  • adds compilation of paths.tests.solidity to the test:solidity task

To compile a subset of sources for solidity tests, I use the build function from the build system programmatically (and prepare required inputs in the solidity test task action).

To make the artifact discovery work properly, I had to add contractArtifactsGenerated property to the CacheHitFileBuildResult. This is because given a compilation job, we need to be able to tell what artifacts were generated, even if that job was cached.

One alternative/extension considered was to define the solidity test paths per build profile. This would have allowed greater level of configuration. We decided not to proceed with that, at least for now.

Copy link

vercel bot commented Oct 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 11:20pm

Copy link

changeset-bot bot commented Oct 28, 2024

⚠️ No Changeset found

Latest commit: 18dca31

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the status:ready This issue is ready to be worked on label Oct 28, 2024
@alcuadrado alcuadrado added the v-next A Hardhat v3 development task label Oct 28, 2024
@galargh galargh changed the title [WIP] feat: define solidity test sources in config feat: define solidity test sources in config Dec 4, 2024
@galargh galargh requested a review from alcuadrado December 4, 2024 11:24
@galargh galargh marked this pull request as ready for review December 4, 2024 11:24
@@ -161,6 +161,11 @@ const config: HardhatUserConfig = {
tests: {
mocha: "test/mocha",
nodeTest: "test/node",
solidity: [
"contracts/Counter.sol",
Copy link
Member

Choose a reason for hiding this comment

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

The semantics of this are slightly different than what the other tests entries use. Here this is "files to be compiled", while the others are "folders where tests can be found".

If we use the rules to find solidity tests files discussed in my other comment, the "folders" approach makes more sense.

}
}),
hre.config.paths.tests.solidity
.map((p) => resolveFromRoot(hre.config.paths.root, p))
Copy link
Member

Choose a reason for hiding this comment

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

This would change based on the other comments

// NOTE: The uncached sources will still be compiled event if `noCompile`
// is true. We could consider adding a `cacheOnly` option to support true
// `noCompile` behavior.
force: !noCompile,
Copy link
Member

Choose a reason for hiding this comment

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

If I run npx hardhat test solidity it will force and recompile everything

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add an issue and address it after we have the compilation cache in place, and when we have the split between production and test compilation caches or while implementing that.

Copy link
Member

Choose a reason for hiding this comment

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

We should also consider removing this option

* It throws a HardhatError if the build results indicate that the compilation
* job failed.
*/
export function throwIfSolidityBuildFailed(
Copy link
Member

Choose a reason for hiding this comment

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

For a future PR: we should use the same implementation here and during compile.

Copy link
Member

Choose a reason for hiding this comment

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

mostly to have a consistent ui

@@ -257,8 +257,9 @@ describe("HookManager", () => {
_context: HookContext,
givenHre: HardhatRuntimeEnvironment,
): Promise<void> => {
givenHre.config.paths.tests =
"./test-folder-from-plugin1";
givenHre.config.paths.tests = {
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit confusing, maybe not needed.

@alcuadrado
Copy link
Member

We chatted about this on a call: we'd treat solidity files as solidity test file if they either end in .t.sol, or they are inside config.paths.tests.

(defaults to paths.sources.solidity value)

Let's default to test/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

2 participants