Skip to content

Commit 50dc961

Browse files
committed
refactor(transaction-controller): remove existing transaction deduplication logic
1 parent ca13ccc commit 50dc961

File tree

2 files changed

+90
-393
lines changed

2 files changed

+90
-393
lines changed

packages/transaction-controller/src/TransactionController.test.ts

Lines changed: 0 additions & 273 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,219 +1532,6 @@ describe('TransactionController', () => {
15321532
});
15331533
});
15341534

1535-
describe('with actionId', () => {
1536-
it('adds single unapproved transaction when called twice with same actionId', async () => {
1537-
const { controller, mockTransactionApprovalRequest } = setupController();
1538-
1539-
const mockOrigin = 'origin';
1540-
1541-
await controller.addTransaction(
1542-
{
1543-
from: ACCOUNT_MOCK,
1544-
to: ACCOUNT_MOCK,
1545-
},
1546-
{
1547-
origin: mockOrigin,
1548-
actionId: ACTION_ID_MOCK,
1549-
networkClientId: NETWORK_CLIENT_ID_MOCK,
1550-
},
1551-
);
1552-
1553-
const firstTransactionCount = controller.state.transactions.length;
1554-
1555-
await controller.addTransaction(
1556-
{
1557-
from: ACCOUNT_MOCK,
1558-
to: ACCOUNT_MOCK,
1559-
},
1560-
{
1561-
origin: mockOrigin,
1562-
actionId: ACTION_ID_MOCK,
1563-
networkClientId: NETWORK_CLIENT_ID_MOCK,
1564-
},
1565-
);
1566-
const secondTransactionCount = controller.state.transactions.length;
1567-
1568-
expect(firstTransactionCount).toStrictEqual(secondTransactionCount);
1569-
expect(
1570-
mockTransactionApprovalRequest.actionHandlerMock,
1571-
).toHaveBeenCalledTimes(1);
1572-
expect(
1573-
mockTransactionApprovalRequest.actionHandlerMock,
1574-
).toHaveBeenCalledWith(
1575-
{
1576-
id: expect.any(String),
1577-
origin: mockOrigin,
1578-
type: 'transaction',
1579-
requestData: { txId: expect.any(String) },
1580-
expectsResult: true,
1581-
},
1582-
true,
1583-
);
1584-
});
1585-
1586-
it('adds multiple transactions with same actionId and ensures second transaction result does not resolves before the first transaction result', async () => {
1587-
const { controller, mockTransactionApprovalRequest } = setupController();
1588-
1589-
const mockOrigin = 'origin';
1590-
let firstTransactionCompleted = false;
1591-
let secondTransactionCompleted = false;
1592-
1593-
const { result: firstResult } = await controller.addTransaction(
1594-
{
1595-
from: ACCOUNT_MOCK,
1596-
to: ACCOUNT_MOCK,
1597-
},
1598-
{
1599-
origin: mockOrigin,
1600-
actionId: ACTION_ID_MOCK,
1601-
networkClientId: NETWORK_CLIENT_ID_MOCK,
1602-
},
1603-
);
1604-
1605-
firstResult
1606-
.then(() => {
1607-
firstTransactionCompleted = true;
1608-
return undefined;
1609-
})
1610-
.catch(() => undefined);
1611-
1612-
const { result: secondResult } = await controller.addTransaction(
1613-
{
1614-
from: ACCOUNT_MOCK,
1615-
to: ACCOUNT_MOCK,
1616-
},
1617-
{
1618-
origin: mockOrigin,
1619-
actionId: ACTION_ID_MOCK,
1620-
networkClientId: NETWORK_CLIENT_ID_MOCK,
1621-
},
1622-
);
1623-
secondResult
1624-
.then(() => {
1625-
secondTransactionCompleted = true;
1626-
return undefined;
1627-
})
1628-
.catch(() => undefined);
1629-
1630-
await wait(0);
1631-
1632-
expect(firstTransactionCompleted).toBe(false);
1633-
expect(secondTransactionCompleted).toBe(false);
1634-
1635-
mockTransactionApprovalRequest.approve();
1636-
await firstResult;
1637-
await secondResult;
1638-
1639-
expect(firstTransactionCompleted).toBe(true);
1640-
expect(secondTransactionCompleted).toBe(true);
1641-
});
1642-
1643-
it.each([
1644-
[
1645-
'does not add duplicate transaction if actionId already used',
1646-
ACTION_ID_MOCK,
1647-
ACTION_ID_MOCK,
1648-
1,
1649-
],
1650-
[
1651-
'adds additional transaction if actionId not used',
1652-
ACTION_ID_MOCK,
1653-
'00000',
1654-
2,
1655-
],
1656-
])(
1657-
'%s',
1658-
async (_, firstActionId, secondActionId, expectedTransactionCount) => {
1659-
const { controller, mockTransactionApprovalRequest } =
1660-
setupController();
1661-
const expectedRequestApprovalCalledTimes = expectedTransactionCount;
1662-
1663-
const mockOrigin = 'origin';
1664-
1665-
await controller.addTransaction(
1666-
{
1667-
from: ACCOUNT_MOCK,
1668-
to: ACCOUNT_MOCK,
1669-
},
1670-
{
1671-
origin: mockOrigin,
1672-
actionId: firstActionId,
1673-
networkClientId: NETWORK_CLIENT_ID_MOCK,
1674-
},
1675-
);
1676-
1677-
await controller.addTransaction(
1678-
{
1679-
from: ACCOUNT_MOCK,
1680-
to: ACCOUNT_MOCK,
1681-
},
1682-
{
1683-
origin: mockOrigin,
1684-
actionId: secondActionId,
1685-
networkClientId: NETWORK_CLIENT_ID_MOCK,
1686-
},
1687-
);
1688-
const { transactions } = controller.state;
1689-
1690-
expect(transactions).toHaveLength(expectedTransactionCount);
1691-
expect(
1692-
mockTransactionApprovalRequest.actionHandlerMock,
1693-
).toHaveBeenCalledTimes(expectedRequestApprovalCalledTimes);
1694-
},
1695-
);
1696-
1697-
it.each([
1698-
[
1699-
'adds single transaction when speed up called twice with the same actionId',
1700-
ACTION_ID_MOCK,
1701-
2,
1702-
1,
1703-
],
1704-
[
1705-
'adds multiple transactions when speed up called with non-existent actionId',
1706-
'00000',
1707-
3,
1708-
2,
1709-
],
1710-
])(
1711-
'%s',
1712-
async (
1713-
_,
1714-
actionId,
1715-
expectedTransactionCount,
1716-
expectedSignCalledTimes,
1717-
) => {
1718-
const { controller } = setupController();
1719-
1720-
const { transactionMeta } = await controller.addTransaction(
1721-
{
1722-
from: ACCOUNT_MOCK,
1723-
gas: '0x0',
1724-
gasPrice: '0x50fd51da',
1725-
to: ACCOUNT_MOCK,
1726-
value: '0x0',
1727-
},
1728-
{
1729-
networkClientId: NETWORK_CLIENT_ID_MOCK,
1730-
},
1731-
);
1732-
1733-
await controller.speedUpTransaction(transactionMeta.id, undefined, {
1734-
actionId: ACTION_ID_MOCK,
1735-
});
1736-
1737-
await controller.speedUpTransaction(transactionMeta.id, undefined, {
1738-
actionId,
1739-
});
1740-
1741-
const { transactions } = controller.state;
1742-
expect(transactions).toHaveLength(expectedTransactionCount);
1743-
expect(signMock).toHaveBeenCalledTimes(expectedSignCalledTimes);
1744-
},
1745-
);
1746-
});
1747-
17481535
describe('addTransaction', () => {
17491536
it('adds unapproved transaction to state', async () => {
17501537
const { controller } = setupController();
@@ -3978,36 +3765,6 @@ describe('TransactionController', () => {
39783765
});
39793766

39803767
describe('stopTransaction', () => {
3981-
it('should avoid creating cancel transaction if actionId already exist', async () => {
3982-
const mockActionId = 'mockActionId';
3983-
const { controller } = setupController({
3984-
options: {
3985-
state: {
3986-
transactions: [
3987-
{
3988-
actionId: mockActionId,
3989-
id: '2',
3990-
chainId: toHex(5),
3991-
networkClientId: NETWORK_CLIENT_ID_MOCK,
3992-
status: TransactionStatus.submitted,
3993-
type: TransactionType.cancel,
3994-
time: 123456789,
3995-
txParams: {
3996-
from: ACCOUNT_MOCK,
3997-
},
3998-
},
3999-
],
4000-
},
4001-
},
4002-
});
4003-
4004-
await controller.stopTransaction('2', undefined, {
4005-
actionId: mockActionId,
4006-
});
4007-
4008-
expect(controller.state.transactions).toHaveLength(1);
4009-
});
4010-
40113768
it('should throw error if transaction already confirmed', async () => {
40123769
const { controller } = setupController({
40133770
options: {
@@ -4366,36 +4123,6 @@ describe('TransactionController', () => {
43664123
expect(speedUpTransaction.type).toBe(TransactionType.retry);
43674124
});
43684125

4369-
it('should avoid creating speedup transaction if actionId already exist', async () => {
4370-
const mockActionId = 'mockActionId';
4371-
const { controller } = setupController({
4372-
options: {
4373-
state: {
4374-
transactions: [
4375-
{
4376-
actionId: mockActionId,
4377-
id: '2',
4378-
networkClientId: NETWORK_CLIENT_ID_MOCK,
4379-
chainId: toHex(5),
4380-
status: TransactionStatus.submitted,
4381-
type: TransactionType.retry,
4382-
time: 123456789,
4383-
txParams: {
4384-
from: ACCOUNT_MOCK,
4385-
},
4386-
},
4387-
],
4388-
},
4389-
},
4390-
});
4391-
4392-
await controller.speedUpTransaction('2', undefined, {
4393-
actionId: mockActionId,
4394-
});
4395-
4396-
expect(controller.state.transactions).toHaveLength(1);
4397-
});
4398-
43994126
it('should throw error if transaction already confirmed', async () => {
44004127
const { controller } = setupController({
44014128
options: {

0 commit comments

Comments
 (0)