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

Sort files when creating the solc input #3305

Merged
merged 3 commits into from Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mean-mice-tell.md
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Fixed an issue that was causing build-info file names to not be deterministic.
Expand Up @@ -4,7 +4,13 @@ export function getInputFromCompilationJob(
compilationJob: CompilationJob
): CompilerInput {
const sources: { [sourceName: string]: { content: string } } = {};
for (const file of compilationJob.getResolvedFiles()) {

// we sort the files so that we always get the same compilation input
const resolvedFiles = compilationJob
.getResolvedFiles()
.sort((a, b) => a.sourceName.localeCompare(b.sourceName));

for (const file of resolvedFiles) {
sources[file.sourceName] = {
content: file.content.rawContent,
};
Expand Down
27 changes: 27 additions & 0 deletions packages/hardhat-core/test/builtin-tasks/compile.ts
@@ -1,4 +1,5 @@
import { assert } from "chai";
import ci from "ci-info";
import * as fsExtra from "fs-extra";
import * as path from "path";

Expand Down Expand Up @@ -817,4 +818,30 @@ Read about compiler configuration at https://hardhat.org/config
});
});
});

describe("project where two contracts import the same dependency", function () {
useFixtureProject("consistent-build-info-names");
useEnvironment();

it("should always produce the same build-info name", async function () {
await this.env.run("compile");

const buildInfos = getBuildInfos();
assert.lengthOf(buildInfos, 1);

const expectedBuildInfoName = buildInfos[0];

const runs = ci.isCI ? 10 : 100;

for (let i = 0; i < runs; i++) {
await this.env.run("clean");
await this.env.run("compile");

const newBuildInfos = getBuildInfos();
assert.lengthOf(newBuildInfos, 1);

assert.equal(newBuildInfos[0], expectedBuildInfoName);
}
});
});
});
@@ -0,0 +1,2 @@
artifacts/
cache/
@@ -0,0 +1,6 @@
pragma solidity ^0.7.0;

import "dependency/contracts/Dep1.sol";
import "dependency/contracts/Dep2.sol";

contract A {}
@@ -0,0 +1,5 @@
pragma solidity ^0.7.0;

import "dependency/contracts/Dep1.sol";

contract B {}
@@ -0,0 +1,3 @@
module.exports = {
solidity: "0.7.3",
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.