1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/components/app/transaction-activity-log/transaction-activity-log.util.test.js

434 lines
13 KiB
JavaScript
Raw Normal View History

2021-06-08 17:25:48 +02:00
import { GAS_LIMITS } from '../../../../shared/constants/gas';
import {
TransactionStatus,
TransactionType,
} from '../../../../shared/constants/transaction';
2020-11-03 00:41:28 +01:00
import {
combineTransactionHistories,
getActivities,
} from './transaction-activity-log.util';
2018-12-09 21:48:06 +01:00
describe('TransactionActivityLog utils', () => {
describe('combineTransactionHistories', () => {
it('should return no activities for an empty list of transactions', () => {
expect(combineTransactionHistories([])).toStrictEqual([]);
});
2018-12-09 21:48:06 +01:00
it('should return activities for an array of transactions', () => {
const transactions = [
{
2022-07-31 20:26:40 +02:00
hash: '0xa14f13d36b3901e352ce3a7acb9b47b001e5a3370f06232a0953c6fc6fad91b3',
history: [
{
2020-11-03 00:41:28 +01:00
id: 6400627574331058,
time: 1543958845581,
status: TransactionStatus.unapproved,
metamaskNetworkId: '5',
chainId: '0x5',
2020-11-03 00:41:28 +01:00
loadingDefaults: true,
txParams: {
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
value: '0x2386f26fc10000',
2021-06-08 17:25:48 +02:00
gas: GAS_LIMITS.SIMPLE,
2020-11-03 00:41:28 +01:00
gasPrice: '0x3b9aca00',
},
type: TransactionType.simpleSend,
2018-12-09 21:48:06 +01:00
},
2020-11-03 00:41:28 +01:00
[
{
op: 'replace',
path: '/status',
value: TransactionStatus.approved,
2020-11-03 00:41:28 +01:00
note: 'txStateManager: setting status to approved',
timestamp: 1543958847813,
},
],
[
{
op: 'replace',
path: '/status',
value: TransactionStatus.submitted,
2020-11-03 00:41:28 +01:00
note: 'txStateManager: setting status to submitted',
timestamp: 1543958848147,
},
],
[
{
op: 'replace',
path: '/status',
value: TransactionStatus.dropped,
2020-11-03 00:41:28 +01:00
note: 'txStateManager: setting status to dropped',
timestamp: 1543958897181,
},
{
op: 'add',
path: '/replacedBy',
value:
'0xecbe181ee67c4291d04a7cb9ffbf1d5d831e4fbaa89994fd06bab5dd4cc79b33',
},
],
],
id: 6400627574331058,
loadingDefaults: false,
metamaskNetworkId: '5',
chainId: '0x5',
status: TransactionStatus.dropped,
submittedTime: 1543958848135,
time: 1543958845581,
txParams: {
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
2021-06-08 17:25:48 +02:00
gas: GAS_LIMITS.SIMPLE,
gasPrice: '0x3b9aca00',
nonce: '0x32',
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
value: '0x2386f26fc10000',
2018-12-09 21:48:06 +01:00
},
type: TransactionType.simpleSend,
2020-11-03 00:41:28 +01:00
},
{
2022-07-31 20:26:40 +02:00
hash: '0xecbe181ee67c4291d04a7cb9ffbf1d5d831e4fbaa89994fd06bab5dd4cc79b33',
history: [
{
2020-11-03 00:41:28 +01:00
id: 6400627574331060,
time: 1543958857697,
status: TransactionStatus.unapproved,
metamaskNetworkId: '5',
chainId: '0x5',
2020-11-03 00:41:28 +01:00
loadingDefaults: false,
txParams: {
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
value: '0x2386f26fc10000',
2021-06-08 17:25:48 +02:00
gas: GAS_LIMITS.SIMPLE,
2020-11-03 00:41:28 +01:00
gasPrice: '0x3b9aca00',
nonce: '0x32',
},
2020-11-03 00:41:28 +01:00
lastGasPrice: '0x4190ab00',
type: TransactionType.retry,
},
2020-11-03 00:41:28 +01:00
[
{
op: 'replace',
path: '/txParams/gasPrice',
value: '0x481f2280',
note: 'confTx: user approved transaction',
timestamp: 1543958859470,
},
],
[
{
op: 'replace',
path: '/status',
value: TransactionStatus.approved,
2020-11-03 00:41:28 +01:00
note: 'txStateManager: setting status to approved',
timestamp: 1543958859485,
},
],
[
{
op: 'replace',
path: '/status',
value: TransactionStatus.signed,
2020-11-03 00:41:28 +01:00
note: 'transactions#publishTransaction',
timestamp: 1543958859889,
},
],
[
{
op: 'replace',
path: '/status',
value: TransactionStatus.submitted,
2020-11-03 00:41:28 +01:00
note: 'txStateManager: setting status to submitted',
timestamp: 1543958860061,
},
],
[
{
op: 'add',
path: '/firstRetryBlockNumber',
value: '0x45a0fd',
note: 'transactions/pending-tx-tracker#event: tx:block-update',
timestamp: 1543958896466,
},
],
[
{
op: 'replace',
path: '/status',
value: TransactionStatus.confirmed,
2020-11-03 00:41:28 +01:00
timestamp: 1543958897165,
},
],
],
id: 6400627574331060,
lastGasPrice: '0x4190ab00',
loadingDefaults: false,
metamaskNetworkId: '5',
chainId: '0x5',
status: TransactionStatus.confirmed,
submittedTime: 1543958860054,
time: 1543958857697,
txParams: {
from: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
2021-06-08 17:25:48 +02:00
gas: GAS_LIMITS.SIMPLE,
gasPrice: '0x481f2280',
nonce: '0x32',
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
value: '0x2386f26fc10000',
},
txReceipt: {
status: '0x1',
},
type: TransactionType.retry,
},
];
const expected = [
{
id: 6400627574331058,
metamaskNetworkId: '5',
chainId: '0x5',
2022-07-31 20:26:40 +02:00
hash: '0xa14f13d36b3901e352ce3a7acb9b47b001e5a3370f06232a0953c6fc6fad91b3',
eventKey: 'transactionCreated',
timestamp: 1543958845581,
value: '0x2386f26fc10000',
2020-11-03 00:41:28 +01:00
},
{
id: 6400627574331058,
metamaskNetworkId: '5',
chainId: '0x5',
2022-07-31 20:26:40 +02:00
hash: '0xa14f13d36b3901e352ce3a7acb9b47b001e5a3370f06232a0953c6fc6fad91b3',
eventKey: 'transactionSubmitted',
timestamp: 1543958848147,
value: '0x1319718a5000',
2020-11-03 00:41:28 +01:00
},
{
id: 6400627574331060,
metamaskNetworkId: '5',
chainId: '0x5',
2022-07-31 20:26:40 +02:00
hash: '0xecbe181ee67c4291d04a7cb9ffbf1d5d831e4fbaa89994fd06bab5dd4cc79b33',
eventKey: 'transactionResubmitted',
timestamp: 1543958860061,
value: '0x171c3a061400',
2020-11-03 00:41:28 +01:00
},
{
id: 6400627574331060,
metamaskNetworkId: '5',
chainId: '0x5',
2022-07-31 20:26:40 +02:00
hash: '0xecbe181ee67c4291d04a7cb9ffbf1d5d831e4fbaa89994fd06bab5dd4cc79b33',
eventKey: 'transactionConfirmed',
timestamp: 1543958897165,
value: '0x171c3a061400',
},
];
expect(combineTransactionHistories(transactions)).toStrictEqual(expected);
});
});
describe('getActivities', () => {
it('should return no activities for an empty history', () => {
const transaction = {
history: [],
id: 1,
status: TransactionStatus.confirmed,
2018-12-09 21:48:06 +01:00
txParams: {
from: '0x1',
2021-06-08 17:25:48 +02:00
gas: GAS_LIMITS.SIMPLE,
2018-12-09 21:48:06 +01:00
gasPrice: '0x3b9aca00',
nonce: '0xa4',
to: '0x2',
2018-12-09 21:48:06 +01:00
value: '0x2386f26fc10000',
},
};
expect(getActivities(transaction)).toStrictEqual([]);
});
it("should return activities for a transaction's history", () => {
const transaction = {
2018-12-09 21:48:06 +01:00
history: [
{
id: 5559712943815343,
loadingDefaults: true,
metamaskNetworkId: '5',
chainId: '0x5',
status: TransactionStatus.unapproved,
time: 1535507561452,
txParams: {
from: '0x1',
2021-06-08 17:25:48 +02:00
gas: GAS_LIMITS.SIMPLE,
gasPrice: '0x3b9aca00',
nonce: '0xa4',
to: '0x2',
value: '0x2386f26fc10000',
2018-12-09 21:48:06 +01:00
},
},
[
{
op: 'replace',
path: '/loadingDefaults',
timestamp: 1535507561515,
value: false,
},
],
[
{
note: '#newUnapprovedTransaction - adding the origin',
op: 'add',
path: '/origin',
timestamp: 1535507561516,
value: 'MetaMask',
},
[],
],
[
{
note: 'confTx: user approved transaction',
op: 'replace',
path: '/txParams/gasPrice',
timestamp: 1535664571504,
value: '0x77359400',
},
],
[
{
note: 'txStateManager: setting status to approved',
op: 'replace',
path: '/status',
timestamp: 1535507564302,
value: TransactionStatus.approved,
},
],
[
{
note: 'transactions#approveTransaction',
op: 'add',
path: '/txParams/nonce',
timestamp: 1535507564439,
value: '0xa4',
},
{
op: 'add',
path: '/nonceDetails',
value: {
local: {},
network: {},
params: {},
},
},
],
[
{
note: 'transactions#publishTransaction',
op: 'replace',
path: '/status',
timestamp: 1535507564518,
value: TransactionStatus.signed,
},
{
op: 'add',
path: '/rawTx',
2020-11-03 00:41:28 +01:00
value:
'0xf86b81a4843b9aca008252089450a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706872386f26fc10000802aa007b30119fc4fc5954fad727895b7e3ba80a78d197e95703cc603bcf017879151a01c50beda40ffaee541da9c05b9616247074f25f392800e0ad6c7a835d5366edf',
},
],
[],
[
{
note: 'transactions#setTxHash',
op: 'add',
path: '/hash',
timestamp: 1535507564658,
2020-11-03 00:41:28 +01:00
value:
'0x7acc4987b5c0dfa8d423798a8c561138259de1f98a62e3d52e7e83c0e0dd9fb7',
},
],
[
{
note: 'txStateManager - add submitted time stamp',
op: 'add',
path: '/submittedTime',
timestamp: 1535507564660,
value: 1535507564660,
},
],
[
{
note: 'txStateManager: setting status to submitted',
op: 'replace',
path: '/status',
timestamp: 1535507564665,
value: TransactionStatus.submitted,
},
],
[
{
note: 'transactions/pending-tx-tracker#event: tx:block-update',
op: 'add',
path: '/firstRetryBlockNumber',
timestamp: 1535507575476,
value: '0x3bf624',
},
],
[
{
note: 'txStateManager: setting status to confirmed',
op: 'replace',
path: '/status',
timestamp: 1535507615993,
value: TransactionStatus.confirmed,
},
],
2018-12-09 21:48:06 +01:00
],
id: 1,
status: TransactionStatus.confirmed,
2018-12-09 21:48:06 +01:00
txParams: {
from: '0x1',
2021-06-08 17:25:48 +02:00
gas: GAS_LIMITS.SIMPLE,
gasPrice: '0x3b9aca00',
nonce: '0xa4',
to: '0x2',
2018-12-09 21:48:06 +01:00
value: '0x2386f26fc10000',
},
hash: '0xabc',
chainId: '0x5',
metamaskNetworkId: '5',
};
2018-12-09 21:48:06 +01:00
const expectedResult = [
{
2020-11-03 00:41:28 +01:00
eventKey: 'transactionCreated',
timestamp: 1535507561452,
value: '0x2386f26fc10000',
id: 1,
hash: '0xabc',
chainId: '0x5',
metamaskNetworkId: '5',
},
{
2020-11-03 00:41:28 +01:00
eventKey: 'transactionSubmitted',
timestamp: 1535507564665,
value: '0x2632e314a000',
id: 1,
hash: '0xabc',
chainId: '0x5',
metamaskNetworkId: '5',
},
{
2020-11-03 00:41:28 +01:00
eventKey: 'transactionConfirmed',
timestamp: 1535507615993,
value: '0x2632e314a000',
id: 1,
hash: '0xabc',
chainId: '0x5',
metamaskNetworkId: '5',
},
];
expect(getActivities(transaction, true)).toStrictEqual(expectedResult);
});
});
});