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: add wallet state injection and yarn start:with-state script #26222

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

seaona
Copy link
Contributor

@seaona seaona commented Jul 30, 2024

Description

With this PR, we add a new script that you can use to build the wallet in dev mode with a preloaded state.

Default Fixtures:

  • Run yarn start:with-state - should load a wallet with the SRP and password set in the metamaskrc file, with several controllers data (contacts, transactions, notifications...) defined in the fixtures-flags file.

Terminal Help:

  • Run yarn start:with-state --help to see the available fixture flags to customize

Screenshot from 2024-09-03 09-30-20

Custom Fixtures:

  • Pass any available fixture flag with your own value to customize the fixtures that will be injected into state. Ie yarn start:with-state --withAccounts=12 --withContacts=13
with-state-final.mp4

Open in GitHub Codespaces

Future Work:

This sets the base for adding and customizing more wallet state. We can expand this as much as we want. Here are the listed possible future tasks:

  • Add unapproved transactions
  • Add different kind of transactions (Send Token, Send NFT, Send Legacy etc)
  • Add unapproved signatures
  • Add read notifications
  • Add different kind of notifications (send, received..)

Related issues

Fixes:

Manual testing steps

Check main functionality:

  1. Add a PASSWORD and a TEST_SRP to your metamaskrc file
  2. Run yarn start:with-state
  3. Upload a fresh MM -- see all the fixtures data is loaded

===============================
Check flags validation:

  1. Run yarn start:with-state --help
  2. See available fixtures
  3. Run with a non-existing flag -- should see an error
  4. Run with an invalid flag value type -- should see an error

===============================
Check custom fixtures:

  1. Apply your customized fixtures yarn start:with-state --withErc20Tokens=false --withXYZ=123 ...
  2. Upload a fresh MM -- see your wallet json state is applied

Screenshots/Recordings

Above

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.

@seaona seaona added the area-qa Relating to QA work (Quality Assurance) label Jul 30, 2024
Copy link

codecov bot commented Jul 30, 2024

Codecov Report

Attention: Patch coverage is 0% with 128 lines in your changes missing coverage. Please review.

Project coverage is 69.90%. Comparing base (c462fb8) to head (46bd784).

Files with missing lines Patch % Lines
app/scripts/fixtures/generate-wallet-state.js 0.00% 86 Missing ⚠️
app/scripts/fixtures/with-address-book.js 0.00% 15 Missing ⚠️
app/scripts/fixtures/with-unread-notifications.js 0.00% 10 Missing ⚠️
...pp/scripts/fixtures/with-confirmed-transactions.js 0.00% 9 Missing ⚠️
app/scripts/background.js 0.00% 3 Missing ⚠️
app/scripts/fixtures/with-erc20-tokens.js 0.00% 2 Missing ⚠️
app/scripts/fixtures/with-app-state.js 0.00% 1 Missing ⚠️
app/scripts/fixtures/with-networks.js 0.00% 1 Missing ⚠️
app/scripts/fixtures/with-preferences.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #26222      +/-   ##
===========================================
- Coverage    70.02%   69.90%   -0.12%     
===========================================
  Files         1443     1450       +7     
  Lines        50162    50249      +87     
  Branches     14039    14046       +7     
===========================================
  Hits         35124    35124              
- Misses       15038    15125      +87     

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

@metamaskbot
Copy link
Collaborator

Builds ready [dabdb0f]
Page Load Metrics (231 ± 230 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint783411145526
domContentLoaded96326147
load511668231478230
domInteractive96326147
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 349.72 KiB (10.11%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [3ffe5c6]
Page Load Metrics (155 ± 182 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint662351013718
domContentLoaded9169293617
load391796155379182
domInteractive9169293617
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 409.85 KiB (11.85%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [14c8f4c]
Page Load Metrics (89 ± 9 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint771481152010
domContentLoaded5012486209
load5712889189
domInteractive126731136
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 380.52 KiB (9.74%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

const { toHex } = require('@metamask/controller-utils');
const { NetworkStatus } = require('@metamask/network-controller');

const { CHAIN_IDS, NETWORK_TYPES } = require('../../shared/constants/network');
const { SMART_CONTRACTS } = require('./seeder/smart-contracts');
const { DAPP_URL, DAPP_ONE_URL, ACCOUNT_1 } = require('./helpers');
Copy link
Contributor Author

@seaona seaona Aug 19, 2024

Choose a reason for hiding this comment

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

instead of using the variables from the helpers file, we now use them from the constants file.
This change was needed in this PR since otherwise we get an error because the test environment variables in the helpers file are not defined (which is expected as we don't run any test environment with the wallet state functionality, but we do need the fixture-builder methods)

@@ -145,7 +145,7 @@ env:
# The unlock password
- PASSWORD: null
- TEST_SRP: null
- SKIP_ONBOARDING: null
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we changed this to a more generic name, as the feature is expanded to handle more wallet state data, than just skipping the onboarding

firstTimeState = { ...firstTimeState, ...skipOnboardingStateOverrides };
if (process.env.WITH_STATE) {
const stateOverrides = await generateWalletState();
firstTimeState = { ...firstTimeState, ...stateOverrides };
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we changed this variable names, as the skip onboarding feature is expanded to handle more wallet state data, than just skipping the onboarding

@metamaskbot
Copy link
Collaborator

Builds ready [e793540]
Page Load Metrics (74 ± 9 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint601291002010
domContentLoaded39112702010
load4611274189
domInteractive86726147
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 381.08 KiB (9.75%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@gauthierpetetin gauthierpetetin mentioned this pull request Aug 26, 2024
7 tasks
@seaona seaona marked this pull request as ready for review August 27, 2024 09:58
@seaona seaona requested a review from a team as a code owner August 27, 2024 09:58
@seaona seaona marked this pull request as draft August 27, 2024 10:50
@metamaskbot
Copy link
Collaborator

Builds ready [3e9ddff]
Page Load Metrics (75 ± 8 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint81148102157
domContentLoaded5113070189
load5813075178
domInteractive187429136
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 285.71 KiB (7.90%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@seaona seaona marked this pull request as ready for review September 3, 2024 12:28
@metamaskbot
Copy link
Collaborator

Builds ready [dd598ba]
Page Load Metrics (67 ± 7 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint6613189178
domContentLoaded3910664168
load4510667157
domInteractive9312352
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 285.6 KiB (7.90%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@chloeYue
Copy link
Contributor

chloeYue commented Sep 6, 2024

Hi @seaona , i tested on your branch, i encountered a issue that the ERC20 tokens are not displayed, not sure what's the problem, could you have a look? Thanks !

Screen.Recording.2024-09-06.at.14.25.50.mov

@seaona
Copy link
Contributor Author

seaona commented Sep 9, 2024

Hi @seaona , i tested on your branch, i encountered a issue that the ERC20 tokens are not displayed, not sure what's the problem, could you have a look? Thanks !

whoaa nice catch 😍 thank you @chloeYue ! the logic for substituting the account address was not correct, so it was appearing only in mine since the address was hardcoded. Now it should be fixed

@metamaskbot
Copy link
Collaborator

Builds ready [27c2962]
Page Load Metrics (1739 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15312084174213766
domContentLoaded15222077172313665
load15312086173913565
domInteractive169137188
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 289.18 KiB (8.48%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@chloeYue
Copy link
Contributor

Test ok on latest commit, ERC20 tokens are displayed:

Screenshot 2024-09-11 at 15 00 57

chloeYue
chloeYue previously approved these changes Sep 11, 2024
Copy link
Contributor

@chloeYue chloeYue left a comment

Choose a reason for hiding this comment

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

QA test OK! LGTM!

@hjetpoluru hjetpoluru self-requested a review September 11, 2024 19:50
hjetpoluru
hjetpoluru previously approved these changes Sep 11, 2024
Copy link
Contributor

@hjetpoluru hjetpoluru left a comment

Choose a reason for hiding this comment

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

LGTM!! Thanks @seaona this helps a lot for testing.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots

See analysis details on SonarCloud

@metamaskbot
Copy link
Collaborator

Builds ready [46bd784]
Page Load Metrics (1742 ± 86 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint23420691529564271
domContentLoaded14472048172517383
load14552059174218086
domInteractive1495392311
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 274.33 KiB (7.75%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@hjetpoluru hjetpoluru self-requested a review September 18, 2024 12:03
@seaona seaona requested a review from chloeYue September 18, 2024 13:28
@chloeYue
Copy link
Contributor

Test OK on the latest branch status !

@HowardBraham HowardBraham merged commit 978ed66 into develop Sep 18, 2024
77 of 78 checks passed
@HowardBraham HowardBraham deleted the wallet-state-injection branch September 18, 2024 16:19
@github-actions github-actions bot locked and limited conversation to collaborators Sep 18, 2024
@metamaskbot metamaskbot added the release-12.6.0 Issue or pull request that will be included in release 12.6.0 label Sep 18, 2024
@metamaskbot metamaskbot added release-12.5.0 Issue or pull request that will be included in release 12.5.0 and removed release-12.6.0 Issue or pull request that will be included in release 12.6.0 labels Sep 29, 2024
@metamaskbot
Copy link
Collaborator

Missing release label release-12.5.0 on PR. Adding release label release-12.5.0 on PR and removing other release labels(release-12.6.0), as PR was added to branch 12.5.0 when release was cut.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-qa Relating to QA work (Quality Assurance) release-12.5.0 Issue or pull request that will be included in release 12.5.0 team-extension-platform
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants