-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix remappings duplication #8120
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "hardhat": patch | ||
| --- | ||
|
|
||
| Fix remappings duplication |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/hardhat/test/fixture-projects/no-duplicated-remappings/contracts-alt/C.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.31; | ||
|
|
||
| library C { | ||
| function value() internal pure returns (uint256) { | ||
| return 3; | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
packages/hardhat/test/fixture-projects/no-duplicated-remappings/contracts/A.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.31; | ||
|
|
||
| library A { | ||
| function value() internal pure returns (uint256) { | ||
| return 1; | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
packages/hardhat/test/fixture-projects/no-duplicated-remappings/contracts/B.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.31; | ||
|
|
||
| library B { | ||
| function value() internal pure returns (uint256) { | ||
| return 2; | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
packages/hardhat/test/fixture-projects/no-duplicated-remappings/contracts/ImportA.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.31; | ||
|
|
||
| import {A} from "@dup/A.sol"; | ||
|
|
||
| contract ImportA { | ||
| function value() external pure returns (uint256) { | ||
| return A.value(); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
packages/hardhat/test/fixture-projects/no-duplicated-remappings/contracts/ImportAB.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.31; | ||
|
|
||
| import {A} from "@dup/A.sol"; | ||
| import {B} from "@dup/B.sol"; | ||
|
|
||
| contract ImportAB { | ||
| function value() external pure returns (uint256) { | ||
| return A.value() + B.value(); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
packages/hardhat/test/fixture-projects/no-duplicated-remappings/contracts/ImportB.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.31; | ||
|
|
||
| import {B} from "@dup/B.sol"; | ||
|
|
||
| contract ImportB { | ||
| function value() external pure returns (uint256) { | ||
| return B.value(); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
packages/hardhat/test/fixture-projects/no-duplicated-remappings/contracts/ImportC.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.31; | ||
|
|
||
| import {C} from "@alt/C.sol"; | ||
|
|
||
| contract ImportC { | ||
| function value() external pure returns (uint256) { | ||
| return C.value(); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
packages/hardhat/test/fixture-projects/no-duplicated-remappings/hardhat.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import type { HardhatUserConfig } from "../../../src/types/config.js"; | ||
|
|
||
| const config: HardhatUserConfig = { | ||
| solidity: { | ||
| version: "0.8.31", | ||
| }, | ||
| }; | ||
|
|
||
| export default config; |
5 changes: 5 additions & 0 deletions
5
packages/hardhat/test/fixture-projects/no-duplicated-remappings/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "hardhat-duplicate-remappings-regression", | ||
| "private": true, | ||
| "type": "module" | ||
| } |
3 changes: 3 additions & 0 deletions
3
packages/hardhat/test/fixture-projects/no-duplicated-remappings/remappings.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| @dup/=contracts/ | ||
| @dup/=contracts/ | ||
| @alt/=contracts-alt/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...st/internal/builtin-plugins/solidity/build-system/regressions/no-duplicated-remappings.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import type { HardhatRuntimeEnvironment } from "../../../../../../src/types/hre.js"; | ||
| import type { GetCompilationJobsResult } from "../../../../../../src/types/solidity.js"; | ||
|
|
||
| import assert from "node:assert/strict"; | ||
| import path from "node:path"; | ||
| import { before, describe, it } from "node:test"; | ||
|
|
||
| import { useFixtureProject } from "@nomicfoundation/hardhat-test-utils"; | ||
|
|
||
| import { | ||
| createHardhatRuntimeEnvironment, | ||
| importUserConfig, | ||
| resolveHardhatConfigPath, | ||
| } from "../../../../../../src/hre.js"; | ||
|
|
||
| const DUP_REMAPPING = "project/:@dup/=project/contracts/"; | ||
| const ALT_REMAPPING = "project/:@alt/=project/contracts-alt/"; | ||
|
|
||
| async function getCompilationJobs( | ||
| hre: HardhatRuntimeEnvironment, | ||
| rootFileNames: string[], | ||
| options = {}, | ||
| ) { | ||
| const allRootFiles = await hre.solidity.getRootFilePaths(); | ||
| const selectedRootFiles = rootFileNames.map((name) => { | ||
| const match = allRootFiles.find((f) => f.endsWith(`${path.sep}${name}`)); | ||
| assert.ok(match !== undefined, `Root file not found: ${name}`); | ||
| return match; | ||
| }); | ||
|
|
||
| const result = await hre.solidity.getCompilationJobs(selectedRootFiles, { | ||
| force: true, | ||
| ...options, | ||
| }); | ||
|
|
||
| assert.equal(result.success, true); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| function getUniqueJobs(compilationJobs: GetCompilationJobsResult) { | ||
| return [...new Set(compilationJobs.compilationJobsPerFile.values())]; | ||
| } | ||
|
|
||
| describe("Solidity build system regression tests: no duplicated remappings", () => { | ||
| useFixtureProject("no-duplicated-remappings"); | ||
| let hre: HardhatRuntimeEnvironment; | ||
| before(async () => { | ||
| const configPath = await resolveHardhatConfigPath(); | ||
| const config = await importUserConfig(configPath); | ||
| hre = await createHardhatRuntimeEnvironment(config, { config: configPath }); | ||
| }); | ||
|
|
||
| it("should not duplicate remappings from duplicate remappings.txt entries", async () => { | ||
| const jobs = getUniqueJobs(await getCompilationJobs(hre, ["ImportA.sol"])); | ||
|
|
||
| assert.equal(jobs.length, 1); | ||
|
|
||
| const solcInput = await jobs[0].getSolcInput(); | ||
| assert.deepEqual(solcInput.settings.remappings, [DUP_REMAPPING]); | ||
| }); | ||
|
|
||
| it("should deduplicate remappings across edges within a single graph", async () => { | ||
| const jobs = getUniqueJobs(await getCompilationJobs(hre, ["ImportAB.sol"])); | ||
|
|
||
| assert.equal(jobs.length, 1); | ||
|
|
||
| const solcInput = await jobs[0].getSolcInput(); | ||
| assert.deepEqual(solcInput.settings.remappings, [DUP_REMAPPING]); | ||
| }); | ||
|
|
||
| it("should deduplicate remappings when merging graphs", async () => { | ||
| const jobs = getUniqueJobs( | ||
| await getCompilationJobs(hre, ["ImportA.sol", "ImportB.sol"]), | ||
| ); | ||
|
|
||
| assert.equal(jobs.length, 1); | ||
|
|
||
| const solcInput = await jobs[0].getSolcInput(); | ||
| assert.deepEqual(solcInput.settings.remappings, [DUP_REMAPPING]); | ||
| }); | ||
|
|
||
| it("should not duplicate remappings in isolated mode", async () => { | ||
| const jobs = getUniqueJobs( | ||
| await getCompilationJobs(hre, ["ImportA.sol", "ImportB.sol"], { | ||
| buildProfile: "production", | ||
| }), | ||
| ); | ||
|
|
||
| assert.equal(jobs.length, 2); | ||
|
|
||
| for (const job of jobs) { | ||
| const solcInput = await job.getSolcInput(); | ||
| assert.deepEqual(solcInput.settings.remappings, [DUP_REMAPPING]); | ||
| } | ||
| }); | ||
|
|
||
| it("should preserve distinct remappings when merging graphs", async () => { | ||
| const jobs = getUniqueJobs( | ||
| await getCompilationJobs(hre, ["ImportA.sol", "ImportC.sol"]), | ||
| ); | ||
|
|
||
| assert.equal(jobs.length, 1); | ||
|
|
||
| const solcInput = await jobs[0].getSolcInput(); | ||
| assert.deepEqual(solcInput.settings.remappings, [ | ||
| ALT_REMAPPING, | ||
| DUP_REMAPPING, | ||
| ]); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.