From 920302f0bb1e09e6ed41c063c827c9a2c620c2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n?= Date: Fri, 20 Dec 2024 16:46:00 +0100 Subject: [PATCH] test: send failing contract (#12802) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This PR is within the scope of the Quality Quest. We're including an e2e test case that send a failing contract in the test dApp. **Steps:** Given I am on the test dapp When I tap on the Send failing transaction button in the Failing Contract section Then the transaction bottom sheet should appear _And I should see a warning "this transaction will likely fail"_ <- This message is not present When I submit the transaction Then the transaction should appear in the transaction history ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [✓] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.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-mobile/blob/main/.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. --- e2e/pages/Browser/TestDApp.js | 11 +++ e2e/selectors/Browser/TestDapp.selectors.js | 1 + .../Transactions/ActivitiesView.selectors.js | 1 + .../send-failing-contract.spec.js | 77 +++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 e2e/specs/confirmations/send-failing-contract.spec.js diff --git a/e2e/pages/Browser/TestDApp.js b/e2e/pages/Browser/TestDApp.js index a9bc65d01d6..1a1f35cbf51 100644 --- a/e2e/pages/Browser/TestDApp.js +++ b/e2e/pages/Browser/TestDApp.js @@ -119,6 +119,13 @@ class TestDApp { ); } + get sendFailingTransactionButton() { + return Matchers.getElementByWebID( + BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID, + TestDappSelectorsWebIDs.SEND_FAILING_TRANSACTION_BUTTON_ID, + ); + } + get erc1155BatchTransferButton() { return Matchers.getElementByWebID( BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID, @@ -188,6 +195,10 @@ class TestDApp { await Gestures.tap(this.approveButtonText, 0); } + async tapSendFailingTransactionButton() { + await this.tapButton(this.sendFailingTransactionButton); + } + async tapERC1155BatchTransferButton() { await this.tapButton(this.erc1155BatchTransferButton); } diff --git a/e2e/selectors/Browser/TestDapp.selectors.js b/e2e/selectors/Browser/TestDapp.selectors.js index e0995aa10f0..f2449607808 100644 --- a/e2e/selectors/Browser/TestDapp.selectors.js +++ b/e2e/selectors/Browser/TestDapp.selectors.js @@ -13,5 +13,6 @@ export const TestDappSelectorsWebIDs = { SIGN_TYPE_DATA_V4: 'signTypedDataV4', ETHEREUM_SIGN: 'siwe', ADD_TOKENS_TO_WALLET_BUTTON: 'watchAssets', + SEND_FAILING_TRANSACTION_BUTTON_ID: 'sendFailingButton', BATCH_TRANSFER_ERC1155_BUTTON_ID: 'batchTransferFromButton', }; diff --git a/e2e/selectors/Transactions/ActivitiesView.selectors.js b/e2e/selectors/Transactions/ActivitiesView.selectors.js index 1aba946d5ec..b7e9c7f1fe5 100644 --- a/e2e/selectors/Transactions/ActivitiesView.selectors.js +++ b/e2e/selectors/Transactions/ActivitiesView.selectors.js @@ -10,6 +10,7 @@ export const ActivitiesViewSelectorsIDs = { export const ActivitiesViewSelectorsText = { CONFIRM_TEXT: enContent.transaction.confirmed, + FAILED_TEXT: enContent.transaction.failed, SMART_CONTRACT_INTERACTION: enContent.transactions.smart_contract_interaction, INCREASE_ALLOWANCE_METHOD: enContent.transactions.increase_allowance, SENT_COLLECTIBLE_MESSAGE_TEXT: enContent.transactions.sent_collectible, diff --git a/e2e/specs/confirmations/send-failing-contract.spec.js b/e2e/specs/confirmations/send-failing-contract.spec.js new file mode 100644 index 00000000000..dac0b112d01 --- /dev/null +++ b/e2e/specs/confirmations/send-failing-contract.spec.js @@ -0,0 +1,77 @@ +'use strict'; + +import { SmokeConfirmations } from '../../tags'; +import TestHelpers from '../../helpers'; +import { loginToApp } from '../../viewHelper'; + +import TabBarComponent from '../../pages/wallet/TabBarComponent'; +import TestDApp from '../../pages/Browser/TestDApp'; +import FixtureBuilder from '../../fixtures/fixture-builder'; +import { + withFixtures, + defaultGanacheOptions, +} from '../../fixtures/fixture-helper'; +import { SMART_CONTRACTS } from '../../../app/util/test/smart-contracts'; +import { ActivitiesViewSelectorsText } from '../../selectors/Transactions/ActivitiesView.selectors'; +import Assertions from '../../utils/Assertions'; +import { mockEvents } from '../../api-mocking/mock-config/mock-events'; + +describe(SmokeConfirmations('Failing contracts'), () => { + const FAILING_CONTRACT = SMART_CONTRACTS.FAILING; + + beforeAll(async () => { + jest.setTimeout(150000); + await TestHelpers.reverseServerPort(); + }); + + it('sends a failing contract transaction', async () => { + + const testSpecificMock = { + GET: [ + mockEvents.GET.suggestedGasFeesApiGanache + ], + }; + await withFixtures( + { + dapp: true, + fixture: new FixtureBuilder() + .withGanacheNetwork() + .withPermissionControllerConnectedToTestDapp() + .build(), + restartDevice: true, + ganacheOptions: defaultGanacheOptions, + smartContract: FAILING_CONTRACT, + testSpecificMock, + }, + async ({ contractRegistry }) => { + const failingAddress = await contractRegistry.getContractAddress( + FAILING_CONTRACT, + ); + await loginToApp(); + + // Navigate to the browser screen + await TabBarComponent.tapBrowser(); + await TestDApp.navigateToTestDappWithContract({ + contractAddress: failingAddress, + }); + + // Send a failing transaction + await TestDApp.tapSendFailingTransactionButton(); + await TestHelpers.delay(3000); + + await TestDApp.tapConfirmButton(); + + // Navigate to the activity screen + await TabBarComponent.tapActivity(); + + // Assert the failed transaction is displayed + await Assertions.checkIfTextIsDisplayed( + ActivitiesViewSelectorsText.SMART_CONTRACT_INTERACTION + ); + await Assertions.checkIfTextIsDisplayed( + ActivitiesViewSelectorsText.FAILED_TEXT + ); + }, + ); + }); +});