-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Port 'hardhat-ethers' plugin from V2 to V3 #5787
Conversation
…ure/port-hh-ethers
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
hardhatTotal size of the bundle: List of dependencies (sorted by size)
|
@@ -0,0 +1,14 @@ | |||
import type { Artifact } from "@ignored/hardhat-vnext/types/artifacts"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the mocked artifacts mentioned in the PR description that currently do not have the source code that generates them, as discussed during the team meeting sync
this.#artifacts = new Map(); | ||
this.#artifactsPaths = new Map(); | ||
|
||
// An array of elements, where every element has an artifact name and artifact file name, is passed as argument during initialization and stored in the map. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the code I copied from the mocked ArtifactsManager PR. As mentioned in the PR description, I modified the logic slightly to suit my specific test scenarios
@@ -21,6 +21,7 @@ | |||
"./hre": "./dist/src/hre.js", | |||
"./plugins": "./dist/src/plugins.js", | |||
"./types/arguments": "./dist/src/types/arguments.js", | |||
"./types/artifacts": "./dist/src/types/artifacts.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a missing export for the artifacts
@@ -0,0 +1,73 @@ | |||
import type { HardhatEthersProvider } from "./internal/hardhat-ethers-provider/hardhat-ethers-provider.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need a more careful review of the types here, to be sure that they properly align with the V3 artifact implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double checked this, I think it looks good.
…ure/port-hh-ethers
// WARNING: this assumes that the hardhat node is being run in the | ||
// same project which might be wrong | ||
// TODO: enable when V3 is ready: blockGasLimit currently missing in networkConfig | ||
// gasLimit = networkConfig.blockGasLimit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the PR description, this is the property (blockGasLimit) that is currently not supported in networkConfig
|
||
export async function deepCopy<T = any>(value: T): Promise<T> { | ||
// The function 'deepClone' from 'hardhat-utils' cannot be used to replace this function, it won't properly clone | ||
// the value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add an explanation about the "why" to this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that dis code comes from v2, so keeping it makes sense. It's just not obvious why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment to better explain why deepClone
cannot be used to replace deepCopy
: 8348448
// depending on the config, we set a fixed gas limit for all transactions | ||
let gasLimit: bigint | undefined; | ||
|
||
if (networkName === "hardhat") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changed. Now this check would be netorkConfig.type !== "http"
.
I think we should create an issue to address this entire section in a follow up pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue to track it and I added the link to it in the issue at the beginning of the PR description
6eba448
to
8348448
Compare
v-next/hardhat-ethers/package.json
Outdated
"license": "MIT", | ||
"type": "module", | ||
"exports": { | ||
".": "./dist/src/index.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also have an export for the types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch. Done here
Short overview on how to use the package
Issue to track TODOs as soon as V3 node is ready
Link to issue
Questions: input needed
In the old v2 code there is a property called
blockGasLimit
that is assigned togasLimit
under specific conditions. But currently the newNetworkConfig
does not have this property. Is it gonna be supported in the future? Or this logic can be removed?in the code I kept the utils functions from
ethers
(e.g.:isHexString
). The reason behind this choice is to have the code logic as close as possible to the originalethers
library. Do we want to keep these ethers utils'functions or do we want to use the hardhat ones fromhardhat-utils
?the old code was using
sinon
, specifically in this file, to ensure that the listener functions were called correctly. I replaced sinon with the builtin nodeJS test runner mocks. Is this ok?the old V2 code had a few TODOs. I kept them, since this PR is only about porting the code from V2 to V3. Is this ok?
As mentioned in the design doc, the current implementation is using the
mocked ArtifactsManager
. For the tests, I copied the code of the mocked artifact manager from this test example and I modified it a bit, see here. Is this ok?Also, as mentioned in one of the team syncing calls, the artifacts used in the tests are currently stored in files but they just include the artifact properties and not the code that originated them. See the artifacts folder here. This is because we currently do not know if we're going to use this approach (in this case the artifacts should have additional information like the source code, etc.) or if we're going to use the old approach of compiling the code during the tests. Is it ok to keep the artifact in this format right now?
in the old V2 code the hardhat helpers were separated in functions, see here. In V3 I grouped them into a class (see here), to simplify the usage of the dependencies that before were imported from the HardhatRuntimeEnvironment. For example, before the functionalities available in the
hre
(like hre.artifacts ) had to be passed several times across functions, now they can be directly accessed viathis
. This approach does not affect how the methods are exposed to the end user. Is this ok?Notes
blockGasLimit
(if it's still gonna be supported - see the question asked in the previous section)To find these portions of code that require the missing V3 features you can search in the code for
TODO: enable when V3 is ready
.In the old V2 code there were a lot of disabled eslint rules. I removed most of them, but a few are required. In the code, they can be found by searching for
eslint-disable-next-line
. In theethers-utils.ts
file all of them have been kept, because almost all the methods in the file are a verbatim copy of theethers
methods. There are also a few disabled eslint rules in the tests, because there are tests that check errors that are not thrown by Hardhat, so there is a warning when using theassert.rejects
method provided by the nodeJS test runner.The old V2 files where quite long, but as agreed in one of the team syncing calls, in V3 we will keep the same file structure as in V2.
Tests
For an explanation on why we currently need a workaround to run the tests, please read the design doc here.
How to run the tests:
npx hardhat node
hardhat-ethers
package run the commandpnpm test:tmp
If you want to run the tests using an INFURA_URL, you can set the env variable INFURA_URL to the desired URL. If the env variable is not set, the test will be skipped.