Skip to content

Commit

Permalink
fix: fix old signature e2e by mocking launch darkly api (MetaMask#13002)
Browse files Browse the repository at this point in the history
## **Description**

Fix old signature pages e2e. by mocking launch darkly api.
## **Related issues**

Fixes: MetaMask/MetaMask-planning#3916

## **Manual testing steps**
NA

## **Screenshots/Recordings**
NA

## **Pre-merge author checklist**

- [X] 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).
- [X] I've completed the PR template to the best of my ability
- [X] I’ve included tests if applicable
- [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [X] 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.
  • Loading branch information
jpuri authored Jan 15, 2025
1 parent 2c8e3cb commit 1f2c1a2
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const useConfirmationRedesignEnabled = () => {
const isRedesignedEnabled = useMemo(
() =>
(confirmation_redesign as Record<string, string>)?.signatures &&
process.env.REDESIGNED_SIGNATURE_REQUEST === 'true' &&
// following condition will ensure that user is redirected to old designs is using QR scan aware hardware
!isSyncingQRHardware &&
!isSigningQRObject &&
Expand Down
55 changes: 36 additions & 19 deletions e2e/api-mocking/mock-config/mock-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,37 @@ export const mockEvents = {
securityAlertApiSupportedChains: {
urlEndpoint: 'https://security-alerts.api.cx.metamask.io/supportedChains',
response: [
'0xa4b1',
'0xa86a',
'0x2105',
'0x138d5',
'0x38',
'0xe708',
'0x1',
'0x1b6e6',
'0xcc',
'0xa',
'0x89',
'0x82750',
'0xaa36a7',
'0x144'
],
'0xa4b1',
'0xa86a',
'0x2105',
'0x138d5',
'0x38',
'0xe708',
'0x1',
'0x1b6e6',
'0xcc',
'0xa',
'0x89',
'0x82750',
'0xaa36a7',
'0x144',
],
responseCode: 200,
},

remoteFeatureFlags: {
urlEndpoint:
'https://client-config.api.cx.metamask.io/v1/flags?client=mobile&distribution=main&environment=dev',
response: [
{
mobileMinimumVersions: {
appMinimumBuild: 1243,
appleMinimumOS: 6,
androidMinimumAPIVersion: 21,
},
},
{ confirmation_redesign: { signatures: false } },
],
responseCode: 200,
},
},
Expand All @@ -77,7 +93,8 @@ export const mockEvents = {
},

securityAlertApiValidate: {
urlEndpoint: 'https://security-alerts.api.cx.metamask.io/validate/0xaa36a7',
urlEndpoint:
'https://security-alerts.api.cx.metamask.io/validate/0xaa36a7',
response: {
block: 20733513,
result_type: 'Benign',
Expand All @@ -93,9 +110,9 @@ export const mockEvents = {
{
from: '0x76cf1cdd1fcc252442b50d6e97207228aa4aefc3',
to: '0x50587e46c5b96a3f6f9792922ec647f13e6efae4',
value: '0x0'
}
]
value: '0x0',
},
],
},
responseCode: 201,
},
Expand Down
6 changes: 6 additions & 0 deletions e2e/api-specs/json-rpc-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ConfirmationsRejectRule from './ConfirmationsRejectionRule';
import { createDriverTransport } from './helpers';
import { BrowserViewSelectorsIDs } from '../selectors/Browser/BrowserView.selectors';
import { getGanachePort } from '../fixtures/utils';
import { mockEvents } from '../api-mocking/mock-config/mock-events';

const port = getGanachePort(8545, process.pid);
const chainId = 1337;
Expand Down Expand Up @@ -156,13 +157,18 @@ const main = async () => {
const server = mockServer(port, openrpcDocument);
server.start();

const testSpecificMock = {
GET: [mockEvents.GET.remoteFeatureFlags],
};

await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder().withGanacheNetwork().build(),
ganacheOptions: defaultGanacheOptions,
disableGanache: true,
restartDevice: true,
testSpecificMock,
},
async () => {
await loginToApp();
Expand Down
6 changes: 6 additions & 0 deletions e2e/specs/confirmations/signatures/ethereum-sign.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { SmokeConfirmations } from '../../../tags';
import TestHelpers from '../../../helpers';
import Assertions from '../../../utils/Assertions';
import { mockEvents } from '../../../api-mocking/mock-config/mock-events';

describe(SmokeConfirmations('Ethereum Sign'), () => {
beforeAll(async () => {
Expand All @@ -20,6 +21,10 @@ describe(SmokeConfirmations('Ethereum Sign'), () => {
});

it('Sign in with Ethereum', async () => {
const testSpecificMock = {
GET: [mockEvents.GET.remoteFeatureFlags],
};

await withFixtures(
{
dapp: true,
Expand All @@ -29,6 +34,7 @@ describe(SmokeConfirmations('Ethereum Sign'), () => {
.build(),
restartDevice: true,
ganacheOptions: defaultGanacheOptions,
testSpecificMock,
},
async () => {
await loginToApp();
Expand Down
6 changes: 6 additions & 0 deletions e2e/specs/confirmations/signatures/personal-sign.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import {
import { SmokeConfirmations } from '../../../tags';
import TestHelpers from '../../../helpers';
import Assertions from '../../../utils/Assertions';
import { mockEvents } from '../../../api-mocking/mock-config/mock-events';

describe(SmokeConfirmations('Personal Sign'), () => {
const testSpecificMock = {
GET: [mockEvents.GET.remoteFeatureFlags],
};

beforeAll(async () => {
jest.setTimeout(2500000);
await TestHelpers.reverseServerPort();
Expand All @@ -29,6 +34,7 @@ describe(SmokeConfirmations('Personal Sign'), () => {
.build(),
restartDevice: true,
ganacheOptions: defaultGanacheOptions,
testSpecificMock,
},
async () => {
await loginToApp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ describe(SmokeConfirmations('Security Alert API - Signature'), () => {

it('should sign typed message', async () => {
const testSpecificMock = {
GET: [mockEvents.GET.securityAlertApiSupportedChains],
GET: [
mockEvents.GET.securityAlertApiSupportedChains,
mockEvents.GET.remoteFeatureFlags,
],
POST: [
{
...mockEvents.POST.securityAlertApiValidate,
Expand All @@ -83,7 +86,10 @@ describe(SmokeConfirmations('Security Alert API - Signature'), () => {

it('should show security alert for malicious request', async () => {
const testSpecificMock = {
GET: [mockEvents.GET.securityAlertApiSupportedChains],
GET: [
mockEvents.GET.securityAlertApiSupportedChains,
mockEvents.GET.remoteFeatureFlags,
],
POST: [
{
...mockEvents.POST.securityAlertApiValidate,
Expand All @@ -108,6 +114,7 @@ describe(SmokeConfirmations('Security Alert API - Signature'), () => {
const testSpecificMock = {
GET: [
mockEvents.GET.securityAlertApiSupportedChains,
mockEvents.GET.remoteFeatureFlags,
{
urlEndpoint:
'https://static.cx.metamask.io/api/v1/confirmations/ppom/ppom_version.json',
Expand Down
6 changes: 6 additions & 0 deletions e2e/specs/confirmations/signatures/typed-sign-v3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import {
import { SmokeConfirmations } from '../../../tags';
import TestHelpers from '../../../helpers';
import Assertions from '../../../utils/Assertions';
import { mockEvents } from '../../../api-mocking/mock-config/mock-events';

describe(SmokeConfirmations('Typed Sign V3'), () => {
const testSpecificMock = {
GET: [mockEvents.GET.remoteFeatureFlags],
};

beforeAll(async () => {
jest.setTimeout(2500000);
await TestHelpers.reverseServerPort();
Expand All @@ -29,6 +34,7 @@ describe(SmokeConfirmations('Typed Sign V3'), () => {
.build(),
restartDevice: true,
ganacheOptions: defaultGanacheOptions,
testSpecificMock,
},
async () => {
await loginToApp();
Expand Down
6 changes: 6 additions & 0 deletions e2e/specs/confirmations/signatures/typed-sign-v4.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import {
import { SmokeConfirmations } from '../../../tags';
import TestHelpers from '../../../helpers';
import Assertions from '../../../utils/Assertions';
import { mockEvents } from '../../../api-mocking/mock-config/mock-events';

describe(SmokeConfirmations('Typed Sign V4'), () => {
const testSpecificMock = {
GET: [mockEvents.GET.remoteFeatureFlags],
};

beforeAll(async () => {
jest.setTimeout(2500000);
await TestHelpers.reverseServerPort();
Expand All @@ -29,6 +34,7 @@ describe(SmokeConfirmations('Typed Sign V4'), () => {
.build(),
restartDevice: true,
ganacheOptions: defaultGanacheOptions,
testSpecificMock,
},
async () => {
await loginToApp();
Expand Down
6 changes: 6 additions & 0 deletions e2e/specs/confirmations/signatures/typed-sign.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import {
import { SmokeConfirmations } from '../../../tags';
import TestHelpers from '../../../helpers';
import Assertions from '../../../utils/Assertions';
import { mockEvents } from '../../../api-mocking/mock-config/mock-events';

describe(SmokeConfirmations('Typed Sign'), () => {
const testSpecificMock = {
GET: [mockEvents.GET.remoteFeatureFlags],
};

beforeAll(async () => {
jest.setTimeout(2500000);
await TestHelpers.reverseServerPort();
Expand All @@ -29,6 +34,7 @@ describe(SmokeConfirmations('Typed Sign'), () => {
.build(),
restartDevice: true,
ganacheOptions: defaultGanacheOptions,
testSpecificMock,
},
async () => {
await loginToApp();
Expand Down
2 changes: 0 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ process.env.MM_SECURITY_ALERTS_API_ENABLED = 'true';
process.env.PORTFOLIO_VIEW = 'true';
process.env.SECURITY_ALERTS_API_URL = 'https://example.com';

process.env.REDESIGNED_SIGNATURE_REQUEST = 'true';

process.env.LAUNCH_DARKLY_URL =
'https://client-config.dev-api.cx.metamask.io/v1';

Expand Down

0 comments on commit 1f2c1a2

Please sign in to comment.