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

add skeleton EDR Solidity Testing integration #5780

Merged
merged 6 commits into from
Oct 1, 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
836 changes: 438 additions & 398 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions v-next/example-project/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@

# pnpm deploy output
/bundle

# Hardhat Build Artifacts
/artifacts

# Hardhat compilation (v2) support directory
/cache
10 changes: 10 additions & 0 deletions v-next/example-project/contracts/Counter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Counter {
uint public x;

function inc() public {
x++;
}
}
21 changes: 21 additions & 0 deletions v-next/example-project/contracts/Counter.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Counter.sol";

contract CounterTest {
Counter counter;

function setUp() public {
counter = new Counter();
}

function testInitialValue() public view {
require(counter.x() == 0, "Initial value should be 0");
}

function testInc() public {
counter.inc();
require(counter.x() == 1, "Value after inc should be 1");
}
}
16 changes: 16 additions & 0 deletions v-next/example-project/contracts/Rocket.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract Rocket {
string public name;
string public status;

constructor(string memory _name) {
name = _name;
status = "ignition";
}

function launch() public {
status = "lift-off";
}
}
12 changes: 7 additions & 5 deletions v-next/hardhat-build-system/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ignored/hardhat-vnext-build-system",
"private": true,
"version": "2.0.1-next.0",
"version": "3.0.0-next.2",
"description": "Build and Solidity compilation system for Hardhat",
"homepage": "https://github.com/nomicfoundation/hardhat/tree/main/v-next/hardhat-build-system",
"repository": {
Expand All @@ -13,6 +13,9 @@
"license": "MIT",
"type": "module",
"types": "dist/src/index.d.ts",
"exports": {
".": "./dist/src/index.js"
},
"keywords": [
"ethereum",
"smart-contracts",
Expand All @@ -38,8 +41,8 @@
"README.md"
],
"dependencies": {
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.0",
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.0",
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
"@nomicfoundation/ethereumjs-util": "9.0.4",
"@nomicfoundation/solidity-analyzer": "^0.1.0",
"adm-zip": "^0.4.16",
Expand All @@ -60,8 +63,7 @@
},
"devDependencies": {
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.0",
"@nomicfoundation/hardhat-test-utils": "workspace:^",
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
"@types/ci-info": "^2.0.0",
"@types/debug": "^4.1.4",
"@types/find-up": "^2.1.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import type { CompilationJob, CompilerInput } from "../../types/index.js";

const defaultSolcOutputSelection = {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata",
],
"": ["ast"],
},
} as const;

export function getInputFromCompilationJob(
compilationJob: CompilationJob,
): CompilerInput {
Expand All @@ -18,9 +31,50 @@ export function getInputFromCompilationJob(

const { settings } = compilationJob.getSolcConfig();

return {
const result = {
language: "Solidity",
sources,
settings,
settings: settings ?? {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anywhere where we could encounter null-ish settings? Should we check an invariant instead maybe?

};

// This code is pulled in from `resolveCompiler` in
// `packages/hardhat-core/src/internal/core/config/config-resolution.ts`
//
// In v2 the config loading sets the default values that will be passed
// to the compiler. I am pulling it to here for the moment to keep
// the build system encapsulated.
result.settings.optimizer = {
enabled: false,
runs: 200,
...result.settings.optimizer,
};

if (result.settings.outputSelection === undefined) {
result.settings.outputSelection = {};
}

for (const [file, contractSelection] of Object.entries(
defaultSolcOutputSelection,
)) {
if (result.settings.outputSelection[file] === undefined) {
result.settings.outputSelection[file] = {};
}

for (const [contract, outputs] of Object.entries(contractSelection)) {
if (result.settings.outputSelection[file][contract] === undefined) {
result.settings.outputSelection[file][contract] = [];
}

for (const output of outputs) {
const includesOutput: boolean =
result.settings.outputSelection[file][contract].includes(output);

if (!includesOutput) {
result.settings.outputSelection[file][contract].push(output);
}
}
}
}

return result;
}
13 changes: 13 additions & 0 deletions v-next/hardhat-errors/src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export const ERROR_CATEGORIES: {
max: 999,
websiteTitle: "Network-helpers errors",
},
SOLIDITY_TESTS: {
min: 1000,
max: 1099,
websiteTitle: "Solidity tests errors",
},
};

export const ERRORS = {
Expand Down Expand Up @@ -685,4 +690,12 @@ This might be caused by using hardhat_reset and loadFixture calls in a testcase.
websiteDescription: "Error while reverting snapshot",
},
},
SOLIDITY_TESTS: {
BUILD_INFO_NOT_FOUND_FOR_CONTRACT: {
number: 1000,
messageTemplate: `Build info not found for contract {fqn}`,
websiteTitle: `Build info not found for contract`,
websiteDescription: `Build info not found for contract while compiling Solidity test contracts.`,
},
},
} as const;
2 changes: 2 additions & 0 deletions v-next/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"typescript-eslint": "7.7.1"
},
"dependencies": {
"@ignored/edr": "0.6.2-alpha.0",
"@ignored/hardhat-vnext-build-system": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-zod-utils": "workspace:^3.0.0-next.2",
Expand Down
Loading