A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/ui/components/app/signature-request/signature-request.component...

139 lines
4.5 KiB

import React from 'react';
import { shallowWithContext } from '../../../../test/lib/render-helpers';
import SignatureRequest from './signature-request.component';
"eth_signTypedData" presents fields that do not appear in 'types' filed (#12905) * Premilimary Sanitize data logic. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitizeData v2 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitizeData: take 3 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Sanitize Data take 4 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Check that version is v4 before sanitizing. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitize arrays. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Tests to check that typeless data are not shwon Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint Fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Do not check value types, Iterate through the message, and ensure each property of the message is declared as a type Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Check that if data type is not defined, it is a solidity type. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint Fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Code cleanup Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move sanitizeData to utils Tests for sanitizeData in utils Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix unit tests for signaturerequest Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove unused type include fixedMxN and ufixedMxN checks. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * move fixtures to before each Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * invert if condition to avoid indentations. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * We should exclude types with [] at the beginning or middle as well: Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * cache nestedType Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Throw error for undefined/invalid types definition Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Throw if base type and types are not defined. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
3 years ago
import Message from './signature-request-message';
describe('Signature Request Component', () => {
describe('render', () => {
"eth_signTypedData" presents fields that do not appear in 'types' filed (#12905) * Premilimary Sanitize data logic. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitizeData v2 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitizeData: take 3 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Sanitize Data take 4 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Check that version is v4 before sanitizing. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitize arrays. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Tests to check that typeless data are not shwon Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint Fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Do not check value types, Iterate through the message, and ensure each property of the message is declared as a type Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Check that if data type is not defined, it is a solidity type. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint Fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Code cleanup Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move sanitizeData to utils Tests for sanitizeData in utils Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix unit tests for signaturerequest Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove unused type include fixedMxN and ufixedMxN checks. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * move fixtures to before each Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * invert if condition to avoid indentations. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * We should exclude types with [] at the beginning or middle as well: Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * cache nestedType Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Throw error for undefined/invalid types definition Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Throw if base type and types are not defined. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
3 years ago
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[]' },
],
},
};
});
it('should render a div message parsed', () => {
const msgParams = {
data: JSON.stringify(messageData),
version: 'V4',
origin: 'test',
};
const wrapper = shallowWithContext(
<SignatureRequest
hardwareWalletRequiresConnection={false}
clearConfirmTransaction={() => undefined}
cancel={() => undefined}
sign={() => undefined}
txData={{
"eth_signTypedData" presents fields that do not appear in 'types' filed (#12905) * Premilimary Sanitize data logic. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitizeData v2 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitizeData: take 3 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Sanitize Data take 4 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Check that version is v4 before sanitizing. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitize arrays. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Tests to check that typeless data are not shwon Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint Fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Do not check value types, Iterate through the message, and ensure each property of the message is declared as a type Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Check that if data type is not defined, it is a solidity type. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint Fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Code cleanup Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move sanitizeData to utils Tests for sanitizeData in utils Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix unit tests for signaturerequest Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove unused type include fixedMxN and ufixedMxN checks. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * move fixtures to before each Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * invert if condition to avoid indentations. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * We should exclude types with [] at the beginning or middle as well: Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * cache nestedType Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Throw error for undefined/invalid types definition Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Throw if base type and types are not defined. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
3 years ago
msgParams,
}}
fromAccount={{ address: fromAddress }}
/>,
);
expect(wrapper.is('div')).toStrictEqual(true);
expect(wrapper).toHaveLength(1);
expect(wrapper.hasClass('signature-request')).toStrictEqual(true);
const messageWrapper = wrapper.find(Message);
expect(messageWrapper).toHaveLength(1);
const { data } = messageWrapper.props();
expect(data.contents).toStrictEqual('Hello, Bob!');
expect(data.from.name).toStrictEqual('Cow');
expect(data.from.wallets).toBeDefined();
expect(data.from.wallets).toHaveLength(2);
expect(data.to).toBeDefined();
const dataTo = data.to;
expect(dataTo[0].name).toStrictEqual('Bob');
expect(dataTo[0].wallets).toHaveLength(3);
});
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',
};
const wrapper = shallowWithContext(
<SignatureRequest
hardwareWalletRequiresConnection={false}
"eth_signTypedData" presents fields that do not appear in 'types' filed (#12905) * Premilimary Sanitize data logic. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitizeData v2 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitizeData: take 3 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Sanitize Data take 4 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Check that version is v4 before sanitizing. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitize arrays. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Tests to check that typeless data are not shwon Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint Fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Do not check value types, Iterate through the message, and ensure each property of the message is declared as a type Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Check that if data type is not defined, it is a solidity type. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint Fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Code cleanup Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move sanitizeData to utils Tests for sanitizeData in utils Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix unit tests for signaturerequest Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove unused type include fixedMxN and ufixedMxN checks. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * move fixtures to before each Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * invert if condition to avoid indentations. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * We should exclude types with [] at the beginning or middle as well: Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * cache nestedType Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Throw error for undefined/invalid types definition Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Throw if base type and types are not defined. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
3 years ago
clearConfirmTransaction={() => undefined}
cancel={() => undefined}
sign={() => undefined}
txData={{
msgParams,
}}
fromAccount={{ address: fromAddress }}
/>,
);
expect(wrapper.is('div')).toStrictEqual(true);
expect(wrapper).toHaveLength(1);
expect(wrapper.hasClass('signature-request')).toStrictEqual(true);
"eth_signTypedData" presents fields that do not appear in 'types' filed (#12905) * Premilimary Sanitize data logic. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitizeData v2 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitizeData: take 3 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Sanitize Data take 4 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Check that version is v4 before sanitizing. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * sanitize arrays. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Tests to check that typeless data are not shwon Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint Fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Do not check value types, Iterate through the message, and ensure each property of the message is declared as a type Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Check that if data type is not defined, it is a solidity type. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint Fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Code cleanup Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move sanitizeData to utils Tests for sanitizeData in utils Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix unit tests for signaturerequest Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove unused type include fixedMxN and ufixedMxN checks. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * move fixtures to before each Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * invert if condition to avoid indentations. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * We should exclude types with [] at the beginning or middle as well: Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * cache nestedType Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Throw error for undefined/invalid types definition Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Throw if base type and types are not defined. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
3 years ago
const messageWrapper = wrapper.find(Message);
expect(messageWrapper).toHaveLength(1);
const { data } = messageWrapper.props();
expect(data.contents).toStrictEqual('Hello, Bob!');
expect(data.from.name).toStrictEqual('Cow');
expect(data.from.wallets).toBeDefined();
expect(data.from.wallets).toHaveLength(2);
expect(data.to).toBeDefined();
const dataTo = data.to;
expect(dataTo[0].name).toStrictEqual('Bob');
expect(dataTo[0].wallets).toHaveLength(3);
expect(data.do_not_display).toBeUndefined();
expect(data.do_not_display2).toBeUndefined();
});
});
});