-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Failing CI check is for coverage and for external contributors, they are not permissioned enough to run this check. The reason being Github doesn't allow granting anything except read for tokens, when PR is from fork https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
- Loading branch information
Showing
12 changed files
with
758 additions
and
21 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
l1-contracts/contracts/dev-contracts/test/DummyBridgehub.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,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
import {Bridgehub} from "../../bridgehub/Bridgehub.sol"; | ||
|
||
/// @title DummyBridgehub | ||
/// @notice A test smart contract that allows to set State Transition Manager for a given chain | ||
contract DummyBridgehub is Bridgehub { | ||
// add this to be excluded from coverage report | ||
function test() internal virtual {} | ||
|
||
constructor() Bridgehub() {} | ||
|
||
function setStateTransitionManager(uint256 _chainId, address _stm) external { | ||
stateTransitionManager[_chainId] = _stm; | ||
} | ||
} |
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
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
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
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
81 changes: 81 additions & 0 deletions
81
...t/foundry/unit/concrete/state-transition/chain-deps/facets/Mailbox/BaseMailboxTests.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,81 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
import {MailboxTest} from "./_Mailbox_Shared.t.sol"; | ||
import {FeeParams, PubdataPricingMode} from "contracts/state-transition/chain-deps/ZkSyncHyperchainStorage.sol"; | ||
import {REQUIRED_L2_GAS_PRICE_PER_PUBDATA} from "contracts/common/Config.sol"; | ||
import {DummyHyperchain} from "contracts/dev-contracts/test/DummyHyperchain.sol"; | ||
|
||
contract MailboxBaseTests is MailboxTest { | ||
function setUp() public virtual { | ||
setupDiamondProxy(); | ||
utilsFacet.util_setBaseTokenGasPriceMultiplierDenominator(1); | ||
utilsFacet.util_setBaseTokenGasPriceMultiplierNominator(1); | ||
} | ||
|
||
function test_mailboxConstructor() public { | ||
DummyHyperchain h = new DummyHyperchain(address(0), eraChainId); | ||
assertEq(h.getEraChainId(), eraChainId); | ||
} | ||
|
||
function test_RevertWhen_badDenominatorInL2TransactionBaseCost() public { | ||
utilsFacet.util_setBaseTokenGasPriceMultiplierDenominator(0); | ||
vm.expectRevert("Mailbox: baseTokenGasPriceDenominator not set"); | ||
mailboxFacet.l2TransactionBaseCost(100, 10000, REQUIRED_L2_GAS_PRICE_PER_PUBDATA); | ||
} | ||
|
||
function test_successful_getL2TransactionBaseCostPricingModeValidium() public { | ||
uint256 gasPrice = 10000000; | ||
uint256 l2GasLimit = 1000000; | ||
uint256 l2GasPerPubdataByteLimit = REQUIRED_L2_GAS_PRICE_PER_PUBDATA; | ||
|
||
FeeParams memory feeParams = FeeParams({ | ||
pubdataPricingMode: PubdataPricingMode.Validium, | ||
batchOverheadL1Gas: 1000000, | ||
maxPubdataPerBatch: 120000, | ||
maxL2GasPerBatch: 80000000, | ||
priorityTxMaxPubdata: 99000, | ||
minimalL2GasPrice: 250000000 | ||
}); | ||
|
||
utilsFacet.util_setFeeParams(feeParams); | ||
|
||
// this was get from running the function, but more reasonable would be to | ||
// have some invariants that the calculation should keep for min required gas | ||
// price and also gas limit | ||
uint256 l2TransactionBaseCost = 250125000000000; | ||
|
||
assertEq( | ||
mailboxFacet.l2TransactionBaseCost(gasPrice, l2GasLimit, l2GasPerPubdataByteLimit), | ||
l2TransactionBaseCost | ||
); | ||
} | ||
|
||
function test_successful_getL2TransactionBaseCostPricingModeRollup() public { | ||
uint256 gasPrice = 10000000; | ||
uint256 l2GasLimit = 1000000; | ||
uint256 l2GasPerPubdataByteLimit = REQUIRED_L2_GAS_PRICE_PER_PUBDATA; | ||
|
||
FeeParams memory feeParams = FeeParams({ | ||
pubdataPricingMode: PubdataPricingMode.Rollup, | ||
batchOverheadL1Gas: 1000000, | ||
maxPubdataPerBatch: 120000, | ||
maxL2GasPerBatch: 80000000, | ||
priorityTxMaxPubdata: 99000, | ||
minimalL2GasPrice: 250000000 | ||
}); | ||
|
||
utilsFacet.util_setFeeParams(feeParams); | ||
|
||
// this was get from running the function, but more reasonable would be to | ||
// have some invariants that the calculation should keep for min required gas | ||
// price and also gas limit | ||
uint256 l2TransactionBaseCost = 250125000000000; | ||
|
||
assertEq( | ||
mailboxFacet.l2TransactionBaseCost(gasPrice, l2GasLimit, l2GasPerPubdataByteLimit), | ||
l2TransactionBaseCost | ||
); | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
...foundry/unit/concrete/state-transition/chain-deps/facets/Mailbox/FinalizeWithdrawal.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,63 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
import {MailboxTest} from "./_Mailbox_Shared.t.sol"; | ||
import {DummyBridgehub} from "contracts/dev-contracts/test/DummyBridgehub.sol"; | ||
import {L1SharedBridge} from "contracts/bridge/L1SharedBridge.sol"; | ||
import {IBridgehub} from "contracts/bridgehub/IBridgehub.sol"; | ||
import {IL1SharedBridge} from "contracts/bridge/interfaces/IL1SharedBridge.sol"; | ||
import {DummySharedBridge} from "contracts/dev-contracts/test/DummySharedBridge.sol"; | ||
|
||
contract MailboxFinalizeWithdrawal is MailboxTest { | ||
bytes32[] proof; | ||
bytes message; | ||
DummySharedBridge l1SharedBridge; | ||
address baseTokenBridgeAddress; | ||
|
||
function setUp() public virtual { | ||
setupDiamondProxy(); | ||
|
||
l1SharedBridge = new DummySharedBridge(keccak256("dummyDepositHash")); | ||
baseTokenBridgeAddress = address(l1SharedBridge); | ||
|
||
proof = new bytes32[](0); | ||
message = "message"; | ||
} | ||
|
||
function test_RevertWhen_notEra() public { | ||
utilsFacet.util_setChainId(eraChainId + 1); | ||
|
||
vm.expectRevert("Mailbox: finalizeEthWithdrawal only available for Era on mailbox"); | ||
mailboxFacet.finalizeEthWithdrawal({ | ||
_l2BatchNumber: 0, | ||
_l2MessageIndex: 0, | ||
_l2TxNumberInBatch: 0, | ||
_message: message, | ||
_merkleProof: proof | ||
}); | ||
} | ||
|
||
function test_success_withdrawal(uint256 amount) public { | ||
address baseTokenBridge = makeAddr("baseTokenBridge"); | ||
utilsFacet.util_setChainId(eraChainId); | ||
utilsFacet.util_setBaseTokenBridge(baseTokenBridgeAddress); | ||
|
||
address l1Receiver = makeAddr("receiver"); | ||
address l1Token = address(1); | ||
vm.deal(baseTokenBridgeAddress, amount); | ||
|
||
bytes memory message = abi.encode(l1Receiver, l1Token, amount); | ||
|
||
mailboxFacet.finalizeEthWithdrawal({ | ||
_l2BatchNumber: 0, | ||
_l2MessageIndex: 0, | ||
_l2TxNumberInBatch: 0, | ||
_message: message, | ||
_merkleProof: proof | ||
}); | ||
|
||
assertEq(l1Receiver.balance, amount); | ||
assertEq(baseTokenBridgeAddress.balance, 0); | ||
} | ||
} |
Oops, something went wrong.