|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.28; |
| 3 | + |
| 4 | +import {CrossChainDepositExists} from "./CrossChainDepositExists.t.sol"; |
| 5 | +import {IETHBridge} from "src/protocol/IETHBridge.sol"; |
| 6 | + |
| 7 | +/// This contract describes behaviours that should be valid when the deposit is cancelable. |
| 8 | +abstract contract DepositIsCancelable is CrossChainDepositExists { |
| 9 | + function test_cancelDeposit_shouldSucceed() public { |
| 10 | + IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); |
| 11 | + bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); |
| 12 | + vm.prank(cancelerAddress); |
| 13 | + bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); |
| 14 | + } |
| 15 | + |
| 16 | + function test_cancelDeposit_shouldSetClaimedFlag() public { |
| 17 | + IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); |
| 18 | + bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); |
| 19 | + (, bytes32 id) = sampleDepositProof.getDepositInternals(_depositIdx()); |
| 20 | + |
| 21 | + assertFalse(bridge.processed(id), "deposit already marked as claimed"); |
| 22 | + |
| 23 | + vm.prank(cancelerAddress); |
| 24 | + bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); |
| 25 | + assertTrue(bridge.processed(id), "deposit not marked as claimed"); |
| 26 | + } |
| 27 | + |
| 28 | + function test_cancelDeposit_shouldEmitEvent() public { |
| 29 | + IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); |
| 30 | + bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); |
| 31 | + (, bytes32 id) = sampleDepositProof.getDepositInternals(_depositIdx()); |
| 32 | + |
| 33 | + vm.expectEmit(); |
| 34 | + emit IETHBridge.DepositCancelled(id, cancellationRecipient, ""); |
| 35 | + |
| 36 | + vm.prank(cancelerAddress); |
| 37 | + bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); |
| 38 | + } |
| 39 | + |
| 40 | + function test_cancelDeposit_shouldSendETH() public { |
| 41 | + IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); |
| 42 | + bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); |
| 43 | + |
| 44 | + uint256 initialCancellationRecipientBalance = cancellationRecipient.balance; |
| 45 | + uint256 initialRecipientBalance = recipient.balance; |
| 46 | + uint256 initialBridgeBalance = address(bridge).balance; |
| 47 | + |
| 48 | + vm.prank(cancelerAddress); |
| 49 | + bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); |
| 50 | + assertEq(recipient.balance, initialRecipientBalance, "recipient balance mismatch"); |
| 51 | + assertEq( |
| 52 | + cancellationRecipient.balance, |
| 53 | + initialCancellationRecipientBalance + deposit.amount, |
| 54 | + "cancel recipient balance mismatch" |
| 55 | + ); |
| 56 | + assertEq(address(bridge).balance, initialBridgeBalance - deposit.amount, "bridge balance mismatch"); |
| 57 | + } |
| 58 | + |
| 59 | + function test_claimDeposit_shouldRevertWhen_DepositIsCancelled() public { |
| 60 | + IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); |
| 61 | + bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); |
| 62 | + |
| 63 | + vm.prank(cancelerAddress); |
| 64 | + bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); |
| 65 | + vm.expectRevert(IETHBridge.AlreadyProcessed.selector); |
| 66 | + bridge.claimDeposit(deposit, HEIGHT, proof); |
| 67 | + } |
| 68 | + |
| 69 | + function test_cancelDeposit_shouldRevertWhen_CancellerIsNotCaller() public { |
| 70 | + IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); |
| 71 | + bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); |
| 72 | + |
| 73 | + vm.expectRevert(IETHBridge.OnlyCanceler.selector); |
| 74 | + vm.prank(makeAddr("notCanceller")); |
| 75 | + bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +abstract contract DepositIsNotCancelable is CrossChainDepositExists { |
| 80 | + function test_cancelDeposit_shouldRevertWhen_NoCancelerIsSet() public { |
| 81 | + IETHBridge.ETHDeposit memory deposit = sampleDepositProof.getEthDeposit(_depositIdx()); |
| 82 | + bytes memory proof = abi.encode(sampleDepositProof.getDepositSignalProof(_depositIdx())); |
| 83 | + |
| 84 | + vm.expectRevert(IETHBridge.OnlyCanceler.selector); |
| 85 | + vm.prank(cancelerAddress); |
| 86 | + bridge.cancelDeposit(deposit, cancellationRecipient, "", HEIGHT, proof); |
| 87 | + } |
| 88 | +} |
0 commit comments