Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEPLOY-512]: Adds L2EP Foundry Tests #11683

Merged
merged 26 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
72364a9
adds l2ep test README and an example test file
chris-de-leon-cll Dec 20, 2023
fdb11cb
adds scroll validator foundry tests
chris-de-leon-cll Dec 20, 2023
89ea525
Updates L2EP contracts README, adds ScrollSequencerUptimeFeed test ca…
chris-de-leon-cll Dec 22, 2023
da01f1a
Updates README, fixes test commands in comments, finish ScrollSequenc…
chris-de-leon-cll Dec 22, 2023
7b40e8a
updates README, adds ScrollCrossDomainForwarder tests, adds better te…
chris-de-leon-cll Dec 23, 2023
f7901ef
Adds ScrollCrossDomainGovernor foundry tests and adds small comment t…
chris-de-leon-cll Dec 23, 2023
92e43c5
fixes style errors and updates README
chris-de-leon-cll Jan 2, 2024
197783a
reorganizing l2ep files and adding OptimismValidator foundry tests
chris-de-leon-cll Jan 2, 2024
be3ed77
adds OptimismSequencerUptimeFeed foundry tests
chris-de-leon-cll Jan 2, 2024
732d728
adds OptimismCrossDomainGovernor and OptimismCrossDomainForwarder fou…
chris-de-leon-cll Jan 3, 2024
33cf41e
adds ArbitrumValidator foundry test
chris-de-leon-cll Jan 4, 2024
2dff440
fixes forge import path for L2EPTest file
chris-de-leon-cll Jan 4, 2024
d585d34
renames L2EPTest.sol to L2EPTest.t.sol, updates README, and fixes fou…
chris-de-leon-cll Jan 4, 2024
bea23f6
fixes styling issues for mock L2EP contracts
chris-de-leon-cll Jan 4, 2024
adba249
fixes paths to mock contracts in scroll hardhat tests
chris-de-leon-cll Jan 5, 2024
88f0b17
formatting files
chris-de-leon-cll Jan 5, 2024
2bad3d9
adds ArbitrumSequencerUptimeFeed test
chris-de-leon-cll Jan 5, 2024
e9b0e56
adds ArbitrumCrossDomainGovernor foundry tests
chris-de-leon-cll Jan 6, 2024
edd4bfc
adds ArbitrumCrossDomainForwarder foundry tests
chris-de-leon-cll Jan 6, 2024
513bc56
refactors test helper functions
chris-de-leon-cll Jan 6, 2024
c07a2c6
adds requested changes
chris-de-leon-cll Jan 10, 2024
2f5aaad
running formatter
chris-de-leon-cll Jan 10, 2024
277a076
renames scroll tests, moves helper variables to L2EPTest, adds wrappe…
chris-de-leon-cll Jan 11, 2024
17986f5
updates imports to comply with style guide
chris-de-leon-cll Jan 11, 2024
0ed5140
Merge branch 'develop' into feat/DEPLOY-512-l2ep-foundry
chris-de-leon-cll Jan 16, 2024
1861158
Merge branch 'develop' into feat/DEPLOY-512-l2ep-foundry
chris-de-leon-cll Jan 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
ArbitrumCrossDomainForwarderAcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 37303)
ArbitrumCrossDomainForwarderAcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 12963)
ArbitrumCrossDomainForwarderConstructor:test_InitialState() (gas: 18431)
ArbitrumCrossDomainForwarderForward:test_Forward() (gas: 47610)
ArbitrumCrossDomainForwarderForward:test_ForwardRevert() (gas: 22157)
ArbitrumCrossDomainForwarderForward:test_NotCallableByUnknownAddress() (gas: 16048)
ArbitrumCrossDomainForwarderTransferL1Ownership:test_CallableByL1Owner() (gas: 41402)
ArbitrumCrossDomainForwarderTransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 19309)
ArbitrumCrossDomainForwarderTransferL1Ownership:test_NotCallableByL2Owner() (gas: 18311)
ArbitrumCrossDomainForwarderTransferL1Ownership:test_NotCallableByNonOwners() (gas: 13200)
ArbitrumCrossDomainGovernorAcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 37303)
ArbitrumCrossDomainGovernorAcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 12963)
ArbitrumCrossDomainGovernorConstructor:test_InitialState() (gas: 18454)
ArbitrumCrossDomainGovernorForward:test_CallableByL2Owner() (gas: 49723)
ArbitrumCrossDomainGovernorForward:test_Forward() (gas: 47661)
ArbitrumCrossDomainGovernorForward:test_ForwardRevert() (gas: 24324)
ArbitrumCrossDomainGovernorForward:test_NotCallableByUnknownAddress() (gas: 18247)
ArbitrumCrossDomainGovernorForwardDelegate:test_BubbleUpRevert() (gas: 19386)
ArbitrumCrossDomainGovernorForwardDelegate:test_CallableByCrossDomainMessengerAddressOrL1Owner() (gas: 60623)
ArbitrumCrossDomainGovernorForwardDelegate:test_CallableByL2Owner() (gas: 62729)
ArbitrumCrossDomainGovernorForwardDelegate:test_NotCallableByUnknownAddress() (gas: 18237)
ArbitrumCrossDomainGovernorForwardDelegate:test_RevertsBatchWhenOneCallFails() (gas: 64116)
ArbitrumCrossDomainGovernorTransferL1Ownership:test_CallableByL1Owner() (gas: 41402)
ArbitrumCrossDomainGovernorTransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 19309)
ArbitrumCrossDomainGovernorTransferL1Ownership:test_NotCallableByL2Owner() (gas: 18311)
ArbitrumCrossDomainGovernorTransferL1Ownership:test_NotCallableByNonOwners() (gas: 13200)
ArbitrumSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForGetAnswer() (gas: 92098)
ArbitrumSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForGetRoundData() (gas: 92653)
ArbitrumSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForGetTimestamp() (gas: 92019)
ArbitrumSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestAnswer() (gas: 89793)
ArbitrumSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestRound() (gas: 89685)
ArbitrumSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestRoundData() (gas: 90226)
ArbitrumSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestTimestamp() (gas: 89670)
ArbitrumSequencerUptimeFeedAggregatorV3Interface:test_AggregatorV3Interface() (gas: 98825)
ArbitrumSequencerUptimeFeedAggregatorV3Interface:test_Return0WhenRoundDoesNotExistYet() (gas: 18309)
ArbitrumSequencerUptimeFeedConstants:test_InitialState() (gas: 5684)
ArbitrumSequencerUptimeFeedGasCosts:test_GasCosts() (gas: 97438)
ArbitrumSequencerUptimeFeedProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() (gas: 602705)
ArbitrumSequencerUptimeFeedProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() (gas: 573793)
ArbitrumSequencerUptimeFeedUpdateStatus:test_IgnoreOutOfOrderUpdates() (gas: 98952)
ArbitrumSequencerUptimeFeedUpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddr() (gas: 15776)
ArbitrumSequencerUptimeFeedUpdateStatus:test_UpdateStatusWhenStatusChangeAndNoTimeChange() (gas: 113233)
ArbitrumSequencerUptimeFeedUpdateStatus:test_UpdateStatusWhenStatusChangeAndTimeChange() (gas: 113293)
ArbitrumValidatorValidate:test_PostSequencerOffline() (gas: 69068)
OptimismCrossDomainForwarderAcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 46891)
OptimismCrossDomainForwarderAcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 22152)
OptimismCrossDomainForwarderConstructor:test_InitialState() (gas: 18266)
OptimismCrossDomainForwarderForward:test_Forward() (gas: 58028)
OptimismCrossDomainForwarderForward:test_ForwardRevert() (gas: 32549)
OptimismCrossDomainForwarderForward:test_NotCallableByUnknownAddress() (gas: 13859)
OptimismCrossDomainForwarderTransferL1Ownership:test_CallableByL1Owner() (gas: 48886)
OptimismCrossDomainForwarderTransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 28767)
OptimismCrossDomainForwarderTransferL1Ownership:test_NotCallableByL2Owner() (gas: 16134)
OptimismCrossDomainForwarderTransferL1Ownership:test_NotCallableByNonOwners() (gas: 11011)
OptimismCrossDomainGovernorAcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 46891)
OptimismCrossDomainGovernorAcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 22152)
OptimismCrossDomainGovernorConstructor:test_InitialState() (gas: 18289)
OptimismCrossDomainGovernorForward:test_CallableByL2Owner() (gas: 47557)
OptimismCrossDomainGovernorForward:test_Forward() (gas: 58087)
OptimismCrossDomainGovernorForward:test_ForwardRevert() (gas: 32633)
OptimismCrossDomainGovernorForward:test_NotCallableByUnknownAddress() (gas: 16061)
OptimismCrossDomainGovernorForwardDelegate:test_BubbleUpRevert() (gas: 29181)
OptimismCrossDomainGovernorForwardDelegate:test_CallableByCrossDomainMessengerAddressOrL1Owner() (gas: 72698)
OptimismCrossDomainGovernorForwardDelegate:test_CallableByL2Owner() (gas: 72688)
OptimismCrossDomainGovernorForwardDelegate:test_NotCallableByUnknownAddress() (gas: 16051)
OptimismCrossDomainGovernorForwardDelegate:test_RevertsBatchWhenOneCallFails() (gas: 75911)
OptimismCrossDomainGovernorTransferL1Ownership:test_CallableByL1Owner() (gas: 48886)
OptimismCrossDomainGovernorTransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 28767)
OptimismCrossDomainGovernorTransferL1Ownership:test_NotCallableByL2Owner() (gas: 16134)
OptimismCrossDomainGovernorTransferL1Ownership:test_NotCallableByNonOwners() (gas: 11011)
OptimismSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForGetAnswer() (gas: 59075)
OptimismSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForGetRoundData() (gas: 59615)
OptimismSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForGetTimestamp() (gas: 58930)
OptimismSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestAnswer() (gas: 56867)
OptimismSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestRound() (gas: 56753)
OptimismSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestRoundData() (gas: 57289)
OptimismSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestTimestamp() (gas: 56720)
OptimismSequencerUptimeFeedAggregatorV3Interface:test_AggregatorV3Interface() (gas: 65617)
OptimismSequencerUptimeFeedAggregatorV3Interface:test_RevertGetAnswerWhenRoundDoesNotExistYet() (gas: 18039)
OptimismSequencerUptimeFeedAggregatorV3Interface:test_RevertGetRoundDataWhenRoundDoesNotExistYet() (gas: 18257)
OptimismSequencerUptimeFeedAggregatorV3Interface:test_RevertGetTimestampWhenRoundDoesNotExistYet() (gas: 17963)
OptimismSequencerUptimeFeedConstructor:test_InitialState() (gas: 21066)
OptimismSequencerUptimeFeedGasCosts:test_GasCosts() (gas: 67140)
OptimismSequencerUptimeFeedProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() (gas: 597634)
OptimismSequencerUptimeFeedProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() (gas: 573798)
OptimismSequencerUptimeFeedUpdateStatus:test_IgnoreOutOfOrderUpdates() (gas: 66508)
OptimismSequencerUptimeFeedUpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddr() (gas: 13560)
OptimismSequencerUptimeFeedUpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddrAndNotL1SenderAddr() (gas: 23967)
OptimismSequencerUptimeFeedUpdateStatus:test_UpdateStatusWhenNoChange() (gas: 73999)
OptimismSequencerUptimeFeedUpdateStatus:test_UpdateStatusWhenStatusChangeAndNoTimeChange() (gas: 96119)
OptimismSequencerUptimeFeedUpdateStatus:test_UpdateStatusWhenStatusChangeAndTimeChange() (gas: 96179)
OptimismValidatorSetGasLimit:test_CorrectlyUpdatesTheGasLimit() (gas: 15503)
OptimismValidatorValidate:test_PostSequencerOffline() (gas: 74813)
OptimismValidatorValidate:test_PostSequencerStatusWhenThereIsNotStatusChange() (gas: 74869)
OptimismValidatorValidate:test_RevertsIfCalledByAnAccountWithNoAccess() (gas: 15563)
ScrollCrossDomainForwarderAcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 46980)
ScrollCrossDomainForwarderAcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 22204)
ScrollCrossDomainForwarderConstructor:test_InitialState() (gas: 17930)
ScrollCrossDomainForwarderForward:test_Forward() (gas: 58095)
ScrollCrossDomainForwarderForward:test_ForwardRevert() (gas: 32613)
ScrollCrossDomainForwarderForward:test_NotCallableByUnknownAddress() (gas: 13859)
ScrollCrossDomainForwarderTransferL1Ownership:test_CallableByL1Owner() (gas: 48952)
ScrollCrossDomainForwarderTransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 28833)
ScrollCrossDomainForwarderTransferL1Ownership:test_NotCallableByL2Owner() (gas: 16134)
ScrollCrossDomainForwarderTransferL1Ownership:test_NotCallableByNonOwners() (gas: 11011)
ScrollCrossDomainGovernorAcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 46980)
ScrollCrossDomainGovernorAcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 22204)
ScrollCrossDomainGovernorConstructor:test_InitialState() (gas: 17953)
ScrollCrossDomainGovernorForward:test_CallableByL2Owner() (gas: 47552)
ScrollCrossDomainGovernorForward:test_Forward() (gas: 58149)
ScrollCrossDomainGovernorForward:test_ForwardRevert() (gas: 32688)
ScrollCrossDomainGovernorForward:test_NotCallableByUnknownAddress() (gas: 16058)
ScrollCrossDomainGovernorForwardDelegate:test_BubbleUpRevert() (gas: 29242)
ScrollCrossDomainGovernorForwardDelegate:test_CallableByCrossDomainMessengerAddressOrL1Owner() (gas: 72750)
ScrollCrossDomainGovernorForwardDelegate:test_CallableByL2Owner() (gas: 72740)
ScrollCrossDomainGovernorForwardDelegate:test_NotCallableByUnknownAddress() (gas: 16048)
ScrollCrossDomainGovernorForwardDelegate:test_RevertsBatchWhenOneCallFails() (gas: 75964)
ScrollCrossDomainGovernorTransferL1Ownership:test_CallableByL1Owner() (gas: 48952)
ScrollCrossDomainGovernorTransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 28833)
ScrollCrossDomainGovernorTransferL1Ownership:test_NotCallableByL2Owner() (gas: 16134)
ScrollCrossDomainGovernorTransferL1Ownership:test_NotCallableByNonOwners() (gas: 11011)
ScrollSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForGetAnswer() (gas: 57230)
ScrollSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForGetRoundData() (gas: 57760)
ScrollSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForGetTimestamp() (gas: 57085)
ScrollSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestAnswer() (gas: 54868)
ScrollSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestRound() (gas: 54748)
ScrollSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestRoundData() (gas: 55453)
ScrollSequencerUptimeFeedAggregatorInterfaceGasCosts:test_GasUsageForLatestTimestamp() (gas: 54738)
ScrollSequencerUptimeFeedAggregatorV3Interface:test_AggregatorV3Interface() (gas: 63903)
ScrollSequencerUptimeFeedAggregatorV3Interface:test_RevertGetAnswerWhenRoundDoesNotExistYet() (gas: 18035)
ScrollSequencerUptimeFeedAggregatorV3Interface:test_RevertGetRoundDataWhenRoundDoesNotExistYet() (gas: 18253)
ScrollSequencerUptimeFeedAggregatorV3Interface:test_RevertGetTimestampWhenRoundDoesNotExistYet() (gas: 17959)
ScrollSequencerUptimeFeedConstructor:test_InitialState() (gas: 21073)
ScrollSequencerUptimeFeedGasCosts:test_GasCosts() (gas: 64831)
ScrollSequencerUptimeFeedProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() (gas: 597485)
ScrollSequencerUptimeFeedProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() (gas: 573798)
ScrollSequencerUptimeFeedUpdateStatus:test_IgnoreOutOfOrderUpdates() (gas: 64393)
ScrollSequencerUptimeFeedUpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddr() (gas: 13560)
ScrollSequencerUptimeFeedUpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddrAndNotL1SenderAddr() (gas: 23967)
ScrollSequencerUptimeFeedUpdateStatus:test_UpdateStatusWhenNoChange() (gas: 71582)
ScrollSequencerUptimeFeedUpdateStatus:test_UpdateStatusWhenStatusChangeAndNoTimeChange() (gas: 91982)
ScrollSequencerUptimeFeedUpdateStatus:test_UpdateStatusWhenStatusChangeAndTimeChange() (gas: 92042)
ScrollValidatorSetGasLimit:test_CorrectlyUpdatesTheGasLimit() (gas: 15503)
ScrollValidatorValidate:test_PostSequencerOffline() (gas: 75094)
ScrollValidatorValidate:test_PostSequencerStatusWhenThereIsNotStatusChange() (gas: 75156)
ScrollValidatorValidate: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/

RensR marked this conversation as resolved.
Show resolved Hide resolved
@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/
137 changes: 137 additions & 0 deletions contracts/src/v0.8/l2ep/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Overview

This folder contains the source code and tests for the Layer 2
Exchange Protocol (L2EP) contracts. It is organized as follows:

```text
.
├─/dev (stores the latest source code for L2EP)
├─/test (stores the Foundry tests for L2EP)
```

## The `/dev` Folder

The `/dev` folder contains subfolders for each chain that
has an L2EP solution implemented for it (e.g. `/scroll`, `/arbitrum`,
`/optimism`). It also contains a subfolder named `/interfaces`,
which stores shared interface types between all the supported
contracts. The top-level contracts (e.g. `CrossDomainOwnable.sol`)
serve as either abstract or parent contracts that are meant
to be reused for each indiviudal chain.

## The `/test` Folder

This folder is arranged as follows:

- `/mocks`: used for both Foundry test cases and Hardhat test cases (NOTE:
Hardhat test cases should be considered deprecated at this point)

- `/[version]`: test cases for a specific version of the L2EP contracts

### Testing Conventions and Methodology

By convention, each testing file should end in `.t.sol` (this is a standard
that other projects have also adopted). Each testing file in this folder
follows a similar structure.

```text
TestFile.t.sol
|
|--- Base Contract (inherits L2EPTest contract)
|
|--- Child Contract 1 (inherits base contract)
| |
| |--- Test Function
| |
| |--- ...
|
|
|--- Child Contract 2 (inherits base contract)
| |
| |--- Test Function
| |
| |--- ...
|
|
...
```

All test files contain a base contract defined at the top of the file. This
base contract inherits from a contract called `L2EPTest`. The `L2EPTest`
contract and base contracts have no test cases. Instead, the `L2EPTest`
contract is meant to store data/functions that will be reused among all
the base contracts. Similarly, the base contract is meant to store data
and/or functions that will be reused by any contracts that inherit it.
As such, each test file will define separate child contracts, and each
will inherit from the base contract + define its own set of tests.

The base contract defines a `setUp` function which is automatically called
exactly once before ***each*** of the tests are run in an inheriting contract.
The `setUp` function typically deploys a fresh set of test contracts so that
tests can run independently of each other. Alongside the `setUp` function,
the base contract can also define variables, constants, events, etc. that
are meant to be reused per test.

The name of the base contract follows the following convention:

```text
<NameOfContractBeingTested>Test
```

The child contract names do not follow a naming convention, but they should
broadly describe the tests defined within it. Each test function follows the
same pattern:

```text
test_<NameOfTest>
```

### Running Foundry Tests

#### Usage

First make sure you are in the contracts directory:

```sh
# Assuming you are currently in the /chainlink directory
cd ./contracts
```

If you already have foundry installed, you can use the following command
to run all L2EP tests:

```sh
FOUNDRY_PROFILE=l2ep forge test -vvv
```

To run a specific L2EP test, you can use a variation of the following command:

```sh
FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/scroll/ScrollSequencerUptimeFeed.t.sol
```

Or alternatively:

```sh
FOUNDRY_PROFILE=l2ep forge test -vvv --match-contract ScrollSequencerUptimeFeed
```

If yu prefer, you can also export `FOUNDRY_PROFILE` so that it doesn't need
to be provided before every command:

```sh
export FOUNDRY_PROFILE=l2ep
forge test -vvv
```

A full list of flags for `forge test` can be found [here](https://book.getfoundry.sh/reference/forge/forge-test).

#### Coverage

First ensure that the correct files are being evaluated. For example, if only
v1 contracts are, being evaluated then temporarily change the L2EP profile in
`./foundry.toml`.

```sh
forge coverage
```
56 changes: 56 additions & 0 deletions contracts/src/v0.8/l2ep/test/mocks/MockAggregatorV2V3.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import {AggregatorV2V3Interface} from "../../../shared/interfaces/AggregatorV2V3Interface.sol";

contract MockAggregatorV2V3 is AggregatorV2V3Interface {
function latestAnswer() external pure returns (int256) {
return 0;
}

function latestTimestamp() external pure returns (uint256) {
return 0;
}

function latestRound() external pure returns (uint256) {
return 0;
}

function getAnswer(uint256) external pure returns (int256) {
return 0;
}

function getTimestamp(uint256 roundId) external pure returns (uint256) {
return roundId;
}

function decimals() external pure returns (uint8) {
return 0;
}

function description() external pure returns (string memory) {
return "";
}

function version() external pure returns (uint256) {
return 0;
}

function getRoundData(
uint80
)
external
pure
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
{
return (0, 0, 0, 0, 0);
}

function latestRoundData()
external
pure
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
{
return (73786976294838220258, 96800000000, 163826896, 1638268960, 73786976294838220258);
}
}
Loading
Loading