2021-02-04 19:15:23 +01:00
|
|
|
import React from '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';
|
2021-03-16 22:00:08 +01:00
|
|
|
import SignatureRequest from './signature-request.component';
|
2019-11-04 13:40:46 +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 fromAddress;
|
|
|
|
let messageData;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
fromAddress = '0x123456789abcdef';
|
|
|
|
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-01-18 20:34:28 +01:00
|
|
|
it('should match snapshot', () => {
|
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
|
2022-06-07 04:30:07 +02:00
|
|
|
hardwareWalletRequiresConnection={false}
|
2020-08-14 13:47:02 +02:00
|
|
|
clearConfirmTransaction={() => undefined}
|
|
|
|
cancel={() => undefined}
|
|
|
|
sign={() => undefined}
|
2020-02-11 17:51:13 +01:00
|
|
|
txData={{
|
2021-12-08 21:56:09 +01:00
|
|
|
msgParams,
|
|
|
|
}}
|
|
|
|
fromAccount={{ address: fromAddress }}
|
2022-11-30 19:11:36 +01:00
|
|
|
provider={{ type: 'rpc' }}
|
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
|
|
|
});
|
|
|
|
|
|
|
|
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
|
2022-06-07 04:30:07 +02:00
|
|
|
hardwareWalletRequiresConnection={false}
|
2021-12-08 21:56:09 +01:00
|
|
|
clearConfirmTransaction={() => undefined}
|
|
|
|
cancel={() => undefined}
|
|
|
|
sign={() => undefined}
|
|
|
|
txData={{
|
|
|
|
msgParams,
|
2020-02-11 17:51:13 +01:00
|
|
|
}}
|
2020-03-06 22:34:56 +01:00
|
|
|
fromAccount={{ address: fromAddress }}
|
2022-11-30 19:11:36 +01:00
|
|
|
provider={{ type: 'rpc' }}
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|