1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Replace unit test from 7f9e24c4 with a test that is compatible with the state of ducks/send on master

This commit is contained in:
Dan Miller 2022-06-28 15:09:54 -02:30 committed by Mark Stacey
parent 60a8d92e9c
commit 52590b8fe3

View File

@ -88,16 +88,11 @@ setBackgroundConnection({
describe('Send Slice', () => {
let getTokenStandardAndDetailsStub;
let addUnapprovedTransactionAndRouteToConfirmationPageStub;
beforeEach(() => {
jest.useFakeTimers();
getTokenStandardAndDetailsStub = jest
.spyOn(Actions, 'getTokenStandardAndDetails')
.mockImplementation(() => Promise.resolve({ standard: 'ERC20' }));
addUnapprovedTransactionAndRouteToConfirmationPageStub = jest.spyOn(
Actions,
'addUnapprovedTransactionAndRouteToConfirmationPage',
);
jest
.spyOn(Actions, 'estimateGas')
.mockImplementation(() => Promise.resolve('0x0'));
@ -588,6 +583,48 @@ describe('Send Slice', () => {
);
});
});
it('should set the correct token transfers', () => {
const tokenTransferTxState = {
...initialState,
status: SEND_STATUSES.VALID,
transactionType: TRANSACTION_ENVELOPE_TYPES.FEE_MARKET,
account: {
address: '0x6784e8507A1A46443f7bDc8f8cA39bdA92A675A6',
},
asset: {
details: {
address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
},
type: 'TOKEN',
},
recipient: {
address: '4F90e18605Fd46F9F9Fab0e225D88e1ACf5F5324',
},
amount: {
value: '0x1',
},
gas: {
maxFeePerGas: '0x2540be400', // 10 GWEI
maxPriorityFeePerGas: '0x3b9aca00', // 1 GWEI
gasLimit: '0x5208', // 21000
},
eip1559support: true,
};
const action = {
type: 'send/updateDraftTransaction',
};
const result = sendReducer(tokenTransferTxState, action);
expect(result.draftTransaction.txParams.data).toStrictEqual(
'0xa9059cbb0000000000000000000000004f90e18605fd46f9f9fab0e225d88e1acf5f53240000000000000000000000000000000000000000000000000000000000000001',
);
expect(result.draftTransaction.txParams.to).toStrictEqual(
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
);
});
});
describe('useDefaultGas', () => {
@ -2149,60 +2186,6 @@ describe('Send Slice', () => {
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 () => {
const editStageSignTxState = {
metamask: {