2022-09-14 16:55:31 +02:00
|
|
|
import { CHAIN_IDS } from '../../shared/constants/network';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { TRANSACTION_STATUSES } from '../../shared/constants/transaction';
|
2020-01-30 20:34:45 +01:00
|
|
|
import {
|
|
|
|
unapprovedMessagesSelector,
|
|
|
|
transactionsSelector,
|
|
|
|
nonceSortedTransactionsSelector,
|
|
|
|
nonceSortedPendingTransactionsSelector,
|
|
|
|
nonceSortedCompletedTransactionsSelector,
|
|
|
|
submittedPendingTransactionsSelector,
|
2021-03-16 22:00:08 +01:00
|
|
|
} from './transactions';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Transaction Selectors', () => {
|
|
|
|
describe('unapprovedMessagesSelector', () => {
|
|
|
|
it('returns eth sign msg from unapprovedMsgs', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const msg = {
|
|
|
|
id: 1,
|
|
|
|
msgParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
data: '0xData',
|
|
|
|
origin: 'origin',
|
|
|
|
},
|
|
|
|
time: 1,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2020-01-30 20:34:45 +01:00
|
|
|
type: 'eth_sign',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedMsgs: {
|
|
|
|
1: msg,
|
|
|
|
},
|
2021-03-01 16:15:42 +01:00
|
|
|
provider: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chainId: '0x5',
|
2021-03-01 16:15:42 +01:00
|
|
|
},
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const msgSelector = unapprovedMessagesSelector(state);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(Array.isArray(msgSelector)).toStrictEqual(true);
|
|
|
|
expect(msgSelector).toStrictEqual([msg]);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('returns personal sign from unapprovedPersonalMsgsSelector', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const msg = {
|
|
|
|
id: 1,
|
|
|
|
msgParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
data: '0xData',
|
|
|
|
origin: 'origin',
|
|
|
|
},
|
|
|
|
time: 1,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2020-01-30 20:34:45 +01:00
|
|
|
type: 'personal_sign',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedPersonalMsgs: {
|
|
|
|
1: msg,
|
|
|
|
},
|
2021-03-01 16:15:42 +01:00
|
|
|
provider: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chainId: '0x5',
|
2021-03-01 16:15:42 +01:00
|
|
|
},
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const msgSelector = unapprovedMessagesSelector(state);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(Array.isArray(msgSelector)).toStrictEqual(true);
|
|
|
|
expect(msgSelector).toStrictEqual([msg]);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('returns typed message from unapprovedTypedMessagesSelector', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const msg = {
|
|
|
|
id: 1,
|
|
|
|
msgParams: {
|
|
|
|
data: '0xData',
|
|
|
|
from: '0xAddress',
|
|
|
|
version: 'V3',
|
|
|
|
origin: 'origin',
|
|
|
|
},
|
|
|
|
time: 1,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2020-01-30 20:34:45 +01:00
|
|
|
type: 'eth_signTypedData',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedTypedMessages: {
|
|
|
|
1: msg,
|
|
|
|
},
|
2021-03-01 16:15:42 +01:00
|
|
|
provider: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chainId: '0x5',
|
2021-03-01 16:15:42 +01:00
|
|
|
},
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const msgSelector = unapprovedMessagesSelector(state);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(Array.isArray(msgSelector)).toStrictEqual(true);
|
|
|
|
expect(msgSelector).toStrictEqual([msg]);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('transactionsSelector', () => {
|
|
|
|
it('selects the currentNetworkTxList', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const state = {
|
|
|
|
metamask: {
|
2020-02-26 18:34:46 +01:00
|
|
|
provider: {
|
|
|
|
nickname: 'mainnet',
|
2022-09-14 16:55:31 +02:00
|
|
|
chainId: CHAIN_IDS.MAINNET,
|
2020-02-26 18:34:46 +01:00
|
|
|
},
|
2020-01-30 20:34:45 +01:00
|
|
|
featureFlags: {
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
},
|
2020-03-06 22:34:56 +01:00
|
|
|
selectedAddress: '0xAddress',
|
|
|
|
currentNetworkTxList: [
|
2020-01-30 20:34:45 +01:00
|
|
|
{
|
|
|
|
id: 0,
|
|
|
|
time: 0,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
time: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const orderedTxList = state.metamask.currentNetworkTxList.sort(
|
|
|
|
(a, b) => b.time - a.time,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const selectedTx = transactionsSelector(state);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(Array.isArray(selectedTx)).toStrictEqual(true);
|
|
|
|
expect(selectedTx).toStrictEqual(orderedTxList);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('nonceSortedTransactionsSelector', () => {
|
|
|
|
it('returns transaction group nonce sorted tx from from selectedTxList wit', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const tx1 = {
|
|
|
|
id: 0,
|
|
|
|
time: 0,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x0',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const tx2 = {
|
|
|
|
id: 1,
|
|
|
|
time: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x1',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
2020-02-26 18:34:46 +01:00
|
|
|
provider: {
|
|
|
|
nickname: 'mainnet',
|
2022-09-14 16:55:31 +02:00
|
|
|
chainId: CHAIN_IDS.MAINNET,
|
2020-02-26 18:34:46 +01:00
|
|
|
},
|
2020-03-06 22:34:56 +01:00
|
|
|
selectedAddress: '0xAddress',
|
2020-01-30 20:34:45 +01:00
|
|
|
featureFlags: {
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
currentNetworkTxList: [tx1, tx2],
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const expectedResult = [
|
|
|
|
{
|
|
|
|
nonce: '0x0',
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [tx1],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: tx1,
|
|
|
|
primaryTransaction: tx1,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nonce: '0x1',
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [tx2],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: tx2,
|
|
|
|
primaryTransaction: tx2,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(nonceSortedTransactionsSelector(state)).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
expectedResult,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Sorting Transactions Selectors', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const submittedTx = {
|
|
|
|
id: 0,
|
|
|
|
time: 0,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x0',
|
|
|
|
},
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SUBMITTED,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const unapprovedTx = {
|
|
|
|
id: 1,
|
|
|
|
time: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x1',
|
|
|
|
},
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const approvedTx = {
|
|
|
|
id: 2,
|
|
|
|
time: 2,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x2',
|
|
|
|
},
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.APPROVED,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const confirmedTx = {
|
|
|
|
id: 3,
|
|
|
|
time: 3,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x3',
|
|
|
|
},
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
2020-02-26 18:34:46 +01:00
|
|
|
provider: {
|
|
|
|
nickname: 'mainnet',
|
2022-09-14 16:55:31 +02:00
|
|
|
chainId: CHAIN_IDS.MAINNET,
|
2020-02-26 18:34:46 +01:00
|
|
|
},
|
2020-03-06 22:34:56 +01:00
|
|
|
selectedAddress: '0xAddress',
|
2020-01-30 20:34:45 +01:00
|
|
|
featureFlags: {
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
},
|
2020-03-06 22:34:56 +01:00
|
|
|
currentNetworkTxList: [
|
2020-01-30 20:34:45 +01:00
|
|
|
submittedTx,
|
|
|
|
unapprovedTx,
|
|
|
|
approvedTx,
|
|
|
|
confirmedTx,
|
|
|
|
],
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('nonceSortedPendingTransactionsSelector', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const expectedResult = [
|
|
|
|
{
|
|
|
|
nonce: submittedTx.txParams.nonce,
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [submittedTx],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: submittedTx,
|
|
|
|
primaryTransaction: submittedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nonce: unapprovedTx.txParams.nonce,
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [unapprovedTx],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: unapprovedTx,
|
|
|
|
primaryTransaction: unapprovedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nonce: approvedTx.txParams.nonce,
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [approvedTx],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: approvedTx,
|
|
|
|
primaryTransaction: approvedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(nonceSortedPendingTransactionsSelector(state)).toStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
expectedResult,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('nonceSortedCompletedTransactionsSelector', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const expectedResult = [
|
|
|
|
{
|
|
|
|
nonce: confirmedTx.txParams.nonce,
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [confirmedTx],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: confirmedTx,
|
|
|
|
primaryTransaction: confirmedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(nonceSortedCompletedTransactionsSelector(state)).toStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
expectedResult,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('submittedPendingTransactionsSelector', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const expectedResult = [submittedTx];
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(submittedPendingTransactionsSelector(state)).toStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
expectedResult,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|