-
-
Notifications
You must be signed in to change notification settings - Fork 267
refactor: handle intent orders in fetch bridge tx function #7756
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
oscarwroche
wants to merge
8
commits into
main
Choose a base branch
from
refactor/fetch_bridge_status_intent_refactoring
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.
+868
−329
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d382a5e
refactor: handle intent orders in fetch bridge tx function
oscarwroche 3d93ccd
refactor: refactor transaction sync from intent
oscarwroche fcbd4e3
fix: add cancelled case in status mapping
oscarwroche 1169802
refactor: move intent tx sync to dedicated class
oscarwroche 8d8f7f4
refactor: extract helpers, add tests, remove c8 ignore blocks
oscarwroche 60aa41b
chore: raise coverage limits
oscarwroche e5bf7c2
chore: fix linting
oscarwroche 6dbe727
refactor: use defined type instead of return type
oscarwroche 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
147 changes: 147 additions & 0 deletions
147
packages/bridge-status-controller/src/bridge-status-controller.intent-manager.test.ts
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 |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| import { StatusTypes } from '@metamask/bridge-controller'; | ||
| import { TransactionStatus } from '@metamask/transaction-controller'; | ||
|
|
||
| import { IntentStatusManager } from './bridge-status-controller.intent'; | ||
| import type { BridgeHistoryItem } from './types'; | ||
| import { translateIntentOrderToBridgeStatus } from './utils/intent-api'; | ||
| import { IntentOrderStatus } from './utils/validators'; | ||
|
|
||
| const makeHistoryItem = ( | ||
| overrides?: Partial<BridgeHistoryItem>, | ||
| ): BridgeHistoryItem => | ||
| ({ | ||
| quote: { | ||
| srcChainId: 1, | ||
| destChainId: 1, | ||
| intent: { protocol: 'cowswap' }, | ||
| }, | ||
| status: { | ||
| status: StatusTypes.PENDING, | ||
| srcChain: { chainId: 1, txHash: '' }, | ||
| }, | ||
| account: '0xaccount1', | ||
| estimatedProcessingTimeInSeconds: 10, | ||
| slippagePercentage: 0, | ||
| hasApprovalTx: false, | ||
| ...overrides, | ||
| }) as BridgeHistoryItem; | ||
|
|
||
| describe('IntentStatusManager', () => { | ||
| it('returns early when no original tx id is present', () => { | ||
| const messenger = { | ||
| call: jest.fn(), | ||
| } as any; | ||
| const updateTransactionFn = jest.fn(); | ||
| const manager = new IntentStatusManager({ | ||
| messenger, | ||
| updateTransactionFn, | ||
| }); | ||
|
|
||
| const translation = translateIntentOrderToBridgeStatus( | ||
| { | ||
| id: 'order-1', | ||
| status: IntentOrderStatus.SUBMITTED, | ||
| metadata: {}, | ||
| }, | ||
| 1, | ||
| ); | ||
|
|
||
| manager.syncTransactionFromIntentStatus( | ||
| 'order-1', | ||
| makeHistoryItem({ | ||
| txMetaId: undefined, | ||
| originalTransactionId: undefined, | ||
| }), | ||
| translation, | ||
| IntentOrderStatus.SUBMITTED, | ||
| ); | ||
|
|
||
| expect(updateTransactionFn).not.toHaveBeenCalled(); | ||
| expect(messenger.call).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('logs when TransactionController access throws', () => { | ||
| const messenger = { | ||
| call: jest.fn(() => { | ||
| throw new Error('boom'); | ||
| }), | ||
| } as any; | ||
| const updateTransactionFn = jest.fn(); | ||
| const manager = new IntentStatusManager({ | ||
| messenger, | ||
| updateTransactionFn, | ||
| }); | ||
|
|
||
| const translation = translateIntentOrderToBridgeStatus( | ||
| { | ||
| id: 'order-2', | ||
| status: IntentOrderStatus.SUBMITTED, | ||
| metadata: {}, | ||
| }, | ||
| 1, | ||
| ); | ||
|
|
||
| const consoleSpy = jest | ||
| .spyOn(console, 'error') | ||
| .mockImplementation(() => undefined); | ||
|
|
||
| manager.syncTransactionFromIntentStatus( | ||
| 'order-2', | ||
| makeHistoryItem({ originalTransactionId: 'tx-1' }), | ||
| translation, | ||
| IntentOrderStatus.SUBMITTED, | ||
| ); | ||
|
|
||
| expect(consoleSpy).toHaveBeenCalled(); | ||
| expect(updateTransactionFn).not.toHaveBeenCalled(); | ||
|
|
||
| consoleSpy.mockRestore(); | ||
| }); | ||
|
|
||
| it('updates transaction meta when tx is found', () => { | ||
| const existingTxMeta = { | ||
| id: 'tx-2', | ||
| status: TransactionStatus.submitted, | ||
| txReceipt: { status: '0x0' }, | ||
| }; | ||
| const messenger = { | ||
| call: jest.fn(() => ({ transactions: [existingTxMeta] })), | ||
| } as any; | ||
| const updateTransactionFn = jest.fn(); | ||
| const manager = new IntentStatusManager({ | ||
| messenger, | ||
| updateTransactionFn, | ||
| }); | ||
|
|
||
| const translation = translateIntentOrderToBridgeStatus( | ||
| { | ||
| id: 'order-3', | ||
| status: IntentOrderStatus.COMPLETED, | ||
| txHash: '0xhash', | ||
| metadata: {}, | ||
| }, | ||
| 1, | ||
| ); | ||
|
|
||
| manager.syncTransactionFromIntentStatus( | ||
| 'order-3', | ||
| makeHistoryItem({ originalTransactionId: 'tx-2' }), | ||
| translation, | ||
| IntentOrderStatus.COMPLETED, | ||
| ); | ||
|
|
||
| expect(updateTransactionFn).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| id: 'tx-2', | ||
| status: TransactionStatus.confirmed, | ||
| hash: '0xhash', | ||
| txReceipt: expect.objectContaining({ | ||
| transactionHash: '0xhash', | ||
| status: '0x1', | ||
| }), | ||
| }), | ||
| expect.stringContaining('Intent order status updated'), | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
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.
I don't see
srcTxHashesbeing used in the mobile codebase. And the only usage I see in the controller is for updating the history item. Can this field be removed?