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

chore: adds Anvil classes and migrates first specs from Ganache to Anvil #27246

Open
wants to merge 68 commits into
base: main
Choose a base branch
from

Conversation

seaona
Copy link
Contributor

@seaona seaona commented Sep 18, 2024

Description

This PR adds Anvil classes (Anvil, Anvil Seeder and Anvil Clients) and migrates 2 specs to use Anvil instead of Ganache.
The way it's done is as follows:

  • Anvil Class: designed to support the same methods as Ganache, like start, quit, getBalance, etc.
  • Anvil Clients: it uses Viem, as a layer of abstraction, which allow us to separate the RPC methods in Wallet, Test and Public Clients. Using Viem is chosen because this will help extend the L2 support, using Viem OP2 stack and the OP2 clients
  • Anvil Seeder: designed to support the same methods as Ganache Seeder, like deploying all the supported contracts we have
  • withFixtures: it now accepts an argument called localNode = 'ganache', defaulting to ganache. This way, in every spec we are able to specify which localNode we want to use. Now we can choose between anvil or ganache, but in the future, this design should be kept, so we can add Bitcoin and Solana, and use those nodes in their specific tests
  • Depending on the localNode chosen, we'll start Ganache or Anvil, as well as use its corresponding contract seeder

Note that some functionalitites are not yet supported like doubleAnvil. this will be done in separate PRs (see below plan), so this PR doesn't become too big.

Ganache Migration Phase:

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3321

Manual testing steps

  1. Run yarn locally --> in the post install script, anvil will be installed automatically, no need to do anything else
  2. Build a test wallet yarn start:test
  3. Run the migrated specs --> see they continue to work

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

Copy link

socket-security bot commented Sep 18, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: npm/@viem/[email protected], npm/[email protected]

View full report↗︎

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

@seaona seaona self-assigned this Sep 18, 2024
Copy link

Copy link

codecov bot commented Sep 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.02%. Comparing base (3e5c0a8) to head (38b4b80).
Report is 17 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #27246      +/-   ##
===========================================
+ Coverage    70.00%   70.02%   +0.02%     
===========================================
  Files         1445     1443       -2     
  Lines        50195    50165      -30     
  Branches     14041    14041              
===========================================
- Hits         35139    35127      -12     
+ Misses       15056    15038      -18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@metamaskbot
Copy link
Collaborator

Builds ready [38b4b80]
Page Load Metrics (1636 ± 45 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1501184916369545
domContentLoaded1491179616159043
load1501184716369445
domInteractive196834157
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 5.26 KiB (0.15%)
  • ui: 0 Bytes (0.00%)
  • common: 56.95 KiB (0.71%)


return { publicClient, testClient, walletClient };
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file will be expanded in the future, for when we want to add Optimism clients for L2 network support. See:

https://www.opviem.sh/

@@ -0,0 +1,149 @@
const { DEFAULT_FIXTURE_ACCOUNT, ENTRYPOINT } = require('../constants');
Copy link
Contributor Author

@seaona seaona Sep 20, 2024

Choose a reason for hiding this comment

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

this file supports the same functionality as ganache seeder, but adapted to viem (meaning using publicClient/walletClient/testClient for the different actions), so we are able to expand to L2's in the future with L2 clients

mnemonic:
'spread raise short crane omit tent fringe mandate neglect detail suspect cradle',
port: 8545,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This are the default network options. Since we have them defined here, there's no need for defaultAnvilOptions, so we don't need to pass anything in the spec files, when we want the default options (see spec files above).

Likewise, we have ganache options defined in the ganache file, we wouldn't need the defaultGanacheOptions (but it's implemented like this)

await this.#server.stop();
} catch (e) {
console.log('Caught error while closing Anvil network:', e);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are the same methods that we support on ganache, so functionality is preserved

davidmurdoch and others added 8 commits December 2, 2024 18:16
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
- Splits the logic of foundryup.ts file into functions, so they are
easier to test
- Adds unit tests
- Updates file extensions from `mts` to `ts`. The reason for that is
because otherwise the unit tests don't run out of the box and it was
suggested to change the config file and add a new dependency to make it
work, which seems unnecessary for the scoped task of installing foundry.
Also, this way we get lint out of the box too (instead of having to
update the lint rules to include mts files)

The unit tests can be run with `yarn test:unit
test/helpers/foundry/foundryup.test.ts`

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28833?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**
- Run unit tests: `yarn test:unit
test/helpers/foundry/foundryup.test.ts`
- Install default (anvil with checksum verification) `yarn foundryup`
- Install forge and cast - it should skip the checksum verification
`yarn foundryup -b forge -b cast`
- See commands `yarn foundryup --help`
- Clean cache before installing `yarn foundryup cache clean`
- Pass alternative repo `yarn foundryup --repo alternative-fork/foundry`



## **Screenshots/Recordings**


![Screenshot from 2024-12-10
11-47-37](https://github.com/user-attachments/assets/88893978-aa78-4bf1-b2bb-e17ab3d6748e)


## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: David Murdoch <[email protected]>
@seaona seaona changed the base branch from main to foundryup January 24, 2025 16:12
@seaona seaona changed the base branch from foundryup to main January 24, 2025 16:14

// Wait for balance to load
await driver.delay(500);

await driver.clickElement('[data-testid="eth-overview-send"]');
await driver.clickElement({ text: 'Account 1', tag: 'button' });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a bug in the test. We are supposed to test a send to a multisig contract, but here we selected the account 1 as recipient. Now this is fixed

@seaona seaona changed the base branch from main to foundryup January 26, 2025 10:32
@seaona seaona changed the base branch from foundryup to main January 26, 2025 10:34
@metamaskbot
Copy link
Collaborator

Builds ready [529314b]
Page Load Metrics (1508 ± 73 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint46820141453270130
domContentLoaded13311990148814369
load13362018150815273
domInteractive2389422211
backgroundConnect9154233115
firstReactRender1578482512
getState413621
initialActions01000
loadScripts9381468108012258
setupStore76013157
uiStartup14912444171219996
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: -583 Bytes (-0.01%)

@seaona seaona marked this pull request as ready for review January 27, 2025 07:43
@seaona seaona requested review from a team as code owners January 27, 2025 07:43
@seaona
Copy link
Contributor Author

seaona commented Jan 27, 2025

@SocketSecurity ignore npm/@viem/[email protected] npm/[email protected]

ℹ️ Viem is used in e2e only with Anvil local network

@seaona seaona changed the title chore: ganache migration base setup chore: adds Anvil classes and migrates first specs from Ganache to Anvil Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-qa Relating to QA work (Quality Assurance) team-extension-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants