Skip to content

Commit

Permalink
test(BridgeheadMailbox): WithdrawFunds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benceharomi committed Oct 5, 2023
1 parent 4c9c140 commit 3948097
Showing 1 changed file with 49 additions and 0 deletions.
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);
}
}

0 comments on commit 3948097

Please sign in to comment.