From c07a2c6c3f0835f8e0ad9a5190e3361e4f9c102f Mon Sep 17 00:00:00 2001 From: Chris De Leon Date: Tue, 9 Jan 2024 18:05:03 -0800 Subject: [PATCH] adds requested changes --- .github/workflows/solidity-foundry.yml | 2 +- contracts/GNUmakefile | 2 +- contracts/gas-snapshots/l2ep.gas-snapshot | 146 ++++++++++++++++++ contracts/src/v0.8/l2ep/README.md | 16 +- .../optimism/MockOVMCrossDomainMessenger.sol | 6 +- .../scroll/MockScrollCrossDomainMessenger.sol | 4 - .../src/v0.8/l2ep/test/v1_0_0/Example.t.sol | 14 -- .../src/v0.8/l2ep/test/v1_0_0/L2EPTest.t.sol | 9 +- .../ArbitrumCrossDomainForwarder.t.sol | 85 ++++------ .../ArbitrumCrossDomainGovernor.t.sol | 117 +++++--------- .../ArbitrumSequencerUptimeFeed.t.sol | 114 ++++---------- .../v1_0_0/arbitrum/ArbitrumValidator.t.sol | 17 +- .../OptimismCrossDomainForwarder.t.sol | 83 ++++------ .../OptimismCrossDomainGovernor.t.sol | 115 ++++---------- .../OptimismSequencerUptimeFeed.t.sol | 130 ++++------------ .../v1_0_0/optimism/OptimismValidator.t.sol | 22 +-- .../scroll/ScrollCrossDomainForwarder.t.sol | 83 ++++------ .../scroll/ScrollCrossDomainGovernor.t.sol | 115 ++++---------- .../scroll/ScrollSequencerUptimeFeed.t.sol | 130 ++++------------ .../test/v1_0_0/scroll/ScrollValidator.t.sol | 22 +-- 20 files changed, 474 insertions(+), 758 deletions(-) create mode 100644 contracts/gas-snapshots/l2ep.gas-snapshot delete mode 100644 contracts/src/v0.8/l2ep/test/v1_0_0/Example.t.sol diff --git a/.github/workflows/solidity-foundry.yml b/.github/workflows/solidity-foundry.yml index b629106972e..447018eb62e 100644 --- a/.github/workflows/solidity-foundry.yml +++ b/.github/workflows/solidity-foundry.yml @@ -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 diff --git a/contracts/GNUmakefile b/contracts/GNUmakefile index 8ec536d520f..f666014c48f 100644 --- a/contracts/GNUmakefile +++ b/contracts/GNUmakefile @@ -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` diff --git a/contracts/gas-snapshots/l2ep.gas-snapshot b/contracts/gas-snapshots/l2ep.gas-snapshot new file mode 100644 index 00000000000..53a512a7680 --- /dev/null +++ b/contracts/gas-snapshots/l2ep.gas-snapshot @@ -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) \ No newline at end of file diff --git a/contracts/src/v0.8/l2ep/README.md b/contracts/src/v0.8/l2ep/README.md index 1aab6e41a92..762f630e410 100644 --- a/contracts/src/v0.8/l2ep/README.md +++ b/contracts/src/v0.8/l2ep/README.md @@ -110,6 +110,20 @@ To run a specific L2EP test, you can use a variation of the following command: 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 @@ -119,5 +133,5 @@ v1 contracts are, being evaluated then temporarily change the L2EP profile in `./foundry.toml`. ```sh -forge coverage --ir-minimum +forge coverage ``` diff --git a/contracts/src/v0.8/l2ep/test/mocks/optimism/MockOVMCrossDomainMessenger.sol b/contracts/src/v0.8/l2ep/test/mocks/optimism/MockOVMCrossDomainMessenger.sol index 9387dd2d2cd..a830fa187fb 100644 --- a/contracts/src/v0.8/l2ep/test/mocks/optimism/MockOVMCrossDomainMessenger.sol +++ b/contracts/src/v0.8/l2ep/test/mocks/optimism/MockOVMCrossDomainMessenger.sol @@ -20,10 +20,6 @@ contract MockOVMCrossDomainMessenger is iOVM_CrossDomainMessenger { s_mockMessageSender = sender; } - /******************** - * Public Functions * - ********************/ - /** * Sends a cross domain message to the target messenger. * @param _target Target contract address. @@ -32,4 +28,6 @@ contract MockOVMCrossDomainMessenger is iOVM_CrossDomainMessenger { function sendMessage(address _target, bytes calldata _message, uint32) external override { Address.functionCall(_target, _message, "sendMessage reverted"); } + } + diff --git a/contracts/src/v0.8/l2ep/test/mocks/scroll/MockScrollCrossDomainMessenger.sol b/contracts/src/v0.8/l2ep/test/mocks/scroll/MockScrollCrossDomainMessenger.sol index cd84d2748c1..161b9f92d43 100644 --- a/contracts/src/v0.8/l2ep/test/mocks/scroll/MockScrollCrossDomainMessenger.sol +++ b/contracts/src/v0.8/l2ep/test/mocks/scroll/MockScrollCrossDomainMessenger.sol @@ -19,10 +19,6 @@ contract MockScrollCrossDomainMessenger is IScrollMessenger { s_mockMessageSender = sender; } - /// ***************************** - /// * Public Mutating Functions * - /// ***************************** - /// @notice Send cross chain message from L1 to L2 or L2 to L1. /// @param _target The address of account who receive the message. /// @param _message The content of the message. diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/Example.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/Example.t.sol deleted file mode 100644 index e6f10448ea6..00000000000 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/Example.t.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import {Test} from "forge-std/Test.sol"; - -// Use the following command to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --mp ./src/v0.8/l2ep/test/v1_0_0/Example.t.sol -// -contract ExampleTest is Test { - function test_example() public { - assertEq(true, true); - } -} diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/L2EPTest.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/L2EPTest.t.sol index 13d4fd1c56e..ede04ce1b44 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/L2EPTest.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/L2EPTest.t.sol @@ -1,11 +1,14 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; -import {MultiSend} from "../../../../v0.8/vendor/MultiSend.sol"; -import {Greeter} from "../../../../v0.8/tests/Greeter.sol"; +import {MultiSend} from "../../../vendor/MultiSend.sol"; +import {Greeter} from "../../../tests/Greeter.sol"; import {Test} from "forge-std/Test.sol"; contract L2EPTest is Test { + /// Helper variable(s) + address internal s_strangerAddr = vm.addr(0x1); + /// @param expectedGasUsage - the expected gas usage /// @param startGasUsage - the gas usage before the code of interest is run /// @param finalGasUsage - the gas usage after the code of interest is run diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumCrossDomainForwarder.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumCrossDomainForwarder.t.sol index 19424300429..d395a991b47 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumCrossDomainForwarder.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumCrossDomainForwarder.t.sol @@ -1,17 +1,12 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {ArbitrumCrossDomainForwarder} from "../../../dev/arbitrum/ArbitrumCrossDomainForwarder.sol"; -import {Greeter} from "../../../../../v0.8/tests/Greeter.sol"; +import {Greeter} from "../../../../tests/Greeter.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumCrossDomainForwarder.t.sol -// contract ArbitrumCrossDomainForwarderTest is L2EPTest { - /// Helper variables - address internal s_strangerAddr = vm.addr(0x1); + /// Helper variable(s) address internal s_l1OwnerAddr = vm.addr(0x2); address internal s_crossDomainMessengerAddr = toArbitrumL2AliasAddress(s_l1OwnerAddr); address internal s_newOwnerCrossDomainMessengerAddr = toArbitrumL2AliasAddress(s_strangerAddr); @@ -27,48 +22,42 @@ contract ArbitrumCrossDomainForwarderTest is L2EPTest { /// Setup function setUp() public { // Deploys contracts - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); s_arbitrumCrossDomainForwarder = new ArbitrumCrossDomainForwarder(s_l1OwnerAddr); s_greeter = new Greeter(address(s_arbitrumCrossDomainForwarder)); vm.stopPrank(); } } -contract Constructor is ArbitrumCrossDomainForwarderTest { - /// @notice it should set the owner correctly - function test_Owner() public { +contract ArbitrumCrossDomainForwarderConstructor is ArbitrumCrossDomainForwarderTest { + /// @notice it should have been deployed with the correct initial state + function test_InitialState() public { + // it should set the owner correctly assertEq(s_arbitrumCrossDomainForwarder.owner(), s_l1OwnerAddr); - } - /// @notice it should set the l1Owner correctly - function test_L1Owner() public { + // it should set the l1Owner correctly assertEq(s_arbitrumCrossDomainForwarder.l1Owner(), s_l1OwnerAddr); - } - /// @notice it should set the crossdomain messenger correctly - function test_CrossDomainMessenger() public { + // it should set the crossdomain messenger correctly assertEq(s_arbitrumCrossDomainForwarder.crossDomainMessenger(), s_crossDomainMessengerAddr); - } - /// @notice it should set the typeAndVersion correctly - function test_TypeAndVersion() public { + // it should set the typeAndVersion correctly assertEq(s_arbitrumCrossDomainForwarder.typeAndVersion(), "ArbitrumCrossDomainForwarder 1.0.0"); } } -contract Forward is ArbitrumCrossDomainForwarderTest { +contract ArbitrumCrossDomainForwarderForward is ArbitrumCrossDomainForwarderTest { /// @notice it should not be callable by unknown address function test_NotCallableByUnknownAddress() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_arbitrumCrossDomainForwarder.forward(address(s_greeter), abi.encode("")); - vm.stopPrank(); } /// @notice it should be callable by crossdomain messenger address / L1 owner function test_Forward() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Defines the cross domain message to send string memory greeting = "hello"; @@ -81,15 +70,12 @@ contract Forward is ArbitrumCrossDomainForwarderTest { // Checks that the greeter got the message assertEq(s_greeter.greeting(), greeting); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert when contract call reverts function test_ForwardRevert() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Sends an invalid message vm.expectRevert("Invalid greeting length"); @@ -97,95 +83,78 @@ contract Forward is ArbitrumCrossDomainForwarderTest { address(s_greeter), abi.encodeWithSelector(s_greeter.setGreeting.selector, "") ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract TransferL1Ownership is ArbitrumCrossDomainForwarderTest { +contract ArbitrumCrossDomainForwarderTransferL1Ownership is ArbitrumCrossDomainForwarderTest { /// @notice it should not be callable by non-owners function test_NotCallableByNonOwners() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_arbitrumCrossDomainForwarder.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should not be callable by L2 owner function test_NotCallableByL2Owner() public { - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); assertEq(s_arbitrumCrossDomainForwarder.owner(), s_l1OwnerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_arbitrumCrossDomainForwarder.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should be callable by current L1 owner function test_CallableByL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_arbitrumCrossDomainForwarder.l1Owner(), s_strangerAddr); // Sends the message s_arbitrumCrossDomainForwarder.transferL1Ownership(s_strangerAddr); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by current L1 owner to zero address function test_CallableByL1OwnerOrZeroAddress() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_arbitrumCrossDomainForwarder.l1Owner(), address(0)); // Sends the message s_arbitrumCrossDomainForwarder.transferL1Ownership(address(0)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AcceptL1Ownership is ArbitrumCrossDomainForwarderTest { +contract ArbitrumCrossDomainForwarderAcceptL1Ownership is ArbitrumCrossDomainForwarderTest { /// @notice it should not be callable by non pending-owners function test_NotCallableByNonPendingOwners() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Sends the message vm.expectRevert("Must be proposed L1 owner"); s_arbitrumCrossDomainForwarder.acceptL1Ownership(); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by pending L1 owner function test_CallableByPendingL1Owner() public { // Request ownership transfer - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); s_arbitrumCrossDomainForwarder.transferL1Ownership(s_strangerAddr); // Prepares expected event payload - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferred(s_l1OwnerAddr, s_strangerAddr); // Accepts ownership transfer request - vm.startPrank(s_newOwnerCrossDomainMessengerAddr, s_newOwnerCrossDomainMessengerAddr); + vm.startPrank(s_newOwnerCrossDomainMessengerAddr); s_arbitrumCrossDomainForwarder.acceptL1Ownership(); // Asserts that the ownership was actually transferred assertEq(s_arbitrumCrossDomainForwarder.l1Owner(), s_strangerAddr); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumCrossDomainGovernor.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumCrossDomainGovernor.t.sol index d49d50d4088..bf967c92374 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumCrossDomainGovernor.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumCrossDomainGovernor.t.sol @@ -1,18 +1,13 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {ArbitrumCrossDomainGovernor} from "../../../dev/arbitrum/ArbitrumCrossDomainGovernor.sol"; -import {MultiSend} from "../../../../../v0.8/vendor/MultiSend.sol"; -import {Greeter} from "../../../../../v0.8/tests/Greeter.sol"; +import {MultiSend} from "../../../../vendor/MultiSend.sol"; +import {Greeter} from "../../../../tests/Greeter.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumCrossDomainGovernor.t.sol -// contract ArbitrumCrossDomainGovernorTest is L2EPTest { - /// Helper variables - address internal s_strangerAddr = vm.addr(0x1); + /// Helper variable(s) address internal s_l1OwnerAddr = vm.addr(0x2); address internal s_crossDomainMessengerAddr = toArbitrumL2AliasAddress(s_l1OwnerAddr); address internal s_newOwnerCrossDomainMessengerAddr = toArbitrumL2AliasAddress(s_strangerAddr); @@ -29,7 +24,7 @@ contract ArbitrumCrossDomainGovernorTest is L2EPTest { /// Setup function setUp() public { // Deploys contracts - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); s_arbitrumCrossDomainGovernor = new ArbitrumCrossDomainGovernor(s_l1OwnerAddr); s_greeter = new Greeter(address(s_arbitrumCrossDomainGovernor)); s_multiSend = new MultiSend(); @@ -37,41 +32,35 @@ contract ArbitrumCrossDomainGovernorTest is L2EPTest { } } -contract Constructor is ArbitrumCrossDomainGovernorTest { - /// @notice it should set the owner correctly - function test_Owner() public { +contract ArbitrumCrossDomainGovernorConstructor is ArbitrumCrossDomainGovernorTest { + /// @notice it should have been deployed with the correct initial state + function test_InitialState() public { + // it should set the owner correctly assertEq(s_arbitrumCrossDomainGovernor.owner(), s_l1OwnerAddr); - } - /// @notice it should set the l1Owner correctly - function test_L1Owner() public { + // it should set the l1Owner correctly assertEq(s_arbitrumCrossDomainGovernor.l1Owner(), s_l1OwnerAddr); - } - /// @notice it should set the crossdomain messenger correctly - function test_CrossDomainMessenger() public { + // it should set the crossdomain messenger correctly assertEq(s_arbitrumCrossDomainGovernor.crossDomainMessenger(), s_crossDomainMessengerAddr); - } - /// @notice it should set the typeAndVersion correctly - function test_TypeAndVersion() public { + // it should set the typeAndVersion correctly assertEq(s_arbitrumCrossDomainGovernor.typeAndVersion(), "ArbitrumCrossDomainGovernor 1.0.0"); } } -contract Forward is ArbitrumCrossDomainGovernorTest { +contract ArbitrumCrossDomainGovernorForward is ArbitrumCrossDomainGovernorTest { /// @notice it should not be callable by unknown address function test_NotCallableByUnknownAddress() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger or owner"); s_arbitrumCrossDomainGovernor.forward(address(s_greeter), abi.encode("")); - vm.stopPrank(); } /// @notice it should be callable by crossdomain messenger address / L1 owner function test_Forward() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Defines the cross domain message to send string memory greeting = "hello"; @@ -84,15 +73,12 @@ contract Forward is ArbitrumCrossDomainGovernorTest { // Checks that the greeter got the message assertEq(s_greeter.greeting(), greeting); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by L2 owner function test_CallableByL2Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); // Defines the cross domain message to send string memory greeting = "hello"; @@ -105,15 +91,12 @@ contract Forward is ArbitrumCrossDomainGovernorTest { // Checks that the greeter message was updated assertEq(s_greeter.greeting(), greeting); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert when contract call reverts function test_ForwardRevert() public { // Sets msg.sender and tx.origin - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); // Sends an invalid message vm.expectRevert("Invalid greeting length"); @@ -121,25 +104,21 @@ contract Forward is ArbitrumCrossDomainGovernorTest { address(s_greeter), abi.encodeWithSelector(s_greeter.setGreeting.selector, "") ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract ForwardDelegate is ArbitrumCrossDomainGovernorTest { +contract ArbitrumCrossDomainGovernorForwardDelegate is ArbitrumCrossDomainGovernorTest { /// @notice it should not be callable by unknown address function test_NotCallableByUnknownAddress() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger or owner"); s_arbitrumCrossDomainGovernor.forwardDelegate(address(s_multiSend), abi.encode("")); - vm.stopPrank(); } /// @notice it should be callable by crossdomain messenger address / L1 owner function test_CallableByCrossDomainMessengerAddressOrL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Sends the message s_arbitrumCrossDomainGovernor.forwardDelegate( @@ -152,15 +131,12 @@ contract ForwardDelegate is ArbitrumCrossDomainGovernorTest { // Checks that the greeter message was updated assertEq(s_greeter.greeting(), "bar"); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by L2 owner function test_CallableByL2Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); // Sends the message s_arbitrumCrossDomainGovernor.forwardDelegate( @@ -173,15 +149,12 @@ contract ForwardDelegate is ArbitrumCrossDomainGovernorTest { // Checks that the greeter message was updated assertEq(s_greeter.greeting(), "bar"); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert batch when one call fails function test_RevertsBatchWhenOneCallFails() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Sends an invalid message (empty transaction data is not allowed) vm.expectRevert("Governor delegatecall reverted"); @@ -195,15 +168,12 @@ contract ForwardDelegate is ArbitrumCrossDomainGovernorTest { // Checks that the greeter message is unchanged assertEq(s_greeter.greeting(), ""); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should bubble up revert when contract call reverts function test_BubbleUpRevert() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Sends an invalid message (empty transaction data is not allowed) vm.expectRevert("Greeter: revert triggered"); @@ -211,95 +181,78 @@ contract ForwardDelegate is ArbitrumCrossDomainGovernorTest { address(s_greeter), abi.encodeWithSelector(Greeter.triggerRevert.selector) ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract TransferL1Ownership is ArbitrumCrossDomainGovernorTest { +contract ArbitrumCrossDomainGovernorTransferL1Ownership is ArbitrumCrossDomainGovernorTest { /// @notice it should not be callable by non-owners function test_NotCallableByNonOwners() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_arbitrumCrossDomainGovernor.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should not be callable by L2 owner function test_NotCallableByL2Owner() public { - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); assertEq(s_arbitrumCrossDomainGovernor.owner(), s_l1OwnerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_arbitrumCrossDomainGovernor.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should be callable by current L1 owner function test_CallableByL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_arbitrumCrossDomainGovernor.l1Owner(), s_strangerAddr); // Sends the message s_arbitrumCrossDomainGovernor.transferL1Ownership(s_strangerAddr); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by current L1 owner to zero address function test_CallableByL1OwnerOrZeroAddress() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_arbitrumCrossDomainGovernor.l1Owner(), address(0)); // Sends the message s_arbitrumCrossDomainGovernor.transferL1Ownership(address(0)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AcceptL1Ownership is ArbitrumCrossDomainGovernorTest { +contract ArbitrumCrossDomainGovernorAcceptL1Ownership is ArbitrumCrossDomainGovernorTest { /// @notice it should not be callable by non pending-owners function test_NotCallableByNonPendingOwners() public { // Sets msg.sender and tx.origin - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); // Sends the message vm.expectRevert("Must be proposed L1 owner"); s_arbitrumCrossDomainGovernor.acceptL1Ownership(); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by pending L1 owner function test_CallableByPendingL1Owner() public { // Request ownership transfer - vm.startPrank(s_crossDomainMessengerAddr, s_crossDomainMessengerAddr); + vm.startPrank(s_crossDomainMessengerAddr); s_arbitrumCrossDomainGovernor.transferL1Ownership(s_strangerAddr); // Prepares expected event payload - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferred(s_l1OwnerAddr, s_strangerAddr); // Accepts ownership transfer request - vm.startPrank(s_newOwnerCrossDomainMessengerAddr, s_newOwnerCrossDomainMessengerAddr); + vm.startPrank(s_newOwnerCrossDomainMessengerAddr); s_arbitrumCrossDomainGovernor.acceptL1Ownership(); // Asserts that the ownership was actually transferred assertEq(s_arbitrumCrossDomainGovernor.l1Owner(), s_strangerAddr); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumSequencerUptimeFeed.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumSequencerUptimeFeed.t.sol index 1481b881068..f6cf8f0bacf 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumSequencerUptimeFeed.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumSequencerUptimeFeed.t.sol @@ -1,24 +1,19 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {SimpleWriteAccessController} from "../../../../shared/access/SimpleWriteAccessController.sol"; import {ArbitrumSequencerUptimeFeed} from "../../../dev/arbitrum/ArbitrumSequencerUptimeFeed.sol"; -import {FeedConsumer} from "../../../../../v0.8/tests/FeedConsumer.sol"; import {MockAggregatorV2V3} from "../../mocks/MockAggregatorV2V3.sol"; +import {FeedConsumer} from "../../../../tests/FeedConsumer.sol"; import {Flags} from "../../../dev/Flags.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumSequencerUptimeFeed.t.sol -// contract ArbitrumSequencerUptimeFeedTest is L2EPTest { /// Constants uint256 internal constant GAS_USED_DEVIATION = 100; - /// Helper variables - address internal s_mockL1OwnerAddr = vm.addr(0x1); - address internal s_strangerAddr = vm.addr(0x2); + /// Helper variable(s) + address internal s_mockL1OwnerAddr = vm.addr(0x2); address internal s_deployerAddr = vm.addr(0x3); address internal s_l2MessengerAddr = toArbitrumL2AliasAddress(s_mockL1OwnerAddr); @@ -47,7 +42,7 @@ contract ArbitrumSequencerUptimeFeedTest is L2EPTest { s_accessController.addAccess(s_deployerAddr); s_flags.addAccess(address(s_arbitrumSequencerUptimeFeed)); - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit Initialized(); s_arbitrumSequencerUptimeFeed.initialize(); @@ -55,14 +50,14 @@ contract ArbitrumSequencerUptimeFeedTest is L2EPTest { } } -contract Constants is ArbitrumSequencerUptimeFeedTest { +contract ArbitrumSequencerUptimeFeedConstants is ArbitrumSequencerUptimeFeedTest { /// @notice it should have the correct value for FLAG_L2_SEQ_OFFLINE' function test_InitialState() public { assertEq(s_arbitrumSequencerUptimeFeed.FLAG_L2_SEQ_OFFLINE(), 0xa438451D6458044c3c8CD2f6f31c91ac882A6d91); } } -contract UpdateStatus is ArbitrumSequencerUptimeFeedTest { +contract ArbitrumSequencerUptimeFeedUpdateStatus is ArbitrumSequencerUptimeFeedTest { /// @notice it should revert if called by an address that is not the L2 Cross Domain Messenger function test_RevertIfNotL2CrossDomainMessengerAddr() public { // Sets msg.sender and tx.origin to an unauthorized address @@ -71,9 +66,6 @@ contract UpdateStatus is ArbitrumSequencerUptimeFeedTest { // Tries to update the status from an unauthorized account vm.expectRevert(abi.encodeWithSelector(ArbitrumSequencerUptimeFeed.InvalidSender.selector)); s_arbitrumSequencerUptimeFeed.updateStatus(true, uint64(1)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should update status when status has changed and incoming timestamp is newer than the latest @@ -83,7 +75,7 @@ contract UpdateStatus is ArbitrumSequencerUptimeFeedTest { // Submits a status update uint256 timestamp = s_arbitrumSequencerUptimeFeed.latestTimestamp(); - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_arbitrumSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_arbitrumSequencerUptimeFeed.latestAnswer(), 1); @@ -91,14 +83,11 @@ contract UpdateStatus is ArbitrumSequencerUptimeFeedTest { // Submit another status update, different status, newer timestamp should update timestamp = timestamp + 200; - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(0, 3, timestamp); s_arbitrumSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); assertEq(s_arbitrumSequencerUptimeFeed.latestAnswer(), 0); assertEq(s_arbitrumSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should update status when status has changed and incoming timestamp is the same as latest @@ -110,21 +99,18 @@ contract UpdateStatus is ArbitrumSequencerUptimeFeedTest { uint256 timestamp = s_arbitrumSequencerUptimeFeed.latestTimestamp(); // Submits a status update - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_arbitrumSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_arbitrumSequencerUptimeFeed.latestAnswer(), 1); assertEq(s_arbitrumSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); // Submit another status update, different status, same timestamp should update - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(0, 3, timestamp); s_arbitrumSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); assertEq(s_arbitrumSequencerUptimeFeed.latestAnswer(), 0); assertEq(s_arbitrumSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should ignore out-of-order updates @@ -134,7 +120,7 @@ contract UpdateStatus is ArbitrumSequencerUptimeFeedTest { // Submits a status update uint256 timestamp = s_arbitrumSequencerUptimeFeed.latestTimestamp() + 10000; - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_arbitrumSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_arbitrumSequencerUptimeFeed.latestAnswer(), 1); @@ -146,13 +132,10 @@ contract UpdateStatus is ArbitrumSequencerUptimeFeedTest { emit UpdateIgnored(true, 0, true, 0); // arguments are dummy values // TODO: how can we check that an AnswerUpdated event was NOT emitted s_arbitrumSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AggregatorV3Interface is ArbitrumSequencerUptimeFeedTest { +contract ArbitrumSequencerUptimeFeedAggregatorV3Interface is ArbitrumSequencerUptimeFeedTest { /// @notice it should return valid answer from getRoundData and latestRoundData function test_AggregatorV3Interface() public { // Sets msg.sender and tx.origin to a valid address @@ -203,9 +186,6 @@ contract AggregatorV3Interface is ArbitrumSequencerUptimeFeedTest { assertEq(startedAt2, startedAt); assertEq(updatedAt2, updatedAt); assertEq(answeredInRound2, answeredInRound); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert from #getRoundData when round does not yet exist (future roundId) @@ -228,13 +208,10 @@ contract AggregatorV3Interface is ArbitrumSequencerUptimeFeedTest { assertEq(startedAt, 0); assertEq(updatedAt, 0); assertEq(answeredInRound, 2); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract ProtectReadsOnAggregatorV2V3InterfaceFunctions is ArbitrumSequencerUptimeFeedTest { +contract ArbitrumSequencerUptimeFeedProtectReadsOnAggregatorV2V3InterfaceFunctions is ArbitrumSequencerUptimeFeedTest { /// @notice it should disallow reads on AggregatorV2V3Interface functions when consuming contract is not whitelisted function test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() public { // Deploys a FeedConsumer contract @@ -259,7 +236,6 @@ contract ProtectReadsOnAggregatorV2V3InterfaceFunctions is ArbitrumSequencerUpti // Whitelist consumer vm.startPrank(s_deployerAddr, s_deployerAddr); s_arbitrumSequencerUptimeFeed.addAccess(address(feedConsumer)); - vm.stopPrank(); // Sanity - consumer is whitelisted assertEq(s_arbitrumSequencerUptimeFeed.checkEnabled(), true); @@ -273,8 +249,8 @@ contract ProtectReadsOnAggregatorV2V3InterfaceFunctions is ArbitrumSequencerUpti } } -contract GasCosts is ArbitrumSequencerUptimeFeedTest { - /// @notice it should consume a known amount of gas for updates @skip-coverage +contract ArbitrumSequencerUptimeFeedGasCosts is ArbitrumSequencerUptimeFeedTest { + /// @notice it should consume a known amount of gas for updates function test_GasCosts() public { // Sets msg.sender and tx.origin to a valid address vm.startPrank(s_l2MessengerAddr, s_l2MessengerAddr); @@ -289,7 +265,7 @@ contract GasCosts is ArbitrumSequencerUptimeFeedTest { uint256 gasFinal; // measures gas used for no update - expectedGasUsed = 5507; // TODO: used to be 28300 + expectedGasUsed = 5507; // NOTE: used to be 28300 in hardhat tests gasStart = gasleft(); s_arbitrumSequencerUptimeFeed.updateStatus(false, uint64(timestamp + 1000)); gasFinal = gasleft(); @@ -297,26 +273,23 @@ contract GasCosts is ArbitrumSequencerUptimeFeedTest { assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); // measures gas used for update - expectedGasUsed = 68198; // TODO: Used to be 93015 + expectedGasUsed = 68198; // NOTE: used to be 93015 in hardhat tests gasStart = gasleft(); s_arbitrumSequencerUptimeFeed.updateStatus(true, uint64(timestamp + 1000)); gasFinal = gasleft(); assertEq(s_arbitrumSequencerUptimeFeed.latestAnswer(), 1); assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AggregatorInterfaceGasCosts is ArbitrumSequencerUptimeFeedTest { - /// @notice it should consume a known amount of gas for getRoundData(uint80) @skip-coverage +contract ArbitrumSequencerUptimeFeedAggregatorInterfaceGasCosts is ArbitrumSequencerUptimeFeedTest { + /// @notice it should consume a known amount of gas for getRoundData(uint80) function test_GasUsageForGetRoundData() public { // Sets msg.sender and tx.origin to a valid address vm.startPrank(s_l2MessengerAddr, s_l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 4658; // TODO: used to be 31157 + uint256 expectedGasUsed = 4658; // NOTE: used to be 31157 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -331,18 +304,15 @@ contract AggregatorInterfaceGasCosts is ArbitrumSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestRoundData() @skip-coverage + /// @notice it should consume a known amount of gas for latestRoundData() function test_GasUsageForLatestRoundData() public { // Sets msg.sender and tx.origin to a valid address vm.startPrank(s_l2MessengerAddr, s_l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 2154; // TODO: used to be 28523 + uint256 expectedGasUsed = 2154; // NOTE: used to be 28523 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -357,18 +327,15 @@ contract AggregatorInterfaceGasCosts is ArbitrumSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestAnswer() @skip-coverage + /// @notice it should consume a known amount of gas for latestAnswer() function test_GasUsageForLatestAnswer() public { // Sets msg.sender and tx.origin to a valid address vm.startPrank(s_l2MessengerAddr, s_l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 1722; // TODO: used to be 28329 + uint256 expectedGasUsed = 1722; // NOTE: used to be 28329 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -383,18 +350,15 @@ contract AggregatorInterfaceGasCosts is ArbitrumSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestTimestamp() @skip-coverage + /// @notice it should consume a known amount of gas for latestTimestamp() function test_GasUsageForLatestTimestamp() public { // Sets msg.sender and tx.origin to a valid address vm.startPrank(s_l2MessengerAddr, s_l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 1652; // TODO: used to be 28229 + uint256 expectedGasUsed = 1652; // NOTE: used to be 28229 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -409,18 +373,15 @@ contract AggregatorInterfaceGasCosts is ArbitrumSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestRound() @skip-coverage + /// @notice it should consume a known amount of gas for latestRound() function test_GasUsageForLatestRound() public { // Sets msg.sender and tx.origin to a valid address vm.startPrank(s_l2MessengerAddr, s_l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 1632; // TODO: used to be 28245 + uint256 expectedGasUsed = 1632; // NOTE: used to be 28245 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -435,18 +396,15 @@ contract AggregatorInterfaceGasCosts is ArbitrumSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for getAnswer() @skip-coverage + /// @notice it should consume a known amount of gas for getAnswer() function test_GasUsageForGetAnswer() public { // Sets msg.sender and tx.origin to a valid address vm.startPrank(s_l2MessengerAddr, s_l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 4059; // TODO: used to be 30799 + uint256 expectedGasUsed = 4059; // NOTE: used to be 30799 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -461,18 +419,15 @@ contract AggregatorInterfaceGasCosts is ArbitrumSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for getTimestamp() @skip-coverage + /// @notice it should consume a known amount of gas for getTimestamp() function test_GasUsageForGetTimestamp() public { // Sets msg.sender and tx.origin to a valid address vm.startPrank(s_l2MessengerAddr, s_l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 4024; // TODO: used to be 30753 + uint256 expectedGasUsed = 4024; // NOTE: used to be 30753 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -487,8 +442,5 @@ contract AggregatorInterfaceGasCosts is ArbitrumSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumValidator.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumValidator.t.sol index 709081188be..abbb7647442 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumValidator.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumValidator.t.sol @@ -1,18 +1,14 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {AccessControllerInterface} from "../../../../shared/interfaces/AccessControllerInterface.sol"; import {SimpleWriteAccessController} from "../../../../shared/access/SimpleWriteAccessController.sol"; import {ArbitrumSequencerUptimeFeed} from "../../../dev/arbitrum/ArbitrumSequencerUptimeFeed.sol"; -import {MockArbitrumInbox} from "../../../../../v0.8/tests/MockArbitrumInbox.sol"; import {ArbitrumValidator} from "../../../dev/arbitrum/ArbitrumValidator.sol"; +import {MockArbitrumInbox} from "../../../../tests/MockArbitrumInbox.sol"; import {MockAggregatorV2V3} from "../../mocks/MockAggregatorV2V3.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/arbitrum/ArbitrumValidator.t.sol -// contract ArbitrumValidatorTest is L2EPTest { /// Helper constants address internal constant L2_SEQ_STATUS_RECORDER_ADDRESS = 0x491B1dDA0A8fa069bbC1125133A975BF4e85a91b; @@ -20,7 +16,7 @@ contract ArbitrumValidatorTest is L2EPTest { uint256 internal constant BASE_FEE = 14000000000; uint256 internal constant MAX_GAS = 1000000; - /// Helper variables + /// Helper variable(s) address internal s_eoaValidator = vm.addr(0x2); /// L2EP contracts @@ -59,7 +55,7 @@ contract ArbitrumValidatorTest is L2EPTest { } } -contract Validate is ArbitrumValidatorTest { +contract ArbitrumValidatorValidate is ArbitrumValidatorTest { /// @notice it post sequencer offline function test_PostSequencerOffline() public { // Gives access to the s_eoaValidator @@ -72,10 +68,10 @@ contract Validate is ArbitrumValidatorTest { uint256 futureTimestampInSeconds = block.timestamp + 5000; vm.warp(futureTimestampInSeconds); vm.deal(address(s_arbitrumValidator), 1 ether); - vm.startPrank(s_eoaValidator, s_eoaValidator); + vm.startPrank(s_eoaValidator); // Sets up the expected event data - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit RetryableTicketNoRefundAliasRewriteCreated( L2_SEQ_STATUS_RECORDER_ADDRESS, // destAddr 0, // arbTxCallValue @@ -89,6 +85,5 @@ contract Validate is ArbitrumValidatorTest { // Runs the function (which produces the event to test) s_arbitrumValidator.validate(0, 0, 1, 1); - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismCrossDomainForwarder.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismCrossDomainForwarder.t.sol index de432f31a6e..fe2b7d68c8a 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismCrossDomainForwarder.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismCrossDomainForwarder.t.sol @@ -1,18 +1,13 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {OptimismCrossDomainForwarder} from "../../../dev/optimism/OptimismCrossDomainForwarder.sol"; import {MockOVMCrossDomainMessenger} from "../../mocks/optimism/MockOVMCrossDomainMessenger.sol"; -import {Greeter} from "../../../../../v0.8/tests/Greeter.sol"; +import {Greeter} from "../../../../tests/Greeter.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/optimism/OptimismCrossDomainForwarder.t.sol -// contract OptimismCrossDomainForwarderTest is L2EPTest { - /// Helper variables - address internal s_strangerAddr = vm.addr(0x1); + /// Helper variable(s) address internal s_l1OwnerAddr = vm.addr(0x2); /// Contracts @@ -27,7 +22,7 @@ contract OptimismCrossDomainForwarderTest is L2EPTest { /// Setup function setUp() public { // Deploys contracts - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); s_mockOptimismCrossDomainMessenger = new MockOVMCrossDomainMessenger(s_l1OwnerAddr); s_optimismCrossDomainForwarder = new OptimismCrossDomainForwarder( s_mockOptimismCrossDomainMessenger, @@ -38,41 +33,35 @@ contract OptimismCrossDomainForwarderTest is L2EPTest { } } -contract Constructor is OptimismCrossDomainForwarderTest { - /// @notice it should set the owner correctly - function test_Owner() public { +contract OptimismCrossDomainForwarderConstructor is OptimismCrossDomainForwarderTest { + /// @notice it should have been deployed with the correct initial state + function test_InitialState() public { + // it should set the owner correctly assertEq(s_optimismCrossDomainForwarder.owner(), s_l1OwnerAddr); - } - /// @notice it should set the l1Owner correctly - function test_L1Owner() public { + // it should set the l1Owner correctly assertEq(s_optimismCrossDomainForwarder.l1Owner(), s_l1OwnerAddr); - } - /// @notice it should set the crossdomain messenger correctly - function test_CrossDomainMessenger() public { + // it should set the crossdomain messenger correctly assertEq(s_optimismCrossDomainForwarder.crossDomainMessenger(), address(s_mockOptimismCrossDomainMessenger)); - } - /// @notice it should set the typeAndVersion correctly - function test_TypeAndVersion() public { + // it should set the typeAndVersion correctly assertEq(s_optimismCrossDomainForwarder.typeAndVersion(), "OptimismCrossDomainForwarder 1.0.0"); } } -contract Forward is OptimismCrossDomainForwarderTest { +contract OptimismCrossDomainForwarderForward is OptimismCrossDomainForwarderTest { /// @notice it should not be callable by unknown address function test_NotCallableByUnknownAddress() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_optimismCrossDomainForwarder.forward(address(s_greeter), abi.encode("")); - vm.stopPrank(); } /// @notice it should be callable by crossdomain messenger address / L1 owner function test_Forward() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send string memory greeting = "hello"; @@ -86,15 +75,12 @@ contract Forward is OptimismCrossDomainForwarderTest { // Checks that the greeter got the message assertEq(s_greeter.greeting(), greeting); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert when contract call reverts function test_ForwardRevert() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends an invalid message vm.expectRevert("Invalid greeting length"); @@ -103,37 +89,32 @@ contract Forward is OptimismCrossDomainForwarderTest { encodeCrossDomainSetGreetingMsg(s_optimismCrossDomainForwarder.forward.selector, address(s_greeter), ""), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract TransferL1Ownership is OptimismCrossDomainForwarderTest { +contract OptimismCrossDomainForwarderTransferL1Ownership is OptimismCrossDomainForwarderTest { /// @notice it should not be callable by non-owners function test_NotCallableByNonOwners() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_optimismCrossDomainForwarder.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should not be callable by L2 owner function test_NotCallableByL2Owner() public { - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); assertEq(s_optimismCrossDomainForwarder.owner(), s_l1OwnerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_optimismCrossDomainForwarder.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should be callable by current L1 owner function test_CallableByL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_optimismCrossDomainForwarder.l1Owner(), s_strangerAddr); // Sends the message @@ -142,18 +123,15 @@ contract TransferL1Ownership is OptimismCrossDomainForwarderTest { abi.encodeWithSelector(s_optimismCrossDomainForwarder.transferL1Ownership.selector, s_strangerAddr), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by current L1 owner to zero address function test_CallableByL1OwnerOrZeroAddress() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_optimismCrossDomainForwarder.l1Owner(), address(0)); // Sends the message @@ -162,17 +140,14 @@ contract TransferL1Ownership is OptimismCrossDomainForwarderTest { abi.encodeWithSelector(s_optimismCrossDomainForwarder.transferL1Ownership.selector, address(0)), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AcceptL1Ownership is OptimismCrossDomainForwarderTest { +contract OptimismCrossDomainForwarderAcceptL1Ownership is OptimismCrossDomainForwarderTest { /// @notice it should not be callable by non pending-owners function test_NotCallableByNonPendingOwners() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends the message vm.expectRevert("Must be proposed L1 owner"); @@ -181,15 +156,12 @@ contract AcceptL1Ownership is OptimismCrossDomainForwarderTest { abi.encodeWithSelector(s_optimismCrossDomainForwarder.acceptL1Ownership.selector), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by pending L1 owner function test_CallableByPendingL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Request ownership transfer s_mockOptimismCrossDomainMessenger.sendMessage( @@ -202,7 +174,7 @@ contract AcceptL1Ownership is OptimismCrossDomainForwarderTest { s_mockOptimismCrossDomainMessenger._setMockMessageSender(s_strangerAddr); // Prepares expected event payload - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferred(s_l1OwnerAddr, s_strangerAddr); // Accepts ownership transfer request @@ -214,8 +186,5 @@ contract AcceptL1Ownership is OptimismCrossDomainForwarderTest { // Asserts that the ownership was actually transferred assertEq(s_optimismCrossDomainForwarder.l1Owner(), s_strangerAddr); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismCrossDomainGovernor.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismCrossDomainGovernor.t.sol index 0bbeabbf0a7..4a885a98f82 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismCrossDomainGovernor.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismCrossDomainGovernor.t.sol @@ -1,19 +1,14 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {OptimismCrossDomainGovernor} from "../../../dev/optimism/OptimismCrossDomainGovernor.sol"; import {MockOVMCrossDomainMessenger} from "../../mocks/optimism/MockOVMCrossDomainMessenger.sol"; -import {MultiSend} from "../../../../../v0.8/vendor/MultiSend.sol"; -import {Greeter} from "../../../../../v0.8/tests/Greeter.sol"; +import {MultiSend} from "../../../../vendor/MultiSend.sol"; +import {Greeter} from "../../../../tests/Greeter.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/optimism/OptimismCrossDomainGovernor.t.sol -// contract OptimismCrossDomainGovernorTest is L2EPTest { - /// Helper variables - address internal s_strangerAddr = vm.addr(0x1); + /// Helper variable(s) address internal s_l1OwnerAddr = vm.addr(0x2); /// Contracts @@ -29,7 +24,7 @@ contract OptimismCrossDomainGovernorTest is L2EPTest { /// Setup function setUp() public { // Deploys contracts - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); s_mockOptimismCrossDomainMessenger = new MockOVMCrossDomainMessenger(s_l1OwnerAddr); s_optimismCrossDomainGovernor = new OptimismCrossDomainGovernor(s_mockOptimismCrossDomainMessenger, s_l1OwnerAddr); s_greeter = new Greeter(address(s_optimismCrossDomainGovernor)); @@ -38,41 +33,35 @@ contract OptimismCrossDomainGovernorTest is L2EPTest { } } -contract Constructor is OptimismCrossDomainGovernorTest { - /// @notice it should set the owner correctly - function test_Owner() public { +contract OptimismCrossDomainGovernorConstructor is OptimismCrossDomainGovernorTest { + /// @notice it should have been deployed with the correct initial state + function test_InitialState() public { + // it should set the owner correctly assertEq(s_optimismCrossDomainGovernor.owner(), s_l1OwnerAddr); - } - /// @notice it should set the l1Owner correctly - function test_L1Owner() public { + // it should set the l1Owner correctly assertEq(s_optimismCrossDomainGovernor.l1Owner(), s_l1OwnerAddr); - } - /// @notice it should set the crossdomain messenger correctly - function test_CrossDomainMessenger() public { + // it should set the crossdomain messenger correctly assertEq(s_optimismCrossDomainGovernor.crossDomainMessenger(), address(s_mockOptimismCrossDomainMessenger)); - } - /// @notice it should set the typeAndVersion correctly - function test_TypeAndVersion() public { + // it should set the typeAndVersion correctly assertEq(s_optimismCrossDomainGovernor.typeAndVersion(), "OptimismCrossDomainGovernor 1.0.0"); } } -contract Forward is OptimismCrossDomainGovernorTest { +contract OptimismCrossDomainGovernorForward is OptimismCrossDomainGovernorTest { /// @notice it should not be callable by unknown address function test_NotCallableByUnknownAddress() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger or owner"); s_optimismCrossDomainGovernor.forward(address(s_greeter), abi.encode("")); - vm.stopPrank(); } /// @notice it should be callable by crossdomain messenger address / L1 owner function test_Forward() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send string memory greeting = "hello"; @@ -86,15 +75,12 @@ contract Forward is OptimismCrossDomainGovernorTest { // Checks that the greeter got the message assertEq(s_greeter.greeting(), greeting); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert when contract call reverts function test_ForwardRevert() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends an invalid message vm.expectRevert("Invalid greeting length"); @@ -103,15 +89,12 @@ contract Forward is OptimismCrossDomainGovernorTest { encodeCrossDomainSetGreetingMsg(s_optimismCrossDomainGovernor.forward.selector, address(s_greeter), ""), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by L2 owner function test_CallableByL2Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); // Defines the cross domain message to send string memory greeting = "hello"; @@ -124,25 +107,21 @@ contract Forward is OptimismCrossDomainGovernorTest { // Checks that the greeter message was updated assertEq(s_greeter.greeting(), greeting); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract ForwardDelegate is OptimismCrossDomainGovernorTest { +contract OptimismCrossDomainGovernorForwardDelegate is OptimismCrossDomainGovernorTest { /// @notice it should not be callable by unknown address function test_NotCallableByUnknownAddress() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger or owner"); s_optimismCrossDomainGovernor.forwardDelegate(address(s_greeter), abi.encode("")); - vm.stopPrank(); } /// @notice it should be callable by crossdomain messenger address / L1 owner function test_CallableByCrossDomainMessengerAddressOrL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends the message s_mockOptimismCrossDomainMessenger.sendMessage( @@ -157,15 +136,12 @@ contract ForwardDelegate is OptimismCrossDomainGovernorTest { // Checks that the greeter message was updated assertEq(s_greeter.greeting(), "bar"); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by L2 owner function test_CallableByL2Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); // Sends the message s_mockOptimismCrossDomainMessenger.sendMessage( @@ -180,15 +156,12 @@ contract ForwardDelegate is OptimismCrossDomainGovernorTest { // Checks that the greeter message was updated assertEq(s_greeter.greeting(), "bar"); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert batch when one call fails function test_RevertsBatchWhenOneCallFails() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends an invalid message (empty transaction data is not allowed) vm.expectRevert("Governor delegatecall reverted"); @@ -204,15 +177,12 @@ contract ForwardDelegate is OptimismCrossDomainGovernorTest { // Checks that the greeter message is unchanged assertEq(s_greeter.greeting(), ""); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should bubble up revert when contract call reverts function test_BubbleUpRevert() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends an invalid message (empty transaction data is not allowed) vm.expectRevert("Greeter: revert triggered"); @@ -225,37 +195,32 @@ contract ForwardDelegate is OptimismCrossDomainGovernorTest { ), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract TransferL1Ownership is OptimismCrossDomainGovernorTest { +contract OptimismCrossDomainGovernorTransferL1Ownership is OptimismCrossDomainGovernorTest { /// @notice it should not be callable by non-owners function test_NotCallableByNonOwners() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_optimismCrossDomainGovernor.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should not be callable by L2 owner function test_NotCallableByL2Owner() public { - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); assertEq(s_optimismCrossDomainGovernor.owner(), s_l1OwnerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_optimismCrossDomainGovernor.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should be callable by current L1 owner function test_CallableByL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_optimismCrossDomainGovernor.l1Owner(), s_strangerAddr); // Sends the message @@ -264,18 +229,15 @@ contract TransferL1Ownership is OptimismCrossDomainGovernorTest { abi.encodeWithSelector(s_optimismCrossDomainGovernor.transferL1Ownership.selector, s_strangerAddr), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by current L1 owner to zero address function test_CallableByL1OwnerOrZeroAddress() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_optimismCrossDomainGovernor.l1Owner(), address(0)); // Sends the message @@ -284,17 +246,14 @@ contract TransferL1Ownership is OptimismCrossDomainGovernorTest { abi.encodeWithSelector(s_optimismCrossDomainGovernor.transferL1Ownership.selector, address(0)), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AcceptL1Ownership is OptimismCrossDomainGovernorTest { +contract OptimismCrossDomainGovernorAcceptL1Ownership is OptimismCrossDomainGovernorTest { /// @notice it should not be callable by non pending-owners function test_NotCallableByNonPendingOwners() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends the message vm.expectRevert("Must be proposed L1 owner"); @@ -303,15 +262,12 @@ contract AcceptL1Ownership is OptimismCrossDomainGovernorTest { abi.encodeWithSelector(s_optimismCrossDomainGovernor.acceptL1Ownership.selector), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by pending L1 owner function test_CallableByPendingL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Request ownership transfer s_mockOptimismCrossDomainMessenger.sendMessage( @@ -324,7 +280,7 @@ contract AcceptL1Ownership is OptimismCrossDomainGovernorTest { s_mockOptimismCrossDomainMessenger._setMockMessageSender(s_strangerAddr); // Prepares expected event payload - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferred(s_l1OwnerAddr, s_strangerAddr); // Accepts ownership transfer request @@ -336,8 +292,5 @@ contract AcceptL1Ownership is OptimismCrossDomainGovernorTest { // Asserts that the ownership was actually transferred assertEq(s_optimismCrossDomainGovernor.l1Owner(), s_strangerAddr); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismSequencerUptimeFeed.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismSequencerUptimeFeed.t.sol index 30f80f7487c..8a31186fecb 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismSequencerUptimeFeed.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismSequencerUptimeFeed.t.sol @@ -1,23 +1,18 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {MockOptimismL1CrossDomainMessenger} from "../../../../tests/MockOptimismL1CrossDomainMessenger.sol"; import {MockOptimismL2CrossDomainMessenger} from "../../../../tests/MockOptimismL2CrossDomainMessenger.sol"; import {OptimismSequencerUptimeFeed} from "../../../dev/optimism/OptimismSequencerUptimeFeed.sol"; -import {FeedConsumer} from "../../../../../v0.8/tests/FeedConsumer.sol"; +import {FeedConsumer} from "../../../../tests/FeedConsumer.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/optimism/OptimismSequencerUptimeFeed.t.sol -// contract OptimismSequencerUptimeFeedTest is L2EPTest { /// Constants uint256 internal constant GAS_USED_DEVIATION = 100; - /// Helper variables - address internal s_mockL1OwnerAddr = vm.addr(0x1); - address internal s_strangerAddr = vm.addr(0x2); + /// Helper variable(s) + address internal s_mockL1OwnerAddr = vm.addr(0x2); /// L2EP contracts MockOptimismL1CrossDomainMessenger internal s_mockOptimismL1CrossDomainMessenger; @@ -45,7 +40,7 @@ contract OptimismSequencerUptimeFeedTest is L2EPTest { } } -contract Constructor is OptimismSequencerUptimeFeedTest { +contract OptimismSequencerUptimeFeedConstructor is OptimismSequencerUptimeFeedTest { /// @notice it should have been deployed with the correct initial state function test_InitialState() public { // Sets msg.sender and tx.origin to a valid address @@ -59,13 +54,10 @@ contract Constructor is OptimismSequencerUptimeFeedTest { (uint80 roundId, int256 answer, , , ) = s_optimismSequencerUptimeFeed.latestRoundData(); assertEq(roundId, 1); assertEq(answer, 0); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract UpdateStatus is OptimismSequencerUptimeFeedTest { +contract OptimismSequencerUptimeFeedUpdateStatus is OptimismSequencerUptimeFeedTest { /// @notice it should revert if called by an address that is not the L2 Cross Domain Messenger function test_RevertIfNotL2CrossDomainMessengerAddr() public { // Sets msg.sender and tx.origin to an unauthorized address @@ -74,9 +66,6 @@ contract UpdateStatus is OptimismSequencerUptimeFeedTest { // Tries to update the status from an unauthorized account vm.expectRevert(abi.encodeWithSelector(OptimismSequencerUptimeFeed.InvalidSender.selector)); s_optimismSequencerUptimeFeed.updateStatus(true, uint64(1)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert if called by an address that is not the L2 Cross Domain Messenger and is not the L1 sender @@ -90,9 +79,6 @@ contract UpdateStatus is OptimismSequencerUptimeFeedTest { // Tries to update the status from an unauthorized account vm.expectRevert(abi.encodeWithSelector(OptimismSequencerUptimeFeed.InvalidSender.selector)); s_optimismSequencerUptimeFeed.updateStatus(true, uint64(1)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should update status when status has not changed and incoming timestamp is the same as latest @@ -105,7 +91,7 @@ contract UpdateStatus is OptimismSequencerUptimeFeedTest { uint256 timestamp = s_optimismSequencerUptimeFeed.latestTimestamp(); // Submits a status update - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_optimismSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 1); @@ -121,7 +107,7 @@ contract UpdateStatus is OptimismSequencerUptimeFeedTest { ) = s_optimismSequencerUptimeFeed.latestRoundData(); // Submit another status update with the same status - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit RoundUpdated(1, uint64(block.timestamp)); s_optimismSequencerUptimeFeed.updateStatus(true, uint64(timestamp + 200)); assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 1); @@ -142,9 +128,6 @@ contract UpdateStatus is OptimismSequencerUptimeFeedTest { assertEq(startedAtAfterUpdate, startedAtBeforeUpdate); assertEq(answeredInRoundAfterUpdate, answeredInRoundBeforeUpdate); assertEq(updatedAtAfterUpdate, block.timestamp); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should update status when status has changed and incoming timestamp is newer than the latest @@ -155,7 +138,7 @@ contract UpdateStatus is OptimismSequencerUptimeFeedTest { // Submits a status update uint256 timestamp = s_optimismSequencerUptimeFeed.latestTimestamp(); - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_optimismSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 1); @@ -163,14 +146,11 @@ contract UpdateStatus is OptimismSequencerUptimeFeedTest { // Submit another status update, different status, newer timestamp should update timestamp = timestamp + 200; - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(0, 3, timestamp); s_optimismSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 0); assertEq(s_optimismSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should update status when status has changed and incoming timestamp is the same as latest @@ -183,21 +163,18 @@ contract UpdateStatus is OptimismSequencerUptimeFeedTest { uint256 timestamp = s_optimismSequencerUptimeFeed.latestTimestamp(); // Submits a status update - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_optimismSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 1); assertEq(s_optimismSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); // Submit another status update, different status, same timestamp should update - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(0, 3, timestamp); s_optimismSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 0); assertEq(s_optimismSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should ignore out-of-order updates @@ -208,7 +185,7 @@ contract UpdateStatus is OptimismSequencerUptimeFeedTest { // Submits a status update uint256 timestamp = s_optimismSequencerUptimeFeed.latestTimestamp() + 10000; - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_optimismSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 1); @@ -220,13 +197,10 @@ contract UpdateStatus is OptimismSequencerUptimeFeedTest { emit UpdateIgnored(true, 0, true, 0); // arguments are dummy values // TODO: how can we check that an AnswerUpdated event was NOT emitted s_optimismSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AggregatorV3Interface is OptimismSequencerUptimeFeedTest { +contract OptimismSequencerUptimeFeedAggregatorV3Interface is OptimismSequencerUptimeFeedTest { /// @notice it should return valid answer from getRoundData and latestRoundData function test_AggregatorV3Interface() public { // Sets msg.sender and tx.origin to a valid address @@ -278,9 +252,6 @@ contract AggregatorV3Interface is OptimismSequencerUptimeFeedTest { assertEq(startedAt2, startedAt); assertEq(updatedAt2, updatedAt); assertEq(answeredInRound2, answeredInRound); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert from #getRoundData when round does not yet exist (future roundId) @@ -291,9 +262,6 @@ contract AggregatorV3Interface is OptimismSequencerUptimeFeedTest { // Gets data from a round that has not happened yet vm.expectRevert(abi.encodeWithSelector(OptimismSequencerUptimeFeed.NoDataPresent.selector)); s_optimismSequencerUptimeFeed.getRoundData(2); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert from #getAnswer when round does not yet exist (future roundId) @@ -304,9 +272,6 @@ contract AggregatorV3Interface is OptimismSequencerUptimeFeedTest { // Gets data from a round that has not happened yet vm.expectRevert(abi.encodeWithSelector(OptimismSequencerUptimeFeed.NoDataPresent.selector)); s_optimismSequencerUptimeFeed.getAnswer(2); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert from #getTimestamp when round does not yet exist (future roundId) @@ -317,13 +282,10 @@ contract AggregatorV3Interface is OptimismSequencerUptimeFeedTest { // Gets data from a round that has not happened yet vm.expectRevert(abi.encodeWithSelector(OptimismSequencerUptimeFeed.NoDataPresent.selector)); s_optimismSequencerUptimeFeed.getTimestamp(2); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract ProtectReadsOnAggregatorV2V3InterfaceFunctions is OptimismSequencerUptimeFeedTest { +contract OptimismSequencerUptimeFeedProtectReadsOnAggregatorV2V3InterfaceFunctions is OptimismSequencerUptimeFeedTest { /// @notice it should disallow reads on AggregatorV2V3Interface functions when consuming contract is not whitelisted function test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() public { // Deploys a FeedConsumer contract @@ -360,8 +322,8 @@ contract ProtectReadsOnAggregatorV2V3InterfaceFunctions is OptimismSequencerUpti } } -contract GasCosts is OptimismSequencerUptimeFeedTest { - /// @notice it should consume a known amount of gas for updates @skip-coverage +contract OptimismSequencerUptimeFeedGasCosts is OptimismSequencerUptimeFeedTest { + /// @notice it should consume a known amount of gas for updates function test_GasCosts() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); @@ -377,7 +339,7 @@ contract GasCosts is OptimismSequencerUptimeFeedTest { uint256 gasFinal; // measures gas used for no update - expectedGasUsed = 10197; // TODO: used to be 38594 + expectedGasUsed = 10197; // NOTE: used to be 38594 in hardhat tests gasStart = gasleft(); s_optimismSequencerUptimeFeed.updateStatus(false, uint64(timestamp + 1000)); gasFinal = gasleft(); @@ -385,27 +347,24 @@ contract GasCosts is OptimismSequencerUptimeFeedTest { assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); // measures gas used for update - expectedGasUsed = 33348; // TODO: Used to be 60170 + expectedGasUsed = 33348; // NOTE: used to be 60170 in hardhat tests gasStart = gasleft(); s_optimismSequencerUptimeFeed.updateStatus(true, uint64(timestamp + 1000)); gasFinal = gasleft(); assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 1); assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AggregatorInterfaceGasCosts is OptimismSequencerUptimeFeedTest { - /// @notice it should consume a known amount of gas for getRoundData(uint80) @skip-coverage +contract OptimismSequencerUptimeFeedAggregatorInterfaceGasCosts is OptimismSequencerUptimeFeedTest { + /// @notice it should consume a known amount of gas for getRoundData(uint80) function test_GasUsageForGetRoundData() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 4504; // TODO: used to be 30952 + uint256 expectedGasUsed = 4504; // NOTE: used to be 30952 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -420,19 +379,16 @@ contract AggregatorInterfaceGasCosts is OptimismSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestRoundData() @skip-coverage + /// @notice it should consume a known amount of gas for latestRoundData() function test_GasUsageForLatestRoundData() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 2154; // TODO: used to be 28523 + uint256 expectedGasUsed = 2154; // NOTE: used to be 28523 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -447,19 +403,16 @@ contract AggregatorInterfaceGasCosts is OptimismSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestAnswer() @skip-coverage + /// @notice it should consume a known amount of gas for latestAnswer() function test_GasUsageForLatestAnswer() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 1722; // TODO: used to be 28329 + uint256 expectedGasUsed = 1722; // NOTE: used to be 28329 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -474,19 +427,16 @@ contract AggregatorInterfaceGasCosts is OptimismSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestTimestamp() @skip-coverage + /// @notice it should consume a known amount of gas for latestTimestamp() function test_GasUsageForLatestTimestamp() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 1598; // TODO: used to be 28229 + uint256 expectedGasUsed = 1598; // NOTE: used to be 28229 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -501,19 +451,16 @@ contract AggregatorInterfaceGasCosts is OptimismSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestRound() @skip-coverage + /// @notice it should consume a known amount of gas for latestRound() function test_GasUsageForLatestRound() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 1632; // TODO: used to be 28245 + uint256 expectedGasUsed = 1632; // NOTE: used to be 28245 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -528,19 +475,16 @@ contract AggregatorInterfaceGasCosts is OptimismSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for getAnswer() @skip-coverage + /// @notice it should consume a known amount of gas for getAnswer() function test_GasUsageForGetAnswer() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 3929; // TODO: used to be 30682 + uint256 expectedGasUsed = 3929; // NOTE: used to be 30682 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -555,19 +499,16 @@ contract AggregatorInterfaceGasCosts is OptimismSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for getTimestamp() @skip-coverage + /// @notice it should consume a known amount of gas for getTimestamp() function test_GasUsageForGetTimestamp() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 3817; // TODO: used to be 30570 + uint256 expectedGasUsed = 3817; // NOTE: used to be 30570 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -582,8 +523,5 @@ contract AggregatorInterfaceGasCosts is OptimismSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismValidator.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismValidator.t.sol index c274ee24c09..ae67eb7350e 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismValidator.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/optimism/OptimismValidator.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {MockOptimismL1CrossDomainMessenger} from "../../../../tests/MockOptimismL1CrossDomainMessenger.sol"; import {MockOptimismL2CrossDomainMessenger} from "../../../../tests/MockOptimismL2CrossDomainMessenger.sol"; @@ -7,17 +7,12 @@ import {OptimismSequencerUptimeFeed} from "../../../dev/optimism/OptimismSequenc import {OptimismValidator} from "../../../dev/optimism/OptimismValidator.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/optimism/OptimismValidator.t.sol -// contract OptimismValidatorTest is L2EPTest { /// Helper constants address internal constant L2_SEQ_STATUS_RECORDER_ADDRESS = 0x491B1dDA0A8fa069bbC1125133A975BF4e85a91b; uint32 internal constant INIT_GAS_LIMIT = 1900000; - /// Helper variables - address internal s_strangerAddress = vm.addr(0x1); + /// Helper variable(s) address internal s_eoaValidator = vm.addr(0x2); /// L2EP contracts @@ -48,7 +43,7 @@ contract OptimismValidatorTest is L2EPTest { } } -contract SetGasLimit is OptimismValidatorTest { +contract OptimismValidatorSetGasLimit is OptimismValidatorTest { /// @notice it correctly updates the gas limit function test_CorrectlyUpdatesTheGasLimit() public { uint32 newGasLimit = 2000000; @@ -58,13 +53,12 @@ contract SetGasLimit is OptimismValidatorTest { } } -contract Validate is OptimismValidatorTest { +contract OptimismValidatorValidate is OptimismValidatorTest { /// @notice it reverts if called by account with no access function test_RevertsIfCalledByAnAccountWithNoAccess() public { - vm.startPrank(s_strangerAddress, s_strangerAddress); + vm.startPrank(s_strangerAddr); vm.expectRevert("No access"); s_optimismValidator.validate(0, 0, 1, 1); - vm.stopPrank(); } /// @notice it posts sequencer status when there is not status change @@ -74,7 +68,7 @@ contract Validate is OptimismValidatorTest { // Sets block.timestamp to a later date uint256 futureTimestampInSeconds = block.timestamp + 5000; - vm.startPrank(s_eoaValidator, s_eoaValidator); + vm.startPrank(s_eoaValidator); vm.warp(futureTimestampInSeconds); // Sets up the expected event data @@ -89,7 +83,6 @@ contract Validate is OptimismValidatorTest { // Runs the function (which produces the event to test) s_optimismValidator.validate(0, 0, 0, 0); - vm.stopPrank(); } /// @notice it post sequencer offline @@ -99,7 +92,7 @@ contract Validate is OptimismValidatorTest { // Sets block.timestamp to a later date uint256 futureTimestampInSeconds = block.timestamp + 10000; - vm.startPrank(s_eoaValidator, s_eoaValidator); + vm.startPrank(s_eoaValidator); vm.warp(futureTimestampInSeconds); // Sets up the expected event data @@ -114,6 +107,5 @@ contract Validate is OptimismValidatorTest { // Runs the function (which produces the event to test) s_optimismValidator.validate(0, 0, 1, 1); - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollCrossDomainForwarder.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollCrossDomainForwarder.t.sol index 78fcc1abbc6..2071e68dfa0 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollCrossDomainForwarder.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollCrossDomainForwarder.t.sol @@ -1,18 +1,13 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {MockScrollCrossDomainMessenger} from "../../mocks/scroll/MockScrollCrossDomainMessenger.sol"; import {ScrollCrossDomainForwarder} from "../../../dev/scroll/ScrollCrossDomainForwarder.sol"; -import {Greeter} from "../../../../../v0.8/tests/Greeter.sol"; +import {Greeter} from "../../../../tests/Greeter.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/scroll/ScrollCrossDomainForwarder.t.sol -// contract ScrollCrossDomainForwarderTest is L2EPTest { - /// Helper variables - address internal s_strangerAddr = vm.addr(0x1); + /// Helper variable(s) address internal s_l1OwnerAddr = vm.addr(0x2); /// Contracts @@ -27,7 +22,7 @@ contract ScrollCrossDomainForwarderTest is L2EPTest { /// Setup function setUp() public { // Deploys contracts - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); s_mockScrollCrossDomainMessenger = new MockScrollCrossDomainMessenger(s_l1OwnerAddr); s_scrollCrossDomainForwarder = new ScrollCrossDomainForwarder(s_mockScrollCrossDomainMessenger, s_l1OwnerAddr); s_greeter = new Greeter(address(s_scrollCrossDomainForwarder)); @@ -35,41 +30,35 @@ contract ScrollCrossDomainForwarderTest is L2EPTest { } } -contract Constructor is ScrollCrossDomainForwarderTest { - /// @notice it should set the owner correctly - function test_Owner() public { +contract ScrollCrossDomainForwarderConstructor is ScrollCrossDomainForwarderTest { + /// @notice it should have been deployed with the correct initial state + function test_InitialState() public { + // it should set the owner correctly assertEq(s_scrollCrossDomainForwarder.owner(), s_l1OwnerAddr); - } - /// @notice it should set the l1Owner correctly - function test_L1Owner() public { + // it should set the l1Owner correctly assertEq(s_scrollCrossDomainForwarder.l1Owner(), s_l1OwnerAddr); - } - /// @notice it should set the crossdomain messenger correctly - function test_CrossDomainMessenger() public { + // it should set the crossdomain messenger correctly assertEq(s_scrollCrossDomainForwarder.crossDomainMessenger(), address(s_mockScrollCrossDomainMessenger)); - } - /// @notice it should set the typeAndVersion correctly - function test_TypeAndVersion() public { + // it should set the typeAndVersion correctly assertEq(s_scrollCrossDomainForwarder.typeAndVersion(), "ScrollCrossDomainForwarder 1.0.0"); } } -contract Forward is ScrollCrossDomainForwarderTest { +contract ScrollCrossDomainForwarderForward is ScrollCrossDomainForwarderTest { /// @notice it should not be callable by unknown address function test_NotCallableByUnknownAddress() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_scrollCrossDomainForwarder.forward(address(s_greeter), abi.encode("")); - vm.stopPrank(); } /// @notice it should be callable by crossdomain messenger address / L1 owner function test_Forward() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send string memory greeting = "hello"; @@ -84,15 +73,12 @@ contract Forward is ScrollCrossDomainForwarderTest { // Checks that the greeter got the message assertEq(s_greeter.greeting(), greeting); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert when contract call reverts function test_ForwardRevert() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends an invalid message vm.expectRevert("Invalid greeting length"); @@ -102,37 +88,32 @@ contract Forward is ScrollCrossDomainForwarderTest { encodeCrossDomainSetGreetingMsg(s_scrollCrossDomainForwarder.forward.selector, address(s_greeter), ""), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract TransferL1Ownership is ScrollCrossDomainForwarderTest { +contract ScrollCrossDomainForwarderTransferL1Ownership is ScrollCrossDomainForwarderTest { /// @notice it should not be callable by non-owners function test_NotCallableByNonOwners() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_scrollCrossDomainForwarder.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should not be callable by L2 owner function test_NotCallableByL2Owner() public { - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); assertEq(s_scrollCrossDomainForwarder.owner(), s_l1OwnerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_scrollCrossDomainForwarder.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should be callable by current L1 owner function test_CallableByL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_scrollCrossDomainForwarder.l1Owner(), s_strangerAddr); // Sends the message @@ -142,18 +123,15 @@ contract TransferL1Ownership is ScrollCrossDomainForwarderTest { abi.encodeWithSelector(s_scrollCrossDomainForwarder.transferL1Ownership.selector, s_strangerAddr), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by current L1 owner to zero address function test_CallableByL1OwnerOrZeroAddress() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_scrollCrossDomainForwarder.l1Owner(), address(0)); // Sends the message @@ -163,17 +141,14 @@ contract TransferL1Ownership is ScrollCrossDomainForwarderTest { abi.encodeWithSelector(s_scrollCrossDomainForwarder.transferL1Ownership.selector, address(0)), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AcceptL1Ownership is ScrollCrossDomainForwarderTest { +contract ScrollCrossDomainForwarderAcceptL1Ownership is ScrollCrossDomainForwarderTest { /// @notice it should not be callable by non pending-owners function test_NotCallableByNonPendingOwners() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends the message vm.expectRevert("Must be proposed L1 owner"); @@ -183,15 +158,12 @@ contract AcceptL1Ownership is ScrollCrossDomainForwarderTest { abi.encodeWithSelector(s_scrollCrossDomainForwarder.acceptL1Ownership.selector), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by pending L1 owner function test_CallableByPendingL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Request ownership transfer s_mockScrollCrossDomainMessenger.sendMessage( @@ -205,7 +177,7 @@ contract AcceptL1Ownership is ScrollCrossDomainForwarderTest { s_mockScrollCrossDomainMessenger._setMockMessageSender(s_strangerAddr); // Prepares expected event payload - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferred(s_l1OwnerAddr, s_strangerAddr); // Accepts ownership transfer request @@ -218,8 +190,5 @@ contract AcceptL1Ownership is ScrollCrossDomainForwarderTest { // Asserts that the ownership was actually transferred assertEq(s_scrollCrossDomainForwarder.l1Owner(), s_strangerAddr); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollCrossDomainGovernor.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollCrossDomainGovernor.t.sol index 3d22e0b8bb8..bf389230d31 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollCrossDomainGovernor.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollCrossDomainGovernor.t.sol @@ -1,19 +1,14 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {MockScrollCrossDomainMessenger} from "../../mocks/scroll/MockScrollCrossDomainMessenger.sol"; import {ScrollCrossDomainGovernor} from "../../../dev/scroll/ScrollCrossDomainGovernor.sol"; -import {MultiSend} from "../../../../../v0.8/vendor/MultiSend.sol"; -import {Greeter} from "../../../../../v0.8/tests/Greeter.sol"; +import {MultiSend} from "../../../../vendor/MultiSend.sol"; +import {Greeter} from "../../../../tests/Greeter.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/scroll/ScrollCrossDomainGovernor.t.sol -// contract ScrollCrossDomainGovernorTest is L2EPTest { - /// Helper variables - address internal s_strangerAddr = vm.addr(0x1); + /// Helper variable(s) address internal s_l1OwnerAddr = vm.addr(0x2); /// Contracts @@ -29,7 +24,7 @@ contract ScrollCrossDomainGovernorTest is L2EPTest { /// Setup function setUp() public { // Deploys contracts - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); s_mockScrollCrossDomainMessenger = new MockScrollCrossDomainMessenger(s_l1OwnerAddr); s_scrollCrossDomainGovernor = new ScrollCrossDomainGovernor(s_mockScrollCrossDomainMessenger, s_l1OwnerAddr); s_greeter = new Greeter(address(s_scrollCrossDomainGovernor)); @@ -38,41 +33,35 @@ contract ScrollCrossDomainGovernorTest is L2EPTest { } } -contract Constructor is ScrollCrossDomainGovernorTest { - /// @notice it should set the owner correctly - function test_Owner() public { +contract ScrollCrossDomainGovernorConstructor is ScrollCrossDomainGovernorTest { + /// @notice it should have been deployed with the correct initial state + function test_InitialState() public { + // it should set the owner correctly assertEq(s_scrollCrossDomainGovernor.owner(), s_l1OwnerAddr); - } - /// @notice it should set the l1Owner correctly - function test_L1Owner() public { + // it should set the l1Owner correctly assertEq(s_scrollCrossDomainGovernor.l1Owner(), s_l1OwnerAddr); - } - /// @notice it should set the crossdomain messenger correctly - function test_CrossDomainMessenger() public { + // it should set the crossdomain messenger correctly assertEq(s_scrollCrossDomainGovernor.crossDomainMessenger(), address(s_mockScrollCrossDomainMessenger)); - } - /// @notice it should set the typeAndVersion correctly - function test_TypeAndVersion() public { + // it should set the typeAndVersion correctly assertEq(s_scrollCrossDomainGovernor.typeAndVersion(), "ScrollCrossDomainGovernor 1.0.0"); } } -contract Forward is ScrollCrossDomainGovernorTest { +contract ScrollCrossDomainGovernorForward is ScrollCrossDomainGovernorTest { /// @notice it should not be callable by unknown address function test_NotCallableByUnknownAddress() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger or owner"); s_scrollCrossDomainGovernor.forward(address(s_greeter), abi.encode("")); - vm.stopPrank(); } /// @notice it should be callable by crossdomain messenger address / L1 owner function test_Forward() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send string memory greeting = "hello"; @@ -87,15 +76,12 @@ contract Forward is ScrollCrossDomainGovernorTest { // Checks that the greeter got the message assertEq(s_greeter.greeting(), greeting); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert when contract call reverts function test_ForwardRevert() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends an invalid message vm.expectRevert("Invalid greeting length"); @@ -105,15 +91,12 @@ contract Forward is ScrollCrossDomainGovernorTest { encodeCrossDomainSetGreetingMsg(s_scrollCrossDomainGovernor.forward.selector, address(s_greeter), ""), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by L2 owner function test_CallableByL2Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); // Defines the cross domain message to send string memory greeting = "hello"; @@ -126,25 +109,21 @@ contract Forward is ScrollCrossDomainGovernorTest { // Checks that the greeter message was updated assertEq(s_greeter.greeting(), greeting); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract ForwardDelegate is ScrollCrossDomainGovernorTest { +contract ScrollCrossDomainGovernorForwardDelegate is ScrollCrossDomainGovernorTest { /// @notice it should not be callable by unknown address function test_NotCallableByUnknownAddress() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger or owner"); s_scrollCrossDomainGovernor.forwardDelegate(address(s_greeter), abi.encode("")); - vm.stopPrank(); } /// @notice it should be callable by crossdomain messenger address / L1 owner function test_CallableByCrossDomainMessengerAddressOrL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends the message s_mockScrollCrossDomainMessenger.sendMessage( @@ -160,15 +139,12 @@ contract ForwardDelegate is ScrollCrossDomainGovernorTest { // Checks that the greeter message was updated assertEq(s_greeter.greeting(), "bar"); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by L2 owner function test_CallableByL2Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); // Sends the message s_mockScrollCrossDomainMessenger.sendMessage( @@ -184,15 +160,12 @@ contract ForwardDelegate is ScrollCrossDomainGovernorTest { // Checks that the greeter message was updated assertEq(s_greeter.greeting(), "bar"); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert batch when one call fails function test_RevertsBatchWhenOneCallFails() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends an invalid message (empty transaction data is not allowed) vm.expectRevert("Governor delegatecall reverted"); @@ -209,15 +182,12 @@ contract ForwardDelegate is ScrollCrossDomainGovernorTest { // Checks that the greeter message is unchanged assertEq(s_greeter.greeting(), ""); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should bubble up revert when contract call reverts function test_BubbleUpRevert() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends an invalid message (empty transaction data is not allowed) vm.expectRevert("Greeter: revert triggered"); @@ -231,37 +201,32 @@ contract ForwardDelegate is ScrollCrossDomainGovernorTest { ), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract TransferL1Ownership is ScrollCrossDomainGovernorTest { +contract ScrollCrossDomainGovernorTransferL1Ownership is ScrollCrossDomainGovernorTest { /// @notice it should not be callable by non-owners function test_NotCallableByNonOwners() public { - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_scrollCrossDomainGovernor.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should not be callable by L2 owner function test_NotCallableByL2Owner() public { - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + vm.startPrank(s_l1OwnerAddr); assertEq(s_scrollCrossDomainGovernor.owner(), s_l1OwnerAddr); vm.expectRevert("Sender is not the L2 messenger"); s_scrollCrossDomainGovernor.transferL1Ownership(s_strangerAddr); - vm.stopPrank(); } /// @notice it should be callable by current L1 owner function test_CallableByL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_scrollCrossDomainGovernor.l1Owner(), s_strangerAddr); // Sends the message @@ -271,18 +236,15 @@ contract TransferL1Ownership is ScrollCrossDomainGovernorTest { abi.encodeWithSelector(s_scrollCrossDomainGovernor.transferL1Ownership.selector, s_strangerAddr), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by current L1 owner to zero address function test_CallableByL1OwnerOrZeroAddress() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Defines the cross domain message to send - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferRequested(s_scrollCrossDomainGovernor.l1Owner(), address(0)); // Sends the message @@ -292,17 +254,14 @@ contract TransferL1Ownership is ScrollCrossDomainGovernorTest { abi.encodeWithSelector(s_scrollCrossDomainGovernor.transferL1Ownership.selector, address(0)), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AcceptL1Ownership is ScrollCrossDomainGovernorTest { +contract ScrollCrossDomainGovernorAcceptL1Ownership is ScrollCrossDomainGovernorTest { /// @notice it should not be callable by non pending-owners function test_NotCallableByNonPendingOwners() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Sends the message vm.expectRevert("Must be proposed L1 owner"); @@ -312,15 +271,12 @@ contract AcceptL1Ownership is ScrollCrossDomainGovernorTest { abi.encodeWithSelector(s_scrollCrossDomainGovernor.acceptL1Ownership.selector), // message 0 // gas limit ); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should be callable by pending L1 owner function test_CallableByPendingL1Owner() public { // Sets msg.sender and tx.origin - vm.startPrank(s_strangerAddr, s_strangerAddr); + vm.startPrank(s_strangerAddr); // Request ownership transfer s_mockScrollCrossDomainMessenger.sendMessage( @@ -334,7 +290,7 @@ contract AcceptL1Ownership is ScrollCrossDomainGovernorTest { s_mockScrollCrossDomainMessenger._setMockMessageSender(s_strangerAddr); // Prepares expected event payload - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit L1OwnershipTransferred(s_l1OwnerAddr, s_strangerAddr); // Accepts ownership transfer request @@ -347,8 +303,5 @@ contract AcceptL1Ownership is ScrollCrossDomainGovernorTest { // Asserts that the ownership was actually transferred assertEq(s_scrollCrossDomainGovernor.l1Owner(), s_strangerAddr); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollSequencerUptimeFeed.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollSequencerUptimeFeed.t.sol index 91a57c3263a..e3cc9e37722 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollSequencerUptimeFeed.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollSequencerUptimeFeed.t.sol @@ -1,23 +1,18 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {MockScrollL1CrossDomainMessenger} from "../../mocks/scroll/MockScrollL1CrossDomainMessenger.sol"; import {MockScrollL2CrossDomainMessenger} from "../../mocks/scroll/MockScrollL2CrossDomainMessenger.sol"; import {ScrollSequencerUptimeFeed} from "../../../dev/scroll/ScrollSequencerUptimeFeed.sol"; -import {FeedConsumer} from "../../../../../v0.8/tests/FeedConsumer.sol"; +import {FeedConsumer} from "../../../../tests/FeedConsumer.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/scroll/ScrollSequencerUptimeFeed.t.sol -// contract ScrollSequencerUptimeFeedTest is L2EPTest { /// Constants uint256 internal constant GAS_USED_DEVIATION = 100; - /// Helper variables - address internal s_mockL1OwnerAddr = vm.addr(0x1); - address internal s_strangerAddr = vm.addr(0x2); + /// Helper variable(s) + address internal s_mockL1OwnerAddr = vm.addr(0x2); /// L2EP contracts MockScrollL1CrossDomainMessenger internal s_mockScrollL1CrossDomainMessenger; @@ -45,7 +40,7 @@ contract ScrollSequencerUptimeFeedTest is L2EPTest { } } -contract Constructor is ScrollSequencerUptimeFeedTest { +contract ScrollSequencerUptimeFeedConstructor is ScrollSequencerUptimeFeedTest { /// @notice it should have been deployed with the correct initial state function test_InitialState() public { // Sets msg.sender and tx.origin to a valid address @@ -59,13 +54,10 @@ contract Constructor is ScrollSequencerUptimeFeedTest { (uint80 roundId, int256 answer, , , ) = s_scrollSequencerUptimeFeed.latestRoundData(); assertEq(roundId, 1); assertEq(answer, 0); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract UpdateStatus is ScrollSequencerUptimeFeedTest { +contract ScrollSequencerUptimeFeedUpdateStatus is ScrollSequencerUptimeFeedTest { /// @notice it should revert if called by an address that is not the L2 Cross Domain Messenger function test_RevertIfNotL2CrossDomainMessengerAddr() public { // Sets msg.sender and tx.origin to an unauthorized address @@ -74,9 +66,6 @@ contract UpdateStatus is ScrollSequencerUptimeFeedTest { // Tries to update the status from an unauthorized account vm.expectRevert(abi.encodeWithSelector(ScrollSequencerUptimeFeed.InvalidSender.selector)); s_scrollSequencerUptimeFeed.updateStatus(true, uint64(1)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert if called by an address that is not the L2 Cross Domain Messenger and is not the L1 sender @@ -90,9 +79,6 @@ contract UpdateStatus is ScrollSequencerUptimeFeedTest { // Tries to update the status from an unauthorized account vm.expectRevert(abi.encodeWithSelector(ScrollSequencerUptimeFeed.InvalidSender.selector)); s_scrollSequencerUptimeFeed.updateStatus(true, uint64(1)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should update status when status has not changed and incoming timestamp is the same as latest @@ -105,7 +91,7 @@ contract UpdateStatus is ScrollSequencerUptimeFeedTest { uint256 timestamp = s_scrollSequencerUptimeFeed.latestTimestamp(); // Submits a status update - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_scrollSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 1); @@ -121,7 +107,7 @@ contract UpdateStatus is ScrollSequencerUptimeFeedTest { ) = s_scrollSequencerUptimeFeed.latestRoundData(); // Submit another status update with the same status - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit RoundUpdated(1, uint64(block.timestamp)); s_scrollSequencerUptimeFeed.updateStatus(true, uint64(timestamp + 200)); assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 1); @@ -142,9 +128,6 @@ contract UpdateStatus is ScrollSequencerUptimeFeedTest { assertEq(startedAtAfterUpdate, startedAtBeforeUpdate); assertEq(answeredInRoundAfterUpdate, answeredInRoundBeforeUpdate); assertEq(updatedAtAfterUpdate, block.timestamp); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should update status when status has changed and incoming timestamp is newer than the latest @@ -155,7 +138,7 @@ contract UpdateStatus is ScrollSequencerUptimeFeedTest { // Submits a status update uint256 timestamp = s_scrollSequencerUptimeFeed.latestTimestamp(); - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_scrollSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 1); @@ -163,14 +146,11 @@ contract UpdateStatus is ScrollSequencerUptimeFeedTest { // Submit another status update, different status, newer timestamp should update timestamp = timestamp + 200; - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(0, 3, timestamp); s_scrollSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 0); assertEq(s_scrollSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should update status when status has changed and incoming timestamp is the same as latest @@ -183,21 +163,18 @@ contract UpdateStatus is ScrollSequencerUptimeFeedTest { uint256 timestamp = s_scrollSequencerUptimeFeed.latestTimestamp(); // Submits a status update - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_scrollSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 1); assertEq(s_scrollSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); // Submit another status update, different status, same timestamp should update - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(0, 3, timestamp); s_scrollSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 0); assertEq(s_scrollSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should ignore out-of-order updates @@ -208,7 +185,7 @@ contract UpdateStatus is ScrollSequencerUptimeFeedTest { // Submits a status update uint256 timestamp = s_scrollSequencerUptimeFeed.latestTimestamp() + 10000; - vm.expectEmit(false, false, false, true); + vm.expectEmit(); emit AnswerUpdated(1, 2, timestamp); s_scrollSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 1); @@ -220,13 +197,10 @@ contract UpdateStatus is ScrollSequencerUptimeFeedTest { emit UpdateIgnored(true, 0, true, 0); // arguments are dummy values // TODO: how can we check that an AnswerUpdated event was NOT emitted s_scrollSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AggregatorV3Interface is ScrollSequencerUptimeFeedTest { +contract ScrollSequencerUptimeFeedAggregatorV3Interface is ScrollSequencerUptimeFeedTest { /// @notice it should return valid answer from getRoundData and latestRoundData function test_AggregatorV3Interface() public { // Sets msg.sender and tx.origin to a valid address @@ -278,9 +252,6 @@ contract AggregatorV3Interface is ScrollSequencerUptimeFeedTest { assertEq(startedAt2, startedAt); assertEq(updatedAt2, updatedAt); assertEq(answeredInRound2, answeredInRound); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert from #getRoundData when round does not yet exist (future roundId) @@ -291,9 +262,6 @@ contract AggregatorV3Interface is ScrollSequencerUptimeFeedTest { // Gets data from a round that has not happened yet vm.expectRevert(abi.encodeWithSelector(ScrollSequencerUptimeFeed.NoDataPresent.selector)); s_scrollSequencerUptimeFeed.getRoundData(2); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert from #getAnswer when round does not yet exist (future roundId) @@ -304,9 +272,6 @@ contract AggregatorV3Interface is ScrollSequencerUptimeFeedTest { // Gets data from a round that has not happened yet vm.expectRevert(abi.encodeWithSelector(ScrollSequencerUptimeFeed.NoDataPresent.selector)); s_scrollSequencerUptimeFeed.getAnswer(2); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } /// @notice it should revert from #getTimestamp when round does not yet exist (future roundId) @@ -317,13 +282,10 @@ contract AggregatorV3Interface is ScrollSequencerUptimeFeedTest { // Gets data from a round that has not happened yet vm.expectRevert(abi.encodeWithSelector(ScrollSequencerUptimeFeed.NoDataPresent.selector)); s_scrollSequencerUptimeFeed.getTimestamp(2); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract ProtectReadsOnAggregatorV2V3InterfaceFunctions is ScrollSequencerUptimeFeedTest { +contract ScrollSequencerUptimeFeedProtectReadsOnAggregatorV2V3InterfaceFunctions is ScrollSequencerUptimeFeedTest { /// @notice it should disallow reads on AggregatorV2V3Interface functions when consuming contract is not whitelisted function test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() public { // Deploys a FeedConsumer contract @@ -360,8 +322,8 @@ contract ProtectReadsOnAggregatorV2V3InterfaceFunctions is ScrollSequencerUptime } } -contract GasCosts is ScrollSequencerUptimeFeedTest { - /// @notice it should consume a known amount of gas for updates @skip-coverage +contract ScrollSequencerUptimeFeedGasCosts is ScrollSequencerUptimeFeedTest { + /// @notice it should consume a known amount of gas for updates function test_GasCosts() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); @@ -377,7 +339,7 @@ contract GasCosts is ScrollSequencerUptimeFeedTest { uint256 gasFinal; // measures gas used for no update - expectedGasUsed = 10197; // TODO: used to be 38594 + expectedGasUsed = 10197; // NOTE: used to be 38594 in hardhat tests gasStart = gasleft(); s_scrollSequencerUptimeFeed.updateStatus(false, uint64(timestamp + 1000)); gasFinal = gasleft(); @@ -385,27 +347,24 @@ contract GasCosts is ScrollSequencerUptimeFeedTest { assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); // measures gas used for update - expectedGasUsed = 31644; // TODO: Used to be 58458 + expectedGasUsed = 31644; // NOTE: used to be 58458 in hardhat tests gasStart = gasleft(); s_scrollSequencerUptimeFeed.updateStatus(true, uint64(timestamp + 1000)); gasFinal = gasleft(); assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 1); assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } -contract AggregatorInterfaceGasCosts is ScrollSequencerUptimeFeedTest { - /// @notice it should consume a known amount of gas for getRoundData(uint80) @skip-coverage +contract ScrollSequencerUptimeFeedAggregatorInterfaceGasCosts is ScrollSequencerUptimeFeedTest { + /// @notice it should consume a known amount of gas for getRoundData(uint80) function test_GasUsageForGetRoundData() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 4504; // TODO: used to be 30952 + uint256 expectedGasUsed = 4504; // NOTE: used to be 30952 in hardhat tesst uint256 gasStart; uint256 gasFinal; @@ -420,19 +379,16 @@ contract AggregatorInterfaceGasCosts is ScrollSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestRoundData() @skip-coverage + /// @notice it should consume a known amount of gas for latestRoundData() function test_GasUsageForLatestRoundData() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 2154; // TODO: used to be 28523 + uint256 expectedGasUsed = 2154; // NOTE: used to be 28523 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -447,19 +403,16 @@ contract AggregatorInterfaceGasCosts is ScrollSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestAnswer() @skip-coverage + /// @notice it should consume a known amount of gas for latestAnswer() function test_GasUsageForLatestAnswer() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 1566; // TODO: used to be 28229 + uint256 expectedGasUsed = 1566; // NOTE: used to be 28229 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -474,19 +427,16 @@ contract AggregatorInterfaceGasCosts is ScrollSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestTimestamp() @skip-coverage + /// @notice it should consume a known amount of gas for latestTimestamp() function test_GasUsageForLatestTimestamp() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 1459; // TODO: used to be 28129 + uint256 expectedGasUsed = 1459; // NOTE: used to be 28129 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -501,19 +451,16 @@ contract AggregatorInterfaceGasCosts is ScrollSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for latestRound() @skip-coverage + /// @notice it should consume a known amount of gas for latestRound() function test_GasUsageForLatestRound() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 1470; // TODO: used to be 28145 + uint256 expectedGasUsed = 1470; // NOTE: used to be 28145 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -528,19 +475,16 @@ contract AggregatorInterfaceGasCosts is ScrollSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for getAnswer() @skip-coverage + /// @notice it should consume a known amount of gas for getAnswer() function test_GasUsageForGetAnswer() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 3929; // TODO: used to be 30682 + uint256 expectedGasUsed = 3929; // NOTE: used to be 30682 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -555,19 +499,16 @@ contract AggregatorInterfaceGasCosts is ScrollSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } - /// @notice it should consume a known amount of gas for getTimestamp() @skip-coverage + /// @notice it should consume a known amount of gas for getTimestamp() function test_GasUsageForGetTimestamp() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); // Defines helper variables for measuring gas usage - uint256 expectedGasUsed = 3817; // TODO: used to be 30570 + uint256 expectedGasUsed = 3817; // NOTE: used to be 30570 in hardhat tests uint256 gasStart; uint256 gasFinal; @@ -582,8 +523,5 @@ contract AggregatorInterfaceGasCosts is ScrollSequencerUptimeFeedTest { // Checks that gas usage is within expected range assertGasUsageIsCloseTo(expectedGasUsed, gasStart, gasFinal, GAS_USED_DEVIATION); - - // Resets msg.sender and tx.origin - vm.stopPrank(); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollValidator.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollValidator.t.sol index 9a83d25c589..8d1e5f1466d 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollValidator.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/scroll/ScrollValidator.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity 0.8.19; import {MockScrollL1CrossDomainMessenger} from "../../mocks/scroll/MockScrollL1CrossDomainMessenger.sol"; import {MockScrollL2CrossDomainMessenger} from "../../mocks/scroll/MockScrollL2CrossDomainMessenger.sol"; @@ -7,17 +7,12 @@ import {ScrollSequencerUptimeFeed} from "../../../dev/scroll/ScrollSequencerUpti import {ScrollValidator} from "../../../dev/scroll/ScrollValidator.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -// Use this command from the /contracts directory to run this test file: -// -// FOUNDRY_PROFILE=l2ep forge test -vvv --match-path ./src/v0.8/l2ep/test/v1_0_0/scroll/ScrollValidator.t.sol -// contract ScrollValidatorTest is L2EPTest { /// Helper constants address internal constant L2_SEQ_STATUS_RECORDER_ADDRESS = 0x491B1dDA0A8fa069bbC1125133A975BF4e85a91b; uint32 internal constant INIT_GAS_LIMIT = 1900000; - /// Helper variables - address internal s_strangerAddress = vm.addr(0x1); + /// Helper variable(s) address internal s_eoaValidator = vm.addr(0x2); /// L2EP contracts @@ -55,7 +50,7 @@ contract ScrollValidatorTest is L2EPTest { } } -contract SetGasLimit is ScrollValidatorTest { +contract ScrollValidatorSetGasLimit is ScrollValidatorTest { /// @notice it correctly updates the gas limit function test_CorrectlyUpdatesTheGasLimit() public { uint32 newGasLimit = 2000000; @@ -65,13 +60,12 @@ contract SetGasLimit is ScrollValidatorTest { } } -contract Validate is ScrollValidatorTest { +contract ScrollValidatorValidate is ScrollValidatorTest { /// @notice it reverts if called by account with no access function test_RevertsIfCalledByAnAccountWithNoAccess() public { - vm.startPrank(s_strangerAddress, s_strangerAddress); + vm.startPrank(s_strangerAddr); vm.expectRevert("No access"); s_scrollValidator.validate(0, 0, 1, 1); - vm.stopPrank(); } /// @notice it posts sequencer status when there is not status change @@ -81,7 +75,7 @@ contract Validate is ScrollValidatorTest { // Sets block.timestamp to a later date uint256 futureTimestampInSeconds = block.timestamp + 5000; - vm.startPrank(s_eoaValidator, s_eoaValidator); + vm.startPrank(s_eoaValidator); vm.warp(futureTimestampInSeconds); // Sets up the expected event data @@ -97,7 +91,6 @@ contract Validate is ScrollValidatorTest { // Runs the function (which produces the event to test) s_scrollValidator.validate(0, 0, 0, 0); - vm.stopPrank(); } /// @notice it post sequencer offline @@ -107,7 +100,7 @@ contract Validate is ScrollValidatorTest { // Sets block.timestamp to a later date uint256 futureTimestampInSeconds = block.timestamp + 10000; - vm.startPrank(s_eoaValidator, s_eoaValidator); + vm.startPrank(s_eoaValidator); vm.warp(futureTimestampInSeconds); // Sets up the expected event data @@ -123,6 +116,5 @@ contract Validate is ScrollValidatorTest { // Runs the function (which produces the event to test) s_scrollValidator.validate(0, 0, 1, 1); - vm.stopPrank(); } }