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 Hardhat Fork Functionality #3247

Merged
merged 10 commits into from
Jun 16, 2023
Merged

Add Hardhat Fork Functionality #3247

merged 10 commits into from
Jun 16, 2023

Conversation

0xDaedalus
Copy link
Contributor

@0xDaedalus 0xDaedalus commented Apr 4, 2023

Necessary environment variables:

USE_MAINNET_FORK
MAINNET_FORK_URL
MAINNET_FORK_CHAIN_ID

Latest build: extension-builds-3247 (as of Fri, 16 Jun 2023 18:14:21 GMT).

michalinacienciala added a commit that referenced this pull request May 8, 2023
This branch is a branch created from `mainnet-fork-triage` (PR #3247). It contains changes that allow for mainnet fork interactions.
The branch keeps the fork config in a yarn workspace.

In order to use it:
```
cd <root-folder>
nvm use 16
yarn install
yarn start #optional
```
And in other shell:
```
cd ci
yarn install
npx hardhat node --network hardhat
```
Sending txs, swapping, NFT discovery should work. No activity history.
Some strange assets listed.

Note that this is a WIP branch and there are some scripts and docs which should be removed before merging the branch to `main`.
michalinacienciala added a commit that referenced this pull request May 8, 2023
This branch is a branch created from `mainnet-fork-triage` (PR #3247). It contains changes that allow for mainnet fork interactions.
The branch keeps the fork config in a yarn workspace.

In order to use it:
```
cd <root-folder>
nvm use 16
yarn install
yarn start #optional
```
And in other shell:
```
cd ci
yarn install
npx hardhat node --network hardhat
```
Sending txs, swapping, NFT discovery should work. No activity history.
Some strange assets listed.

Note that this is a WIP branch and there are some scripts and docs which should be removed before merging the branch to `main`.
In this commit we create a Hardhat project that allows for running Taho
extension on a forked Mainnet. As part of this we're configuring a `hardhat`
network in the Hardhat config file. The fork will begin on a block specified in
the `blockNumber` parameter. The `url` parameter should hold an url to a
JSON-RPC node that's based on your personal Infura/Alchemy API key (e.g.
`https://mainnet.infura.io/v3/<key>`). The suggested value for `chainId` is
`1337`.
The steps to run the network are described in the README file.
Any actions performed on the `hardhat` network will only be applied locally,
they will not affect the real Mainnet network.
@michalinacienciala michalinacienciala marked this pull request as ready for review June 15, 2023 10:47
@michalinacienciala michalinacienciala requested a review from a team as a code owner June 15, 2023 10:47
@michalinacienciala michalinacienciala self-assigned this Jun 15, 2023
Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

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

I would love to try moving the hardhat dependency into the ci package and removing that package from workspaces given how much yarn.lock garbage it pulls in.

What I expect would happen:

  • Drop hardhat from top-level package.json and drop ci from the workspaces list there as well.
  • Add hardhat to ci/package.json.
  • git checkout main -- yarn.lock to revert yarn.lock to the latest main version.
  • yarn install
  • cd ci; yarn install
  • Then add ci/yarn.lock.

If any of this runs into issues I think we can merge as-is rather than wasting too much more time on it though.

ci/README.md Outdated
`yarn install`
`yarn start` (or `yarn build`)
`cd ci`
`npx hardhat node --network hardhat`
Copy link
Contributor

Choose a reason for hiding this comment

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

This can just be yarn hardhat node --network hardhat for simplicity fwiw.

forking: {
enabled: true,
url: process.env.CHAIN_API_URL || "",
blockNumber: parseInt(process.env.FORKING_BLOCK ?? "", 10),
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if this is NaN? (The result of parsing "".)

{
"name": "@tallyho/ci",
"version": "0.0.1",
"description": "Taho, the community owned and operated Web3 wallet: window provider is responsible for creating the in-page object for communication.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably update the second part to reference CI.

package.json Outdated
@@ -56,7 +56,8 @@
"background",
"provider-bridge",
"provider-bridge-shared",
"window-provider"
"window-provider",
"ci"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this listed as a workspace?

package.json Outdated
@@ -110,6 +111,7 @@
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"fork-ts-checker-webpack-plugin": "^6.3.2",
"hardhat": "^2.14.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

This dependency should probably be in the ci package, no? It's unused elsewhere afaict.

This instead of a workspace in the top-level project. This allows the ci
project to have its own dependencies, rather than polluting the lockfile
for the top-level extension project with the large amount of hardhat
dependencies.
Shadowfiend
Shadowfiend previously approved these changes Jun 16, 2023
Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

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

All righty let's rock and roll 🎸

@Shadowfiend
Copy link
Contributor

I guess also not clear to me is how much this differs from what's in dev-utils/local-chain… It feels like not at all… But we can reconcile later.

Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

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

Ok but this time though let's do it lol.

@Shadowfiend Shadowfiend merged commit 5456a9c into main Jun 16, 2023
@Shadowfiend Shadowfiend deleted the mainnet-fork-triage branch June 16, 2023 18:04
@jagodarybacka jagodarybacka mentioned this pull request Jun 22, 2023
jagodarybacka added a commit that referenced this pull request Jun 23, 2023
## What's Changed
* Repeater Connection: Forward requests to new default when default is
switched off during dApp connection flow by @Shadowfiend in
#3462
* Auto-Not-So-Matic: Fix two matic.network URLs to polygon.technology by
@Shadowfiend in #3483
* v0.38.0 by @kkosiorowska in
#3480
* Case Dismissed: Forcibly show DAppConnectionInfoBar popover on first
dApp connection by @Shadowfiend in
#3464
* Add Hardhat Fork Functionality by @0xDaedalus in
#3247
* Faded Jeans: Rename fadeIn class to fade_in by @Shadowfiend in
#3485
* Fix issue for discovery transaction hash by @kkosiorowska in
#3458
* Full Sweep: Drop the USE_UPDATED_SIGNING_UI feature flag by
@Shadowfiend in #3475
* Token Discovery - Remap redux asset balances by @hyphenized in
#3195
* Make specific warnings for adding custom asset by @kkosiorowska in
#3478
* Run NFTs e2e tests on a controlled wallet address by
@michalinacienciala in #3487
* v0.38.1 by @jagodarybacka in
#3484


**Full Changelog**:
v0.38.1...v0.39.0
Latest build:
[extension-builds-3496](https://github.com/tahowallet/extension/suites/13792957673/artifacts/764738599)
(as of Thu, 22 Jun 2023 14:27:32 GMT).
Shadowfiend added a commit that referenced this pull request Jul 17, 2023
This commit introduces automated E2E tests for asset transactions and
changes to
the testing framework needed for the tests to run successfully.

Changes to the framework include:
* The changes from #3247
which
added support for the hardhat functionality in the wallet's code.
* Creation of a Hardhat project in `./ci` folder. In the project we
configure a
`hardhat` network, which is a network that's a fork of Mainnet. The fork
begins
on the block specified in the `blockNumber` parameter in
`hardhat.config.ts`
(currently it's set to `17094516`, which is a starting point for our
fork-based
E2E tests). Any actions performed on the `hardhat` network will only be
applied
locally, they will not affect the real Mainnet network.
* Creation of the helper files and functions in `./e2e-tests/utils`.
* Modification of the GH Actions workflow. A new job (`e2e-tests-fork`)
is added
to the `build.yml` workflow. The job uses the build artifact from
earlier jobs,
installs the project, installs Hardhat and runs the local `hardhat`
network with
the Mainnet fork. Then it runs the Playwright E2E tests designed for
fork (the
ones with `-fork` suffix) and upload the test artifacts in case of tests
failure.
Also the old `e2e-tests` job gets modified - it's now running only those
E2E
tests which are not intended for running on fork (don't contain the
`-fork`
suffix.)

The following tests got added:
* User can send base asset (executed on forked Mainnet)
* User can open ERC-20 transfer from asset list and can reject the
transfer
  (executed on forked Mainnet)
* User can send ERC-20 from header (executed on forked Mainnet)
* User can send base asset (executed on Goerli testnet)
Most of the tests are run on Mainnet fork (to not waste the funds), but
one test
is run on Goerli - this is to verify the display of the transaction on
the
activity views (activity history doesn't work currently on fork).

TODO:

- [x] Change the settings of workflow artifacts accessibility (storing
of artifacts turned off until we switch to importing accounts using
JSON, not seed)
- [x] Change the `TEST_WALLET_RECOVERY_PHRASE` secret to the seed phrase
of the `testertesting.eth` wallet (**please don't do that before
previous TODOs are checked!**)
- [x] Once secrets are set, do final testing of the workflow
- [x] Clean the testing config from the workflow once tests are done

Latest build:
[extension-builds-3418](https://github.com/tahowallet/extension/suites/14283396113/artifacts/802860953)
(as of Thu, 13 Jul 2023 18:53:15 GMT).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants