-
Notifications
You must be signed in to change notification settings - Fork 5.4k
test: MMQA-224 add test eth to weth #31278
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
Merged
+577
−211
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
012aa47
test: add test eth to weth
racitores 5c9b6c6
test: add send swap eth to weth
racitores 01e4a53
fix: lint and add details
racitores 32b129e
refactor
racitores be85b09
lint
racitores c38743b
fix comments
racitores 76f61ea
remove random value check
racitores 82e51e2
added delays
racitores 1e9354d
fix: flaky test `Settings - general tab validate "मानक हिन्दी" langua…
seaona f4c42ac
fix: cp-12.15.0 support link in EIP-5792 cancel request modal. (#31386)
jpuri 5ceca04
chore: Updating @metamask/user-operation-controller to version 31.0.0…
jpuri ad4fd0d
feat: fetch asset metadata on search (#31258)
micaelae 3f64a71
fix: cp-12.16.0 Follow up on the publishBatch hook (#31401)
dan437 b41ec14
fix: balance and token icons are unavailable when the bridge page is …
micaelae 97cb9b2
chore: add workflow_dispatch to security-code-scanner (#30620)
metamaskbot 28f844b
test: fix mocha vs jest type conflicts in test files (#31049)
dbrans 37a06db
revert(snaps): Revert breaking changes from #31058 (#31391)
GuillaumeRx 2bc6f53
fix: cp-12.15.0 remove sentry cdn url from sentry script (#31360)
davidmurdoch b63afec
test: rename double and triple ganache references (#31385)
seaona 0487ca6
chore: updating font family from euclid to centra (#31303)
georgewrmarshall b53283b
style: Update tabs color, hover and animations (#30907)
amandaye0h c22e1a1
fix: token name sort (#31302)
gambinish 2191b1d
style: Update color of values to text-default (#30886)
amandaye0h e6cfc5c
fix: cp-12.15.0 Prevent fullscreen UI from opening every startup (#31…
Gudahtt 1dad947
fix: should not auto-close notification window if loaded in a tab (#3…
dbrans 48eac16
chore: PR comments addressed
racitores 54ed212
Merge branch 'main' into add-swap-test-eth-to-weth
racitores 2f2995d
chore: PR comments addressed
racitores File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
297 changes: 297 additions & 0 deletions
297
test/e2e/tests/swap-send/swap-send-eth-with-loaded-state.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,297 @@ | ||
| import { Suite } from 'mocha'; | ||
| import { MockttpServer } from 'mockttp'; | ||
| import { | ||
| logInWithBalanceValidation, | ||
| openActionMenuAndStartSendFlow, | ||
| withFixtures, | ||
| } from '../../helpers'; | ||
| import FixtureBuilder from '../../fixture-builder'; | ||
| import HeaderNavbar from '../../page-objects/pages/header-navbar'; | ||
| import SettingsPage from '../../page-objects/pages/settings/settings-page'; | ||
| import AdvancedSettings from '../../page-objects/pages/settings/advanced-settings'; | ||
| import HomePage from '../../page-objects/pages/home/homepage'; | ||
| import { DEFAULT_FIXTURE_ACCOUNT } from '../../constants'; | ||
| import { NATIVE_TOKEN_SYMBOL, SwapSendPage } from './swap-send-test-utils'; | ||
|
|
||
| async function mockSwapQuotes(mockServer: MockttpServer) { | ||
| return [ | ||
| await mockServer | ||
| .forGet('https://swap.api.cx.metamask.io/token/1') | ||
| .thenCallback(() => ({ | ||
| statusCode: 200, | ||
| json: { | ||
| symbol: 'WETH', | ||
| type: 'erc20', | ||
| aggregators: [ | ||
| 'metamask', | ||
| 'aave', | ||
| 'coinGecko', | ||
| 'oneInch', | ||
| 'pmm', | ||
| 'zerion', | ||
| 'lifi', | ||
| 'socket', | ||
| 'squid', | ||
| 'sonarwatch', | ||
| 'uniswapLabs', | ||
| 'coinmarketcap', | ||
| 'rango', | ||
| ], | ||
| occurrences: 13, | ||
| iconUrl: | ||
| 'https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/weth.svg', | ||
| address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', | ||
| name: 'Wrapped Ether', | ||
| decimals: 18, | ||
| }, | ||
| })), | ||
| await mockServer | ||
| .forPost('https://transaction.api.cx.metamask.io/networks/1/getFees') | ||
| .thenCallback(() => ({ | ||
| statusCode: 200, | ||
| json: { | ||
| blockNumber: 22017409, | ||
| id: 'b6d9c5f3-4fee-4470-be1b-6c574fe61315', | ||
| txs: [ | ||
| { | ||
| cancelFees: [], | ||
| return: '0x', | ||
| status: 1, | ||
| gasUsed: 188186, | ||
| gasLimit: 241302, | ||
| fees: [ | ||
| { | ||
| maxFeePerGas: 6393950816, | ||
| maxPriorityFeePerGas: 1000000004, | ||
| gas: 241302, | ||
| balanceNeeded: 1542873120043734, | ||
| currentBalance: 30009434625664560, | ||
| error: '', | ||
| }, | ||
| ], | ||
| feeEstimate: 821886724082654, | ||
| baseFeePerGas: 3367416938, | ||
| maxFeeEstimate: 1542873119802432, | ||
| }, | ||
| ], | ||
| }, | ||
| })), | ||
|
|
||
| await mockServer | ||
| .forGet('https://swap.api.cx.metamask.io/v2/networks/1/quotes') | ||
| .thenCallback(() => ({ | ||
| statusCode: 200, | ||
| json: [ | ||
| { | ||
| aggregator: 'WETH', | ||
| aggregatorType: 'CONTRACT', | ||
| destinationToken: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', | ||
| sourceToken: '0x0000000000000000000000000000000000000000', | ||
| sourceAmount: '10000000000000000000', | ||
| destinationAmount: '10000000000000000000', | ||
| trade: { | ||
| data: '0xd0e30db0', | ||
| from: '0x5CfE73b6021E818B776b421B1c4Db2474086a7e1', | ||
| to: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', | ||
| value: '10000000000000000000', | ||
| }, | ||
| sender: '0x5CfE73b6021E818B776b421B1c4Db2474086a7e1', | ||
| recipient: '0x5CfE73b6021E818B776b421B1c4Db2474086a7e1', | ||
| error: null, | ||
| gasParams: { | ||
| maxGas: 500000, | ||
| averageGas: 300000, | ||
| estimatedRefund: 0, | ||
| gasMultiplier: 1, | ||
| }, | ||
| fee: 0, | ||
| approvalNeeded: null, | ||
| priceSlippage: null, | ||
| sourceTokenRate: 1, | ||
| destinationTokenRate: 0.9999285710414016, | ||
| }, | ||
| ], | ||
| })), | ||
|
|
||
| await mockServer | ||
| .forGet('https://swap.api.cx.metamask.io/networks/1') | ||
| .thenCallback(() => ({ | ||
| statusCode: 200, | ||
| json: { | ||
| active: true, | ||
| networkId: 1, | ||
| chainId: 1, | ||
| chainName: 'Ethereum Mainnet', | ||
| nativeCurrency: { | ||
| name: 'Ether', | ||
| symbol: 'ETH', | ||
| decimals: 18, | ||
| address: '0x0000000000000000000000000000000000000000', | ||
| }, | ||
| iconUrl: 'https://s3.amazonaws.com/airswap-token-images/ETH.png', | ||
| blockExplorerUrl: 'https://etherscan.io', | ||
| networkType: 'L1', | ||
| aggregators: [ | ||
| 'airswapV3', | ||
| 'airswapV4', | ||
| 'oneInchV4', | ||
| 'oneInchV5', | ||
| 'paraswap', | ||
| 'pmm', | ||
| 'zeroEx', | ||
| 'openOcean', | ||
| 'hashFlow', | ||
| 'wrappedNative', | ||
| 'kyberSwap', | ||
| 'airSwapV4_3', | ||
| 'hashFlowV3', | ||
| ], | ||
| refreshRates: { | ||
| quotes: 30, | ||
| quotesPrefetching: 30, | ||
| stxGetTransactions: 10, | ||
| stxBatchStatus: 1, | ||
| stxStatusDeadline: 160, | ||
| stxMaxFeeMultiplier: 2, | ||
| }, | ||
| parameters: { | ||
| refreshRates: { | ||
| quotes: 30, | ||
| quotesPrefetching: 30, | ||
| stxGetTransactions: 10, | ||
| stxBatchStatus: 1, | ||
| }, | ||
| stxStatusDeadline: 160, | ||
| stxMaxFeeMultiplier: 2, | ||
| }, | ||
| }, | ||
| })), | ||
| ]; | ||
| } | ||
|
|
||
| describe('Swap-Send ETH', function () { | ||
| describe('to non-contract address with data that matches swap data signature', function (this: Suite) { | ||
| it('submits a transaction successfully with max amount', async function () { | ||
| await withFixtures( | ||
| { | ||
| fixtures: new FixtureBuilder() | ||
| .withNetworkControllerOnMainnet() | ||
| .withTokensController({ | ||
| allTokens: { | ||
| '0x1': { | ||
| '0x5cfe73b6021e818b776b421b1c4db2474086a7e1': [ | ||
| { | ||
| address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', | ||
| symbol: 'WETH', | ||
| decimals: 18, | ||
| isERC721: false, | ||
| aggregators: [], | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }) | ||
| .build(), | ||
| title: this.test?.fullTitle(), | ||
| testSpecificMock: mockSwapQuotes, | ||
| localNodeOptions: [ | ||
| { | ||
| type: 'anvil', | ||
| options: { | ||
| chainId: 1, | ||
| hardfork: 'london', | ||
| loadState: | ||
| './test/e2e/seeder/network-states/swap-state/withSwapContracts.json', | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| async ({ driver }) => { | ||
| const swapSendPage = new SwapSendPage(driver); | ||
| await logInWithBalanceValidation(driver); | ||
|
|
||
seaona marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const homePage = new HomePage(driver); | ||
| await homePage.check_pageIsLoaded(); | ||
| await homePage.check_expectedTokenBalanceIsDisplayed('50', 'WETH'); | ||
| await homePage.check_expectedTokenBalanceIsDisplayed('25', 'ETH'); | ||
|
|
||
| // disable smart transactions | ||
| const headerNavbar = new HeaderNavbar(driver); | ||
| await headerNavbar.check_pageIsLoaded(); | ||
| await headerNavbar.openSettingsPage(); | ||
|
|
||
| const settingsPage = new SettingsPage(driver); | ||
| await settingsPage.check_pageIsLoaded(); | ||
| await settingsPage.clickAdvancedTab(); | ||
| const advancedSettingsPage = new AdvancedSettings(driver); | ||
| await advancedSettingsPage.check_pageIsLoaded(); | ||
| await advancedSettingsPage.toggleSmartTransactions(); | ||
| await settingsPage.closeSettingsPage(); | ||
|
|
||
| // START SWAP AND SEND FLOW | ||
| await openActionMenuAndStartSendFlow(driver); | ||
|
|
||
| await swapSendPage.fillRecipientAddressInput(DEFAULT_FIXTURE_ACCOUNT); | ||
| await swapSendPage.fillAmountInput('1'); | ||
|
|
||
| await swapSendPage.verifyMaxButtonClick( | ||
| ['ETH', 'ETH'], | ||
| ['24.99945808355143', '24.99945808355143'], | ||
| ); | ||
|
|
||
| await swapSendPage.fillAmountInput('10'); | ||
| await swapSendPage.verifyAssetSymbolsAndAmounts( | ||
| [NATIVE_TOKEN_SYMBOL, NATIVE_TOKEN_SYMBOL], | ||
| ['10', '10'], | ||
| ); | ||
|
|
||
| await swapSendPage.fillAmountInput('10'); | ||
|
|
||
| const ETH_WETH_TOKEN_INPUTS = [ | ||
| [NATIVE_TOKEN_SYMBOL, 'WETH'], | ||
| ['10', '10'], | ||
| ]; | ||
| const ETH_WETH_FIAT_INPUTS = [ | ||
| ['USD', 'USD'], | ||
| ['1,700.00', '1,701.09'], | ||
| ]; | ||
|
|
||
| await swapSendPage.clickOnAsset('WETH', 'dest'); | ||
| await swapSendPage.verifyAssetSymbolsAndAmounts( | ||
| ETH_WETH_TOKEN_INPUTS[0], | ||
| ETH_WETH_TOKEN_INPUTS[1], | ||
| ); | ||
|
|
||
| await swapSendPage.verifySwitchPrimaryCurrency( | ||
| ETH_WETH_TOKEN_INPUTS, | ||
| ETH_WETH_FIAT_INPUTS, | ||
| ); | ||
|
|
||
| await swapSendPage.verifyQuoteDisplay( | ||
| '1 ETH = 1 WETH', | ||
| '0.0129028 ETH', | ||
| '≈ $21.93', | ||
| ); | ||
|
|
||
| await swapSendPage.submitSwap(); | ||
| await swapSendPage.verifyHistoryEntry( | ||
| 'Send ETH as WETH', | ||
| 'Confirmed', | ||
| '-10 ETH', | ||
| '', | ||
| ); | ||
|
|
||
| await homePage.goToTokensTab(); | ||
| await homePage.check_expectedTokenBalanceIsDisplayed('60', 'WETH'); | ||
| // https://github.com/MetaMask/metamask-extension/issues/31427 | ||
| // await homePage.check_expectedTokenBalanceIsDisplayed( | ||
| // '14.99994', | ||
| // 'ETH', | ||
| // ); | ||
|
|
||
| driver.summarizeErrorsAndExceptions(); | ||
| }, | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.