Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/brown-glasses-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Add ArtifactManager#getAllArtifactPaths
6 changes: 6 additions & 0 deletions .changeset/eight-corners-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@nomicfoundation/hardhat-typechain": patch
"hardhat": patch
---

Make typechain work when compiling a subset of the Solidity files
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

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

9 changes: 9 additions & 0 deletions v-next/hardhat-ethers/test/helpers/artifact-manager-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ export class MockArtifactManager implements ArtifactManager {
);
}

public async getAllArtifactPaths(): Promise<ReadonlySet<string>> {
throw new HardhatError(
HardhatError.ERRORS.CORE.INTERNAL.NOT_IMPLEMENTED_ERROR,
{
message: "Not implemented in MockArtifactManager",
},
);
}

public async getBuildInfoId(
_contractNameOrFullyQualifiedName: string,
): Promise<string | undefined> {
Expand Down
14 changes: 14 additions & 0 deletions v-next/hardhat-exposed-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Node modules
/node_modules

# Compilation output
/dist

# pnpm deploy output
/bundle

# test coverage output
coverage

# all the tmp folders in the fixture projects
/test/fixture-projects/tmp/
6 changes: 6 additions & 0 deletions v-next/hardhat-exposed-example/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
/dist
/coverage
CHANGELOG.md
/test/fixture-projects/**/artifacts
/test/fixture-projects/**/cache
9 changes: 9 additions & 0 deletions v-next/hardhat-exposed-example/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2024 Nomic Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
84 changes: 84 additions & 0 deletions v-next/hardhat-exposed-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# hardhat-exposed-example

A Hardhat plugin that generates exposed contract wrappers, allowing you to test internal functions in your Solidity contracts.

## What it does

When testing Solidity contracts, internal functions are not directly accessible from test code. This plugin automatically generates wrapper contracts that inherit from your original contracts, exposing internal functions so they can be called in tests.

For a contract like:

```solidity
contract MyContract {
function _internalHelper(uint256 x) internal pure returns (uint256) {
return x * 2;
}
}
```

The plugin generates:

```solidity
import "../contracts/MyContract.sol";

contract MyContractExposed is MyContract {
function internalHelper(uint256 x) internal pure returns (uint256) {
return _internalHelper(x);
}
}
```

You can then deploy `MyContractExposed` in your tests and call the internal function through inheritance.

## Installation

```bash
npm install hardhat-exposed-example
```

## Usage

Import the plugin in your Hardhat config and add it to the `plugins` array:

```typescript
import HardhatExposedExample from "hardhat-exposed-example";

export default {
plugins: [
// ... other plugins ...,
HardhatExposedExample,
],
};
```

The plugin hooks into the Solidity build process and automatically generates exposed contracts for all your Solidity files.

## Configuration

You can configure the output directory for generated contracts:

```typescript
// hardhat.config.ts
export default {
paths: {
exposedContracts: "exposed-contracts", // default
},
};
```

The path can be relative (resolved from project root) or absolute.

## Clean Behavior

When running `npx hardhat clean`, this plugin automatically deletes the `exposedContracts` directory along with all generated wrapper contracts.

This ensures that stale exposed contracts are removed when you clean your project. The directory will be regenerated on the next build.

## How it works

1. During the Solidity build, the plugin detects all contract definitions
2. For each contract (excluding npm libraries), it generates a wrapper contract
3. The wrapper inherits from the original contract, making internal functions accessible (TODO: the current generation is super basic)
4. Generated files are placed in the configured `exposedContracts` directory
5. The exposed contracts are compiled separately from your main contracts, but during the same build process
6. All the cache system and ts bindings generations still works for the exposed contracts.
3 changes: 3 additions & 0 deletions v-next/hardhat-exposed-example/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createConfig } from "../config/eslint.config.js";

export default createConfig(import.meta.filename);
60 changes: 60 additions & 0 deletions v-next/hardhat-exposed-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "hardhat-exposed-example",
"private": true,
"version": "3.0.0",
"description": "hardhat-exposed-example",
"homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-exposed-example",
"repository": {
"type": "git",
"url": "https://github.com/NomicFoundation/hardhat",
"directory": "v-next/hardhat-exposed-example"
},
"author": "Nomic Foundation",
"license": "MIT",
"type": "module",
"types": "dist/src/index.d.ts",
"exports": {
".": "./dist/src/index.js"
},
"keywords": [
"ethereum",
"smart-contracts",
"hardhat"
],
"scripts": {
"lint": "pnpm prettier --check && pnpm eslint",
"lint:fix": "pnpm prettier --write && pnpm eslint --fix",
"eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"prettier": "prettier \"**/*.{ts,js,md,json}\"",
"test": "node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"test:only": "node --import tsx/esm --test --test-only --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"test:coverage": "c8 --reporter html --reporter text --all --exclude test --exclude \"src/**/{types,type-extensions}.ts\" --src src node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"pretest": "pnpm build",
"pretest:only": "pnpm build",
"build": "tsc --build .",
"prepublishOnly": "pnpm build",
"clean": "rimraf dist"
},
"files": [
"dist/src/",
"src/",
"CHANGELOG.md",
"LICENSE",
"README.md"
],
"devDependencies": {
"@nomicfoundation/hardhat-node-test-reporter": "workspace:^3.0.2",
"@types/node": "^22.0.0",
"c8": "^9.1.0",
"eslint": "9.25.1",
"expect-type": "^1.2.1",
"hardhat": "workspace:^3.1.5",
"prettier": "3.2.5",
"rimraf": "^5.0.5",
"tsx": "^4.19.3",
"typescript": "~5.8.0"
},
"peerDependencies": {
"hardhat": "workspace:^3.1.5"
}
}
Loading