mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Ensure that addresses are properly hex-prefixed in the generate ERC token transfer functions (#15064)
* Ensure that addresses are properly hex-prefixed in the generate ERC token transfer functions * Ensure hex-prefixed addresses in send input * Update unit tests Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
This commit is contained in:
parent
51311e4024
commit
7f9e24c4f0
@ -88,11 +88,16 @@ setBackgroundConnection({
|
|||||||
|
|
||||||
describe('Send Slice', () => {
|
describe('Send Slice', () => {
|
||||||
let getTokenStandardAndDetailsStub;
|
let getTokenStandardAndDetailsStub;
|
||||||
|
let addUnapprovedTransactionAndRouteToConfirmationPageStub;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
getTokenStandardAndDetailsStub = jest
|
getTokenStandardAndDetailsStub = jest
|
||||||
.spyOn(Actions, 'getTokenStandardAndDetails')
|
.spyOn(Actions, 'getTokenStandardAndDetails')
|
||||||
.mockImplementation(() => Promise.resolve({ standard: 'ERC20' }));
|
.mockImplementation(() => Promise.resolve({ standard: 'ERC20' }));
|
||||||
|
addUnapprovedTransactionAndRouteToConfirmationPageStub = jest.spyOn(
|
||||||
|
Actions,
|
||||||
|
'addUnapprovedTransactionAndRouteToConfirmationPage',
|
||||||
|
);
|
||||||
jest
|
jest
|
||||||
.spyOn(Actions, 'estimateGas')
|
.spyOn(Actions, 'estimateGas')
|
||||||
.mockImplementation(() => Promise.resolve('0x0'));
|
.mockImplementation(() => Promise.resolve('0x0'));
|
||||||
@ -2144,6 +2149,60 @@ describe('Send Slice', () => {
|
|||||||
expect(actionResult[1].type).toStrictEqual('SHOW_CONF_TX_PAGE');
|
expect(actionResult[1].type).toStrictEqual('SHOW_CONF_TX_PAGE');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('with token transfers', () => {
|
||||||
|
it('should pass the correct transaction parameters to addUnapprovedTransactionAndRouteToConfirmationPage', async () => {
|
||||||
|
const tokenTransferTxState = {
|
||||||
|
metamask: {
|
||||||
|
unapprovedTxs: {
|
||||||
|
1: {
|
||||||
|
id: 1,
|
||||||
|
txParams: {
|
||||||
|
value: 'oldTxValue',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
send: {
|
||||||
|
...signTransactionState.send,
|
||||||
|
stage: SEND_STAGES.DRAFT,
|
||||||
|
id: 1,
|
||||||
|
account: {
|
||||||
|
address: '0x6784e8507A1A46443f7bDc8f8cA39bdA92A675A6',
|
||||||
|
},
|
||||||
|
asset: {
|
||||||
|
details: {
|
||||||
|
address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
||||||
|
},
|
||||||
|
type: 'TOKEN',
|
||||||
|
},
|
||||||
|
recipient: {
|
||||||
|
address: '4F90e18605Fd46F9F9Fab0e225D88e1ACf5F5324',
|
||||||
|
},
|
||||||
|
amount: {
|
||||||
|
value: '0x1',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
jest.mock('../../store/actions.js');
|
||||||
|
|
||||||
|
const store = mockStore(tokenTransferTxState);
|
||||||
|
|
||||||
|
await store.dispatch(signTransaction());
|
||||||
|
|
||||||
|
expect(
|
||||||
|
addUnapprovedTransactionAndRouteToConfirmationPageStub.mock
|
||||||
|
.calls[0][0].data,
|
||||||
|
).toStrictEqual(
|
||||||
|
'0xa9059cbb0000000000000000000000004f90e18605fd46f9f9fab0e225d88e1acf5f53240000000000000000000000000000000000000000000000000000000000000001',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
addUnapprovedTransactionAndRouteToConfirmationPageStub.mock
|
||||||
|
.calls[0][0].to,
|
||||||
|
).toStrictEqual('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should create actions for updateTransaction rejecting', async () => {
|
it('should create actions for updateTransaction rejecting', async () => {
|
||||||
const editStageSignTxState = {
|
const editStageSignTxState = {
|
||||||
metamask: {
|
metamask: {
|
||||||
|
@ -2,6 +2,7 @@ import React, { Component } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
|
||||||
|
import { addHexPrefix } from '../../../../../app/scripts/lib/util';
|
||||||
import { isValidDomainName } from '../../../../helpers/utils/util';
|
import { isValidDomainName } from '../../../../helpers/utils/util';
|
||||||
import {
|
import {
|
||||||
isBurnAddress,
|
isBurnAddress,
|
||||||
@ -36,6 +37,7 @@ export default class EnsInput extends Component {
|
|||||||
|
|
||||||
onPaste = (event) => {
|
onPaste = (event) => {
|
||||||
if (event.clipboardData.items?.length) {
|
if (event.clipboardData.items?.length) {
|
||||||
|
event.preventDefault();
|
||||||
const clipboardItem = event.clipboardData.items[0];
|
const clipboardItem = event.clipboardData.items[0];
|
||||||
clipboardItem?.getAsString((text) => {
|
clipboardItem?.getAsString((text) => {
|
||||||
const input = text.trim();
|
const input = text.trim();
|
||||||
@ -43,7 +45,7 @@ export default class EnsInput extends Component {
|
|||||||
!isBurnAddress(input) &&
|
!isBurnAddress(input) &&
|
||||||
isValidHexAddress(input, { mixedCaseUseChecksum: true })
|
isValidHexAddress(input, { mixedCaseUseChecksum: true })
|
||||||
) {
|
) {
|
||||||
this.props.onPaste(input);
|
this.props.onPaste(addHexPrefix(input));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -74,7 +76,7 @@ export default class EnsInput extends Component {
|
|||||||
!isBurnAddress(input) &&
|
!isBurnAddress(input) &&
|
||||||
isValidHexAddress(input, { mixedCaseUseChecksum: true })
|
isValidHexAddress(input, { mixedCaseUseChecksum: true })
|
||||||
) {
|
) {
|
||||||
onValidAddressTyped(input);
|
onValidAddressTyped(addHexPrefix(input));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ function generateERC20TransferData({
|
|||||||
.call(
|
.call(
|
||||||
abi.rawEncode(
|
abi.rawEncode(
|
||||||
['address', 'uint256'],
|
['address', 'uint256'],
|
||||||
[toAddress, addHexPrefix(amount)],
|
[addHexPrefix(toAddress), addHexPrefix(amount)],
|
||||||
),
|
),
|
||||||
(x) => `00${x.toString(16)}`.slice(-2),
|
(x) => `00${x.toString(16)}`.slice(-2),
|
||||||
)
|
)
|
||||||
@ -164,7 +164,7 @@ function generateERC721TransferData({
|
|||||||
.call(
|
.call(
|
||||||
abi.rawEncode(
|
abi.rawEncode(
|
||||||
['address', 'address', 'uint256'],
|
['address', 'address', 'uint256'],
|
||||||
[fromAddress, toAddress, tokenId],
|
[addHexPrefix(fromAddress), addHexPrefix(toAddress), tokenId],
|
||||||
),
|
),
|
||||||
(x) => `00${x.toString(16)}`.slice(-2),
|
(x) => `00${x.toString(16)}`.slice(-2),
|
||||||
)
|
)
|
||||||
|
@ -73,7 +73,7 @@ describe('send utils', () => {
|
|||||||
expect(rawEncode.mock.calls[0].toString()).toStrictEqual(
|
expect(rawEncode.mock.calls[0].toString()).toStrictEqual(
|
||||||
[
|
[
|
||||||
['address', 'uint256'],
|
['address', 'uint256'],
|
||||||
['mockAddress', '0xab'],
|
['0xmockAddress', '0xab'],
|
||||||
].toString(),
|
].toString(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user