-
Notifications
You must be signed in to change notification settings - Fork 10
Cancel eth tests #136
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
Merged
Merged
Cancel eth tests #136
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ee2d18e
cancellation tests
LeoPatOZ 42de4fb
update claimed to processed in error, added test
LeoPatOZ bcd11c8
comment
LeoPatOZ 615cd12
Merge branch 'main' into cancel-eth-tests
LeoPatOZ ceae146
update scenarios so not all deposits are cancelable
LeoPatOZ 6023b80
cancel to payable function
LeoPatOZ 23b951b
fix cancel scenario to contract
LeoPatOZ 4555b9f
Merge branch 'main' into cancel-eth-tests
LeoPatOZ 2732d1d
change comments add more scenarios
LeoPatOZ 3406250
nit
LeoPatOZ ff8118d
Merge branch 'main' into cancel-eth-tests
LeoPatOZ 64b2d8b
merge and add cancel test
LeoPatOZ fe3c87e
Merge branch 'main' into cancel-eth-tests
LeoPatOZ d1a1cd8
fix cancel tests
LeoPatOZ 62935cb
fmt
LeoPatOZ 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| { "num_publications": 20, "average_gas_used_publish": 44563 } | ||
|
|
||
| {num_publications:20, | ||
| average_gas_used_publish: 44563} | ||
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
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,88 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import {CrossChainDepositExists} from "./CrossChainDepositExists.t.sol"; | ||
| import {IETHBridge} from "src/protocol/IETHBridge.sol"; | ||
|
|
||
| /// This contract describes behaviours that should be valid when the deposit is cancelable. | ||
| abstract contract DepositIsCancelable is CrossChainDepositExists { | ||
| function test_cancelDeposit_shouldSucceed() public { | ||
| IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); | ||
| bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); | ||
| vm.prank(cancelerAddress); | ||
| bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); | ||
| } | ||
|
|
||
| function test_cancelDeposit_shouldSetClaimedFlag() public { | ||
| IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); | ||
| bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); | ||
| (, bytes32 id) = sampleDepositProof.getDepositInternals(_depositIdx()); | ||
|
|
||
| assertFalse(bridge.processed(id), "deposit already marked as claimed"); | ||
|
|
||
| vm.prank(cancelerAddress); | ||
| bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); | ||
| assertTrue(bridge.processed(id), "deposit not marked as claimed"); | ||
| } | ||
|
|
||
| function test_cancelDeposit_shouldEmitEvent() public { | ||
| IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); | ||
| bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); | ||
| (, bytes32 id) = sampleDepositProof.getDepositInternals(_depositIdx()); | ||
|
|
||
| vm.expectEmit(); | ||
| emit IETHBridge.DepositCancelled(id, cancellationRecipient, ""); | ||
|
|
||
| vm.prank(cancelerAddress); | ||
| bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); | ||
| } | ||
|
|
||
| function test_cancelDeposit_shouldSendETH() public { | ||
| IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); | ||
| bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); | ||
|
|
||
| uint256 initialCancellationRecipientBalance = cancellationRecipient.balance; | ||
| uint256 initialRecipientBalance = recipient.balance; | ||
| uint256 initialBridgeBalance = address(bridge).balance; | ||
|
|
||
| vm.prank(cancelerAddress); | ||
| bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); | ||
| assertEq(recipient.balance, initialRecipientBalance, "recipient balance mismatch"); | ||
| assertEq( | ||
| cancellationRecipient.balance, | ||
| initialCancellationRecipientBalance + deposit.amount, | ||
| "cancel recipient balance mismatch" | ||
| ); | ||
| assertEq(address(bridge).balance, initialBridgeBalance - deposit.amount, "bridge balance mismatch"); | ||
| } | ||
|
|
||
| function test_claimDeposit_shouldRevertWhen_DepositIsCancelled() public { | ||
| IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); | ||
| bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); | ||
|
|
||
| vm.prank(cancelerAddress); | ||
| bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); | ||
| vm.expectRevert(IETHBridge.AlreadyProcessed.selector); | ||
| bridge.claimDeposit(deposit, HEIGHT, proof); | ||
| } | ||
|
|
||
| function test_cancelDeposit_shouldRevertWhen_CancellerIsNotCaller() public { | ||
| IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); | ||
| bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); | ||
|
|
||
| vm.expectRevert(IETHBridge.OnlyCanceler.selector); | ||
| vm.prank(makeAddr("notCanceller")); | ||
| bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); | ||
| } | ||
| } | ||
|
|
||
| abstract contract DepositIsNotCancelable is CrossChainDepositExists { | ||
| function test_cancelDeposit_shouldRevertWhen_NoCancelerIsSet() public { | ||
| IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); | ||
| bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); | ||
|
|
||
| vm.expectRevert(IETHBridge.OnlyCanceler.selector); | ||
| vm.prank(cancelerAddress); | ||
| bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); | ||
| } | ||
| } |
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
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.
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.
Fix invalid JSON format.
The JSON file has unquoted property keys which violates JSON specification and will cause parsing errors. Property keys must be enclosed in double quotes.
Apply this diff to fix the JSON formatting:
📝 Committable suggestion
🧰 Tools
🪛 Biome (2.1.2)
[error] 1-1: Property key must be double quoted
(parse)
[error] 1-2: Property key must be double quoted
(parse)
🤖 Prompt for AI Agents