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: ganache migration base setup #27246

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft

Conversation

seaona
Copy link
Contributor

@seaona seaona commented Sep 18, 2024

Description

Ganache Migration Phase:

Open in GitHub Codespaces

Related issues

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

Manual testing steps

  1. Go to this page...

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

Copy link

socket-security bot commented Sep 18, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Network access npm/@viem/[email protected] 🚫
Network access npm/@viem/[email protected] 🚫

View full report↗︎

Next steps

What is network access?

This module accesses the network.

Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

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

sonarcloud bot commented Sep 18, 2024

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%)

@@ -1,4 +1,4 @@
import GanacheContractAddressRegistry from '../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../seeder/contract-address-registry';
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.

just a rename, as now it's used both with ganache and anvil - no functionality change

*/
class GanacheContractAddressRegistry {
class ContractAddressRegistry {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just a rename, as now it's used both with ganache and anvil - no functionality change

@@ -3,14 +3,14 @@ const { ContractFactory, Contract } = require('@ethersproject/contracts');

const { ENTRYPOINT, GANACHE_ACCOUNT } = require('../constants');
const { SMART_CONTRACTS, contractConfiguration } = require('./smart-contracts');
const GanacheContractAddressRegistry = require('./ganache-contract-address-registry');
const ContractAddressRegistry = require('./contract-address-registry');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just a rename, as now it's used both with ganache and anvil - no functionality change

@@ -18,11 +17,10 @@ describe('Send ETH', function () {
await withFixtures(
{
fixtures: new FixtureBuilder().build(),
ganacheOptions: defaultGanacheOptions,
title: this.test.fullTitle(),
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 spec is using anvil.
All tests that use defaultGanacheOptions, once migrated to anvil, won't need to pass defaultXYZOptions, since those will be already default in the anvil config, so we can remove this.

@@ -154,18 +150,17 @@ describe('Send ETH', function () {
await withFixtures(
{
fixtures: new FixtureBuilder().build(),
ganacheOptions: {
...defaultGanacheOptions,
networkOptions: {
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 spec is using anvil! When we need to pass custom network options, we can pass them and we can omit the default.
I've name the options with a generic name networkOptions

@@ -321,8 +313,7 @@ describe('Send ETH', function () {
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: {
...defaultGanacheOptions,
networkOptions: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same. This spec is using anvil

@@ -11,7 +11,6 @@ describe('Simple send eth', function (this: Suite) {
await withFixtures(
{
fixtures: new FixtureBuilder().build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
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 spec is using anvil


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

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 anvil (meaning using publicClient/walletClient/testClient for the different actions)

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

);
contractRegistry = ganacheSeeder.getContractRegistry();
if (smartContract) {
if (ganacheServer) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

once we have migrated all tests, we'll be able to remove this code block and use the below one with the AnvilSeeder

Copy link

sonarcloud bot commented Sep 20, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@metamaskbot
Copy link
Collaborator

Builds ready [a33e7ae]
Page Load Metrics (2019 ± 99 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint171025312010208100
domContentLoaded17022464197619292
load17122535201920699
domInteractive14146433115
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 5.26 KiB (0.13%)
  • ui: 0 Bytes (0.00%)
  • common: 56.95 KiB (0.70%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants