-
Notifications
You must be signed in to change notification settings - Fork 0
fix: avoid checked ethers sends for bridge EVM txs #196
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
Draft
tansawit
wants to merge
7
commits into
main
Choose a base branch
from
fix/exp-188-unchecked-send
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.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
82b2da8
fix: avoid checked ethers sends for bridge evm txs
tansawit 9261470
fix: check EVM transaction receipt status and throw on revert
cursoragent 475bfbd
fix: restore unchecked EVM confirmation handling
tansawit 3b71f27
Merge origin/main into fix/exp-188-unchecked-send
tansawit ca578c5
fix: narrow evm transaction fallback
tansawit 05e9fa2
refactor: extract evm receipt wait helper
tansawit 11e9b2e
fix: restore evm confirmation timeout
tansawit 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
148 changes: 148 additions & 0 deletions
148
packages/interwovenkit-react/src/pages/bridge/data/evm.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,148 @@ | ||
| import { ethers } from "ethers" | ||
| import { createErc20ApproveTx, sendUncheckedEvmTransaction } from "./evm" | ||
|
|
||
| describe("createErc20ApproveTx", () => { | ||
| it("encodes ERC-20 approve calldata", () => { | ||
| const tx = createErc20ApproveTx({ | ||
| tokenContract: "0x0000000000000000000000000000000000000001", | ||
| spender: "0x0000000000000000000000000000000000000002", | ||
| amount: "123", | ||
| }) | ||
|
|
||
| expect(tx.to).toBe("0x0000000000000000000000000000000000000001") | ||
|
|
||
| const parsed = new ethers.Interface([ | ||
| "function approve(address spender, uint256 amount) external returns (bool)", | ||
| ]).parseTransaction({ data: tx.data as string }) | ||
|
|
||
| expect(parsed?.name).toBe("approve") | ||
| expect(parsed?.args[0]).toBe("0x0000000000000000000000000000000000000002") | ||
| expect(parsed?.args[1]).toBe(123n) | ||
| }) | ||
| }) | ||
|
|
||
| describe("sendUncheckedEvmTransaction", () => { | ||
| it("falls back to waiting by hash with a confirmation timeout", async () => { | ||
| const receipt = { status: 1 } | ||
| const signer = { | ||
| sendUncheckedTransaction: vi.fn().mockResolvedValue("0xabc"), | ||
| } | ||
| const provider = { | ||
| getBlockNumber: vi.fn().mockResolvedValue(123), | ||
| getTransaction: vi.fn().mockResolvedValue(null), | ||
| waitForTransaction: vi.fn().mockResolvedValue(receipt), | ||
| } | ||
| const tx = { to: "0x0000000000000000000000000000000000000001", data: "0x1234" } | ||
|
|
||
| const result = await sendUncheckedEvmTransaction(signer as never, provider as never, tx) | ||
|
|
||
| expect(signer.sendUncheckedTransaction).toHaveBeenCalledWith(tx) | ||
| expect(provider.getBlockNumber).toHaveBeenCalledTimes(1) | ||
| expect(provider.getTransaction).toHaveBeenCalledWith("0xabc") | ||
| await expect(result.wait).resolves.toBe(receipt) | ||
| expect(provider.waitForTransaction).toHaveBeenCalledWith("0xabc", 1, 30000) | ||
| expect(result.txHash).toBe("0xabc") | ||
| }) | ||
|
|
||
| it("falls back to waiting by hash when getTransaction rejects", async () => { | ||
| const receipt = { status: 1 } | ||
| const signer = { | ||
| sendUncheckedTransaction: vi.fn().mockResolvedValue("0xabc"), | ||
| } | ||
| const provider = { | ||
| getBlockNumber: vi.fn().mockResolvedValue(123), | ||
| getTransaction: vi.fn().mockRejectedValue(new Error("invalid value for value.nonce")), | ||
| waitForTransaction: vi.fn().mockResolvedValue(receipt), | ||
| } | ||
| const tx = { to: "0x0000000000000000000000000000000000000001", data: "0x1234" } | ||
|
|
||
| const result = await sendUncheckedEvmTransaction(signer as never, provider as never, tx) | ||
|
|
||
| expect(signer.sendUncheckedTransaction).toHaveBeenCalledWith(tx) | ||
| expect(provider.getTransaction).toHaveBeenCalledWith("0xabc") | ||
| await expect(result.wait).resolves.toBe(receipt) | ||
| expect(provider.waitForTransaction).toHaveBeenCalledWith("0xabc", 1, 30000) | ||
| expect(result.txHash).toBe("0xabc") | ||
| }) | ||
|
|
||
| it("rethrows unrelated getTransaction errors", async () => { | ||
| const signer = { | ||
| sendUncheckedTransaction: vi.fn().mockResolvedValue("0xabc"), | ||
| } | ||
| const provider = { | ||
| getBlockNumber: vi.fn().mockResolvedValue(123), | ||
| getTransaction: vi.fn().mockRejectedValue(new Error("rpc unavailable")), | ||
| waitForTransaction: vi.fn(), | ||
| } | ||
| const tx = { to: "0x0000000000000000000000000000000000000001", data: "0x1234" } | ||
|
|
||
| const result = await sendUncheckedEvmTransaction(signer as never, provider as never, tx) | ||
|
|
||
| await expect(result.wait).rejects.toThrow("rpc unavailable") | ||
| expect(provider.waitForTransaction).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("uses a replaceable transaction wait when the transaction response is available", async () => { | ||
| const receipt = { status: 1 } | ||
| const wait = vi.fn().mockResolvedValue(receipt) | ||
| const replaceableTransaction = vi.fn().mockReturnValue({ wait }) | ||
| const signer = { | ||
| sendUncheckedTransaction: vi.fn().mockResolvedValue("0xabc"), | ||
| } | ||
| const provider = { | ||
| getBlockNumber: vi.fn().mockResolvedValue(123), | ||
| getTransaction: vi.fn().mockResolvedValue({ replaceableTransaction }), | ||
| waitForTransaction: vi.fn(), | ||
| } | ||
| const tx = { to: "0x0000000000000000000000000000000000000001", data: "0x1234" } | ||
|
|
||
| const result = await sendUncheckedEvmTransaction(signer as never, provider as never, tx) | ||
|
|
||
| await expect(result.wait).resolves.toBe(receipt) | ||
| expect(replaceableTransaction).toHaveBeenCalledWith(123) | ||
| expect(wait).toHaveBeenCalledWith(1, 30000) | ||
| expect(provider.waitForTransaction).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("throws CALL_EXCEPTION when transaction reverts", async () => { | ||
| const receipt = { status: 0 } | ||
| const signer = { | ||
| sendUncheckedTransaction: vi.fn().mockResolvedValue("0xabc"), | ||
| } | ||
| const provider = { | ||
| getBlockNumber: vi.fn().mockResolvedValue(123), | ||
| getTransaction: vi.fn().mockResolvedValue(null), | ||
| waitForTransaction: vi.fn().mockResolvedValue(receipt), | ||
| } | ||
| const tx = { to: "0x0000000000000000000000000000000000000001", data: "0x1234" } | ||
|
|
||
| const result = await sendUncheckedEvmTransaction(signer as never, provider as never, tx) | ||
|
|
||
| expect(result.txHash).toBe("0xabc") | ||
| await expect(result.wait).rejects.toMatchObject({ | ||
| message: "transaction execution reverted", | ||
| code: "CALL_EXCEPTION", | ||
| receipt, | ||
| }) | ||
| }) | ||
|
|
||
| it("throws a timeout error when confirmation does not arrive in time", async () => { | ||
| const signer = { | ||
| sendUncheckedTransaction: vi.fn().mockResolvedValue("0xabc"), | ||
| } | ||
| const provider = { | ||
| getBlockNumber: vi.fn().mockResolvedValue(123), | ||
| getTransaction: vi.fn().mockResolvedValue(null), | ||
| waitForTransaction: vi.fn().mockResolvedValue(null), | ||
| } | ||
| const tx = { to: "0x0000000000000000000000000000000000000001", data: "0x1234" } | ||
|
|
||
| const result = await sendUncheckedEvmTransaction(signer as never, provider as never, tx) | ||
|
|
||
| await expect(result.wait).rejects.toMatchObject({ | ||
| message: "Transaction confirmation timed out", | ||
| code: "TIMEOUT", | ||
| transactionHash: "0xabc", | ||
| }) | ||
| }) | ||
| }) |
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
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.