-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(BridgeheadMailbox): WithdrawFunds tests
- Loading branch information
1 parent
4c9c140
commit 3948097
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
ethereum/test/foundry/unit/concrete/Bridgehead/BridgeheadMailbox/WithdrawFunds.t.sol
This file contains 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,49 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.17; | ||
|
||
/* solhint-disable max-line-length */ | ||
|
||
import {BridgeheadMailboxTest} from "./_BridgeheadMailbox_Shared.t.sol"; | ||
|
||
/* solhint-enable max-line-length */ | ||
|
||
contract WithdrawFundsTest is BridgeheadMailboxTest { | ||
address internal to; | ||
uint256 internal amount; | ||
|
||
function setUp() public { | ||
to = makeAddr("to"); | ||
amount = 123456789; | ||
} | ||
|
||
function test_RevertWhen_CalledByNonChainContract() public { | ||
address nonChainContract = makeAddr("nonChainContract"); | ||
|
||
vm.expectRevert(abi.encodePacked("12c")); | ||
vm.startPrank(nonChainContract); | ||
bridgehead.withdrawFunds(chainId, to, amount); | ||
} | ||
|
||
function test_RevertWhen_NotEnoughBalance() public { | ||
address chainContract = bridgehead.getChainContract(chainId); | ||
|
||
// setting the balance of the bridgehead to 0 and trying to withdraw 1 ether | ||
vm.deal(chainContract, 0 ether); | ||
amount = 1 ether; | ||
|
||
vm.expectRevert(abi.encodePacked("pz")); | ||
vm.startPrank(chainContract); | ||
bridgehead.withdrawFunds(chainId, to, amount); | ||
} | ||
|
||
function test_SuccessfulWithdraw() public { | ||
address chainContract = bridgehead.getChainContract(chainId); | ||
|
||
vm.deal(address(bridgehead), 100 ether); | ||
amount = 10 ether; | ||
|
||
vm.startPrank(chainContract); | ||
bridgehead.withdrawFunds(chainId, to, amount); | ||
} | ||
} |