Skip to content

Commit

Permalink
Merge branch 'develop' into test-scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
chloeYue authored Oct 18, 2023
2 parents e747491 + fd84e8b commit 10f2d23
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 95 deletions.
2 changes: 1 addition & 1 deletion app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export default class TransactionController extends EventEmitter {
this._requestTransactionApproval(txMeta, {
shouldShowRequest: false,
}).catch((error) => {
if (error.code === errorCodes.provider.userRejectedRequest) {
if (error?.code === errorCodes.provider.userRejectedRequest) {
return;
}
log.error('Error during persisted transaction approval', error);
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/snaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const SNAPS_DERIVATION_PATHS: SnapsDerivationPath[] = [
name: 'Secret Network',
},
{
path: ['m', `44'`, `397'`],
path: ['m', `44'`, `397'`, `0'`],
curve: 'ed25519',
name: 'NEAR Protocol',
},
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/flask/ppom-blockaid-alert-erc20-approval.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const FixtureBuilder = require('../fixture-builder');
const { mockServerJsonRpc } = require('../mock-server-json-rpc');

const {
WINDOW_TITLES,
defaultGanacheOptions,
openDapp,
unlockWallet,
Expand Down Expand Up @@ -52,6 +53,7 @@ async function mockInfura(mockServer) {
},
],
['eth_estimateGas'],
['eth_feeHistory'],
['eth_gasPrice'],
['eth_getBalance'],
['eth_getBlockByNumber'],
Expand All @@ -62,6 +64,7 @@ async function mockInfura(mockServer) {
params: [CONTRACT_ADDRESS.BUSD],
},
],
['eth_getTransactionCount'],
]);

await mockServer
Expand Down Expand Up @@ -191,7 +194,7 @@ describe('PPOM Blockaid Alert - Malicious ERC20 Approval', function () {

// Wait for confirmation pop-up
await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle('MetaMask Notification');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Notification);

const bannerAlertFoundByTitle = await driver.findElement({
css: bannerAlertSelector,
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/flask/ppom-blockaid-alert-erc20-transfer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const FixtureBuilder = require('../fixture-builder');
const { mockServerJsonRpc } = require('../mock-server-json-rpc');

const {
WINDOW_TITLES,
defaultGanacheOptions,
openDapp,
unlockWallet,
Expand Down Expand Up @@ -52,6 +53,7 @@ async function mockInfura(mockServer) {
},
],
['eth_estimateGas'],
['eth_feeHistory'],
['eth_gasPrice'],
['eth_getBalance'],
['eth_getBlockByNumber'],
Expand All @@ -62,6 +64,7 @@ async function mockInfura(mockServer) {
params: [CONTRACT_ADDRESS.USDC],
},
],
['eth_getTransactionCount'],
]);

await mockServer
Expand Down Expand Up @@ -188,7 +191,7 @@ describe('PPOM Blockaid Alert - Malicious ERC20 Transfer', function () {

// Wait for confirmation pop-up
await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle('MetaMask Notification');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Notification);

const bannerAlertFoundByTitle = await driver.findElement({
css: bannerAlertSelector,
Expand Down
223 changes: 142 additions & 81 deletions test/e2e/flask/ppom-blockaid-alert.spec.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions test/mocks/json-rpc-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ export const mockJsonRpcResult: mockJsonRpcResultType = {
'0x0000000000000000000000000000000000000000000000000ddfe4d79cbd3de5',
},

eth_feeHistory: {
default: {
baseFeePerGas: [
'0x69b11e562',
'0x666a7c239',
'0x6d9e609f6',
'0x6e9ab5408',
'0x6bca983cb',
'0x6a6f790c3',
],
gasUsedRatio: [
0.37602026666666666, 0.7813118333333333, 0.5359671, 0.39827006666666664,
0.44968263333333336,
],
oldestBlock: '0x115e9c0',
reward: [
['0xfbc521', '0x21239e6', '0x5f5e100'],
['0x5f5e100', '0x68e7780', '0x314050eb'],
['0xfbc521', '0xfbc521', '0xfbc521'],
['0x21239e6', '0x5f5e100', '0x5f5e100'],
['0x21239e6', '0x5f5e100', '0x5f5e100'],
],
},
},

eth_gasPrice: {
default: '0x09184e72a000',
},
Expand Down Expand Up @@ -275,7 +300,12 @@ export const mockJsonRpcResult: mockJsonRpcResultType = {
},

eth_getCode: {
default: '0x',
BUSD: '0x60806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633659cfe681146100765780634f1ef286146100975780635c60da1b146100b75780638f283970146100e8578063f851a44014610109575b61007461011e565b005b34801561008257600080fd5b50610074600160a060020a0360043516610138565b61007460048035600160a060020a03169060248035908101910135610172565b3480156100c357600080fd5b506100cc6101ea565b60408051600160a060020a039092168252519081900360200190f35b3480156100f457600080fd5b50610074600160a060020a0360043516610227565b34801561011557600080fd5b506100cc610339565b610126610364565b610136610131610411565b610436565b565b61014061045a565b600160a060020a031633600160a060020a03161415610167576101628161047f565b61016f565b61016f61011e565b50565b61017a61045a565b600160a060020a031633600160a060020a031614156101dd5761019c8361047f565b30600160a060020a03163483836040518083838082843782019150509250505060006040518083038185875af19250505015156101d857600080fd5b6101e5565b6101e561011e565b505050565b60006101f461045a565b600160a060020a031633600160a060020a0316141561021c57610215610411565b9050610224565b61022461011e565b90565b61022f61045a565b600160a060020a031633600160a060020a0316141561016757600160a060020a03811615156102e557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603660248201527f43616e6e6f74206368616e6765207468652061646d696e206f6620612070726f60448201527f787920746f20746865207a65726f206164647265737300000000000000000000606482015290519081900360840190fd5b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f61030e61045a565b60408051600160a060020a03928316815291841660208301528051918290030190a1610162816104c7565b600061034361045a565b600160a060020a031633600160a060020a0316141561021c5761021561045a565b61036c61045a565b600160a060020a031633141561040957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603260248201527f43616e6e6f742063616c6c2066616c6c6261636b2066756e6374696f6e20667260448201527f6f6d207468652070726f78792061646d696e0000000000000000000000000000606482015290519081900360840190fd5b610136610136565b7f7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c35490565b3660008037600080366000845af43d6000803e808015610455573d6000f35b3d6000fd5b7f10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b5490565b610488816104eb565b60408051600160a060020a038316815290517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b9181900360200190a150565b7f10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b55565b60006104f6826105ae565b151561058957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603b60248201527f43616e6e6f742073657420612070726f787920696d706c656d656e746174696f60448201527f6e20746f2061206e6f6e2d636f6e747261637420616464726573730000000000606482015290519081900360840190fd5b507f7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c355565b6000903b11905600a165627a7a72305820b274fe16b200679a229fcce27c65314a32b3cff995c434133f535dd565bba4740029',
USDC: '0x60806040526004361061006d576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633659cfe6146100775780634f1ef286146100ba5780635c60da1b146101085780638f2839701461015f578063f851a440146101a2575b6100756101f9565b005b34801561008357600080fd5b506100b8600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610213565b005b610106600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001908201803590602001919091929391929390505050610268565b005b34801561011457600080fd5b5061011d610308565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561016b57600080fd5b506101a0600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610360565b005b3480156101ae57600080fd5b506101b761051e565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610201610576565b61021161020c610651565b610682565b565b61021b6106a8565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561025c57610257816106d9565b610265565b6102646101f9565b5b50565b6102706106a8565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102fa576102ac836106d9565b3073ffffffffffffffffffffffffffffffffffffffff163483836040518083838082843782019150509250505060006040518083038185875af19250505015156102f557600080fd5b610303565b6103026101f9565b5b505050565b60006103126106a8565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156103545761034d610651565b905061035d565b61035c6101f9565b5b90565b6103686106a8565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561051257600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614151515610466576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260368152602001807f43616e6e6f74206368616e6765207468652061646d696e206f6620612070726f81526020017f787920746f20746865207a65726f20616464726573730000000000000000000081525060400191505060405180910390fd5b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f61048f6106a8565b82604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a161050d81610748565b61051b565b61051a6101f9565b5b50565b60006105286106a8565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561056a576105636106a8565b9050610573565b6105726101f9565b5b90565b61057e6106a8565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151515610647576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260328152602001807f43616e6e6f742063616c6c2066616c6c6261636b2066756e6374696f6e20667281526020017f6f6d207468652070726f78792061646d696e000000000000000000000000000081525060400191505060405180910390fd5b61064f610777565b565b6000807f7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c36001029050805491505090565b3660008037600080366000845af43d6000803e80600081146106a3573d6000f35b3d6000fd5b6000807f10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b6001029050805491505090565b6106e281610779565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b81604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a150565b60007f10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b60010290508181555050565b565b60006107848261084b565b151561081e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603b8152602001807f43616e6e6f742073657420612070726f787920696d706c656d656e746174696f81526020017f6e20746f2061206e6f6e2d636f6e74726163742061646472657373000000000081525060400191505060405180910390fd5b7f7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c360010290508181555050565b600080823b9050600081119150509190505600a165627a7a72305820a4a547cfc7202c5acaaae74d428e988bc62ad5024eb0165532d3a8f91db4ed240029',
},

eth_getTransactionCount: {
default: MOCK_BLOCK_NUMBER,
},
};
25 changes: 16 additions & 9 deletions ui/components/app/token-cell/__snapshots__/token-cell.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@ exports[`Token Cell should match snapshot 1`] = `
class="mm-box mm-badge-wrapper mm-box--margin-right-3 mm-box--display-inline-block"
>
<div
class="mm-box mm-text mm-avatar-base mm-avatar-base--size-md mm-avatar-token mm-avatar-token--with-halo mm-text--body-sm mm-text--text-transform-uppercase mm-box--display-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-full mm-box--border-color-border-default box--border-style-solid box--border-width-1"
class="mm-box mm-text mm-avatar-base mm-avatar-base--size-md mm-avatar-token mm-avatar-token--with-halo mm-text--body-sm mm-text--text-transform-uppercase mm-box--display-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-full mm-box--border-color-transparent box--border-style-solid box--border-width-1"
>
T
<img
aria-hidden="true"
class="mm-avatar-token__token-image--blurred"
src="./images/test_image.svg"
/>
<img
alt="TEST logo"
class="mm-avatar-token__token-image--size-reduced"
src="./images/test_image.svg"
/>
</div>
<div
class="mm-box mm-badge-wrapper__badge-container mm-badge-wrapper__badge-container--circular-top-right"
>
<div
class="mm-box mm-text mm-avatar-base mm-avatar-base--size-xs mm-avatar-network mm-text--body-xs mm-text--text-transform-uppercase mm-box--display-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-full mm-box--border-color-border-muted box--border-style-solid box--border-width-1"
class="mm-box mm-text mm-avatar-base mm-avatar-base--size-xs mm-avatar-network mm-text--body-xs mm-text--text-transform-uppercase mm-box--display-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default mm-box--rounded-full mm-box--border-color-border-muted box--border-style-solid box--border-width-1"
>
<img
alt="Ethereum Mainnet logo"
class="mm-avatar-network__network-image"
src="./images/eth_logo.png"
/>
?
</div>
</div>
</div>
Expand All @@ -51,7 +56,9 @@ exports[`Token Cell should match snapshot 1`] = `
</div>
<p
class="mm-box mm-text mm-text--body-md mm-text--font-weight-medium mm-text--text-align-end mm-box--width-2/3 mm-box--color-text-default"
/>
>
5.00
</p>
</div>
<p
class="mm-box mm-text mm-text--body-md mm-box--color-text-alternative"
Expand Down
2 changes: 1 addition & 1 deletion ui/components/app/token-cell/token-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TokenListItem } from '../../multichain';
export default function TokenCell({ address, image, symbol, string, onClick }) {
const tokenList = useSelector(getTokenList);
const tokenData = Object.values(tokenList).find(
(token) => token.symbol === symbol,
(token) => token.symbol === symbol && token.address === address,
);
const title = tokenData?.name || symbol;
const tokenImage = tokenData?.iconUrl || image;
Expand Down
55 changes: 55 additions & 0 deletions ui/components/app/token-cell/token-cell.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@ import React from 'react';
import thunk from 'redux-thunk';
import configureMockStore from 'redux-mock-store';
import { fireEvent } from '@testing-library/react';
import { useSelector } from 'react-redux';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount';

import TokenCell from '.';

jest.mock('react-redux', () => {
const actual = jest.requireActual('react-redux');

return {
...actual,
useSelector: jest.fn(),
};
});

jest.mock('../../../hooks/useTokenFiatAmount', () => {
return {
useTokenFiatAmount: jest.fn(),
};
});
describe('Token Cell', () => {
const mockState = {
metamask: {
Expand All @@ -23,6 +40,28 @@ describe('Token Cell', () => {
},
};

// two tokens with the same symbol but different addresses
const MOCK_GET_TOKEN_LIST = {
'0xAddress': {
name: 'TEST-2',
erc20: true,
symbol: 'TEST',
decimals: 18,
address: '0xAddress',
iconUrl: './images/test_1_image.svg',
aggregators: [],
},
'0xAnotherToken': {
name: 'TEST',
erc20: true,
symbol: 'TEST',
decimals: 18,
address: '0xAnotherToken',
iconUrl: './images/test_image.svg',
aggregators: [],
},
};

const mockStore = configureMockStore([thunk])(mockState);

const props = {
Expand All @@ -33,6 +72,9 @@ describe('Token Cell', () => {
onClick: jest.fn(),
};

useSelector.mockReturnValue(MOCK_GET_TOKEN_LIST);
useTokenFiatAmount.mockReturnValue('5.00');

it('should match snapshot', () => {
const { container } = renderWithProvider(
<TokenCell {...props} />,
Expand All @@ -52,4 +94,17 @@ describe('Token Cell', () => {

expect(props.onClick).toHaveBeenCalled();
});

it('should render the correct token and filter by symbol and address', () => {
const { queryByText, getByAltText } = renderWithProvider(
<TokenCell {...props} />,
mockStore,
);

const image = getByAltText('TEST logo');

expect(queryByText('TEST')).toBeInTheDocument();
expect(image).toBeInTheDocument();
expect(image).toHaveAttribute('src', './images/test_image.svg');
});
});

0 comments on commit 10f2d23

Please sign in to comment.