Skip to content

Commit

Permalink
test(BridgeheadMailbox): IsEthWithdrawalFinalized tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benceharomi committed Oct 4, 2023
1 parent 382ac30 commit 87f53ee
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

/* solhint-disable max-line-length */

import {BridgeheadMailboxTest} from "./_BridgeheadMailbox_Shared.t.sol";
import {IChainGetters} from "../../../../../../cache/solpp-generated-contracts/bridgehead/chain-interfaces/IChainGetters.sol";

/* solhint-enable max-line-length */

contract IsEthWithdrawalFinalizedTest is BridgeheadMailboxTest {
uint256 internal l2MessageIndex;
uint256 internal l2TxNumberInBlock;

function setUp() public {
l2MessageIndex = 123456789;
l2TxNumberInBlock = 23456;
}

function test_WhenChainContractReturnsTrue() public {
vm.mockCall(
bridgehead.getChainContract(chainId),
abi.encodeWithSelector(IChainGetters.isEthWithdrawalFinalized.selector, l2MessageIndex, l2TxNumberInBlock),
abi.encode(true)
);

vm.expectCall(
bridgehead.getChainContract(chainId),
abi.encodeWithSelector(IChainGetters.isEthWithdrawalFinalized.selector, l2MessageIndex, l2TxNumberInBlock)
);

bool res = bridgehead.isEthWithdrawalFinalized(chainId, l2MessageIndex, l2TxNumberInBlock);
assertEq(res, true, "ETH withdrawal should be finalized");
}

function test_WhenChainContractReturnsFalse() public {
vm.mockCall(
bridgehead.getChainContract(chainId),
abi.encodeWithSelector(IChainGetters.isEthWithdrawalFinalized.selector, l2MessageIndex, l2TxNumberInBlock),
abi.encode(false)
);

vm.expectCall(
bridgehead.getChainContract(chainId),
abi.encodeWithSelector(IChainGetters.isEthWithdrawalFinalized.selector, l2MessageIndex, l2TxNumberInBlock)
);

bool res = bridgehead.isEthWithdrawalFinalized(chainId, l2MessageIndex, l2TxNumberInBlock);
assertEq(res, false, "ETH withdrawal should not be finalized");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

/* solhint-disable max-line-length */

import {BridgeheadTest} from "../_Bridgehead_Shared.t.sol";
import {IAllowList} from "../../../../../../cache/solpp-generated-contracts/common/interfaces/IAllowList.sol";
import {IBridgeheadChain} from "../../../../../../cache/solpp-generated-contracts/bridgehead/chain-interfaces/IBridgeheadChain.sol";
import {IProofForBridgehead} from "../../../../../../cache/solpp-generated-contracts/proof-system/proof-system-interfaces/IProofForBridgehead.sol";

/* solhint-enable max-line-length */

contract BridgeheadMailboxTest is BridgeheadTest {
uint256 internal chainId;
address internal chainProofSystem;
address internal chainGovernor;
IAllowList internal chainAllowList;

constructor() {
chainId = 987654321;
chainProofSystem = makeAddr("chainProofSystem");
chainGovernor = makeAddr("chainGovernor");
chainAllowList = IAllowList(makeAddr("chainAllowList"));

vm.mockCall(
bridgehead.getChainImplementation(),
abi.encodeWithSelector(IBridgeheadChain.initialize.selector),
""
);
vm.mockCall(chainProofSystem, abi.encodeWithSelector(IProofForBridgehead.newChain.selector), "");

vm.startPrank(GOVERNOR);
bridgehead.newProofSystem(chainProofSystem);
bridgehead.newChain(chainId, chainProofSystem, chainGovernor, chainAllowList, getDiamondCutData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pragma solidity ^0.8.17;
import {RegistryTest} from "./_Registry_Shared.t.sol";
import {IAllowList} from "../../../../../../cache/solpp-generated-contracts/common/interfaces/IAllowList.sol";
import {AllowList} from "../../../../../../cache/solpp-generated-contracts/common/AllowList.sol";
import {Diamond} from "../../../../../../cache/solpp-generated-contracts/common/libraries/Diamond.sol";
import {IProofForBridgehead} from "../../../../../../cache/solpp-generated-contracts/proof-system/proof-system-interfaces/IProofForBridgehead.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {IBridgeheadChain} from "../../../../../../cache/solpp-generated-contracts/bridgehead/chain-interfaces/IBridgeheadChain.sol";
Expand All @@ -31,15 +30,6 @@ contract NewChainTest is RegistryTest {
bridgehead.newProofSystem(proofSystemAddress);
}

function getDiamondCutData() internal pure returns (Diamond.DiamondCutData memory) {
return
Diamond.DiamondCutData({
facetCuts: new Diamond.FacetCut[](0),
initAddress: address(0x3030303030303030),
initCalldata: bytes("")
});
}

function getChainContractAddress() internal returns (address chainContractAddress) {
vm.mockCall(
bridgehead.getChainImplementation(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.17;
import {Test} from "forge-std/Test.sol";
import {Bridgehead} from "../../../../../cache/solpp-generated-contracts/bridgehead/Bridgehead.sol";
import {IAllowList} from "../../../../../cache/solpp-generated-contracts/common/interfaces/IAllowList.sol";
import {Diamond} from "../../../../../../cache/solpp-generated-contracts/common/libraries/Diamond.sol";

contract BridgeheadTest is Test {
Bridgehead internal bridgehead;
Expand All @@ -21,4 +22,13 @@ contract BridgeheadTest is Test {
bridgehead = new Bridgehead();
bridgehead.initialize(governor, chainImplementation, chainProxyAdmin, allowList, priorityTxMaxGasLimit);
}

function getDiamondCutData() internal pure returns (Diamond.DiamondCutData memory) {
return
Diamond.DiamondCutData({
facetCuts: new Diamond.FacetCut[](0),
initAddress: address(0x3030303030303030),
initCalldata: bytes("")
});
}
}

0 comments on commit 87f53ee

Please sign in to comment.