Skip to content

Commit

Permalink
[DEPLOY-512]: Adds L2EP Foundry Tests (#11683)
Browse files Browse the repository at this point in the history
* adds l2ep test README and an example test file

* adds scroll validator foundry tests

* Updates L2EP contracts README, adds ScrollSequencerUptimeFeed test cases, and refactors test cases by using a L2EPTest helper

* Updates README, fixes test commands in comments, finish ScrollSequencerUptimeFeed test cases, adds ScrollCrossDomainForwarder skeleton

* updates README, adds ScrollCrossDomainForwarder tests, adds better test case grouping and more comments

* Adds ScrollCrossDomainGovernor foundry tests and adds small comment to ScrollCrossDomainForwarder helper function

* fixes style errors and updates README

* reorganizing l2ep files and adding OptimismValidator foundry tests

* adds OptimismSequencerUptimeFeed foundry tests

* adds OptimismCrossDomainGovernor and OptimismCrossDomainForwarder foundry tests

* adds ArbitrumValidator foundry test

* fixes forge import path for L2EPTest file

* renames L2EPTest.sol to L2EPTest.t.sol, updates README, and fixes foundry import path for Example test

* fixes styling issues for mock L2EP contracts

* fixes paths to mock contracts in scroll hardhat tests

* formatting files

* adds ArbitrumSequencerUptimeFeed test

* adds ArbitrumCrossDomainGovernor foundry tests

* adds ArbitrumCrossDomainForwarder foundry tests

* refactors test helper functions

* adds requested changes

* running formatter

* renames scroll tests, moves helper variables to L2EPTest, adds wrappers script for L2EP, updates README

* updates imports to comply with style guide
  • Loading branch information
chris-de-leon-cll authored Jan 20, 2024
1 parent 6133df8 commit e4bde64
Show file tree
Hide file tree
Showing 29 changed files with 3,821 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/solidity-foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
product: [vrf, automation, llo-feeds, functions, shared]
product: [vrf, automation, llo-feeds, l2ep, functions, shared]
needs: [changes]
name: Foundry Tests ${{ matrix.product }}
# See https://github.com/foundry-rs/foundry/issues/3827
Expand Down
2 changes: 1 addition & 1 deletion contracts/GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ALL_FOUNDRY_PRODUCTS contains a list of all products that have a foundry
# profile defined and use the Foundry snapshots.
ALL_FOUNDRY_PRODUCTS = llo-feeds functions shared
ALL_FOUNDRY_PRODUCTS = l2ep llo-feeds functions shared

# To make a snapshot for a specific product, either set the `FOUNDRY_PROFILE` env var
# or call the target with `FOUNDRY_PROFILE=product`
Expand Down
146 changes: 146 additions & 0 deletions contracts/gas-snapshots/l2ep.gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
ArbitrumCrossDomainForwarder_AcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 37312)
ArbitrumCrossDomainForwarder_AcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 12963)
ArbitrumCrossDomainForwarder_Constructor:test_InitialState() (gas: 18431)
ArbitrumCrossDomainForwarder_Forward:test_Forward() (gas: 47601)
ArbitrumCrossDomainForwarder_Forward:test_ForwardRevert() (gas: 22151)
ArbitrumCrossDomainForwarder_Forward:test_NotCallableByUnknownAddress() (gas: 16048)
ArbitrumCrossDomainForwarder_TransferL1Ownership:test_CallableByL1Owner() (gas: 41408)
ArbitrumCrossDomainForwarder_TransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 19312)
ArbitrumCrossDomainForwarder_TransferL1Ownership:test_NotCallableByL2Owner() (gas: 18323)
ArbitrumCrossDomainForwarder_TransferL1Ownership:test_NotCallableByNonOwners() (gas: 13200)
ArbitrumCrossDomainGovernor_AcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 37312)
ArbitrumCrossDomainGovernor_AcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 12963)
ArbitrumCrossDomainGovernor_Constructor:test_InitialState() (gas: 18454)
ArbitrumCrossDomainGovernor_Forward:test_CallableByL2Owner() (gas: 49720)
ArbitrumCrossDomainGovernor_Forward:test_Forward() (gas: 47658)
ArbitrumCrossDomainGovernor_Forward:test_ForwardRevert() (gas: 24348)
ArbitrumCrossDomainGovernor_Forward:test_NotCallableByUnknownAddress() (gas: 18247)
ArbitrumCrossDomainGovernor_ForwardDelegate:test_BubbleUpRevert() (gas: 19386)
ArbitrumCrossDomainGovernor_ForwardDelegate:test_CallableByCrossDomainMessengerAddressOrL1Owner() (gas: 60617)
ArbitrumCrossDomainGovernor_ForwardDelegate:test_CallableByL2Owner() (gas: 62723)
ArbitrumCrossDomainGovernor_ForwardDelegate:test_NotCallableByUnknownAddress() (gas: 18237)
ArbitrumCrossDomainGovernor_ForwardDelegate:test_RevertsBatchWhenOneCallFails() (gas: 64110)
ArbitrumCrossDomainGovernor_TransferL1Ownership:test_CallableByL1Owner() (gas: 41408)
ArbitrumCrossDomainGovernor_TransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 19312)
ArbitrumCrossDomainGovernor_TransferL1Ownership:test_NotCallableByL2Owner() (gas: 18323)
ArbitrumCrossDomainGovernor_TransferL1Ownership:test_NotCallableByNonOwners() (gas: 13200)
ArbitrumSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForGetAnswer() (gas: 92118)
ArbitrumSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForGetRoundData() (gas: 92673)
ArbitrumSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForGetTimestamp() (gas: 92039)
ArbitrumSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestAnswer() (gas: 89813)
ArbitrumSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestRound() (gas: 89705)
ArbitrumSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestRoundData() (gas: 90246)
ArbitrumSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestTimestamp() (gas: 89690)
ArbitrumSequencerUptimeFeed_AggregatorV3Interface:test_AggregatorV3Interface() (gas: 98825)
ArbitrumSequencerUptimeFeed_AggregatorV3Interface:test_Return0WhenRoundDoesNotExistYet() (gas: 18309)
ArbitrumSequencerUptimeFeed_Constants:test_InitialState() (gas: 5684)
ArbitrumSequencerUptimeFeed_GasCosts:test_GasCosts() (gas: 97495)
ArbitrumSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() (gas: 602711)
ArbitrumSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() (gas: 573802)
ArbitrumSequencerUptimeFeed_UpdateStatus:test_IgnoreOutOfOrderUpdates() (gas: 98976)
ArbitrumSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddr() (gas: 15776)
ArbitrumSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndNoTimeChange() (gas: 113269)
ArbitrumSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndTimeChange() (gas: 113329)
ArbitrumValidator_Validate:test_PostSequencerOffline() (gas: 69068)
OptimismCrossDomainForwarder_AcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 46888)
OptimismCrossDomainForwarder_AcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 22155)
OptimismCrossDomainForwarder_Constructor:test_InitialState() (gas: 18266)
OptimismCrossDomainForwarder_Forward:test_Forward() (gas: 58025)
OptimismCrossDomainForwarder_Forward:test_ForwardRevert() (gas: 32546)
OptimismCrossDomainForwarder_Forward:test_NotCallableByUnknownAddress() (gas: 13859)
OptimismCrossDomainForwarder_TransferL1Ownership:test_CallableByL1Owner() (gas: 48886)
OptimismCrossDomainForwarder_TransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 28767)
OptimismCrossDomainForwarder_TransferL1Ownership:test_NotCallableByL2Owner() (gas: 16134)
OptimismCrossDomainForwarder_TransferL1Ownership:test_NotCallableByNonOwners() (gas: 11011)
OptimismCrossDomainGovernor_AcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 46888)
OptimismCrossDomainGovernor_AcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 22155)
OptimismCrossDomainGovernor_Constructor:test_InitialState() (gas: 18289)
OptimismCrossDomainGovernor_Forward:test_CallableByL2Owner() (gas: 47557)
OptimismCrossDomainGovernor_Forward:test_Forward() (gas: 58096)
OptimismCrossDomainGovernor_Forward:test_ForwardRevert() (gas: 32627)
OptimismCrossDomainGovernor_Forward:test_NotCallableByUnknownAddress() (gas: 16061)
OptimismCrossDomainGovernor_ForwardDelegate:test_BubbleUpRevert() (gas: 29181)
OptimismCrossDomainGovernor_ForwardDelegate:test_CallableByCrossDomainMessengerAddressOrL1Owner() (gas: 72695)
OptimismCrossDomainGovernor_ForwardDelegate:test_CallableByL2Owner() (gas: 72685)
OptimismCrossDomainGovernor_ForwardDelegate:test_NotCallableByUnknownAddress() (gas: 16051)
OptimismCrossDomainGovernor_ForwardDelegate:test_RevertsBatchWhenOneCallFails() (gas: 75908)
OptimismCrossDomainGovernor_TransferL1Ownership:test_CallableByL1Owner() (gas: 48886)
OptimismCrossDomainGovernor_TransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 28767)
OptimismCrossDomainGovernor_TransferL1Ownership:test_NotCallableByL2Owner() (gas: 16134)
OptimismCrossDomainGovernor_TransferL1Ownership:test_NotCallableByNonOwners() (gas: 11011)
OptimismSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForGetAnswer() (gas: 59095)
OptimismSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForGetRoundData() (gas: 59635)
OptimismSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForGetTimestamp() (gas: 58950)
OptimismSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestAnswer() (gas: 56887)
OptimismSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestRound() (gas: 56773)
OptimismSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestRoundData() (gas: 57309)
OptimismSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestTimestamp() (gas: 56740)
OptimismSequencerUptimeFeed_AggregatorV3Interface:test_AggregatorV3Interface() (gas: 65617)
OptimismSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetAnswerWhenRoundDoesNotExistYet() (gas: 18039)
OptimismSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetRoundDataWhenRoundDoesNotExistYet() (gas: 18257)
OptimismSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetTimestampWhenRoundDoesNotExistYet() (gas: 17963)
OptimismSequencerUptimeFeed_Constructor:test_InitialState() (gas: 21078)
OptimismSequencerUptimeFeed_GasCosts:test_GasCosts() (gas: 67197)
OptimismSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() (gas: 597640)
OptimismSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() (gas: 573807)
OptimismSequencerUptimeFeed_UpdateStatus:test_IgnoreOutOfOrderUpdates() (gas: 66532)
OptimismSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddr() (gas: 13560)
OptimismSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddrAndNotL1SenderAddr() (gas: 23967)
OptimismSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenNoChange() (gas: 74035)
OptimismSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndNoTimeChange() (gas: 96155)
OptimismSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndTimeChange() (gas: 96215)
OptimismValidator_SetGasLimit:test_CorrectlyUpdatesTheGasLimit() (gas: 15503)
OptimismValidator_Validate:test_PostSequencerOffline() (gas: 74813)
OptimismValidator_Validate:test_PostSequencerStatusWhenThereIsNotStatusChange() (gas: 74869)
OptimismValidator_Validate:test_RevertsIfCalledByAnAccountWithNoAccess() (gas: 15563)
ScrollCrossDomainForwarder_AcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 46988)
ScrollCrossDomainForwarder_AcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 22207)
ScrollCrossDomainForwarder_Constructor:test_InitialState() (gas: 17930)
ScrollCrossDomainForwarder_Forward:test_Forward() (gas: 58092)
ScrollCrossDomainForwarder_Forward:test_ForwardRevert() (gas: 32619)
ScrollCrossDomainForwarder_Forward:test_NotCallableByUnknownAddress() (gas: 13859)
ScrollCrossDomainForwarder_TransferL1Ownership:test_CallableByL1Owner() (gas: 48952)
ScrollCrossDomainForwarder_TransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 28833)
ScrollCrossDomainForwarder_TransferL1Ownership:test_NotCallableByL2Owner() (gas: 16134)
ScrollCrossDomainForwarder_TransferL1Ownership:test_NotCallableByNonOwners() (gas: 11011)
ScrollCrossDomainGovernor_AcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 46988)
ScrollCrossDomainGovernor_AcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 22207)
ScrollCrossDomainGovernor_Constructor:test_InitialState() (gas: 17953)
ScrollCrossDomainGovernor_Forward:test_CallableByL2Owner() (gas: 47552)
ScrollCrossDomainGovernor_Forward:test_Forward() (gas: 58158)
ScrollCrossDomainGovernor_Forward:test_ForwardRevert() (gas: 32697)
ScrollCrossDomainGovernor_Forward:test_NotCallableByUnknownAddress() (gas: 16058)
ScrollCrossDomainGovernor_ForwardDelegate:test_BubbleUpRevert() (gas: 29248)
ScrollCrossDomainGovernor_ForwardDelegate:test_CallableByCrossDomainMessengerAddressOrL1Owner() (gas: 72756)
ScrollCrossDomainGovernor_ForwardDelegate:test_CallableByL2Owner() (gas: 72746)
ScrollCrossDomainGovernor_ForwardDelegate:test_NotCallableByUnknownAddress() (gas: 16048)
ScrollCrossDomainGovernor_ForwardDelegate:test_RevertsBatchWhenOneCallFails() (gas: 75970)
ScrollCrossDomainGovernor_TransferL1Ownership:test_CallableByL1Owner() (gas: 48952)
ScrollCrossDomainGovernor_TransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 28833)
ScrollCrossDomainGovernor_TransferL1Ownership:test_NotCallableByL2Owner() (gas: 16134)
ScrollCrossDomainGovernor_TransferL1Ownership:test_NotCallableByNonOwners() (gas: 11011)
ScrollSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForGetAnswer() (gas: 57250)
ScrollSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForGetRoundData() (gas: 57780)
ScrollSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForGetTimestamp() (gas: 57105)
ScrollSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestAnswer() (gas: 54888)
ScrollSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestRound() (gas: 54768)
ScrollSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestRoundData() (gas: 55473)
ScrollSequencerUptimeFeed_AggregatorInterfaceGasCosts:test_GasUsageForLatestTimestamp() (gas: 54758)
ScrollSequencerUptimeFeed_AggregatorV3Interface:test_AggregatorV3Interface() (gas: 63903)
ScrollSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetAnswerWhenRoundDoesNotExistYet() (gas: 18035)
ScrollSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetRoundDataWhenRoundDoesNotExistYet() (gas: 18253)
ScrollSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetTimestampWhenRoundDoesNotExistYet() (gas: 17959)
ScrollSequencerUptimeFeed_Constructor:test_InitialState() (gas: 21085)
ScrollSequencerUptimeFeed_GasCosts:test_GasCosts() (gas: 64888)
ScrollSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() (gas: 597491)
ScrollSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() (gas: 573807)
ScrollSequencerUptimeFeed_UpdateStatus:test_IgnoreOutOfOrderUpdates() (gas: 64417)
ScrollSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddr() (gas: 13560)
ScrollSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddrAndNotL1SenderAddr() (gas: 23967)
ScrollSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenNoChange() (gas: 71618)
ScrollSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndNoTimeChange() (gas: 92018)
ScrollSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndTimeChange() (gas: 92078)
ScrollValidator_SetGasLimit:test_CorrectlyUpdatesTheGasLimit() (gas: 15503)
ScrollValidator_Validate:test_PostSequencerOffline() (gas: 75094)
ScrollValidator_Validate:test_PostSequencerStatusWhenThereIsNotStatusChange() (gas: 75156)
ScrollValidator_Validate:test_RevertsIfCalledByAnAccountWithNoAccess() (gas: 15563)
7 changes: 4 additions & 3 deletions contracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ds-test/=foundry-lib/forge-std/lib/ds-test/src
forge-std/=foundry-lib/forge-std/src
ds-test/=foundry-lib/forge-std/lib/ds-test/src/
forge-std/=foundry-lib/forge-std/src/

@openzeppelin/=node_modules/@openzeppelin/
hardhat/=node_modules/hardhat/
@eth-optimism/=node_modules/@eth-optimism
@eth-optimism/=node_modules/@eth-optimism/
@scroll-tech/=node_modules/@scroll-tech/
70 changes: 70 additions & 0 deletions contracts/scripts/native_solc_compile_all_l2ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

###########
# Logging #
###########

set -e

echo " ┌──────────────────────────────────────────────┐"
echo " │ Compiling L2EP contracts... │"
echo " └──────────────────────────────────────────────┘"

######################
# Helper Variable(s) #
######################

export SOLC_VERSION="0.8.19"

SCRIPTPATH="$(
cd "$(dirname "$0")" >/dev/null 2>&1
pwd -P
)"

ROOT="$(
cd "$(dirname "$0")" >/dev/null 2>&1
cd ../ && pwd -P
)"

######################
# Helper Function(s) #
######################

compileContract() {
local optimize_runs=1000000
local version="$1"
local srcpath="$2"
solc \
@openzeppelin/=$ROOT/node_modules/@openzeppelin/ \
@eth-optimism/=$ROOT/node_modules/@eth-optimism/ \
@scroll-tech/=$ROOT/node_modules/@scroll-tech/ \
--overwrite --optimize --optimize-runs $optimize_runs --metadata-hash none \
-o $ROOT/solc/v$SOLC_VERSION/l2ep/"$version" \
--abi --bin \
--allow-paths $ROOT/src/v0.8,$ROOT/node_modules \
$ROOT/src/v0.8/l2ep/"$srcpath"
}

#################
# Version 1.0.0 #
#################

python3 -m pip install --require-hashes -r $SCRIPTPATH/requirements.txt

solc-select install $SOLC_VERSION
solc-select use $SOLC_VERSION

compileContract v1_0_0 dev/arbitrum/ArbitrumValidator.sol
compileContract v1_0_0 dev/arbitrum/ArbitrumSequencerUptimeFeed.sol
compileContract v1_0_0 dev/arbitrum/ArbitrumCrossDomainForwarder.sol
compileContract v1_0_0 dev/arbitrum/ArbitrumCrossDomainGovernor.sol

compileContract v1_0_0 dev/optimism/OptimismValidator.sol
compileContract v1_0_0 dev/optimism/OptimismSequencerUptimeFeed.sol
compileContract v1_0_0 dev/optimism/OptimismCrossDomainForwarder.sol
compileContract v1_0_0 dev/optimism/OptimismCrossDomainGovernor.sol

compileContract v1_0_0 dev/scroll/ScrollValidator.sol
compileContract v1_0_0 dev/scroll/ScrollSequencerUptimeFeed.sol
compileContract v1_0_0 dev/scroll/ScrollCrossDomainForwarder.sol
compileContract v1_0_0 dev/scroll/ScrollCrossDomainGovernor.sol
Loading

0 comments on commit e4bde64

Please sign in to comment.