Repository: NomicFoundation/hardhat
Pull request #6529: fix: pass all artifacts to edr when executing solidity tests
Author: login: galargh
Created: 2025-04-01T14:18:40Z | Merged: 2025-04-08T11:23:07Z

<!--
Thank you for using Hardhat and taking the time to send a Pull Request!

If you are introducing a new feature, please discuss it in an Issue or with someone from the team before submitting your change.

Please:
 - consider the checklist items below
 - keep the ones that make sense for your PR, and
 - DELETE the items that DON'T make sense for your PR.

## Note about small PRs and airdrop farming

We generally really appreciate external contributions, and strongly encourage meaningful additions and fixes! However, due to a recent increase in small PRs potentially created to farm airdrops, we might need to close a PR without explanation if any of the following apply:

- It is a change of very minor value that still requires additional review time/fixes (e.g. PRs fixing trivial spelling errors that can’t be merged in less than a couple of minutes due to incorrect suggestions)
- It introduces inconsequential changes (e.g. rewording phrases)
- The author of the PR does not respond in a timely manner
- We suspect the Github account of the author was created for airdrop farming
-->

- [ ] 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.
- [x] I didn't do anything of this.

---

Resolves #6522

In this PR, I ensure the `compile` task is executed before the test sources compilation in the `test solidity` task. I also ensure that all the artifacts present in the artifacts folder after these two compilations are passed over to EDR for the solidity tests execution.

Context: https://nomicfoundation.slack.com/archives/C03P6B72ZHU/p1743408250467489

Linked issue #6522: Solidity tests task is not passing non-test artifacts to EDR
### Feedback

The `getCode/getDeployedCode` cheatcodes require all the project's artifacts to be available. But Hardhat is only passing test artifacts to EDR, meaning that the code of non-test contracts (which are the ones you are most likely to want) cannot be accessed.

Reproduction:

```solidity
// contracts/Foo.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

contract Foo {}
```

```solidity
// contracts/Foo.t.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

import { Test } from "forge-std/Test.sol";
import { Foo } from "./Foo.sol";

contract FooTest is Test {
    function test() public {
        bytes memory barBytecode = vm.getCode("contracts/Foo.sol:Foo");
    }
}
```

This test will fail with "No matching artifact found". If you change the argument to `"contracts/Foo.t.sol:FooTest"` it does work.
Linked issue comments: user: login: kanej
created_at: 2025-03-31T15:35:50Z
body: As a first move (we can refine later in the Alpha) we should pass in all built contracts to the Solidity Test EDR instance.
author_association: MEMBER

Diff:
diff --git a/.changeset/wet-students-act.md b/.changeset/wet-students-act.md
new file mode 100644
index 00000000000..aab0fef8033
--- /dev/null
+++ b/.changeset/wet-students-act.md
@@ -0,0 +1,5 @@
+---
+"hardhat": patch
+---
+
+Compile all sources and pass all generated artifacts to EDR when executing solidity tests
diff --git a/v-next/hardhat-mocha/src/index.ts b/v-next/hardhat-mocha/src/index.ts
index e7ff9ec38f6..e2937a0baa8 100644
--- a/v-next/hardhat-mocha/src/index.ts
+++ b/v-next/hardhat-mocha/src/index.ts
@@ -24,7 +24,7 @@ const hardhatPlugin: HardhatPlugin = {
       })
       .addFlag({
         name: "noCompile",
-        description: "Don't compile the project before running the test",
+        description: "Don't compile the project before running the tests",
       })
       .setAction(import.meta.resolve("./task-action.js"))
       .build(),
diff --git a/v-next/hardhat-node-test-runner/src/index.ts b/v-next/hardhat-node-test-runner/src/index.ts
index 00d99ed796a..d342e3a00a2 100644
--- a/v-next/hardhat-node-test-runner/src/index.ts
+++ b/v-next/hardhat-node-test-runner/src/index.ts
@@ -24,7 +24,7 @@ const hardhatPlugin: HardhatPlugin = {
       })
       .addFlag({
         name: "noCompile",
-        description: "Don't compile the project before running the test",
+        description: "Don't compile the project before running the tests",
       })
       .setAction(import.meta.resolve("./task-action.js"))
       .build(),
diff --git a/v-next/hardhat/src/internal/builtin-plugins/solidity-test/index.ts b/v-next/hardhat/src/internal/builtin-plugins/solidity-test/index.ts
index 18c1826e6f2..fc271ba98cb 100644
--- a/v-next/hardhat/src/internal/builtin-plugins/solidity-test/index.ts
+++ b/v-next/hardhat/src/internal/builtin-plugins/solidity-test/index.ts
@@ -21,6 +21,10 @@ const hardhatPlugin: HardhatPlugin = {
         description: "Not implemented yet - The chain type to use",
         defaultValue: "l1",
       })
+      .addFlag({
+        name: "noCompile",
+        description: "Don't compile the project before running the tests",
+      })
       .setAction(import.meta.resolve("./task-action.js"))
       .build(),
   ],
diff --git a/v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts b/v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts
index 703eaad72a6..3c2ba540c57 100644
--- a/v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts
+++ b/v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts
@@ -31,10 +31,11 @@ import { run } from "./runner.js";
 interface TestActionArguments {
   testFiles: string[];
   chainType: string;
+  noCompile: boolean;
 }
 
 const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
-  { testFiles, chainType },
+  { testFiles, chainType, noCompile },
   hre,
 ) => {
   let rootFilePaths: string[];
@@ -49,6 +50,13 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
     return;
   }
 
+  // NOTE: We run the compile task first to ensure all the artifacts for them are generated
+  // Then, we compile just the test sources. We don't do it in one go because the user
+  // is likely to use different compilation options for the tests and the sources.
+  if (noCompile === false) {
+    await hre.tasks.getTask("compile").run();
+  }
+
   if (testFiles.length > 0) {
     rootFilePaths = testFiles.map((f) =>
       resolveFromRoot(hre.config.paths.root, f),
@@ -71,19 +79,25 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
   // the tests.solidity paths and the sources paths
   rootFilePaths = Array.from(new Set(rootFilePaths));
 
+  // NOTE: We are not skipping the test compilation even if the noCompile flag is set
+  // because the user cannot run test compilation outside of the test task yet.
+  // TODO: Allow users to run test compilation outside of the test task.
   const buildOptions: BuildOptions = {
     force: false,
     buildProfile: hre.globalOptions.buildProfile,
     quiet: true,
   };
-
   const results = await hre.solidity.build(rootFilePaths, buildOptions);
-
   throwIfSolidityBuildFailed(results);
 
-  const buildInfos = await getBuildInfos(results, hre.artifacts);
-  const artifacts = await getArtifacts(results);
+  const buildInfos = await getBuildInfos(hre.artifacts);
+  const artifacts = await getArtifacts(hre.artifacts);
   const testSuiteIds = artifacts
+    .filter((artifact) =>
+      rootFilePaths.includes(
+        resolveFromRoot(hre.config.paths.root, artifact.id.source),
+      ),
+    )
     .filter(isTestSuiteArtifact)
     .map((artifact) => artifact.id);
 
diff --git a/v-next/hardhat/src/internal/builtin-plugins/solidity/build-results.ts b/v-next/hardhat/src/internal/builtin-plugins/solidity/build-results.ts
index c7ebe2fce7d..9ff8a9dbef2 100644
--- a/v-next/hardhat/src/internal/builtin-plugins/solidity/build-results.ts
+++ b/v-next/hardhat/src/internal/builtin-plugins/solidity/build-results.ts
@@ -1,7 +1,4 @@
-import type {
-  Artifact as HardhatArtifact,
-  ArtifactManager,
-} from "../../../types/artifacts.js";
+import type { ArtifactManager, BuildInfo } from "../../../types/artifacts.js";
 import type {
   CompilationJobCreationError,
   FailedFileBuildResult,
@@ -59,26 +56,18 @@ export function throwIfSolidityBuildFailed(
 }
 
 /**
- * This function returns the build infos and outputs associated with the given
- * Solidity build results.
+ * This function returns all the build infos and associated outputs.
  *
- * @param results The successful Solidity build results.
  * @param artifactManager The artifact manager.
  * @returns The build infos in the Hardhat v3 format as expected by the EDR.
  */
 export async function getBuildInfos(
-  results: SuccessfulSolidityBuildResults,
   artifactManager: ArtifactManager,
 ): Promise<BuildInfoAndOutput[]> {
-  const buildIds = await Promise.all(
-    Array.from(new Set(results.values())).map(async ({ compilationJob }) =>
-      compilationJob.getBuildId(),
-    ),
-  );
-  const uniqueBuildIds = Array.from(new Set(buildIds));
+  const buildIds = await artifactManager.getAllBuildInfoIds();
 
   return Promise.all(
-    uniqueBuildIds.map(async (buildId) => {
+    Array.from(buildIds).map(async (buildId) => {
       const buildInfoPath = await artifactManager.getBuildInfoPath(buildId);
       const buildInfoOutputPath =
         await artifactManager.getBuildInfoOutputPath(buildId);
@@ -109,46 +98,77 @@ export async function getBuildInfos(
 }
 
 /**
- * This function returns the artifacts generated during the compilation associated
- * with the given Solidity build results. It relies on the fact that each successful
- * build result has a corresponding artifact generated property.
+ * This function returns the artifacts generated during the compilation.
  *
- * @param results The successful Solidity build results.
+ * @param artifactManager The artifact manager.
  * @returns The artifacts in the format expected by the EDR.
  */
 export async function getArtifacts(
-  results: SuccessfulSolidityBuildResults,
+  artifactManager: ArtifactManager,
 ): Promise<EdrArtifact[]> {
-  const contractArtifacts = Array.from(results.entries())
-    .map(([source, result]) => {
-      return result.contractArtifactsGenerated.map((artifactPath) => ({
-        source,
-        solcVersion: result.compilationJob.solcConfig.version,
-        artifactPath,
-      }));
-    })
-    .flat();
+  const fullyQualifiedNames = await artifactManager.getAllFullyQualifiedNames();
 
-  return Promise.all(
-    contractArtifacts.map(async ({ source, artifactPath, solcVersion }) => {
-      const artifact: HardhatArtifact = await readJsonFile(artifactPath);
+  const artifacts = await Promise.all(
+    Array.from(fullyQualifiedNames).map(async (fullyQualifiedName) => {
+      return artifactManager.readArtifact(fullyQualifiedName);
+    }),
+  );
 
-      const id = {
-        name: artifact.contractName,
-        solcVersion,
-        source,
-      };
+  const buildInfoIds = Array.from(
+    new Set(artifacts.map((artifact) => artifact.buildInfoId)),
+  );
 
-      const contract = {
-        abi: JSON.stringify(artifact.abi),
-        bytecode: artifact.bytecode,
-        deployedBytecode: artifact.deployedBytecode,
-      };
+  const solcVersionsArray: Array<[string, string]> = await Promise.all(
+    buildInfoIds.map(async (buildInfoId) => {
+      assertHardhatInvariant(
+        buildInfoId !== undefined,
+        "artifactBuildInfoId should not be undefined",
+      );
 
-      return {
-        id,
-        contract,
-      };
+      const buildInfoPath = await artifactManager.getBuildInfoPath(buildInfoId);
+
+      assertHardhatInvariant(
+        buildInfoPath !== undefined,
+        "buildInfoPath should not be undefined",
+      );
+
+      const buildInfo: BuildInfo = await readJsonFile(buildInfoPath);
+
+      return [buildInfoId, buildInfo.solcVersion];
     }),
   );
+  const solcVersions = new Map(solcVersionsArray);
+
+  return artifacts.map((artifact) => {
+    assertHardhatInvariant(
+      artifact.buildInfoId !== undefined,
+      "solcVersion should not be undefined",
+    );
+
+    const solcVersion = solcVersions.get(artifact.buildInfoId);
+
+    assertHardhatInvariant(
+      solcVersion !== undefined,
+      "solcVersion should not be undefined",
+    );
+
+    const id = {
+      name: artifact.contractName,
+      solcVersion,
+      source: artifact.inputSourceName ?? artifact.sourceName,
+    };
+
+    const contract = {
+      abi: JSON.stringify(artifact.abi),
+      bytecode: artifact.bytecode,
+      linkReferences: artifact.linkReferences,
+      deployedBytecode: artifact.deployedBytecode,
+      deployedLinkReferences: artifact.deployedLinkReferences,
+    };
+
+    return {
+      id,
+      contract,
+    };
+  });
 }


Reviews:
user: login: galargh
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-01T14:44:16Z
user: login: agostbiro
body: Hey thanks for this PR!

I might be wrong, but I think we should change `task-action.ts:L67` to include all `*.sol` files not just `*.t.sol`, so that all the contracts in Solidity sources get built even if they aren't part of the dependency graph of a test file. The reason for this is that users could try to load them with the `getCode/getDeployedCode` cheatcodes.

https://github.com/NomicFoundation/hardhat/blob/fc34b963ca980e4cf7f419fe209788782972d5cf/v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts#L67
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T09:16:22Z
user: login: galargh
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T13:24:59Z
user: login: agostbiro
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T13:28:56Z
user: login: galargh
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T13:33:29Z
user: login: alcuadrado
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T16:36:04Z
user: login: alcuadrado
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T16:40:58Z
user: login: alcuadrado
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T16:41:23Z
user: login: alcuadrado
body: Left two comments, otherwise it looks good to me.
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-04-07T16:42:27Z
user: login: alcuadrado
body: 🚀
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-07T23:03:44Z

Review comments:
diff_hunk: @@ -109,46 +98,75 @@ export async function getBuildInfos(
 }
 
 /**
- * This function returns the artifacts generated during the compilation associated
- * with the given Solidity build results. It relies on the fact that each successful
- * build result has a corresponding artifact generated property.
+ * This function returns the artifacts generated during the compilation.
  *
- * @param results The successful Solidity build results.
+ * @param artifactManager The artifact manager.
  * @returns The artifacts in the format expected by the EDR.
  */
 export async function getArtifacts(
-  results: SuccessfulSolidityBuildResults,
+  artifactManager: ArtifactManager,
 ): Promise<EdrArtifact[]> {
-  const contractArtifacts = Array.from(results.entries())
-    .map(([source, result]) => {
-      return result.contractArtifactsGenerated.map((artifactPath) => ({
-        source,
-        solcVersion: result.compilationJob.solcConfig.version,
-        artifactPath,
-      }));
-    })
-    .flat();
+  const fullyQualifiedNames = await artifactManager.getAllFullyQualifiedNames();
 
-  return Promise.all(
-    contractArtifacts.map(async ({ source, artifactPath, solcVersion }) => {
-      const artifact: HardhatArtifact = await readJsonFile(artifactPath);
+  const artifacts = await Promise.all(
+    Array.from(fullyQualifiedNames).map(async (fullyQualifiedName) => {
+      return artifactManager.readArtifact(fullyQualifiedName);
+    }),
+  );
 
-      const id = {
-        name: artifact.contractName,
-        solcVersion,
-        source,
-      };
+  const buildInfoIds = Array.from(
+    new Set(artifacts.map((artifact) => artifact.buildInfoId)),
+  );
 
-      const contract = {
-        abi: JSON.stringify(artifact.abi),
-        bytecode: artifact.bytecode,
-        deployedBytecode: artifact.deployedBytecode,
-      };
+  const solcVersionsArray: Array<[string, string]> = await Promise.all(
+    buildInfoIds.map(async (buildInfoId) => {
+      assertHardhatInvariant(
+        buildInfoId !== undefined,
+        "artifactBuildInfoId should not be undefined",
+      );
 
-      return {
-        id,
-        contract,
-      };
+      const buildInfoPath = await artifactManager.getBuildInfoPath(buildInfoId);
+
+      assertHardhatInvariant(
+        buildInfoPath !== undefined,
+        "buildInfoPath should not be undefined",
+      );
+
+      const buildInfo: BuildInfo = await readJsonFile(buildInfoPath);
+
+      return [buildInfoId, buildInfo.solcVersion];
     }),
   );
+  const solcVersions = new Map(solcVersionsArray);
+
+  return artifacts.map((artifact) => {
+    assertHardhatInvariant(
+      artifact.buildInfoId !== undefined,
+      "solcVersion should not be undefined",
+    );
+
+    const solcVersion = solcVersions.get(artifact.buildInfoId);
+
+    assertHardhatInvariant(
+      solcVersion !== undefined,
+      "solcVersion should not be undefined",
+    );
+
+    const id = {
+      name: artifact.contractName,
+      solcVersion,
+      source: artifact.sourceName,
path: v-next/hardhat/src/internal/builtin-plugins/solidity/build-results.ts
user: login: galargh
body: I wonder what value should we use for npm artifacts here?
created_at: 2025-04-01T14:44:16Z
author_association: CONTRIBUTOR
diff_hunk: @@ -49,6 +49,8 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
     return;
   }
 
+  await hre.tasks.getTask("compile").run();
path: v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts
user: login: galargh
body: > I might be wrong, but I think we should change task-action.ts:L67 to include all *.sol files not just *.t.sol, so that all the contracts in Solidity sources get built even if they aren't part of the dependency graph of a test file. The reason for this is that users could try to load them with the getCode/getDeployedCode cheatcodes.

@agostbiro I'll reply here because this line is why the one you mentioned is correct. So what will be happening in the task after the changes introduced in this PR is:
1. We compile all the sources, excluding the test sources. We do that by calling the compile task. We don't compile the sources together with the test sources because we want the user to be able to use different build options for this step.
2. We compile all the test sources using the test build options.
3. We collect everything from artifacts folder to pass it to EDR. These include compilation artifacts from 1. and 2.
4. We find the test suite IDs that we want to pass to EDR. We do that by looking at all the artifacts and checking if:
  a. the source of the artifact matches one of the requested test sources
  b. the artifact contains any tests.
5. We pass 3. and 4. to EDR for the test execution. 
created_at: 2025-04-07T13:24:59Z
author_association: CONTRIBUTOR
diff_hunk: @@ -49,6 +49,8 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
     return;
   }
 
+  await hre.tasks.getTask("compile").run();
path: v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts
user: login: agostbiro
body: Ah thanks for the explanation, sounds good! Could you add the first two points as comments? 
created_at: 2025-04-07T13:28:51Z
author_association: CONTRIBUTOR
diff_hunk: @@ -49,6 +49,8 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
     return;
   }
 
+  await hre.tasks.getTask("compile").run();
path: v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts
user: login: galargh
body: Of course, done :) 
created_at: 2025-04-07T13:33:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -49,6 +49,11 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
     return;
   }
 
+  // NOTE: We run the compile task first to ensure all the artifacts for them are generated
+  // Then, we compile just the test sources. We don't do it in one go because the user
+  // is likely to use different compilation options for the tests and the sources.
+  await hre.tasks.getTask("compile").run();
path: v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts
user: login: alcuadrado
body: I think we need to reintroduce the `--no-compile` here, otherwise running `hardhat test` will compile twice.
created_at: 2025-04-07T16:36:04Z
author_association: MEMBER
diff_hunk: @@ -109,46 +98,75 @@ export async function getBuildInfos(
 }
 
 /**
- * This function returns the artifacts generated during the compilation associated
- * with the given Solidity build results. It relies on the fact that each successful
- * build result has a corresponding artifact generated property.
+ * This function returns the artifacts generated during the compilation.
  *
- * @param results The successful Solidity build results.
+ * @param artifactManager The artifact manager.
  * @returns The artifacts in the format expected by the EDR.
  */
 export async function getArtifacts(
-  results: SuccessfulSolidityBuildResults,
+  artifactManager: ArtifactManager,
 ): Promise<EdrArtifact[]> {
-  const contractArtifacts = Array.from(results.entries())
-    .map(([source, result]) => {
-      return result.contractArtifactsGenerated.map((artifactPath) => ({
-        source,
-        solcVersion: result.compilationJob.solcConfig.version,
-        artifactPath,
-      }));
-    })
-    .flat();
+  const fullyQualifiedNames = await artifactManager.getAllFullyQualifiedNames();
 
-  return Promise.all(
-    contractArtifacts.map(async ({ source, artifactPath, solcVersion }) => {
-      const artifact: HardhatArtifact = await readJsonFile(artifactPath);
+  const artifacts = await Promise.all(
+    Array.from(fullyQualifiedNames).map(async (fullyQualifiedName) => {
+      return artifactManager.readArtifact(fullyQualifiedName);
+    }),
+  );
 
-      const id = {
-        name: artifact.contractName,
-        solcVersion,
-        source,
-      };
+  const buildInfoIds = Array.from(
+    new Set(artifacts.map((artifact) => artifact.buildInfoId)),
+  );
 
-      const contract = {
-        abi: JSON.stringify(artifact.abi),
-        bytecode: artifact.bytecode,
-        deployedBytecode: artifact.deployedBytecode,
-      };
+  const solcVersionsArray: Array<[string, string]> = await Promise.all(
+    buildInfoIds.map(async (buildInfoId) => {
+      assertHardhatInvariant(
+        buildInfoId !== undefined,
+        "artifactBuildInfoId should not be undefined",
+      );
 
-      return {
-        id,
-        contract,
-      };
+      const buildInfoPath = await artifactManager.getBuildInfoPath(buildInfoId);
+
+      assertHardhatInvariant(
+        buildInfoPath !== undefined,
+        "buildInfoPath should not be undefined",
+      );
+
+      const buildInfo: BuildInfo = await readJsonFile(buildInfoPath);
+
+      return [buildInfoId, buildInfo.solcVersion];
     }),
   );
+  const solcVersions = new Map(solcVersionsArray);
+
+  return artifacts.map((artifact) => {
+    assertHardhatInvariant(
+      artifact.buildInfoId !== undefined,
+      "solcVersion should not be undefined",
+    );
+
+    const solcVersion = solcVersions.get(artifact.buildInfoId);
+
+    assertHardhatInvariant(
+      solcVersion !== undefined,
+      "solcVersion should not be undefined",
+    );
+
+    const id = {
+      name: artifact.contractName,
+      solcVersion,
+      source: artifact.sourceName,
path: v-next/hardhat/src/internal/builtin-plugins/solidity/build-results.ts
user: login: alcuadrado
body: It should be the `artifact.inputSourceName`, otherwise EDR won't find it.

We should polish the `sourceName` vs `inputSourceName` vs `publicSourceName` situation.
created_at: 2025-04-07T16:40:57Z
author_association: MEMBER
diff_hunk: @@ -109,46 +98,75 @@ export async function getBuildInfos(
 }
 
 /**
- * This function returns the artifacts generated during the compilation associated
- * with the given Solidity build results. It relies on the fact that each successful
- * build result has a corresponding artifact generated property.
+ * This function returns the artifacts generated during the compilation.
  *
- * @param results The successful Solidity build results.
+ * @param artifactManager The artifact manager.
  * @returns The artifacts in the format expected by the EDR.
  */
 export async function getArtifacts(
-  results: SuccessfulSolidityBuildResults,
+  artifactManager: ArtifactManager,
 ): Promise<EdrArtifact[]> {
-  const contractArtifacts = Array.from(results.entries())
-    .map(([source, result]) => {
-      return result.contractArtifactsGenerated.map((artifactPath) => ({
-        source,
-        solcVersion: result.compilationJob.solcConfig.version,
-        artifactPath,
-      }));
-    })
-    .flat();
+  const fullyQualifiedNames = await artifactManager.getAllFullyQualifiedNames();
 
-  return Promise.all(
-    contractArtifacts.map(async ({ source, artifactPath, solcVersion }) => {
-      const artifact: HardhatArtifact = await readJsonFile(artifactPath);
+  const artifacts = await Promise.all(
+    Array.from(fullyQualifiedNames).map(async (fullyQualifiedName) => {
+      return artifactManager.readArtifact(fullyQualifiedName);
+    }),
+  );
 
-      const id = {
-        name: artifact.contractName,
-        solcVersion,
-        source,
-      };
+  const buildInfoIds = Array.from(
+    new Set(artifacts.map((artifact) => artifact.buildInfoId)),
+  );
 
-      const contract = {
-        abi: JSON.stringify(artifact.abi),
-        bytecode: artifact.bytecode,
-        deployedBytecode: artifact.deployedBytecode,
-      };
+  const solcVersionsArray: Array<[string, string]> = await Promise.all(
+    buildInfoIds.map(async (buildInfoId) => {
+      assertHardhatInvariant(
+        buildInfoId !== undefined,
+        "artifactBuildInfoId should not be undefined",
+      );
 
-      return {
-        id,
-        contract,
-      };
+      const buildInfoPath = await artifactManager.getBuildInfoPath(buildInfoId);
+
+      assertHardhatInvariant(
+        buildInfoPath !== undefined,
+        "buildInfoPath should not be undefined",
+      );
+
+      const buildInfo: BuildInfo = await readJsonFile(buildInfoPath);
+
+      return [buildInfoId, buildInfo.solcVersion];
     }),
   );
+  const solcVersions = new Map(solcVersionsArray);
+
+  return artifacts.map((artifact) => {
+    assertHardhatInvariant(
+      artifact.buildInfoId !== undefined,
+      "solcVersion should not be undefined",
+    );
+
+    const solcVersion = solcVersions.get(artifact.buildInfoId);
+
+    assertHardhatInvariant(
+      solcVersion !== undefined,
+      "solcVersion should not be undefined",
+    );
+
+    const id = {
+      name: artifact.contractName,
+      solcVersion,
+      source: artifact.sourceName,
path: v-next/hardhat/src/internal/builtin-plugins/solidity/build-results.ts
user: login: alcuadrado
body: but for now, something like `artifact.inputSourceName ?? artifact.sourceName`.
created_at: 2025-04-07T16:41:23Z
author_association: MEMBER

PR comments:
user: login: changeset-bot[bot]
created_at: 2025-04-01T14:18:44Z
body: ###  🦋  Changeset detected

Latest commit: c48a1f13e66d6d13626c602dc0f55e27c63db6ab

**The changes in this PR will be included in the next version bump.**

<details><summary>This PR includes changesets to release 1 package</summary>

  | Name    | Type  |
| ------- | ----- |
| hardhat | Patch |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/NomicFoundation/hardhat/new/test-compile?filename=.changeset/shiny-eels-repair.md&value=---%0A%22%40nomicfoundation%2Fhardhat-mocha%22%3A%20patch%0A%22%40nomicfoundation%2Fhardhat-node-test-runner%22%3A%20patch%0A%22hardhat%22%3A%20patch%0A---%0A%0Afix%3A%20pass%20all%20artifacts%20to%20edr%20when%20executing%20solidity%20tests%0A)


author_association: NONE
user: login: vercel[bot]
created_at: 2025-04-01T14:18:45Z
body: [vc]: #LVOjErbBqC83sT1Ol3WLNr2RlqfVfydJc93j9Um6vvo=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJoYXJkaGF0IiwibGl2ZUZlZWRiYWNrIjp7InJlc29sdmVkIjowLCJ1bnJlc29sdmVkIjowLCJ0b3RhbCI6MCwibGluayI6ImhhcmRoYXQtZ2l0LXRlc3QtY29tcGlsZS1ub21pYy1mb3VuZGF0aW9uLnZlcmNlbC5hcHAifSwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL25vbWljLWZvdW5kYXRpb24vaGFyZGhhdC9FYW0zUGtZRVZvTlZyVkVkVllSWW1ZYWY1VExUIiwicHJldmlld1VybCI6ImhhcmRoYXQtZ2l0LXRlc3QtY29tcGlsZS1ub21pYy1mb3VuZGF0aW9uLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQiLCJyb290RGlyZWN0b3J5IjoiZG9jcyJ9XX0=
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Comments | Updated (UTC) |
| :--- | :----- | :------ | :------- | :------ |
| **hardhat** | ✅ Ready ([Inspect](https://vercel.com/nomic-foundation/hardhat/Eam3PkYEVoNVrVEdVYRYmYaf5TLT)) | [Visit Preview](https://hardhat-git-test-compile-nomic-foundation.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/hardhat-git-test-compile-nomic-foundation.vercel.app?via=pr-comment-feedback-link) | Apr 8, 2025 11:07am |


author_association: NONE