Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
303 changes: 0 additions & 303 deletions src/SmartTransactionsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
type NetworkState,
} from '@metamask/network-controller';
import type {
TransactionControllerConfirmExternalTransactionAction,
TransactionControllerGetNonceLockAction,
TransactionControllerGetTransactionsAction,
TransactionControllerUpdateTransactionAction,
Expand Down Expand Up @@ -308,7 +307,7 @@
},
];

const createTransactionMeta = (

Check failure on line 310 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

'createTransactionMeta' is assigned a value but never used

Check failure on line 310 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

'createTransactionMeta' is assigned a value but never used
status: TransactionStatus = TransactionStatus.signed,
) => {
return {
Expand Down Expand Up @@ -460,7 +459,7 @@

controller.timeoutHandle = setTimeout(() => ({}));

controller.poll(1000);

Check warning on line 462 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 462 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

expect(updateSmartTransactionsSpy).toHaveBeenCalled();
});
Expand Down Expand Up @@ -1225,301 +1224,6 @@
);
});

it('confirms a smart transaction that has status success', async () => {
const { smartTransactionsState } =
getDefaultSmartTransactionsControllerState();
const pendingStx = {
...createStateAfterPending()[0],
history: testHistory,
};
const confirmExternalTransactionSpy = jest.fn();
const getRegularTransactionsSpy = jest.fn().mockImplementation(() => {
return [createTransactionMeta()];
});
await withController(
{
options: {
state: {
smartTransactionsState: {
...smartTransactionsState,
smartTransactions: {
[ChainId.mainnet]: [pendingStx] as SmartTransaction[],
},
},
},
},
confirmExternalTransaction: confirmExternalTransactionSpy,
getTransactions: getRegularTransactionsSpy,
},
async ({ controller }) => {
const updateTransaction = {
...pendingStx,
statusMetadata: {
...pendingStx.statusMetadata,
minedHash: txHash,
},
status: SmartTransactionStatuses.SUCCESS,
};

controller.updateSmartTransaction(
updateTransaction as SmartTransaction,
{
networkClientId: NetworkType.mainnet,
},
);
await flushPromises();

expect(confirmExternalTransactionSpy).toHaveBeenCalledTimes(1);
expect(
controller.state.smartTransactionsState.smartTransactions[
ChainId.mainnet
],
).toStrictEqual([
{
...updateTransaction,
confirmed: true,
},
]);
},
);
});

it('confirms a smart transaction that was not found in the list of regular transactions', async () => {
const { smartTransactionsState } =
getDefaultSmartTransactionsControllerState();
const pendingStx = {
...createStateAfterPending()[0],
history: testHistory,
};
const confirmExternalTransactionSpy = jest.fn();
const getRegularTransactionsSpy = jest.fn().mockImplementation(() => {
return [];
});
await withController(
{
options: {
state: {
smartTransactionsState: {
...smartTransactionsState,
smartTransactions: {
[ChainId.mainnet]: [pendingStx] as SmartTransaction[],
},
},
},
},
confirmExternalTransaction: confirmExternalTransactionSpy,
getTransactions: getRegularTransactionsSpy,
},
async ({ controller }) => {
const updateTransaction = {
...pendingStx,
statusMetadata: {
...pendingStx.statusMetadata,
minedHash: txHash,
},
status: SmartTransactionStatuses.SUCCESS,
};

controller.updateSmartTransaction(
updateTransaction as SmartTransaction,
{
networkClientId: NetworkType.mainnet,
},
);
await flushPromises();

expect(confirmExternalTransactionSpy).toHaveBeenCalledTimes(1);
expect(
controller.state.smartTransactionsState.smartTransactions[
ChainId.mainnet
],
).toStrictEqual([
{
...updateTransaction,
confirmed: true,
},
]);
},
);
});

it('confirms a smart transaction that does not have a minedHash', async () => {
const { smartTransactionsState } =
getDefaultSmartTransactionsControllerState();
const pendingStx = {
...createStateAfterPending()[0],
history: testHistory,
};
const confirmExternalTransactionSpy = jest.fn();
const getRegularTransactionsSpy = jest.fn().mockImplementation(() => {
return [createTransactionMeta(TransactionStatus.confirmed)];
});
await withController(
{
options: {
state: {
smartTransactionsState: {
...smartTransactionsState,
smartTransactions: {
[ChainId.mainnet]: [pendingStx] as SmartTransaction[],
},
},
},
},
confirmExternalTransaction: confirmExternalTransactionSpy,
getTransactions: getRegularTransactionsSpy,
},
async ({ controller }) => {
const updateTransaction = {
...pendingStx,
statusMetadata: {
...pendingStx.statusMetadata,
minedHash: '',
},
status: SmartTransactionStatuses.SUCCESS,
};

controller.updateSmartTransaction(
updateTransaction as SmartTransaction,
{
networkClientId: NetworkType.mainnet,
},
);
await flushPromises();

expect(confirmExternalTransactionSpy).toHaveBeenCalledTimes(1);
expect(
controller.state.smartTransactionsState.smartTransactions[
ChainId.mainnet
],
).toStrictEqual([
{
...updateTransaction,
confirmed: true,
},
]);
},
);
});

it('does not call the "confirmExternalTransaction" fn if a tx is already confirmed', async () => {
const { smartTransactionsState } =
getDefaultSmartTransactionsControllerState();
const pendingStx = {
...createStateAfterPending()[0],
history: testHistory,
};
const confirmExternalTransactionSpy = jest.fn();
const getRegularTransactionsSpy = jest.fn().mockImplementation(() => {
return [createTransactionMeta(TransactionStatus.confirmed)];
});
await withController(
{
options: {
state: {
smartTransactionsState: {
...smartTransactionsState,
smartTransactions: {
[ChainId.mainnet]: [pendingStx] as SmartTransaction[],
},
},
},
},
confirmExternalTransaction: confirmExternalTransactionSpy,
getTransactions: getRegularTransactionsSpy,
},
async ({ controller }) => {
const updateTransaction = {
...pendingStx,
status: SmartTransactionStatuses.SUCCESS,
statusMetadata: {
...pendingStx.statusMetadata,
minedHash: txHash,
},
};

controller.updateSmartTransaction(
updateTransaction as SmartTransaction,
{
networkClientId: NetworkType.mainnet,
},
);
await flushPromises();

expect(confirmExternalTransactionSpy).not.toHaveBeenCalled();
expect(
controller.state.smartTransactionsState.smartTransactions[
ChainId.mainnet
],
).toStrictEqual([
{
...updateTransaction,
confirmed: true,
},
]);
},
);
});

it('does not call the "confirmExternalTransaction" fn if a tx is already submitted', async () => {
const { smartTransactionsState } =
getDefaultSmartTransactionsControllerState();
const pendingStx = {
...createStateAfterPending()[0],
history: testHistory,
};
const confirmExternalTransactionSpy = jest.fn();
const getRegularTransactionsSpy = jest.fn().mockImplementation(() => {
return [createTransactionMeta(TransactionStatus.submitted)];
});
await withController(
{
options: {
state: {
smartTransactionsState: {
...smartTransactionsState,
smartTransactions: {
[ChainId.mainnet]: [pendingStx] as SmartTransaction[],
},
},
},
},
confirmExternalTransaction: confirmExternalTransactionSpy,
getTransactions: getRegularTransactionsSpy,
},
async ({ controller }) => {
const updateTransaction = {
...pendingStx,
status: SmartTransactionStatuses.SUCCESS,
statusMetadata: {
...pendingStx.statusMetadata,
minedHash: txHash,
},
};

controller.updateSmartTransaction(
updateTransaction as SmartTransaction,
{
networkClientId: NetworkType.mainnet,
},
);
await flushPromises();

expect(confirmExternalTransactionSpy).not.toHaveBeenCalled();
expect(
controller.state.smartTransactionsState.smartTransactions[
ChainId.mainnet
],
).toStrictEqual([
{
...updateTransaction,
confirmed: true,
},
]);
},
);
});

it('calls updateTransaction when smart transaction is cancelled and returnTxHashAsap is true', async () => {
const mockUpdateTransaction = jest.fn();
const defaultState = getDefaultSmartTransactionsControllerState();
Expand Down Expand Up @@ -2691,7 +2395,6 @@
ConstructorParameters<typeof SmartTransactionsController>[0]
>;
getNonceLock?: TransactionControllerGetNonceLockAction['handler'];
confirmExternalTransaction?: TransactionControllerConfirmExternalTransactionAction['handler'];
getTransactions?: TransactionControllerGetTransactionsAction['handler'];
updateTransaction?: TransactionControllerUpdateTransactionAction['handler'];
};
Expand Down Expand Up @@ -2719,7 +2422,6 @@
nextNonce: 42,
releaseLock: jest.fn(),
}),
confirmExternalTransaction = jest.fn(),
getTransactions = jest.fn(),
updateTransaction = jest.fn(),
} = rest;
Expand Down Expand Up @@ -2792,10 +2494,6 @@
'TransactionController:getNonceLock',
getNonceLock,
);
rootMessenger.registerActionHandler(
'TransactionController:confirmExternalTransaction',
confirmExternalTransaction,
);
rootMessenger.registerActionHandler(
'TransactionController:getTransactions',
getTransactions,
Expand All @@ -2820,7 +2518,6 @@
'NetworkController:getNetworkClientById',
'NetworkController:getState',
'TransactionController:getNonceLock',
'TransactionController:confirmExternalTransaction',
'TransactionController:getTransactions',
'TransactionController:updateTransaction',
],
Expand Down Expand Up @@ -2880,7 +2577,7 @@
triggerNetworStateChange,
});
} finally {
controller.stop();

Check warning on line 2580 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 2580 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
controller.stopAllPolling();
}
}
Loading
Loading