Skip to content

Commit b5ec8c5

Browse files
committed
fix: update batch tx unit test
1 parent 71b21dc commit b5ec8c5

File tree

2 files changed

+93
-86
lines changed

2 files changed

+93
-86
lines changed

packages/transaction-controller/src/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,9 +1722,6 @@ export type PublishBatchHookTransaction = {
17221722

17231723
/** Signed transaction data to publish. */
17241724
signedTx: Hex;
1725-
1726-
/** Type of the nested transaction. */
1727-
type?: TransactionType;
17281725
};
17291726

17301727
/**

packages/transaction-controller/src/utils/batch.test.ts

Lines changed: 93 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,55 @@ describe('Batch Utils', () => {
370370
expect(result.batchId).toMatch(/^0x[0-9a-f]{32}$/u);
371371
});
372372

373+
it('preserves nested transaction types when disable7702 is true', async () => {
374+
const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn();
375+
mockRequestApproval(MESSENGER_MOCK, {
376+
state: 'approved',
377+
});
378+
379+
addTransactionMock
380+
.mockResolvedValueOnce({
381+
transactionMeta: {
382+
...TRANSACTION_META_MOCK,
383+
id: TRANSACTION_ID_MOCK,
384+
},
385+
result: Promise.resolve(''),
386+
})
387+
.mockResolvedValueOnce({
388+
transactionMeta: {
389+
...TRANSACTION_META_MOCK,
390+
id: TRANSACTION_ID_2_MOCK,
391+
},
392+
result: Promise.resolve(''),
393+
});
394+
addTransactionBatch({
395+
...request,
396+
publishBatchHook,
397+
request: {
398+
...request.request,
399+
transactions: [
400+
{
401+
...request.request.transactions[0],
402+
type: TransactionType.swap,
403+
},
404+
{
405+
...request.request.transactions[1],
406+
type: TransactionType.bridge,
407+
},
408+
],
409+
disable7702: true,
410+
},
411+
}).catch(() => {
412+
// Intentionally empty
413+
});
414+
415+
await flushPromises();
416+
417+
expect(addTransactionMock).toHaveBeenCalledTimes(2);
418+
expect(addTransactionMock.mock.calls[0][1].type).toBe('swap');
419+
expect(addTransactionMock.mock.calls[1][1].type).toBe('bridge');
420+
});
421+
373422
it('preserves nested transaction types when disable7702 is false', async () => {
374423
const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn();
375424

@@ -883,89 +932,50 @@ describe('Batch Utils', () => {
883932
PUBLISH_BATCH_HOOK_PARAMS,
884933
);
885934
});
886-
887-
it('calls publish batch hook with requested transaction type', async () => {
888-
const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn();
889-
890-
addTransactionMock
891-
.mockResolvedValueOnce({
892-
transactionMeta: {
893-
...TRANSACTION_META_MOCK,
894-
id: TRANSACTION_ID_MOCK,
895-
},
896-
result: Promise.resolve(''),
897-
})
898-
.mockResolvedValueOnce({
899-
transactionMeta: {
900-
...TRANSACTION_META_MOCK,
901-
id: TRANSACTION_ID_2_MOCK,
902-
},
903-
result: Promise.resolve(''),
904-
});
905-
906-
publishBatchHook.mockResolvedValue({
907-
results: [
908-
{
909-
transactionHash: TRANSACTION_HASH_MOCK,
910-
},
911-
{
912-
transactionHash: TRANSACTION_HASH_2_MOCK,
913-
},
914-
],
915-
});
916-
917-
addTransactionBatch({
918-
...request,
919-
publishBatchHook,
920-
request: {
921-
...request.request,
922-
transactions: [
923-
{
924-
...request.request.transactions[0],
925-
type: TransactionType.swap,
926-
},
927-
{
928-
...request.request.transactions[1],
929-
type: TransactionType.bridge,
930-
},
931-
],
932-
disable7702: true,
933-
},
934-
}).catch(() => {
935-
// Intentionally empty
936-
});
937-
938-
expect(request.request.transactions).toHaveLength(2);
939-
await flushPromises();
940-
941-
const publishHooks = addTransactionMock.mock.calls.map(
942-
([, options]) => options.publishHook,
943-
);
944-
945-
publishHooks[0]?.(
946-
TRANSACTION_META_MOCK,
947-
TRANSACTION_SIGNATURE_MOCK,
948-
).catch(() => {
949-
// Intentionally empty
950-
});
951-
952-
publishHooks[1]?.(
953-
TRANSACTION_META_MOCK,
954-
TRANSACTION_SIGNATURE_2_MOCK,
955-
).catch(() => {
956-
// Intentionally empty
957-
});
958-
959-
await flushPromises();
960-
961-
expect(publishBatchHook).toHaveBeenCalledTimes(1);
962-
expect(publishBatchHook.mock.calls[0][0].transactions[0].type).toBe(
963-
TransactionType.swap,
964-
);
965-
expect(publishBatchHook.mock.calls[0][0].transactions[1].type).toBe(
966-
TransactionType.bridge,
967-
);
968-
});
935+
// const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn();
936+
937+
// addTransactionMock
938+
// .mockResolvedValueOnce({
939+
// transactionMeta: {
940+
// ...TRANSACTION_META_MOCK,
941+
// id: TRANSACTION_ID_MOCK,
942+
// },
943+
// result: Promise.resolve(''),
944+
// })
945+
// .mockResolvedValueOnce({
946+
// transactionMeta: {
947+
// ...TRANSACTION_META_MOCK,
948+
// id: TRANSACTION_ID_2_MOCK,
949+
// },
950+
// result: Promise.resolve(''),
951+
// });
952+
// addTransactionBatch({
953+
// ...request,
954+
// publishBatchHook,
955+
// request: {
956+
// ...request.request,
957+
// transactions: [
958+
// {
959+
// ...request.request.transactions[0],
960+
// type: TransactionType.swap,
961+
// },
962+
// {
963+
// ...request.request.transactions[1],
964+
// type: TransactionType.bridge,
965+
// },
966+
// ],
967+
// disable7702: true,
968+
// },
969+
// }).catch(() => {
970+
// // Intentionally empty
971+
// });
972+
973+
// await flushPromises();
974+
975+
// expect(addTransactionMock).toHaveBeenCalledTimes(2);
976+
// expect(addTransactionMock.mock.calls[0][1].type).toBe('swap');
977+
// expect(addTransactionMock.mock.calls[1][1].type).toBe('bridge');
978+
// });
969979

970980
it('resolves individual publish hooks with transaction hashes from publish batch hook', async () => {
971981
const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn();

0 commit comments

Comments
 (0)