2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
2023-01-31 16:29:23 +01:00
|
|
|
import { fireEvent } from '@testing-library/react';
|
2023-01-18 20:34:28 +01:00
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
2023-02-23 12:38:09 +01:00
|
|
|
import { SECURITY_PROVIDER_MESSAGE_SEVERITIES } from '../security-provider-banner-message/security-provider-banner-message.constants';
|
2021-03-16 22:00:08 +01:00
|
|
|
import SignatureRequest from './signature-request.component';
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2023-03-08 17:05:55 +01:00
|
|
|
const baseProps = {
|
|
|
|
hardwareWalletRequiresConnection: false,
|
|
|
|
clearConfirmTransaction: () => undefined,
|
|
|
|
cancel: () => undefined,
|
|
|
|
cancelAll: () => undefined,
|
|
|
|
mostRecentOverviewPage: '/',
|
|
|
|
showRejectTransactionsConfirmationModal: () => undefined,
|
|
|
|
sign: () => undefined,
|
|
|
|
history: { push: '/' },
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: { type: 'rpc' },
|
2023-03-08 17:05:55 +01:00
|
|
|
nativeCurrency: 'ABC',
|
|
|
|
currentCurrency: 'def',
|
|
|
|
fromAccount: {
|
|
|
|
address: '0x123456789abcdef',
|
|
|
|
balance: '0x346ba7725f412cbfdb',
|
|
|
|
name: 'Antonio',
|
|
|
|
},
|
2023-04-25 12:47:12 +02:00
|
|
|
selectedAccount: {
|
|
|
|
address: '0x123456789abcdef',
|
|
|
|
},
|
2023-03-08 17:05:55 +01:00
|
|
|
};
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Signature Request Component', () => {
|
2023-01-18 20:34:28 +01:00
|
|
|
const store = configureMockStore()(mockState);
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('render', () => {
|
2021-12-08 21:56:09 +01:00
|
|
|
let messageData;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
messageData = {
|
|
|
|
domain: {
|
|
|
|
chainId: 97,
|
|
|
|
name: 'Ether Mail',
|
|
|
|
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
|
|
|
version: '1',
|
|
|
|
},
|
|
|
|
message: {
|
|
|
|
contents: 'Hello, Bob!',
|
|
|
|
from: {
|
|
|
|
name: 'Cow',
|
|
|
|
wallets: [
|
|
|
|
'0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
|
|
|
'0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
to: [
|
|
|
|
{
|
|
|
|
name: 'Bob',
|
|
|
|
wallets: [
|
|
|
|
'0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
|
|
'0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
|
|
|
|
'0xB0B0b0b0b0b0B000000000000000000000000000',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
primaryType: 'Mail',
|
|
|
|
types: {
|
|
|
|
EIP712Domain: [
|
|
|
|
{ name: 'name', type: 'string' },
|
|
|
|
{ name: 'version', type: 'string' },
|
|
|
|
{ name: 'chainId', type: 'uint256' },
|
|
|
|
{ name: 'verifyingContract', type: 'address' },
|
|
|
|
],
|
|
|
|
Mail: [
|
|
|
|
{ name: 'from', type: 'Person' },
|
|
|
|
{ name: 'to', type: 'Person[]' },
|
|
|
|
{ name: 'contents', type: 'string' },
|
|
|
|
],
|
|
|
|
Person: [
|
|
|
|
{ name: 'name', type: 'string' },
|
|
|
|
{ name: 'wallets', type: 'address[]' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-03-08 17:05:55 +01:00
|
|
|
it('should match snapshot when we want to switch to fiat', () => {
|
2021-12-08 21:56:09 +01:00
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
2023-01-18 20:34:28 +01:00
|
|
|
const { container } = renderWithProvider(
|
2020-02-11 17:51:13 +01:00
|
|
|
<SignatureRequest
|
2023-03-08 17:05:55 +01:00
|
|
|
{...baseProps}
|
2020-02-11 17:51:13 +01:00
|
|
|
txData={{
|
2021-12-08 21:56:09 +01:00
|
|
|
msgParams,
|
|
|
|
}}
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate={1567}
|
2023-03-02 13:40:07 +01:00
|
|
|
/>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2023-03-08 17:05:55 +01:00
|
|
|
it('should match snapshot when we are using eth', () => {
|
2023-03-02 13:40:07 +01:00
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<SignatureRequest
|
2023-03-08 17:05:55 +01:00
|
|
|
{...baseProps}
|
2023-03-02 13:40:07 +01:00
|
|
|
txData={{
|
|
|
|
msgParams,
|
|
|
|
}}
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate={null}
|
2021-12-08 21:56:09 +01:00
|
|
|
/>,
|
2023-01-18 20:34:28 +01:00
|
|
|
store,
|
2021-12-08 21:56:09 +01:00
|
|
|
);
|
|
|
|
|
2023-01-18 20:34:28 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
2021-12-08 21:56:09 +01:00
|
|
|
});
|
|
|
|
|
2023-01-31 16:29:23 +01:00
|
|
|
it('should render navigation', () => {
|
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
|
|
|
<SignatureRequest
|
2023-03-08 17:05:55 +01:00
|
|
|
{...baseProps}
|
2023-01-31 16:29:23 +01:00
|
|
|
txData={{
|
|
|
|
msgParams,
|
|
|
|
}}
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate={null}
|
2023-01-31 16:29:23 +01:00
|
|
|
/>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(queryByTestId('navigation-container')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2021-12-08 21:56:09 +01:00
|
|
|
it('should render a div message parsed without typeless data', () => {
|
|
|
|
messageData.message.do_not_display = 'one';
|
|
|
|
messageData.message.do_not_display_2 = {
|
|
|
|
do_not_display: 'two',
|
|
|
|
};
|
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
2023-01-18 20:34:28 +01:00
|
|
|
const { queryByText } = renderWithProvider(
|
2021-12-08 21:56:09 +01:00
|
|
|
<SignatureRequest
|
2023-03-08 17:05:55 +01:00
|
|
|
{...baseProps}
|
2021-12-08 21:56:09 +01:00
|
|
|
txData={{
|
|
|
|
msgParams,
|
2020-02-11 17:51:13 +01:00
|
|
|
}}
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate={null}
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
2023-01-18 20:34:28 +01:00
|
|
|
store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2023-01-18 20:34:28 +01:00
|
|
|
expect(queryByText('do_not_display')).not.toBeInTheDocument();
|
|
|
|
expect(queryByText('one')).not.toBeInTheDocument();
|
|
|
|
expect(queryByText('do_not_display_2')).not.toBeInTheDocument();
|
|
|
|
expect(queryByText('two')).not.toBeInTheDocument();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2023-01-31 16:29:23 +01:00
|
|
|
|
|
|
|
it('should not render a reject multiple requests link if there is not multiple requests', () => {
|
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<SignatureRequest
|
2023-03-08 17:05:55 +01:00
|
|
|
{...baseProps}
|
2023-01-31 16:29:23 +01:00
|
|
|
txData={{
|
|
|
|
msgParams,
|
|
|
|
}}
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate={null}
|
2023-01-31 16:29:23 +01:00
|
|
|
/>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
container.querySelector('.signature-request__reject-all-button'),
|
|
|
|
).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a reject multiple requests link if there is multiple requests (greater than 1)', () => {
|
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<SignatureRequest
|
2023-03-08 17:05:55 +01:00
|
|
|
{...baseProps}
|
2023-01-31 16:29:23 +01:00
|
|
|
txData={{
|
|
|
|
msgParams,
|
|
|
|
}}
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate={null}
|
2023-01-31 16:29:23 +01:00
|
|
|
unapprovedMessagesCount={2}
|
|
|
|
/>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
container.querySelector('.signature-request__reject-all-button'),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call reject all button when button is clicked', () => {
|
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<SignatureRequest
|
2023-03-08 17:05:55 +01:00
|
|
|
{...baseProps}
|
2023-01-31 16:29:23 +01:00
|
|
|
txData={{
|
|
|
|
msgParams,
|
|
|
|
}}
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate={null}
|
2023-01-31 16:29:23 +01:00
|
|
|
unapprovedMessagesCount={2}
|
|
|
|
/>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
const rejectRequestsLink = container.querySelector(
|
|
|
|
'.signature-request__reject-all-button',
|
|
|
|
);
|
|
|
|
fireEvent.click(rejectRequestsLink);
|
|
|
|
expect(rejectRequestsLink).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render text of reject all button', () => {
|
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<SignatureRequest
|
2023-03-08 17:05:55 +01:00
|
|
|
{...baseProps}
|
2023-01-31 16:29:23 +01:00
|
|
|
txData={{
|
|
|
|
msgParams,
|
|
|
|
}}
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate={null}
|
2023-01-31 16:29:23 +01:00
|
|
|
unapprovedMessagesCount={2}
|
|
|
|
/>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(getByText('Reject 2 requests')).toBeInTheDocument();
|
|
|
|
});
|
2023-02-23 12:38:09 +01:00
|
|
|
|
|
|
|
it('should render SecurityProviderBannerMessage component properly', () => {
|
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
|
|
|
|
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<SignatureRequest
|
2023-03-08 17:05:55 +01:00
|
|
|
{...baseProps}
|
|
|
|
conversionRate={null}
|
2023-02-23 12:38:09 +01:00
|
|
|
txData={{
|
|
|
|
msgParams,
|
|
|
|
securityProviderResponse: {
|
|
|
|
flagAsDangerous: '?',
|
|
|
|
reason: 'Some reason...',
|
|
|
|
reason_header: 'Some reason header...',
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
unapprovedMessagesCount={2}
|
|
|
|
/>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(queryByText('Request not verified')).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
queryByText(
|
|
|
|
'Because of an error, this request was not verified by the security provider. Proceed with caution.',
|
|
|
|
),
|
|
|
|
).toBeInTheDocument();
|
2023-05-04 20:21:46 +02:00
|
|
|
expect(queryByText('OpenSea')).toBeInTheDocument();
|
2023-02-23 12:38:09 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render SecurityProviderBannerMessage component when flagAsDangerous is not malicious', () => {
|
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
|
|
|
|
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<SignatureRequest
|
2023-03-08 17:05:55 +01:00
|
|
|
{...baseProps}
|
|
|
|
conversionRate={null}
|
2023-02-23 12:38:09 +01:00
|
|
|
txData={{
|
|
|
|
msgParams,
|
|
|
|
securityProviderResponse: {
|
|
|
|
flagAsDangerous:
|
|
|
|
SECURITY_PROVIDER_MESSAGE_SEVERITIES.NOT_MALICIOUS,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
unapprovedMessagesCount={2}
|
|
|
|
/>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(queryByText('Request not verified')).toBeNull();
|
|
|
|
expect(
|
|
|
|
queryByText(
|
|
|
|
'Because of an error, this request was not verified by the security provider. Proceed with caution.',
|
|
|
|
),
|
|
|
|
).toBeNull();
|
2023-05-04 20:21:46 +02:00
|
|
|
expect(queryByText('OpenSea')).toBeNull();
|
2023-02-23 12:38:09 +01:00
|
|
|
});
|
2023-04-25 12:47:12 +02:00
|
|
|
|
|
|
|
it('should render a warning when the selected account is not the one being used to sign', () => {
|
|
|
|
const msgParams = {
|
|
|
|
data: JSON.stringify(messageData),
|
|
|
|
version: 'V4',
|
|
|
|
origin: 'test',
|
|
|
|
};
|
|
|
|
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<SignatureRequest
|
|
|
|
{...baseProps}
|
|
|
|
selectedAccount={{
|
|
|
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
balance: '0x0',
|
|
|
|
name: 'Account 1',
|
|
|
|
}}
|
|
|
|
conversionRate={null}
|
|
|
|
txData={{
|
|
|
|
msgParams,
|
|
|
|
securityProviderResponse: {
|
|
|
|
flagAsDangerous:
|
|
|
|
SECURITY_PROVIDER_MESSAGE_SEVERITIES.NOT_MALICIOUS,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
unapprovedMessagesCount={2}
|
|
|
|
/>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
container.querySelector('.request-signature__mismatch-info'),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|