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

test: Redesign Signature Decoding Simulation #13026

Merged
merged 92 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
87b746e
feat: Permit Simulation
digiwand Dec 6, 2024
60086e1
refactor: PermitSimulation const name
digiwand Dec 6, 2024
ae2a2cb
fix: label_change_type i18n
digiwand Dec 9, 2024
5b5d094
feat: add PermitSimulation metrics
digiwand Dec 9, 2024
dfc086f
feat: create ButtonPill component
digiwand Dec 10, 2024
d96f9aa
feat: PermitSimulation token value BottomModal
digiwand Dec 12, 2024
a665679
Merge branch 'main' into feat-permit-simulation
digiwand Dec 13, 2024
518e51d
feat: Add Permit Simulation to TypedSignV3V4 redesign
digiwand Dec 16, 2024
f069e37
refactor: cleanup
digiwand Dec 17, 2024
fe15f12
chore: update todo ValueDisplay shorten comment
digiwand Dec 17, 2024
6777319
refactor: update useGetTokenStandardAndDetails import
digiwand Dec 18, 2024
4bc90e0
fix: PermitSimulation changeType
digiwand Dec 18, 2024
b65adf3
test: PermitSimulation
digiwand Dec 18, 2024
a79f2cd
fix: useTrackERC20WithoutDecimalInformation should run once
digiwand Dec 18, 2024
a5d96ec
fix: include typedSignV4ConfirmationState for PermitSimulation test
digiwand Dec 18, 2024
05669d3
test: create PermitSimulationValueDisplay test
digiwand Dec 18, 2024
bcccb06
fix: TS lint signature util
digiwand Dec 19, 2024
22f754f
Merge branch 'main' into feat-permit-simulation
digiwand Jan 7, 2025
567fc66
fix: readd dep to useTrackERC20WithoutDecimalInformation
digiwand Jan 7, 2025
0c215c4
chore: update useTrackERC20WithoutDecimalInformation TS metricLocation
digiwand Jan 7, 2025
1683123
test: ValueDisplay test
digiwand Jan 7, 2025
79a4003
fix: test allow style param InfoAddress
digiwand Jan 7, 2025
aa43eb9
test:fix: OrderDetails allow undefined style param
digiwand Jan 7, 2025
8577591
test:fix: include InfoAddress undefined style param
digiwand Jan 7, 2025
d53035f
chore: ButtonPill pressed -> isPressed
digiwand Jan 7, 2025
2bdb950
build: mv ButtonPill files -> components-temp
digiwand Jan 7, 2025
1ffe22e
test: create confirmations/utils/signature test
digiwand Jan 9, 2025
779f36f
test: add parseTypedDataMessage tests
digiwand Jan 9, 2025
5852d87
test: add shortenString tests for skipCharacterInEnd + update TS
digiwand Jan 9, 2025
fce5367
Merge branch 'main' into feat-permit-simulation
digiwand Jan 11, 2025
f0cc923
build: mv permit simulation files
digiwand Jan 11, 2025
98d89c7
build: rn path Simulation/Permit -> Simulation/TypedSignPermit
digiwand Jan 11, 2025
666f11d
fix: Simulation/TypedSignPermit path
digiwand Jan 13, 2025
f2e16ef
build: mv Simulation Value Display
digiwand Jan 13, 2025
fb9e3ae
refactor: rn PermitSimulationValueDisplay ->
digiwand Jan 13, 2025
4e32c99
Merge branch 'main' into feat-permit-simulation
digiwand Jan 14, 2025
f99a239
refactor: rn onPressTokenValue -> handlePressTokenValue
digiwand Jan 14, 2025
2e75fb1
refactor: PermitSimulation use signatureRequest chain id instead of g…
digiwand Jan 14, 2025
3bfc4ae
Merge branch 'main' into feat-permit-simulation
digiwand Jan 14, 2025
b5a8372
test:fix: ValueDisplay update mock paths
digiwand Jan 14, 2025
72ba710
refactor: revert Address style param + wrap ValueDisplay address
digiwand Jan 14, 2025
9053d15
refactor: useGetTokenStandardAndDetails accept options param
digiwand Jan 14, 2025
ddfbfb0
feat: permit simulation include NetworkClientId to get token details
digiwand Jan 14, 2025
e89622c
fix: TypedSignPermit use networkClientId by chainID
digiwand Jan 14, 2025
ab0b8c2
fix: Simulation permit following use of useSignatureRequest hook
digiwand Jan 14, 2025
a415894
fix: rm unused useSelector import Permit simulation
digiwand Jan 14, 2025
97ad785
build: mv simulation code back into info
digiwand Jan 14, 2025
da11a11
Merge branch 'main' into feat-permit-simulation
digiwand Jan 14, 2025
c88eec4
Merge branch 'main' into feat-permit-simulation
digiwand Jan 15, 2025
cab0624
test:fix: mock paths after relocation Simulation files
digiwand Jan 15, 2025
2a6f66a
Merge branch 'main' into feat-permit-simulation
digiwand Jan 15, 2025
0505891
style: add alignItems: 'center' to flexRowTokenValueAndAddress
digiwand Jan 15, 2025
41c0cbd
refactor: add isRecognizedPermit SignatureRequest support
digiwand Jan 15, 2025
64d7415
refactor: configure decoding for SignatureController
digiwand Jan 15, 2025
770e80b
feat: add NativeValueDisplay component and update ValueDisplay component
digiwand Jan 15, 2025
95387ba
refactor: update type ApprovalRequestType to include decoding props
digiwand Jan 15, 2025
1dc8c13
feat: add Decoding Simulation components
digiwand Jan 15, 2025
724bcbe
fix: selectConversionRate optional param
digiwand Jan 15, 2025
b71c8ef
refactor: selectCurrencyRateControllerState optionalize showFiatOnTes…
digiwand Jan 15, 2025
2f8a2b4
fix: tslint
digiwand Jan 15, 2025
ad6945a
fix: replace Ramp/Box with View components
digiwand Jan 15, 2025
2cb0929
Merge branch 'main' into feat-decoding-simulation
digiwand Jan 15, 2025
4273dab
fix: Revoke en i18n casing
digiwand Jan 15, 2025
786ed46
fix: i18n en alphabetical ordering
digiwand Jan 15, 2025
7770519
fix: optional chainId selectConversionRate selector
digiwand Jan 15, 2025
b19b59c
refactor: format code Simulation
digiwand Jan 15, 2025
2c78752
refactor: revert selectConversionRate param updates + fix lint
digiwand Jan 15, 2025
f3c81b9
refactor: useTypesSignSimulationEnabled -> useTypedSignSimulationEnabled
digiwand Jan 15, 2025
9f96a79
refactor: update useTypedSignSimulationEnabled to use useSignatureReq…
digiwand Jan 15, 2025
43d7a0f
fix: mv DECODING_API_URL to AppConstants
digiwand Jan 16, 2025
af9e69b
fix: update isRecognizedPermit to check only signature request types
digiwand Jan 16, 2025
18999f8
fix: rm unused ApprovalRequest import
digiwand Jan 16, 2025
29fbf83
fix: revert ApprovalRequestType type update
digiwand Jan 16, 2025
f42522d
refactor: rm useMemo from ValueDisplay + add isNumberValue util
digiwand Jan 16, 2025
a083490
fix: update ValueDisplay disable ButtonPill when tokenId
digiwand Jan 16, 2025
00d6f09
revert: selectConversionRate optional chainId param
digiwand Jan 16, 2025
fb047c5
refactor: utilize new selectConversionRateByChainId in NativeValueDis…
digiwand Jan 16, 2025
28fcc62
revert: selectConversionRate 5th param
digiwand Jan 16, 2025
76ba380
test: CurrencyRateController#selectConversionRateByChainId
digiwand Jan 16, 2025
21ad733
refactor: non-default export useTypedSignSimulationEnabled
digiwand Jan 16, 2025
08030f0
fix: lint unused imports currencyRateController test
digiwand Jan 16, 2025
ccc001a
test: create TypedSignDecoded tests
digiwand Jan 16, 2025
add8c45
fix: lint paths
digiwand Jan 16, 2025
ee1d98d
refactor: remove duplicate NativeValueDisplay styles
digiwand Jan 16, 2025
95ffdf8
fix: NativeValueDisplay style names
digiwand Jan 16, 2025
155af9f
test: Create TypedSignV3V4Simulation tests + replace curly quote in i…
digiwand Jan 16, 2025
3d0038e
refactor: use ' ASCII standard single quote instead of curly quote
digiwand Jan 16, 2025
9c23f01
test: create Simulation NativeValueDisplay tests
digiwand Jan 16, 2025
064a40d
test: create Simulation Static tests
digiwand Jan 16, 2025
70ac787
refactor: format selection
digiwand Jan 16, 2025
da451db
test:fix: phrase ' quote
digiwand Jan 16, 2025
854fa84
Merge branch 'main' into feat-decoding-simulation-tests
digiwand Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Confirm', () => {
expect(getByText('Estimated changes')).toBeDefined();
expect(
getByText(
'Youre signing into a site and there are no predicted changes to your account.',
"You're signing into a site and there are no predicted changes to your account.",
),
).toBeDefined();
expect(getByText('Request from')).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('TypedSignV1', () => {
expect(getByText('Estimated changes')).toBeDefined();
expect(
getByText(
'Youre signing into a site and there are no predicted changes to your account.',
"You're signing into a site and there are no predicted changes to your account.",
),
).toBeDefined();
expect(getByText('Request from')).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import React from 'react';
import cloneDeep from 'lodash/cloneDeep';
import {
DecodingData,
DecodingDataChangeType,
DecodingDataStateChanges,
SignatureRequest,
} from '@metamask/signature-controller';
import useGetTokenStandardAndDetails from '../../../../../hooks/useGetTokenStandardAndDetails';
import { typedSignV4ConfirmationState } from '../../../../../../../../util/test/confirm-data-helpers';
import renderWithProvider from '../../../../../../../../util/test/renderWithProvider';
import { memoizedGetTokenStandardAndDetails } from '../../../../../utils/token';
import TypedSignV3V4Simulation from './Simulation';

jest.mock('../../../../../hooks/useGetTokenStandardAndDetails');

jest.mock('../../../../../../../../core/Engine', () => ({
context: {
NetworkController: {
findNetworkClientIdByChainId: () => 'mainnet',
},
},
}));

const stateChangesApprove = [
{
assetType: 'ERC20',
changeType: DecodingDataChangeType.Approve,
address: '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad',
amount: '12345',
contractAddress: '0x6b175474e89094c44da98b954eedeac495271d0f',
},
];

const mockState = (
mockStateChanges: DecodingDataStateChanges,
{
mockDecodingDataProps,
stubDecodingLoading = false,
}: {
mockDecodingDataProps?: Partial<DecodingData>;
stubDecodingLoading?: boolean;
} = {
mockDecodingDataProps: {},
stubDecodingLoading: false,
},
) => {
const clonedMockState = cloneDeep(typedSignV4ConfirmationState);
const request = clonedMockState.engine.backgroundState.SignatureController
.signatureRequests[
'fb2029e1-b0ab-11ef-9227-05a11087c334'
] as SignatureRequest;

request.decodingLoading = stubDecodingLoading;
request.decodingData = {
...mockDecodingDataProps,
stateChanges: mockStateChanges,
};

return clonedMockState;
};

describe('PermitSimulation', () => {
afterEach(() => {
jest.clearAllMocks();

/** Reset memoized function using getTokenStandardAndDetails for each test */
memoizedGetTokenStandardAndDetails?.cache?.clear?.();
});

it('renders DecodedSimulation loader if decodingLoading is true', async () => {
const { queryByTestId } = renderWithProvider(<TypedSignV3V4Simulation />, {
state: mockState(stateChangesApprove, {
stubDecodingLoading: true,
}),
});

expect(await queryByTestId('confirm-v3v4-simulation-loader')).toBeDefined();
});

it('renders DecodingSimulation with "Unavailable" if decoding data is empty', async () => {
const { getByText } = renderWithProvider(<TypedSignV3V4Simulation />, {
state: mockState([]),
});

expect(await getByText('Estimated changes')).toBeDefined();
expect(await getByText('Unavailable')).toBeDefined();
});

it('renders DecodingSimulation for permits', async () => {
(
useGetTokenStandardAndDetails as jest.MockedFn<
typeof useGetTokenStandardAndDetails
>
).mockReturnValue({
symbol: 'TST',
decimals: '4',
balance: undefined,
standard: 'ERC20',
decimalsNumber: 4,
});

const { getByText } = renderWithProvider(<TypedSignV3V4Simulation />, {
state: mockState(stateChangesApprove),
});

expect(await getByText('Estimated changes')).toBeDefined();
expect(await getByText('Spending cap')).toBeDefined();
expect(await getByText('1.235')).toBeDefined();
});

it('renders PermitSimulation if decoding api returns error', async () => {
(
useGetTokenStandardAndDetails as jest.MockedFn<
typeof useGetTokenStandardAndDetails
>
).mockReturnValue({
symbol: 'TST',
decimals: '2',
balance: undefined,
standard: 'ERC20',
decimalsNumber: 4,
});

const { getByText } = renderWithProvider(<TypedSignV3V4Simulation />, {
state: mockState([], {
mockDecodingDataProps: {
error: { message: 'some error', type: 'SOME_ERROR' },
} as Partial<DecodingData>,
}),
});

expect(await getByText('Estimated changes')).toBeDefined();
expect(await getByText('Spending cap')).toBeDefined();
expect(await getByText('0.3')).toBeDefined();
expect(
await getByText(
"You're giving the spender permission to spend this many tokens from your account.",
),
).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { Text } from 'react-native';
import { render } from '@testing-library/react-native';
import StaticSimulation from './Static';

const mockProps = {
title: 'Test Title',
titleTooltip: 'Test Tooltip',
description: 'Test Description',
simulationElements: <></>,
};

describe('StaticSimulation', () => {
it('renders correctly with basic props', () => {
const { getByText } = render(<StaticSimulation {...mockProps} />);

expect(getByText('Test Title')).toBeDefined();
expect(getByText('Test Description')).toBeDefined();
});

it('shows loader when isLoading is true', () => {
const { queryByTestId } = render(
<StaticSimulation {...mockProps} isLoading />,
);

expect(queryByTestId('confirm-v3v4-simulation-loader')).toBeDefined();
});

it('shows simulation elements when not loading', () => {
const simulationElements = <Text>Test Simulation</Text>;
const { getByText } = render(
<StaticSimulation
{...mockProps}
simulationElements={simulationElements}
isLoading={false}
/>,
);

expect(getByText('Test Simulation')).toBeDefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
import { strings } from '../../../../../../../../../../locales/i18n';
import { typedSignV4ConfirmationState } from '../../../../../../../../../util/test/confirm-data-helpers';
import renderWithProvider from '../../../../../../../../../util/test/renderWithProvider';
import TypedSignDecoded, { getStateChangeToolip, getStateChangeType, StateChangeType } from './TypedSignDecoded';
import TypedSignDecoded, {
getStateChangeToolip,
getStateChangeType,
StateChangeType,
} from './TypedSignDecoded';

const stateChangesApprove = [
{
Expand Down Expand Up @@ -75,9 +79,15 @@ const stateChangesNftBidding: DecodingDataStateChanges = [
},
];

const mockState = (mockStateChanges: DecodingDataStateChanges, stubDecodingLoading: boolean = false) => {
const mockState = (
mockStateChanges: DecodingDataStateChanges,
stubDecodingLoading: boolean = false,
) => {
const clonedMockState = cloneDeep(typedSignV4ConfirmationState);
const request = clonedMockState.engine.backgroundState.SignatureController.signatureRequests['fb2029e1-b0ab-11ef-9227-05a11087c334'] as SignatureRequest;
const request = clonedMockState.engine.backgroundState.SignatureController
.signatureRequests[
'fb2029e1-b0ab-11ef-9227-05a11087c334'
] as SignatureRequest;
request.decodingLoading = stubDecodingLoading;
request.decodingData = {
stateChanges: mockStateChanges,
Expand Down Expand Up @@ -121,7 +131,11 @@ describe('DecodedSimulation', () => {

it('renders label only once if there are multiple state changes of same changeType', async () => {
const { getAllByText } = renderWithProvider(<TypedSignDecoded />, {
state: mockState([stateChangesApprove[0], stateChangesApprove[0], stateChangesApprove[0]]),
state: mockState([
stateChangesApprove[0],
stateChangesApprove[0],
stateChangesApprove[0],
]),
});

expect(await getAllByText('12,345')).toHaveLength(3);
Expand All @@ -139,28 +153,34 @@ describe('DecodedSimulation', () => {

describe('getStateChangeToolip', () => {
it('return correct tooltip when permit is for listing NFT', () => {
const tooltip = getStateChangeToolip(
StateChangeType.NFTListingReceive,
const tooltip = getStateChangeToolip(StateChangeType.NFTListingReceive);
expect(tooltip).toBe(
strings('confirm.simulation.decoded_tooltip_list_nft'),
);
expect(tooltip).toBe(strings('confirm.simulation.decoded_tooltip_list_nft'));
});

it('return correct tooltip when permit is for bidding NFT', () => {
const tooltip = getStateChangeToolip(
StateChangeType.NFTBiddingReceive,
const tooltip = getStateChangeToolip(StateChangeType.NFTBiddingReceive);
expect(tooltip).toBe(
strings('confirm.simulation.decoded_tooltip_bid_nft'),
);
expect(tooltip).toBe(strings('confirm.simulation.decoded_tooltip_bid_nft'));
});
});

describe('getStateChangeType', () => {
it('return correct state change type for NFT listing receive', () => {
const stateChange = getStateChangeType(stateChangesNftListing, stateChangesNftListing[1]);
const stateChange = getStateChangeType(
stateChangesNftListing,
stateChangesNftListing[1],
);
expect(stateChange).toBe(StateChangeType.NFTListingReceive);
});

it('return correct state change type for NFT bidding receive', () => {
const stateChange = getStateChangeType(stateChangesNftBidding, stateChangesNftBidding[1]);
const stateChange = getStateChangeType(
stateChangesNftBidding,
stateChangesNftBidding[1],
);
expect(stateChange).toBe(StateChangeType.NFTBiddingReceive);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ describe('PermitSimulation', () => {
});

expect(getByText('Estimated changes')).toBeDefined();
expect(getByText('You’re giving the spender permission to spend this many tokens from your account.')).toBeDefined();
expect(
getByText(
"You're giving the spender permission to spend this many tokens from your account.",
),
).toBeDefined();
expect(getByText('Spending cap')).toBeDefined();
expect(getByText('3,000')).toBeDefined();
expect(getByText('0xCcCCc...ccccC')).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import NativeValueDisplay from './NativeValueDisplay';
import { backgroundState } from '../../../../../../../../../../util/test/initial-root-state';
import renderWithProvider from '../../../../../../../../../../util/test/renderWithProvider';
import { fireEvent } from '@testing-library/react-native';

const mockInitialState = {
engine: {
backgroundState,
},
};

describe('NativeValueDisplay', () => {
it('renders component correctly', async () => {
const { findByText } = renderWithProvider(
<NativeValueDisplay
labelChangeType={'Spending Cap'}
value={'4321'}
chainId={'0x1'}
/>,
{ state: mockInitialState },
);

expect(await findByText('< 0.000001')).toBeDefined();
expect(await findByText('ETH')).toBeDefined();
});

it('displays modal when clicking on the value', async () => {
const { findByText } = renderWithProvider(
<NativeValueDisplay
labelChangeType={'Spending Cap'}
value={'4321'}
chainId={'0x1'}
/>,
{ state: mockInitialState },
);

const button = await findByText('< 0.000001');
fireEvent.press(button);

expect(await findByText('Spending Cap')).toBeDefined();
});
});
Loading
Loading