Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
70 changes: 70 additions & 0 deletions src/SmartTransactionsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@

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

controller.poll(1000);

Check warning on line 450 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 450 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 @@ -1578,6 +1578,76 @@
);
});

it('iterates over transactions from all networks when updating statuses', async () => {
// Setup: Create controller with pending transactions on two different networks
const mainnetPendingTx = {
uuid: 'mainnet-tx',
status: SmartTransactionStatuses.PENDING,
chainId: ChainId.mainnet,
networkClientId: NetworkType.mainnet,
};

const sepoliaPendingTx = {
uuid: 'sepolia-tx',
status: SmartTransactionStatuses.PENDING,
chainId: ChainId.sepolia,
networkClientId: NetworkType.sepolia,
};

await withController(
{
options: {
supportedChainIds: [ChainId.mainnet, ChainId.sepolia],
state: {
smartTransactionsState: {
...getDefaultSmartTransactionsControllerState()
.smartTransactionsState,
smartTransactions: {
[ChainId.mainnet]: [mainnetPendingTx] as SmartTransaction[],
[ChainId.sepolia]: [sepoliaPendingTx] as SmartTransaction[],
},
},
},
},
},
async ({ controller }) => {
// Mock the API responses for both networks
nock(API_BASE_URL)
.get(`/networks/1/batchStatus?uuids=mainnet-tx`)
.reply(200, { 'mainnet-tx': {} });

nock(API_BASE_URL)
.get(`/networks/11155111/batchStatus?uuids=sepolia-tx`)
.reply(200, { 'sepolia-tx': {} });

const fetchStatusSpy = jest.spyOn(
controller,
'fetchSmartTransactionsStatus',
);

// Call updateSmartTransactions
await controller.updateSmartTransactions();

// Verify both calls were made with correct parameters
expect(fetchStatusSpy).toHaveBeenCalledTimes(2);
expect(fetchStatusSpy).toHaveBeenNthCalledWith(1, [
expect.objectContaining({
uuid: 'mainnet-tx',
chainId: ChainId.mainnet,
networkClientId: NetworkType.mainnet,
}),
]);
expect(fetchStatusSpy).toHaveBeenNthCalledWith(2, [
expect.objectContaining({
uuid: 'sepolia-tx',
chainId: ChainId.sepolia,
networkClientId: NetworkType.sepolia,
}),
]);
},
);
});

it('does not call updateTransaction when smart transaction is cancelled but returnTxHashAsap is false', async () => {
const mockUpdateTransaction = jest.fn();
await withController(
Expand Down Expand Up @@ -2559,7 +2629,7 @@
triggerNetworStateChange,
});
} finally {
controller.stop();

Check warning on line 2632 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 2632 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();
}
}
9 changes: 5 additions & 4 deletions src/SmartTransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@
isSmartTransactionPending,
);
if (!this.timeoutHandle && pendingTransactions?.length > 0) {
this.poll();

Check warning on line 351 in src/SmartTransactionsController.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 351 in src/SmartTransactionsController.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
} else if (this.timeoutHandle && pendingTransactions?.length === 0) {
this.stop();

Check warning on line 353 in src/SmartTransactionsController.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 353 in src/SmartTransactionsController.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
}
}

Expand All @@ -375,7 +375,7 @@
}

this.timeoutHandle = setInterval(() => {
safelyExecute(async () => this.updateSmartTransactions());

Check warning on line 378 in src/SmartTransactionsController.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 378 in src/SmartTransactionsController.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
}, this.#interval);
await safelyExecute(async () => this.updateSmartTransactions());
}
Expand Down Expand Up @@ -442,7 +442,7 @@
ethQuery = new EthQuery(provider);
}

this.#createOrUpdateSmartTransaction(smartTransaction, {

Check warning on line 445 in src/SmartTransactionsController.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 445 in src/SmartTransactionsController.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
chainId,
ethQuery,
});
Expand Down Expand Up @@ -622,23 +622,24 @@
if (chainIds && !chainIds.includes(chainId as Hex)) {
continue;
}
// Filter pending transactions and map them to the desired shape

// Filter pending transactions for this chainId
const pendingTransactions = transactions
.filter(isSmartTransactionPending)
.map((pendingSmartTransaction) => {
// Use the transaction's chainId (from the key) to derive a networkClientId
// Use the transaction's chainId to derive a networkClientId
const networkClientIdToUse = this.#getNetworkClientId({
chainId: chainId as Hex,
});
return {
uuid: pendingSmartTransaction.uuid,
networkClientId: networkClientIdToUse,
chainId: pendingSmartTransaction.chainId as Hex, // same as the key, but explicit on the transaction
chainId: chainId as Hex,
};
});

if (pendingTransactions.length > 0) {
// Since each group is per chain, all transactions share the same chainId.
// Fetch status updates for all pending transactions on this chain
await this.fetchSmartTransactionsStatus(pendingTransactions);
}
}
Expand Down Expand Up @@ -729,7 +730,7 @@
: originalTxMeta;

if (this.#doesTransactionNeedConfirmation(txHash)) {
this.#confirmExternalTransaction(

Check warning on line 733 in src/SmartTransactionsController.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 733 in src/SmartTransactionsController.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
// TODO: Replace 'as' assertion with correct typing for `txMeta`
txMeta as TransactionMeta,
transactionReceipt,
Expand Down
Loading