-
-
Notifications
You must be signed in to change notification settings - Fork 241
fix: preserve transaction type of batched transactions #6056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
micaelae
wants to merge
10
commits into
main
Choose a base branch
from
batched-tx-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3dc5441
fix: preserve transaction type of batched transactions
micaelae 9cc92e6
chore: update changelog
micaelae 51e299e
chore: resolve PR comments
micaelae b19678c
Merge branch 'main' into batched-tx-types
micaelae 242887c
chore: rename type usages
micaelae c466dfb
chore: add unit test for 7702-enabled batch transactions
micaelae 34d6594
chore: add type to PublishBatchHookTransaction and NestedTransactionM…
micaelae e252d70
fix: unit test
micaelae 958a0d2
chore: update changelog
micaelae 71b21dc
Merge branch 'main' into batched-tx-types
micaelae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,6 +370,52 @@ describe('Batch Utils', () => { | |
expect(result.batchId).toMatch(/^0x[0-9a-f]{32}$/u); | ||
}); | ||
|
||
it('preserves nested transaction types when disable7702 is false', async () => { | ||
const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn(); | ||
|
||
isAccountUpgradedToEIP7702Mock.mockResolvedValueOnce({ | ||
delegationAddress: undefined, | ||
isSupported: true, | ||
}); | ||
|
||
addTransactionMock.mockResolvedValueOnce({ | ||
transactionMeta: TRANSACTION_META_MOCK, | ||
result: Promise.resolve(''), | ||
}); | ||
|
||
const result = await addTransactionBatch({ | ||
...request, | ||
publishBatchHook, | ||
request: { | ||
...request.request, | ||
transactions: [ | ||
{ | ||
...request.request.transactions[0], | ||
type: TransactionType.swapApproval, | ||
}, | ||
{ | ||
...request.request.transactions[1], | ||
type: TransactionType.bridgeApproval, | ||
}, | ||
], | ||
disable7702: false, | ||
}, | ||
}); | ||
|
||
expect(result.batchId).toMatch(/^0x[0-9a-f]{32}$/u); | ||
expect(addTransactionMock).toHaveBeenCalledTimes(1); | ||
expect(addTransactionMock.mock.calls[0][1].type).toStrictEqual( | ||
TransactionType.batch, | ||
); | ||
|
||
expect( | ||
addTransactionMock.mock.calls[0][1].nestedTransactions?.[0].type, | ||
).toBe(TransactionType.swapApproval); | ||
expect( | ||
addTransactionMock.mock.calls[0][1].nestedTransactions?.[1].type, | ||
).toBe(TransactionType.bridgeApproval); | ||
}); | ||
|
||
it('returns provided batch ID', async () => { | ||
isAccountUpgradedToEIP7702Mock.mockResolvedValueOnce({ | ||
delegationAddress: undefined, | ||
|
@@ -838,6 +884,89 @@ describe('Batch Utils', () => { | |
); | ||
}); | ||
|
||
it('calls publish batch hook with requested transaction type', async () => { | ||
micaelae marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn(); | ||
|
||
addTransactionMock | ||
.mockResolvedValueOnce({ | ||
transactionMeta: { | ||
...TRANSACTION_META_MOCK, | ||
id: TRANSACTION_ID_MOCK, | ||
}, | ||
result: Promise.resolve(''), | ||
}) | ||
.mockResolvedValueOnce({ | ||
transactionMeta: { | ||
...TRANSACTION_META_MOCK, | ||
id: TRANSACTION_ID_2_MOCK, | ||
}, | ||
result: Promise.resolve(''), | ||
}); | ||
|
||
publishBatchHook.mockResolvedValue({ | ||
results: [ | ||
{ | ||
transactionHash: TRANSACTION_HASH_MOCK, | ||
}, | ||
{ | ||
transactionHash: TRANSACTION_HASH_2_MOCK, | ||
}, | ||
], | ||
}); | ||
|
||
addTransactionBatch({ | ||
...request, | ||
publishBatchHook, | ||
request: { | ||
...request.request, | ||
transactions: [ | ||
{ | ||
...request.request.transactions[0], | ||
type: TransactionType.swap, | ||
}, | ||
{ | ||
...request.request.transactions[1], | ||
type: TransactionType.bridge, | ||
}, | ||
], | ||
disable7702: true, | ||
}, | ||
}).catch(() => { | ||
// Intentionally empty | ||
}); | ||
|
||
expect(request.request.transactions).toHaveLength(2); | ||
await flushPromises(); | ||
|
||
const publishHooks = addTransactionMock.mock.calls.map( | ||
([, options]) => options.publishHook, | ||
); | ||
|
||
publishHooks[0]?.( | ||
TRANSACTION_META_MOCK, | ||
TRANSACTION_SIGNATURE_MOCK, | ||
).catch(() => { | ||
// Intentionally empty | ||
}); | ||
|
||
publishHooks[1]?.( | ||
TRANSACTION_META_MOCK, | ||
TRANSACTION_SIGNATURE_2_MOCK, | ||
).catch(() => { | ||
// Intentionally empty | ||
}); | ||
|
||
await flushPromises(); | ||
|
||
expect(publishBatchHook).toHaveBeenCalledTimes(1); | ||
expect(publishBatchHook.mock.calls[0][0].transactions[0].type).toBe( | ||
TransactionType.swap, | ||
); | ||
expect(publishBatchHook.mock.calls[0][0].transactions[1].type).toBe( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than asserting the hook is called with the type, ideally the hook wouldn't know, and instead we could verify that |
||
TransactionType.bridge, | ||
); | ||
}); | ||
|
||
it('resolves individual publish hooks with transaction hashes from publish batch hook', async () => { | ||
const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn(); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the
type
here?The intent of providing the
id
is so the hook can require any specific transaction metadata it needs via the transaction controller state and that reference.