Skip to content

Commit cdd6565

Browse files
authored
Merge pull request #7016 from NomicFoundation/fix-artifacts-linkReferences
Use input source names in the link references
2 parents 3ba2d73 + 417d49d commit cdd6565

File tree

6 files changed

+19
-48
lines changed

6 files changed

+19
-48
lines changed

.changeset/tough-rice-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Use input source names in the link references, fixing a bug in the solidity test runner

v-next/hardhat-utils/src/internal/bytecode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { isAddress } from "../eth.js";
1212
export interface Artifact {
1313
bytecode: string;
1414
linkReferences: {
15-
[sourceName: string]: {
15+
[inputSourceName: string]: {
1616
[libraryName: string]: Array<{ start: number; length: number }>;
1717
};
1818
};

v-next/hardhat-viem/test/contracts.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ describe("contracts", () => {
383383
contractName: "OnlyNormalLib",
384384
error:
385385
"The following libraries are missing:\n" +
386-
'\t* "contracts/WithLibs.sol:NormalLib"\n' +
386+
'\t* "project/contracts/WithLibs.sol:NormalLib"\n' +
387387
"\n" +
388388
"Please provide all the required libraries.",
389389
},
@@ -461,8 +461,8 @@ describe("contracts", () => {
461461
error:
462462
"The following libraries may resolve to multiple libraries:\n" +
463463
'\t* "ConstructorLib":\n' +
464-
'\t\t* "contracts/ConstructorLib.sol:ConstructorLib"\n' +
465-
'\t\t* "contracts/WithLibs.sol:ConstructorLib"\n' +
464+
'\t\t* "project/contracts/ConstructorLib.sol:ConstructorLib"\n' +
465+
'\t\t* "project/contracts/WithLibs.sol:ConstructorLib"\n' +
466466
"\n" +
467467
"Please provide the fully qualified name for these libraries.",
468468
},
@@ -484,8 +484,8 @@ describe("contracts", () => {
484484
error:
485485
"The following libraries may resolve to multiple libraries:\n" +
486486
'\t* "ConstructorLib":\n' +
487-
'\t\t* "contracts/ConstructorLib.sol:ConstructorLib"\n' +
488-
'\t\t* "contracts/WithLibs.sol:ConstructorLib"\n' +
487+
'\t\t* "project/contracts/ConstructorLib.sol:ConstructorLib"\n' +
488+
'\t\t* "project/contracts/WithLibs.sol:ConstructorLib"\n' +
489489
"\n" +
490490
"Please provide the fully qualified name for these libraries.",
491491
},
@@ -498,9 +498,9 @@ describe("contracts", () => {
498498
[2n],
499499
{
500500
libraries: {
501-
"contracts/ConstructorLib.sol:ConstructorLib":
501+
"project/contracts/ConstructorLib.sol:ConstructorLib":
502502
constructorLibConstructorLibContract.address,
503-
"contracts/WithLibs.sol:ConstructorLib":
503+
"project/contracts/WithLibs.sol:ConstructorLib":
504504
withLibsConstructorLibContract.address,
505505
},
506506
},
@@ -523,7 +523,7 @@ describe("contracts", () => {
523523
networkConnection.viem.deployContract("OnlyConstructorLib", [1n], {
524524
libraries: {
525525
ConstructorLib: constructorLibContract.address,
526-
"contracts/WithLibs.sol:ConstructorLib":
526+
"project/contracts/WithLibs.sol:ConstructorLib":
527527
constructorLibContract.address,
528528
},
529529
}),
@@ -532,7 +532,7 @@ describe("contracts", () => {
532532
contractName: "OnlyConstructorLib",
533533
error:
534534
"The following libraries are provided more than once:\n" +
535-
'\t* "contracts/WithLibs.sol:ConstructorLib"\n' +
535+
'\t* "project/contracts/WithLibs.sol:ConstructorLib"\n' +
536536
"\n" +
537537
"Please ensure that each library is provided only once, either by its name or its fully qualified name.",
538538
},

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/artifacts.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import type {
2-
Artifact,
3-
BuildInfo,
4-
LinkReferences,
5-
} from "../../../../types/artifacts.js";
1+
import type { Artifact, BuildInfo } from "../../../../types/artifacts.js";
62
import type { CompilationJob } from "../../../../types/solidity/compilation-job.js";
73
import type {
84
CompilerOutput,
@@ -21,7 +17,6 @@ export function getContractArtifact(
2117
inputSourceName: string,
2218
contractName: string,
2319
contract: CompilerOutputContract,
24-
userSourceNameMap: Record<string, string>,
2520
): Artifact {
2621
const evmBytecode = contract.evm?.bytecode;
2722
const bytecode: string =
@@ -47,14 +42,8 @@ export function getContractArtifact(
4742
abi: contract.abi,
4843
bytecode,
4944
deployedBytecode,
50-
linkReferences: applyUserSourceNamesToLinkReferences(
51-
linkReferences,
52-
userSourceNameMap,
53-
),
54-
deployedLinkReferences: applyUserSourceNamesToLinkReferences(
55-
deployedLinkReferences,
56-
userSourceNameMap,
57-
),
45+
linkReferences,
46+
deployedLinkReferences,
5847
immutableReferences,
5948
inputSourceName,
6049
buildInfoId,
@@ -63,18 +52,6 @@ export function getContractArtifact(
6352
return artifact;
6453
}
6554

66-
function applyUserSourceNamesToLinkReferences(
67-
linkReferences: LinkReferences,
68-
userSourceNameMap: Record<string, string>,
69-
): LinkReferences {
70-
return Object.fromEntries(
71-
Object.entries(linkReferences).map(([sourceName, references]) => [
72-
userSourceNameMap[sourceName] ?? sourceName,
73-
references,
74-
]),
75-
);
76-
}
77-
7855
export function getArtifactsDeclarationFile(artifacts: Artifact[]): string {
7956
if (artifacts.length === 0) {
8057
return "";

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,6 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
471471
const result = new Map<string, string[]>();
472472
const buildId = await compilationJob.getBuildId();
473473

474-
const userSourceNameMap = Object.fromEntries(
475-
compilationJob.dependencyGraph
476-
.getRoots()
477-
.entries()
478-
.map(([userSourceName, root]) => [
479-
root.inputSourceName,
480-
userSourceName,
481-
]),
482-
);
483-
484474
// We emit the artifacts for each root file, first emitting one artifact
485475
// for each contract, and then one declaration file for the entire file,
486476
// which defines their types and augments the ArtifactMap type.
@@ -511,7 +501,6 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
511501
root.inputSourceName,
512502
contractName,
513503
contract,
514-
userSourceNameMap,
515504
);
516505

517506
await writeUtf8File(

v-next/hardhat/src/types/artifacts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export interface Artifact<AbiT extends Abi = Abi> {
218218
* The link references of a contract, which need to be resolved before using it.
219219
*/
220220
export interface LinkReferences {
221-
[librarySourceName: string]: {
221+
[libraryInputSourceName: string]: {
222222
[libraryName: string]: Array<{ length: number; start: number }>;
223223
};
224224
}

0 commit comments

Comments
 (0)