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

A few messaging improvements #5891

Merged
merged 6 commits into from
Oct 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions v-next/example-project/contracts/Counter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract CounterTest {
require(counter.x() == x, "Value after calling inc x times should be x");
}

function invariant() public {
function invariant() public pure {
assert(true);
}
}
Expand All @@ -41,10 +41,13 @@ contract FailingCounterTest {
for (uint8 i = 0; i < x; i++) {
counter.inc();
}
require(counter.x() == x + 1, "Value after calling inc x times should be x + 1");
require(
counter.x() == x + 1,
"Value after calling inc x times should be x + 1"
);
}

function invariant() public {
function invariant() public pure {
assert(false);
}
}
3 changes: 3 additions & 0 deletions v-next/example-project/contracts/D.sol
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;

import "./C.sol";
7 changes: 5 additions & 2 deletions v-next/example-project/contracts/WithForge.t.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;

import "forge-std/Test.sol";

contract TestContract is Test {
Expand All @@ -14,7 +17,7 @@ contract TestContract is Test {
}

contract ErrorsTest {
function arithmeticError(uint256 a) public {
uint256 a = a - 100;
function arithmeticError(uint256 a) public pure returns (uint256) {
return a - 100;
}
}
8 changes: 6 additions & 2 deletions v-next/hardhat-mocha-test-runner/src/task-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ const testWithHardhat: NewTaskActionFunction<TestActionArguments> = async (
hre,
) => {
if (!noCompile) {
await hre.tasks.getTask("compile").run({ quiet: true });
await hre.tasks.getTask("compile").run({});
console.log();
}

const files = await getTestFiles(testFiles, hre.config);
Expand Down Expand Up @@ -85,7 +86,8 @@ const testWithHardhat: NewTaskActionFunction<TestActionArguments> = async (
}
testsAlreadyRun = true;

console.log("Running Mocha tests");
// We write instead of console.log because Mocha already prints some newlines
process.stdout.write("Running Mocha tests");

// This instructs Mocha to use the more verbose file loading infrastructure
// which supports both ESM and CJS
Expand All @@ -99,6 +101,8 @@ const testWithHardhat: NewTaskActionFunction<TestActionArguments> = async (
process.exitCode = 1;
}

console.log();

return testFailures;
};

Expand Down
5 changes: 4 additions & 1 deletion v-next/hardhat-node-test-runner/src/task-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const testWithHardhat: NewTaskActionFunction<TestActionArguments> = async (
hre,
) => {
if (!noCompile) {
await hre.tasks.getTask("compile").run({ quiet: true });
await hre.tasks.getTask("compile").run({});
console.log();
}

const files = await getTestFiles(testFiles, hre.config);
Expand Down Expand Up @@ -111,6 +112,8 @@ const testWithHardhat: NewTaskActionFunction<TestActionArguments> = async (
process.exitCode = 1;
}

console.log();

return testFailures;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
hre,
) => {
if (!noCompile) {
await hre.tasks.getTask("compile").run({ quiet: true });
await hre.tasks.getTask("compile").run({});
console.log();
}

const artifacts = await getArtifacts(hre.artifacts);
Expand Down Expand Up @@ -81,8 +82,9 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (

if (includesFailures || includesErrors) {
process.exitCode = 1;
return;
}

console.log();
};

export default runSolidityTests;
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
rootFilePaths: string[],
options?: BuildOptions,
): Promise<CompilationJobCreationError | Map<string, FileBuildResult>> {
if (options?.quiet !== true) {
console.log("Compiling your Solidity contracts");
}

await this.#downloadConfiguredCompilers(options?.quiet);

const compilationJobsPerFile = await this.getCompilationJobs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const runAllTests: NewTaskActionFunction<TestActionArguments> = async (
const thisTask = hre.tasks.getTask("test");

if (!noCompile) {
await hre.tasks.getTask("compile").run({ quiet: true });
await hre.tasks.getTask("compile").run({});
console.log();
}

for (const subtask of thisTask.subtasks.values()) {
await subtask.run({ noCompile: true });
console.log();
}

if (process.exitCode !== undefined && process.exitCode !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion v-next/hardhat/src/internal/core/tasks/resolved-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class ResolvedTask implements Task {
const pluginId = this.actions[currentIndex].pluginId;

if (
typeof currentAction === "string" &&
typeof currentAction === "function" &&
pluginId !== undefined &&
SHOULD_WARN_ABOUT_INLINE_TASK_ACTIONS_AND_HOOK_HANDLERS
) {
Expand Down
4 changes: 2 additions & 2 deletions v-next/hardhat/templates/mocha-ethers/contracts/Counter.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

contract Counter {
uint public x;
Expand Down
4 changes: 2 additions & 2 deletions v-next/hardhat/templates/mocha-ethers/contracts/Counter.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import "./Counter.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import "forge-std/Test.sol";

contract TestContract is Test {
Expand All @@ -14,7 +17,7 @@ contract TestContract is Test {
}

contract ErrorsTest {
function arithmeticError(uint256 a) public {
uint256 a = a - 100;
function arithmeticError(uint256 a) public pure returns (uint256) {
return a - 100;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

contract Counter {
uint public x;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import "./Counter.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import "forge-std/Test.sol";

contract TestContract is Test {
Expand All @@ -14,7 +17,7 @@ contract TestContract is Test {
}

contract ErrorsTest {
function arithmeticError(uint256 a) public {
uint256 a = a - 100;
function arithmeticError(uint256 a) public pure returns (uint256) {
return a - 100;
}
}