Skip to content

Commit

Permalink
chore: Address derived from SRP (#12528)
Browse files Browse the repository at this point in the history
## **Description**

Added an assertion that the selected address would be the same as the
one derived from the SRP


## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **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.
  • Loading branch information
tommasini authored Dec 3, 2024
1 parent b2f9eec commit 1a0dc3b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { render } from '@testing-library/react-native';

import AesCryptoTestForm from './AesCryptoTestForm';

jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useSelector: jest.fn(),
}));

jest.mock('@react-navigation/native', () => {
const actualReactNavigation = jest.requireActual('@react-navigation/native');
return {
Expand Down
20 changes: 19 additions & 1 deletion app/components/Views/AesCryptoTestForm/AesCryptoTestForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useCallback } from 'react';
import { SafeAreaView, ScrollView } from 'react-native';
import { SafeAreaView, ScrollView, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';

import {
Expand All @@ -19,7 +19,13 @@ import {
aesCryptoFormResponses,
aesCryptoFormButtons,
aesCryptoFormScrollIdentifier,
accountAddress,
} from '../../../../e2e/selectors/AesCrypto.selectors';
import Text, {
TextVariant,
} from '../../../component-library/components/Texts/Text';
import { selectSelectedInternalAccountFormattedAddress } from '../../../selectors/accountsController';
import { useSelector } from 'react-redux';

const AesCryptoTestForm = () => {
const navigation = useNavigation();
Expand All @@ -35,6 +41,10 @@ const AesCryptoTestForm = () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [keyEncryptedData, setKeyEncryptedData] = useState<any>();

const selectedFormattedAddress = useSelector(
selectSelectedInternalAccountFormattedAddress,
);

useEffect(() => {
const encryptorInstance = new Encryptor({
keyDerivationOptions: DERIVATION_OPTIONS_DEFAULT_OWASP2023,
Expand Down Expand Up @@ -136,6 +146,14 @@ const AesCryptoTestForm = () => {
return (
<ScrollView testID={aesCryptoFormScrollIdentifier}>
<SafeAreaView style={styles.container}>
<View style={styles.container}>
<Text variant={TextVariant.HeadingSM} style={styles.formTitle}>
Current selected address
</Text>
<Text variant={TextVariant.HeadingSM} testID={accountAddress}>
{selectedFormattedAddress}
</Text>
</View>
<TestForm
title={strings('aes_crypto_test_form.generate_random_salt')}
buttonLabel={strings('aes_crypto_test_form.generate')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,44 @@ exports[`AesCryptoTestForm renders correctly 1`] = `
}
}
>
<View
style={
{
"paddingHorizontal": 15,
}
}
>
<Text
accessibilityRole="text"
style={
{
"color": "#141618",
"fontFamily": "EuclidCircularB-Bold",
"fontSize": 16,
"fontWeight": "700",
"letterSpacing": 0,
"lineHeight": 24,
"paddingVertical": 5,
}
}
>
Current selected address
</Text>
<Text
accessibilityRole="text"
style={
{
"color": "#141618",
"fontFamily": "EuclidCircularB-Bold",
"fontSize": 16,
"fontWeight": "700",
"letterSpacing": 0,
"lineHeight": 24,
}
}
testID="account-address"
/>
</View>
<RCTSafeAreaView
style={
{
Expand Down
6 changes: 6 additions & 0 deletions e2e/pages/Settings/AesCryptoTestForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
aesCryptoFormResponses,
aesCryptoFormButtons,
aesCryptoFormScrollIdentifier,
accountAddress,
} from '../../selectors/AesCrypto.selectors';
import Matchers from '../../utils/Matchers';
import Gestures from '../../utils/Gestures';
Expand All @@ -12,6 +13,11 @@ class AesCryptoTestForm {
return Matchers.getIdentifier(aesCryptoFormScrollIdentifier);
}

// Get account address
get accountAddress() {
return Matchers.getElementByID(accountAddress);
}

// Generate salt getters
get generateSaltBytesCountInput() {
return Matchers.getElementByID(aesCryptoFormInputs.saltBytesCountInput);
Expand Down
3 changes: 2 additions & 1 deletion e2e/selectors/AesCrypto.selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ const aesCryptoFormButtons = {
};

const aesCryptoFormScrollIdentifier = 'aes-crypto-form-scroll';

const accountAddress = 'account-address';
export {
aesCryptoFormInputs,
aesCryptoFormResponses,
aesCryptoFormButtons,
aesCryptoFormScrollIdentifier,
accountAddress,
};
6 changes: 6 additions & 0 deletions e2e/specs/accounts/aes/encryption-with-key.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ describe(
await SettingsView.scrollToAesCryptoButton();
await SettingsView.tapAesCryptoTestForm();

// Assert the address derived from SRP
await Assertions.checkIfElementToHaveText(
AesCryptoTestForm.accountAddress,
'0x76cf1CdD1fcC252442b50D6e97207228aA4aefC3',
);

const encryptionKey = await AesCryptoTestForm.generateEncryptionKey(
PASSWORD_ONE,
SALT_ONE,
Expand Down

0 comments on commit 1a0dc3b

Please sign in to comment.