Skip to content

Commit

Permalink
Merge pull request #5787 from NomicFoundation/feature/port-hh-ethers
Browse files Browse the repository at this point in the history
Port 'hardhat-ethers' plugin from V2 to V3
  • Loading branch information
ChristopherDedominici authored Oct 3, 2024
2 parents 32b867e + 5a170ac commit 929ccb5
Show file tree
Hide file tree
Showing 54 changed files with 8,050 additions and 0 deletions.
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@ignored/hardhat-vnext": "2.0.0",
"@ignored/hardhat-vnext-build-system": "2.0.0",
"@ignored/hardhat-vnext-errors": "2.0.0",
"@ignored/hardhat-vnext-ethers": "2.0.0",
"@ignored/hardhat-vnext-keystore": "2.0.0",
"@ignored/hardhat-vnext-network-helpers": "2.0.0",
"@ignored/hardhat-vnext-node-test-reporter": "2.0.0",
Expand Down
79 changes: 79 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 2 additions & 0 deletions v-next/example-project/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import HardhatMochaTestRunner from "@ignored/hardhat-vnext-mocha-test-runner";
import HardhatKeystore from "@ignored/hardhat-vnext-keystore";
import { viemScketchPlugin } from "./viem-scketch-plugin.js";
import hardhatNetworkHelpersPlugin from "@ignored/hardhat-vnext-network-helpers";
import hardhatEthersPlugin from "@ignored/hardhat-vnext-ethers";

const exampleEmptyTask = emptyTask("empty", "An example empty task").build();

Expand Down Expand Up @@ -120,6 +121,7 @@ const config: HardhatUserConfig = {
],
plugins: [
pluginExample,
hardhatEthersPlugin,
HardhatKeystore,
// HardhatMochaTestRunner,
// if testing node plugin, use the following line instead
Expand Down
1 change: 1 addition & 0 deletions v-next/example-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"devDependencies": {
"@ignored/hardhat-vnext": "workspace:^3.0.0-next.3",
"@ignored/hardhat-vnext-ethers": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-keystore": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-mocha-test-runner": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-network-helpers": "workspace:^3.0.0-next.2",
Expand Down
18 changes: 18 additions & 0 deletions v-next/example-project/scripts/hardhat-ethers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* How to run this script:
* 1) Start a Hardhat V2 node (until the V3 node is ready)
* 3) Run this script with `npx hardhat run scripts/hardhat-ethers.ts`.
*/

import hre from "@ignored/hardhat-vnext";

const { ethers } = await hre.network.connect();

// ethers functionalities
ethers.isAddress("0x1234567890123456789012345678901234567890");

// ethers.Provider
await ethers.provider.getBlockNumber();

// Hardhat helper methods
await ethers.getSigners();
3 changes: 3 additions & 0 deletions v-next/example-project/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
},
{
"path": "../hardhat-keystore"
},
{
"path": "../hardhat-ethers"
}
]
}
93 changes: 93 additions & 0 deletions v-next/hardhat-errors/src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export const ERROR_CATEGORIES: {
max: 1099,
websiteTitle: "Solidity tests errors",
},
ETHERS: {
min: 1100,
max: 1199,
websiteTitle: "Ethers errors",
},
};

export const ERRORS = {
Expand Down Expand Up @@ -698,4 +703,92 @@ This might be caused by using hardhat_reset and loadFixture calls in a testcase.
websiteDescription: `Build info not found for contract while compiling Solidity test contracts.`,
},
},
ETHERS: {
METHOD_NOT_IMPLEMENTED: {
number: 1100,
messageTemplate: `Method "{method}" is not implemented`,
websiteTitle: "Method not implemented",
websiteDescription: "Method not implemented",
},
EVENT_NOT_SUPPORTED: {
number: 1101,
messageTemplate: `Event "{event}" is not supported`,
websiteTitle: "Event not supported",
websiteDescription: "Event not supported",
},
ACCOUNT_INDEX_OUT_OF_RANGE: {
number: 1102,
messageTemplate: `Tried to get account with index {accountIndex} but there are only {accountsLength} accounts`,
websiteTitle: "Account index out of range",
websiteDescription: "Account index out of range",
},
BROADCASTED_TX_DIFFERENT_HASH: {
number: 1103,
messageTemplate: `Expected broadcasted transaction to have hash "{txHash}", but got "{broadcastedTxHash}"`,
websiteTitle: "Broadcasted transaction hash mismatch",
websiteDescription: "Broadcasted transaction hash mismatch",
},
CANNOT_GET_ACCOUNT: {
number: 1104,
messageTemplate: `Cannot get account with address "{address}"`,
websiteTitle: "Cannot get account",
websiteDescription: "Cannot get account",
},
INVALID_BLOCK_TAG: {
number: 1105,
messageTemplate: `Invalid block tag "{blockTag}"`,
websiteTitle: "Invalid block tag",
websiteDescription: "Invalid block tag",
},
INVALID_ARTIFACT_FOR_FACTORY: {
number: 1106,
messageTemplate:
"You are trying to create a contract factory from an artifact, but you have not passed a valid artifact parameter.",
websiteTitle: "Invalid artifact for contract factory creation",
websiteDescription: "Invalid artifact for contract factory creation",
},
INVALID_ABSTRACT_CONTRACT_FOR_FACTORY: {
number: 1107,
messageTemplate: `You are trying to create a contract factory for the contract "{contractName}", which is abstract and can't be deployed. If you want to call a contract using "{contractName}" as its interface use the "getContractAt" function instead.`,
websiteTitle: "Invalid abstract contract for contract factory creation",
websiteDescription:
"Invalid abstract contract for contract factory creation",
},
INVALID_ADDRESS_TO_LINK_CONTRACT_TO_LIBRARY: {
number: 1108,
messageTemplate: `You tried to link the contract "{contractName}" with the library "{linkedLibraryName}", but you provided this invalid address: {resolvedAddress}`,
websiteTitle: "Invalid address to link contract",
websiteDescription: "Invalid address to link contract",
},
LIBRARY_NOT_AMONG_CONTRACT_LIBRARIES: {
number: 1109,
messageTemplate: `You tried to link the contract "{contractName}" with the library "{linkedLibraryName}", which is not one of its libraries. Detailed message: {detailedMessage}`,
websiteTitle: "Library is not one of the contract libraries",
websiteDescription: "Library is not one of the contract libraries",
},
AMBIGUOUS_LIBRARY_NAME: {
number: 1110,
messageTemplate: `The library name "{linkedLibraryName}" is ambiguous for the contract "{contractName}". It may resolve to one of the following libraries: "{matchingNeededLibrariesFQNs}". To fix this, choose one of these fully qualified library names and replace where appropriate.`,
websiteTitle: "Ambiguous library name",
websiteDescription: "Ambiguous library name",
},
REFERENCE_TO_SAME_LIBRARY: {
number: 1111,
messageTemplate: `The library names "{linkedLibraryName1}" and "{linkedLibraryName2}" refer to the same library and were given as two separate library links. Remove one of them and review your library links before proceeding.`,
websiteTitle: "Reference to same library",
websiteDescription: "Reference to same library",
},
MISSING_LINK_FOR_LIBRARY: {
number: 1112,
messageTemplate: `The contract "{contractName}" is missing links for the following libraries: "{missingLibraries}". Learn more about linking contracts at (https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-ethers#library-linking).`,
websiteTitle: "Missing links for library",
websiteDescription: "Missing links for library",
},
UNSUPPORTED_TYPE_FOR_DEEP_COPY: {
number: 1113,
messageTemplate: `The value "{value}" with type "{type}" is not supported by the deepCopy function.`,
websiteTitle: "Unsupported type for deep copy",
websiteDescription: "Unsupported type for deep copy",
},
},
} as const;
3 changes: 3 additions & 0 deletions v-next/hardhat-ethers/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { createConfig } = require("../../config-v-next/eslint.cjs");

module.exports = createConfig(__filename);
5 changes: 5 additions & 0 deletions v-next/hardhat-ethers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Node modules
/node_modules

# Compilation output
/dist
4 changes: 4 additions & 0 deletions v-next/hardhat-ethers/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules
/dist
/coverage
CHANGELOG.md
9 changes: 9 additions & 0 deletions v-next/hardhat-ethers/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.
25 changes: 25 additions & 0 deletions v-next/hardhat-ethers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# hardhat-ethers

[Hardhat](https://hardhat.org) plugin for integration with [ethers.js](https://github.com/ethers-io/ethers.js/).

### Usage

```ts
const { ethers } = await hre.network.connect();

// ethers functionalities
ethers.isAddress("0x1234567890123456789012345678901234567890");

// ethers.Provider
await ethers.provider.getBlockNumber();

// Hardhat helper methods
await ethers.getSigners();
```

### Tests

Temporary solution to run manual tests until the V3 node is ready.

1. Start a node in Hardhat V2: `npx hardhat node`
2. Run the tests: `pnpm test:tmp`
76 changes: 76 additions & 0 deletions v-next/hardhat-ethers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@ignored/hardhat-vnext-ethers",
"version": "3.0.0-next.2",
"description": "Hardhat plugin for ethers",
"homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-ethers",
"repository": {
"type": "git",
"url": "https://github.com/NomicFoundation/hardhat",
"directory": "v-next/ethers"
},
"author": "Nomic Foundation",
"license": "MIT",
"type": "module",
"exports": {
".": "./dist/src/index.js",
"./types": "./dist/src/types.js"
},
"keywords": [
"ethereum",
"smart-contracts",
"hardhat",
"ethers.js"
],
"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=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"test:tmp": "node --import tsx/esm ./run-tests.ts",
"test:only": "node --import tsx/esm --test --test-only --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"test:coverage": "c8 --reporter html --reporter text --all --exclude test --exclude src/internal/types.ts --exclude src/internal/ui/direct-user-interruption-manager.ts --src src node --import tsx/esm --test --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"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": {
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
"@nomicfoundation/hardhat-test-utils": "workspace:^",
"@types/debug": "^4.1.4",
"@types/node": "^20.14.9",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"c8": "^9.1.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-only-tests": "3.1.0",
"expect-type": "^0.19.0",
"prettier": "3.2.5",
"rimraf": "^5.0.5",
"tsx": "^4.11.0",
"typescript": "~5.5.0",
"typescript-eslint": "7.7.1"
},
"dependencies": {
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
"debug": "^4.1.1",
"ethers": "^6.13.2"
},
"peerDependencies": {
"@ignored/hardhat-vnext": "workspace:^3.0.0-next.2"
}
}
Loading

0 comments on commit 929ccb5

Please sign in to comment.