From 202e6b5652d7109c599678d7686e81811ee18373 Mon Sep 17 00:00:00 2001 From: jlaveracll Date: Mon, 9 Dec 2024 16:42:55 -0300 Subject: [PATCH] [SHIP-3521] Add tests to L2EP contracts to improve test coverage (#14341) * Add tests trying to improve test coverage * Increate testing and clean up * prettier * Update MockBaseSequencerUptimeFeed.sol * Create stale-cougars-approve.md * Update l2ep.gas-snapshot * [Bot] Update changeset file with jira issue * Revert "Update l2ep.gas-snapshot" This reverts commit 6e0d21131eb46355d8ff189370c2bb11a08514e1. * Update l2ep.gas-snapshot * fix comments and clean up scroll tests * Update l2ep.gas-snapshot * Update ZKSyncSequencerUptimeFeed.t.sol * fix gas snapshot * Update ScrollSequencerUptimeFeed.t.sol * Update ScrollSequencerUptimeFeed.t.sol * Update l2ep.gas-snapshot * rename l2ep -> shared to l2ep -> base * cleanup * address feedback * Renames tests to follow Solidity convetions * [Bot] Update changeset file with jira issues --------- Co-authored-by: app-token-issuer-infra-releng[bot] <120227048+app-token-issuer-infra-releng[bot]@users.noreply.github.com> Co-authored-by: Mohamed Mehany <7327188+mohamed-mehany@users.noreply.github.com> --- .github/workflows/solidity-foundry.yml | 2 +- contracts/.changeset/thirty-rules-rule.md | 10 + contracts/gas-snapshots/l2ep.gas-snapshot | 79 ++-- .../BaseSequencerUptimeFeed.sol | 19 +- .../l2ep/{shared => base}/BaseValidator.sol | 2 +- .../optimism/OptimismSequencerUptimeFeed.sol | 2 +- .../v0.8/l2ep/optimism/OptimismValidator.sol | 2 +- .../l2ep/scroll/ScrollSequencerUptimeFeed.sol | 2 +- .../src/v0.8/l2ep/scroll/ScrollValidator.sol | 2 +- .../mocks/MockBaseSequencerUptimeFeed.sol | 25 ++ .../l2ep/test/mocks/MockBaseValidator.sol | 23 ++ .../OptimismSequencerUptimeFeed.t.sol | 302 ++------------ .../v1_0_0/optimism/OptimismValidator.t.sol | 24 +- .../scroll/ScrollCrossDomainForwarder.t.sol | 6 - .../scroll/ScrollCrossDomainGovernor.t.sol | 11 - .../scroll/ScrollSequencerUptimeFeed.t.sol | 310 +++----------- .../test/v1_0_0/scroll/ScrollValidator.t.sol | 37 +- .../shared/BaseSequencerUptimeFeed.t.sol | 377 ++++++++++++++++++ .../test/v1_0_0/shared/BaseValidator.t.sol | 57 +++ .../zksync/ZKSyncSequencerUptimeFeed.t.sol | 293 ++------------ .../test/v1_0_0/zksync/ZKSyncValidator.t.sol | 50 +-- .../l2ep/zksync/ZKSyncSequencerUptimeFeed.sol | 2 +- .../src/v0.8/l2ep/zksync/ZKSyncValidator.sol | 2 +- 23 files changed, 702 insertions(+), 937 deletions(-) create mode 100644 contracts/.changeset/thirty-rules-rule.md rename contracts/src/v0.8/l2ep/{shared => base}/BaseSequencerUptimeFeed.sol (93%) rename contracts/src/v0.8/l2ep/{shared => base}/BaseValidator.sol (96%) create mode 100644 contracts/src/v0.8/l2ep/test/mocks/MockBaseSequencerUptimeFeed.sol create mode 100644 contracts/src/v0.8/l2ep/test/mocks/MockBaseValidator.sol create mode 100644 contracts/src/v0.8/l2ep/test/v1_0_0/shared/BaseSequencerUptimeFeed.t.sol create mode 100644 contracts/src/v0.8/l2ep/test/v1_0_0/shared/BaseValidator.t.sol diff --git a/.github/workflows/solidity-foundry.yml b/.github/workflows/solidity-foundry.yml index b94c0236155..850374b0cd3 100644 --- a/.github/workflows/solidity-foundry.yml +++ b/.github/workflows/solidity-foundry.yml @@ -33,7 +33,7 @@ jobs: { "name": "ccip", "setup": { "run-coverage": true, "min-coverage": 98.8, "extra-coverage-params": "--no-match-path='*End2End*'", "run-gas-snapshot": true, "run-forge-fmt": true }}, { "name": "functions", "setup": { "run-coverage": false, "min-coverage": 98.5, "run-gas-snapshot": true, "run-forge-fmt": false }}, { "name": "keystone", "setup": { "run-coverage": true, "min-coverage": 72.8, "run-gas-snapshot": false, "run-forge-fmt": false }}, - { "name": "l2ep", "setup": { "run-coverage": true, "min-coverage": 61.0, "run-gas-snapshot": true, "run-forge-fmt": false }}, + { "name": "l2ep", "setup": { "run-coverage": true, "min-coverage": 65.0, "run-gas-snapshot": true, "run-forge-fmt": false }}, { "name": "liquiditymanager", "setup": { "run-coverage": true, "min-coverage": 44, "run-gas-snapshot": true, "run-forge-fmt": false }}, { "name": "llo-feeds", "setup": { "run-coverage": true, "min-coverage": 49.3, "run-gas-snapshot": true, "run-forge-fmt": false }}, { "name": "operatorforwarder", "setup": { "run-coverage": true, "min-coverage": 55.7, "run-gas-snapshot": true, "run-forge-fmt": false }}, diff --git a/contracts/.changeset/thirty-rules-rule.md b/contracts/.changeset/thirty-rules-rule.md new file mode 100644 index 00000000000..1c69192981c --- /dev/null +++ b/contracts/.changeset/thirty-rules-rule.md @@ -0,0 +1,10 @@ +--- +'@chainlink/contracts': patch +--- + +[L2EP] Refactor tests and fix file exclusion for coverage + + +PR issue: SHIP-3521 + +Solidity Review issue: SHIP-4050 \ No newline at end of file diff --git a/contracts/gas-snapshots/l2ep.gas-snapshot b/contracts/gas-snapshots/l2ep.gas-snapshot index 643127b6212..7caca346f48 100644 --- a/contracts/gas-snapshots/l2ep.gas-snapshot +++ b/contracts/gas-snapshots/l2ep.gas-snapshot @@ -34,6 +34,18 @@ ArbitrumSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerA ArbitrumSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndNoTimeChange() (gas: 114527) ArbitrumSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndTimeChange() (gas: 114610) ArbitrumValidator_Validate:test_PostSequencerOffline() (gas: 69009) +BaseSequencerUptimeFeed_AggregatorV3Interface:test_AggregatorV3Interface_ReturnsValidData() (gas: 69197) +BaseSequencerUptimeFeed_AggregatorV3Interface:test_getAnswer_ReturnsValidAnswer() (gas: 57300) +BaseSequencerUptimeFeed_AggregatorV3Interface:test_getTimestamp_ReturnsValidTimestamp() (gas: 57151) +BaseSequencerUptimeFeed_Constructor:test_Constructor_InitialState() (gas: 22050) +BaseSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_ProtectReads_AllowWhen_Whitelisted() (gas: 589517) +BaseSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_ProtectReads_DisallowWhen_NotWhitelisted() (gas: 562342) +BaseSequencerUptimeFeed_UpdateStatus:test_updateStatus_IgnoreOutOfOrderUpdates() (gas: 69490) +BaseSequencerUptimeFeed_UpdateStatus:test_updateStatus_UpdateWhen_NoStatusChangeSameTimestamp() (gas: 77166) +BaseSequencerUptimeFeed_UpdateStatus:test_updateStatus_UpdateWhen_StatusChangeAndNoTimeChange() (gas: 96021) +BaseSequencerUptimeFeed_UpdateStatus:test_updateStatus_UpdateWhen_StatusChangeAndTimeChange() (gas: 96100) +BaseSequencerUptimeFeed_transferL1Sender:test_transferL1Sender_CorrectlyTransfersL1Sender() (gas: 1479310) +BaseValidator_GetAndSetGasLimit:test_GetAndSetGasLimit_CorrectlyHandlesGasLimit() (gas: 20119) OptimismCrossDomainForwarder_AcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 47110) OptimismCrossDomainForwarder_AcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 22135) OptimismCrossDomainForwarder_Constructor:test_InitialState() (gas: 21947) @@ -60,23 +72,10 @@ OptimismCrossDomainGovernor_TransferL1Ownership:test_CallableByL1Owner() (gas: 4 OptimismCrossDomainGovernor_TransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 28733) OptimismCrossDomainGovernor_TransferL1Ownership:test_NotCallableByL2Owner() (gas: 16456) OptimismCrossDomainGovernor_TransferL1Ownership:test_NotCallableByNonOwners() (gas: 11044) -OptimismSequencerUptimeFeed_AggregatorV3Interface:test_AggregatorV3Interface() (gas: 72286) -OptimismSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetAnswerWhenRoundDoesNotExistYet() (gas: 17639) -OptimismSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetRoundDataWhenRoundDoesNotExistYet() (gas: 17875) -OptimismSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetTimestampWhenRoundDoesNotExistYet() (gas: 17628) -OptimismSequencerUptimeFeed_Constructor:test_InitialState() (gas: 22002) -OptimismSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() (gas: 589475) -OptimismSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() (gas: 562336) -OptimismSequencerUptimeFeed_UpdateStatus:test_IgnoreOutOfOrderUpdates() (gas: 67804) -OptimismSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddr() (gas: 13109) -OptimismSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddrAndNotL1SenderAddr() (gas: 23523) -OptimismSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenNoChange() (gas: 77205) -OptimismSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndNoTimeChange() (gas: 96089) -OptimismSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndTimeChange() (gas: 96172) -OptimismValidator_SetGasLimit:test_CorrectlyUpdatesTheGasLimit() (gas: 18636) -OptimismValidator_Validate:test_PostSequencerOffline() (gas: 74764) -OptimismValidator_Validate:test_PostSequencerStatusWhenThereIsNotStatusChange() (gas: 74798) -OptimismValidator_Validate:test_RevertsIfCalledByAnAccountWithNoAccess() (gas: 15556) +OptimismSequencerUptimeFeed_Constructor:test_Constructor_InitialState() (gas: 1530881) +OptimismSequencerUptimeFeed_ValidateSender:test_ValidateSender_UpdateStatusWhen_StatusChangeAndNoTimeChange() (gas: 17874) +OptimismValidator_Validate:test_Validate_PostSequencerOffline() (gas: 74773) +OptimismValidator_Validate:test_Validate_PostSequencerStatus_NoStatusChange() (gas: 74788) ScrollCrossDomainForwarder_AcceptL1Ownership:test_CallableByPendingL1Owner() (gas: 47196) ScrollCrossDomainForwarder_AcceptL1Ownership:test_NotCallableByNonPendingOwners() (gas: 22185) ScrollCrossDomainForwarder_Constructor:test_InitialState() (gas: 21623) @@ -103,40 +102,12 @@ ScrollCrossDomainGovernor_TransferL1Ownership:test_CallableByL1Owner() (gas: 489 ScrollCrossDomainGovernor_TransferL1Ownership:test_CallableByL1OwnerOrZeroAddress() (gas: 28791) ScrollCrossDomainGovernor_TransferL1Ownership:test_NotCallableByL2Owner() (gas: 16456) ScrollCrossDomainGovernor_TransferL1Ownership:test_NotCallableByNonOwners() (gas: 11044) -ScrollSequencerUptimeFeed_AggregatorV3Interface:test_AggregatorV3Interface() (gas: 72309) -ScrollSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetAnswerWhenRoundDoesNotExistYet() (gas: 17639) -ScrollSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetRoundDataWhenRoundDoesNotExistYet() (gas: 17875) -ScrollSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetTimestampWhenRoundDoesNotExistYet() (gas: 17628) -ScrollSequencerUptimeFeed_Constructor:test_InitialState() (gas: 174353) -ScrollSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() (gas: 589475) -ScrollSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() (gas: 562336) -ScrollSequencerUptimeFeed_UpdateStatus:test_IgnoreOutOfOrderUpdates() (gas: 67850) -ScrollSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddr() (gas: 13109) -ScrollSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddrAndNotL1SenderAddr() (gas: 23523) -ScrollSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenNoChange() (gas: 77251) -ScrollSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndNoTimeChange() (gas: 96135) -ScrollSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndTimeChange() (gas: 96218) -ScrollValidator_SetGasLimit:test_CorrectlyUpdatesTheGasLimit() (gas: 18770) -ScrollValidator_Validate:test_PostSequencerOffline() (gas: 78299) -ScrollValidator_Validate:test_PostSequencerStatusWhenThereIsNotStatusChange() (gas: 78339) -ScrollValidator_Validate:test_RevertsIfCalledByAnAccountWithNoAccess() (gas: 15556) -ZKSyncSequencerUptimeFeed_AggregatorV3Interface:test_AggregatorV3Interface() (gas: 67090) -ZKSyncSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetAnswerWhenRoundDoesNotExistYet() (gas: 17639) -ZKSyncSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetRoundDataWhenRoundDoesNotExistYet() (gas: 17875) -ZKSyncSequencerUptimeFeed_AggregatorV3Interface:test_RevertGetTimestampWhenRoundDoesNotExistYet() (gas: 17628) -ZKSyncSequencerUptimeFeed_Constructor:test_InitialState() (gas: 22006) -ZKSyncSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() (gas: 589495) -ZKSyncSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions:test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() (gas: 562342) -ZKSyncSequencerUptimeFeed_UpdateStatus:test_IgnoreOutOfOrderUpdates() (gas: 61883) -ZKSyncSequencerUptimeFeed_UpdateStatus:test_RevertIfNotL2CrossDomainMessengerAddr() (gas: 13055) -ZKSyncSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenNoChange() (gas: 71321) -ZKSyncSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndNoTimeChange() (gas: 90176) -ZKSyncSequencerUptimeFeed_UpdateStatus:test_UpdateStatusWhenStatusChangeAndTimeChange() (gas: 90259) -ZKSyncValidator_Constructor:test_ConstructingRevertedWithInvalidChainId() (gas: 104069) -ZKSyncValidator_Constructor:test_ConstructingRevertedWithZeroL1BridgeAddress() (gas: 81784) -ZKSyncValidator_Constructor:test_ConstructingRevertedWithZeroL2UpdateFeedAddress() (gas: 81796) -ZKSyncValidator_GetChainId:test_CorrectlyGetsTheChainId() (gas: 8346) -ZKSyncValidator_GetSetL2GasPerPubdataByteLimit:test_CorrectlyGetsAndUpdatesTheGasPerPubdataByteLimit() (gas: 18896) -ZKSyncValidator_Validate:test_PostSequencerOffline() (gas: 52210) -ZKSyncValidator_Validate:test_PostSequencerStatusWhenThereIsNotStatusChange() (gas: 52279) -ZKSyncValidator_Validate:test_RevertsIfCalledByAnAccountWithNoAccess() (gas: 15623) \ No newline at end of file +ScrollSequencerUptimeFeed_Constructor:test_Constructor_InitialState_WhenValidL2XDomainMessenger() (gas: 1511902) +ScrollSequencerUptimeFeed_ValidateSender:test_ValidateSender_UpdateStatusWhen_StatusChangeAndNoTimeChange() (gas: 17864) +ScrollValidator_Validate:test_Validate_PostSequencerOffline() (gas: 78317) +ScrollValidator_Validate:test_Validate_PostSequencerStatus_NoStatusChange() (gas: 78338) +ZKSyncSequencerUptimeFeed_ValidateSender:test_ValidateSender_SuccessWhen_SenderIsValid() (gas: 12611) +ZKSyncValidator_GetChainId:test_GetChainId_CorrectlyGetsTheChainId() (gas: 8369) +ZKSyncValidator_GetSetL2GasPerPubdataByteLimit:test_GetSetL2GasPerPubdataByteLimit_CorrectlyHandlesGasPerPubdataByteLimit() (gas: 18918) +ZKSyncValidator_Validate:test_Validate_PostSequencerOffline() (gas: 52208) +ZKSyncValidator_Validate:test_Validate_PostSequencerStatus_NoStatusChange() (gas: 52280) \ No newline at end of file diff --git a/contracts/src/v0.8/l2ep/shared/BaseSequencerUptimeFeed.sol b/contracts/src/v0.8/l2ep/base/BaseSequencerUptimeFeed.sol similarity index 93% rename from contracts/src/v0.8/l2ep/shared/BaseSequencerUptimeFeed.sol rename to contracts/src/v0.8/l2ep/base/BaseSequencerUptimeFeed.sol index 344270fcff8..81fcb11ca95 100644 --- a/contracts/src/v0.8/l2ep/shared/BaseSequencerUptimeFeed.sol +++ b/contracts/src/v0.8/l2ep/base/BaseSequencerUptimeFeed.sol @@ -59,7 +59,7 @@ abstract contract BaseSequencerUptimeFeed is /// @param l1SenderAddress Address of the L1 contract that is permissioned to call this contract /// @param initialStatus The initial status of the feed constructor(address l1SenderAddress, bool initialStatus) { - // We neet to allow l1SenderAddress to be zero because this contract is deployed first + // We need to allow l1SenderAddress to be zero because this contract is deployed first // After deploying the validator contract, this contract will be updated with the correct L1 sender address _setL1Sender(l1SenderAddress); @@ -81,9 +81,9 @@ abstract contract BaseSequencerUptimeFeed is /// @notice Set the allowed L1 sender for this contract to a new L1 sender /// @dev Can be disabled by setting the L1 sender as `address(0)`. Accessible only by owner. - /// @param to new L1 sender that will be allowed to call `updateStatus` on this contract - function transferL1Sender(address to) external virtual onlyOwner { - _setL1Sender(to); + /// @param newSender new L1 sender that will be allowed to call `updateStatus` on this contract + function transferL1Sender(address newSender) external virtual onlyOwner { + _setL1Sender(newSender); } /// @notice internal method that stores the L1 sender @@ -164,13 +164,10 @@ abstract contract BaseSequencerUptimeFeed is return s_rounds[uint80(roundId)].startedAt; } - /** - * @notice Record a new status and timestamp if it has changed since the last round. - * @dev This function will revert if not called from `l1Sender` via the L1->L2 messenger. - * - * @param status Sequencer status - * @param timestamp Block timestamp of status update - */ + /// @notice Record a new status and timestamp if it has changed since the last round. + /// @dev This function will revert if not called from `l1Sender` via the L1->L2 messenger. + /// @param status Sequencer status + /// @param timestamp Block timestamp of status update function updateStatus(bool status, uint64 timestamp) external override { _validateSender(s_l1Sender); diff --git a/contracts/src/v0.8/l2ep/shared/BaseValidator.sol b/contracts/src/v0.8/l2ep/base/BaseValidator.sol similarity index 96% rename from contracts/src/v0.8/l2ep/shared/BaseValidator.sol rename to contracts/src/v0.8/l2ep/base/BaseValidator.sol index 8b38da391ec..4f9c6912a00 100644 --- a/contracts/src/v0.8/l2ep/shared/BaseValidator.sol +++ b/contracts/src/v0.8/l2ep/base/BaseValidator.sol @@ -24,7 +24,7 @@ abstract contract BaseValidator is SimpleWriteAccessController, AggregatorValida uint32 internal s_gasLimit; /// @param l1CrossDomainMessengerAddress address the L1CrossDomainMessenger contract address - /// @param l2UptimeFeedAddr the address of the SequencerUptimeFeed contract address + /// @param l2UptimeFeedAddr the address of the L2 SequencerUptimeFeed contract address /// @param gasLimit the gasLimit to use for sending a message from L1 to L2 constructor(address l1CrossDomainMessengerAddress, address l2UptimeFeedAddr, uint32 gasLimit) { if (l1CrossDomainMessengerAddress == address(0)) { diff --git a/contracts/src/v0.8/l2ep/optimism/OptimismSequencerUptimeFeed.sol b/contracts/src/v0.8/l2ep/optimism/OptimismSequencerUptimeFeed.sol index 0e6f9c52f22..b160fe46155 100644 --- a/contracts/src/v0.8/l2ep/optimism/OptimismSequencerUptimeFeed.sol +++ b/contracts/src/v0.8/l2ep/optimism/OptimismSequencerUptimeFeed.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.19; -import {BaseSequencerUptimeFeed} from "../shared/BaseSequencerUptimeFeed.sol"; +import {BaseSequencerUptimeFeed} from "../base/BaseSequencerUptimeFeed.sol"; import {IL2CrossDomainMessenger} from "@eth-optimism/contracts/L2/messaging/IL2CrossDomainMessenger.sol"; diff --git a/contracts/src/v0.8/l2ep/optimism/OptimismValidator.sol b/contracts/src/v0.8/l2ep/optimism/OptimismValidator.sol index cf5222f017e..97c202dcd88 100644 --- a/contracts/src/v0.8/l2ep/optimism/OptimismValidator.sol +++ b/contracts/src/v0.8/l2ep/optimism/OptimismValidator.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.19; import {ISequencerUptimeFeed} from "./../interfaces/ISequencerUptimeFeed.sol"; -import {BaseValidator} from "../shared/BaseValidator.sol"; +import {BaseValidator} from "../base/BaseValidator.sol"; import {IL1CrossDomainMessenger} from "@eth-optimism/contracts/L1/messaging/IL1CrossDomainMessenger.sol"; diff --git a/contracts/src/v0.8/l2ep/scroll/ScrollSequencerUptimeFeed.sol b/contracts/src/v0.8/l2ep/scroll/ScrollSequencerUptimeFeed.sol index 40f2941aa69..9c0c22290f2 100644 --- a/contracts/src/v0.8/l2ep/scroll/ScrollSequencerUptimeFeed.sol +++ b/contracts/src/v0.8/l2ep/scroll/ScrollSequencerUptimeFeed.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.24; -import {BaseSequencerUptimeFeed} from "../shared/BaseSequencerUptimeFeed.sol"; +import {BaseSequencerUptimeFeed} from "../base/BaseSequencerUptimeFeed.sol"; import {IL2ScrollMessenger} from "@scroll-tech/contracts/L2/IL2ScrollMessenger.sol"; diff --git a/contracts/src/v0.8/l2ep/scroll/ScrollValidator.sol b/contracts/src/v0.8/l2ep/scroll/ScrollValidator.sol index b009c80fdfd..0eda14d0adc 100644 --- a/contracts/src/v0.8/l2ep/scroll/ScrollValidator.sol +++ b/contracts/src/v0.8/l2ep/scroll/ScrollValidator.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.24; import {ISequencerUptimeFeed} from "../interfaces/ISequencerUptimeFeed.sol"; -import {BaseValidator} from "../shared/BaseValidator.sol"; +import {BaseValidator} from "../base/BaseValidator.sol"; import {IL1MessageQueue} from "@scroll-tech/contracts/L1/rollup/IL1MessageQueue.sol"; import {IL1ScrollMessenger} from "@scroll-tech/contracts/L1/IL1ScrollMessenger.sol"; diff --git a/contracts/src/v0.8/l2ep/test/mocks/MockBaseSequencerUptimeFeed.sol b/contracts/src/v0.8/l2ep/test/mocks/MockBaseSequencerUptimeFeed.sol new file mode 100644 index 00000000000..50d852faa45 --- /dev/null +++ b/contracts/src/v0.8/l2ep/test/mocks/MockBaseSequencerUptimeFeed.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {BaseSequencerUptimeFeed} from "../../base/BaseSequencerUptimeFeed.sol"; + +contract MockBaseSequencerUptimeFeed is BaseSequencerUptimeFeed { + string public constant override typeAndVersion = "MockSequencerUptimeFeed 1.1.0-dev"; + + /// @dev this will be used for internal testing + bool private s_validateSenderShouldPass; + + constructor( + address l1SenderAddress, + bool initialStatus, + bool validateSenderShouldPass + ) BaseSequencerUptimeFeed(l1SenderAddress, initialStatus) { + s_validateSenderShouldPass = validateSenderShouldPass; + } + + function _validateSender(address /* l1Sender */) internal view override { + if (!s_validateSenderShouldPass) { + revert InvalidSender(); + } + } +} diff --git a/contracts/src/v0.8/l2ep/test/mocks/MockBaseValidator.sol b/contracts/src/v0.8/l2ep/test/mocks/MockBaseValidator.sol new file mode 100644 index 00000000000..d23efb48656 --- /dev/null +++ b/contracts/src/v0.8/l2ep/test/mocks/MockBaseValidator.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {BaseValidator} from "../../base/BaseValidator.sol"; + +contract MockBaseValidator is BaseValidator { + string public constant override typeAndVersion = "MockValidator 1.1.0-dev"; + + constructor( + address l1CrossDomainMessengerAddress, + address l2UptimeFeedAddr, + uint32 gasLimit + ) BaseValidator(l1CrossDomainMessengerAddress, l2UptimeFeedAddr, gasLimit) {} + + function validate( + uint256 /* previousRoundId */, + int256 /* previousAnswer */, + uint256 /* currentRoundId */, + int256 /* currentAnswer */ + ) external view override checkAccess returns (bool) { + return true; + } +} 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 daf50962a1e..34010c313e8 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 @@ -4,30 +4,36 @@ pragma solidity 0.8.24; import {MockOptimismL1CrossDomainMessenger} from "../../../../tests/MockOptimismL1CrossDomainMessenger.sol"; import {MockOptimismL2CrossDomainMessenger} from "../../../../tests/MockOptimismL2CrossDomainMessenger.sol"; import {OptimismSequencerUptimeFeed} from "../../../optimism/OptimismSequencerUptimeFeed.sol"; -import {BaseSequencerUptimeFeed} from "../../../shared/BaseSequencerUptimeFeed.sol"; -import {FeedConsumer} from "../../../../tests/FeedConsumer.sol"; +import {BaseSequencerUptimeFeed} from "../../../base/BaseSequencerUptimeFeed.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -contract OptimismSequencerUptimeFeedTest is L2EPTest { - /// Constants - uint256 internal constant GAS_USED_DEVIATION = 100; +contract OptimismSequencerUptimeFeed_TestWrapper is OptimismSequencerUptimeFeed { + constructor( + address l1SenderAddress, + address l2CrossDomainMessengerAddr, + bool initialStatus + ) OptimismSequencerUptimeFeed(l1SenderAddress, l2CrossDomainMessengerAddr, initialStatus) {} + + /// @notice Exposes the internal `_validateSender` function for testing + function validateSenderTestWrapper(address l1Sender) external view { + super._validateSender(l1Sender); + } +} + +contract OptimismSequencerUptimeFeed_Setup is L2EPTest { + event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt); /// L2EP contracts MockOptimismL1CrossDomainMessenger internal s_mockOptimismL1CrossDomainMessenger; MockOptimismL2CrossDomainMessenger internal s_mockOptimismL2CrossDomainMessenger; - OptimismSequencerUptimeFeed internal s_optimismSequencerUptimeFeed; - - /// Events - event UpdateIgnored(bool latestStatus, uint64 latestTimestamp, bool incomingStatus, uint64 incomingTimestamp); - event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt); - event RoundUpdated(int256 status, uint64 updatedAt); + OptimismSequencerUptimeFeed_TestWrapper internal s_optimismSequencerUptimeFeed; /// Setup function setUp() public { - // Deploys contracts + // Deploy contracts s_mockOptimismL1CrossDomainMessenger = new MockOptimismL1CrossDomainMessenger(); s_mockOptimismL2CrossDomainMessenger = new MockOptimismL2CrossDomainMessenger(); - s_optimismSequencerUptimeFeed = new OptimismSequencerUptimeFeed( + s_optimismSequencerUptimeFeed = new OptimismSequencerUptimeFeed_TestWrapper( s_l1OwnerAddr, address(s_mockOptimismL2CrossDomainMessenger), false @@ -38,12 +44,14 @@ contract OptimismSequencerUptimeFeedTest is L2EPTest { } } -contract OptimismSequencerUptimeFeed_Constructor is OptimismSequencerUptimeFeedTest { - /// @notice it should have been deployed with the correct initial state - function test_InitialState() public { +contract OptimismSequencerUptimeFeed_Constructor is OptimismSequencerUptimeFeed_Setup { + /// @notice Tests the initial state of the contract + function test_Constructor_InitialState() public { // Sets msg.sender and tx.origin to a valid address vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + new OptimismSequencerUptimeFeed_TestWrapper(s_l1OwnerAddr, address(s_mockOptimismL2CrossDomainMessenger), false); + // Checks L1 sender address actualL1Addr = s_optimismSequencerUptimeFeed.l1Sender(); assertEq(actualL1Addr, s_l1OwnerAddr); @@ -55,267 +63,33 @@ contract OptimismSequencerUptimeFeed_Constructor is OptimismSequencerUptimeFeedT } } -contract OptimismSequencerUptimeFeed_UpdateStatus 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 - vm.startPrank(s_strangerAddr, s_strangerAddr); +contract OptimismSequencerUptimeFeed_ValidateSender is OptimismSequencerUptimeFeed_Setup { + /// @notice Reverts if called by an address that is not the L2 Cross Domain Messenger + function test_ValidateSender_RevertWhen_SenderIsNotL2CrossDomainMessengerAddr() public { + address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); + // Sets msg.sender to a different address + vm.startPrank(s_strangerAddr, l2MessengerAddr); - // Tries to update the status from an unauthorized account vm.expectRevert(BaseSequencerUptimeFeed.InvalidSender.selector); - s_optimismSequencerUptimeFeed.updateStatus(true, uint64(1)); + s_optimismSequencerUptimeFeed.validateSenderTestWrapper(s_l1OwnerAddr); } - /// @notice it should revert if called by an address that is not the L2 Cross Domain Messenger and is not the L1 sender - function test_RevertIfNotL2CrossDomainMessengerAddrAndNotL1SenderAddr() public { + /// @notice Reverts if the L1 sender address is not the L1 Cross Domain Messenger Sender + function test_ValidateSender_RevertWhen_L1CrossDomainMessengerAddrIsNotL1SenderAddr() public { // Sets msg.sender and tx.origin to an unauthorized address - vm.startPrank(s_strangerAddr, s_strangerAddr); - - // Sets mock sender in mock L2 messenger contract - s_mockOptimismL2CrossDomainMessenger.setSender(s_strangerAddr); - - // Tries to update the status from an unauthorized account - vm.expectRevert(BaseSequencerUptimeFeed.InvalidSender.selector); - s_optimismSequencerUptimeFeed.updateStatus(true, uint64(1)); - } - - /// @notice it should update status when status has not changed and incoming timestamp is the same as latest - function test_UpdateStatusWhenNoChange() public { - // Sets msg.sender and tx.origin to a valid address - address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); - vm.startPrank(l2MessengerAddr, l2MessengerAddr); - - // Fetches the latest timestamp - uint256 timestamp = s_optimismSequencerUptimeFeed.latestTimestamp(); - - // Submits a status update - vm.expectEmit(); - emit AnswerUpdated(1, 2, timestamp); - s_optimismSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_optimismSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Stores the current round data before updating it - ( - uint80 roundIdBeforeUpdate, - int256 answerBeforeUpdate, - uint256 startedAtBeforeUpdate, - , - uint80 answeredInRoundBeforeUpdate - ) = s_optimismSequencerUptimeFeed.latestRoundData(); - - // Submit another status update with the same status - vm.expectEmit(); - emit RoundUpdated(1, uint64(block.timestamp)); - s_optimismSequencerUptimeFeed.updateStatus(true, uint64(timestamp + 200)); - assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_optimismSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Stores the current round data after updating it - ( - uint80 roundIdAfterUpdate, - int256 answerAfterUpdate, - uint256 startedAtAfterUpdate, - uint256 updatedAtAfterUpdate, - uint80 answeredInRoundAfterUpdate - ) = s_optimismSequencerUptimeFeed.latestRoundData(); - - // Verifies the latest round data has been properly updated - assertEq(roundIdAfterUpdate, roundIdBeforeUpdate); - assertEq(answerAfterUpdate, answerBeforeUpdate); - assertEq(startedAtAfterUpdate, startedAtBeforeUpdate); - assertEq(answeredInRoundAfterUpdate, answeredInRoundBeforeUpdate); - assertEq(updatedAtAfterUpdate, block.timestamp); - } - - /// @notice it should update status when status has changed and incoming timestamp is newer than the latest - function test_UpdateStatusWhenStatusChangeAndTimeChange() public { - // Sets msg.sender and tx.origin to a valid address - address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); - vm.startPrank(l2MessengerAddr, l2MessengerAddr); - - // Submits a status update - uint256 timestamp = s_optimismSequencerUptimeFeed.latestTimestamp(); - 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, newer timestamp should update - timestamp = timestamp + 200; - vm.expectEmit(); - emit AnswerUpdated(0, 3, timestamp); - s_optimismSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); - assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 0); - assertEq(s_optimismSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - } - - /// @notice it should update status when status has changed and incoming timestamp is the same as latest - function test_UpdateStatusWhenStatusChangeAndNoTimeChange() public { - // Sets msg.sender and tx.origin to a valid address - address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); - vm.startPrank(l2MessengerAddr, l2MessengerAddr); - - // Fetches the latest timestamp - uint256 timestamp = s_optimismSequencerUptimeFeed.latestTimestamp(); - - // Submits a status update - 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(); - emit AnswerUpdated(0, 3, timestamp); - s_optimismSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); - assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 0); - assertEq(s_optimismSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - } - - /// @notice it should ignore out-of-order updates - function test_IgnoreOutOfOrderUpdates() public { - // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); - // Submits a status update - uint256 timestamp = s_optimismSequencerUptimeFeed.latestTimestamp() + 10000; - vm.expectEmit(); - emit AnswerUpdated(1, 2, timestamp); - s_optimismSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - assertEq(s_optimismSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_optimismSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Update with different status, but stale timestamp, should be ignored - timestamp = timestamp - 1000; - vm.expectEmit(false, false, false, false); - 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)); + vm.expectRevert(BaseSequencerUptimeFeed.InvalidSender.selector); + s_optimismSequencerUptimeFeed.validateSenderTestWrapper(s_strangerAddr); } -} -contract OptimismSequencerUptimeFeed_AggregatorV3Interface is OptimismSequencerUptimeFeedTest { - /// @notice it should return valid answer from getRoundData and latestRoundData - function test_AggregatorV3Interface() public { + /// @notice Updates status when status has changed and incoming timestamp is the same as the latest + function test_ValidateSender_UpdateStatusWhen_StatusChangeAndNoTimeChange() public { // Sets msg.sender and tx.origin to a valid address address l2MessengerAddr = address(s_mockOptimismL2CrossDomainMessenger); vm.startPrank(l2MessengerAddr, l2MessengerAddr); - // Defines helper variables - uint80 roundId; - int256 answer; - uint256 startedAt; - uint256 updatedAt; - uint80 answeredInRound; - - // Checks initial state - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_optimismSequencerUptimeFeed.latestRoundData(); - assertEq(roundId, 1); - assertEq(answer, 0); - assertEq(answeredInRound, roundId); - assertEq(startedAt, updatedAt); - - // Submits status update with different status and newer timestamp, should update - uint256 timestamp = startedAt + 1000; - s_optimismSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_optimismSequencerUptimeFeed.getRoundData(2); - assertEq(roundId, 2); - assertEq(answer, 1); - assertEq(answeredInRound, roundId); - assertEq(startedAt, timestamp); - assertLe(updatedAt, startedAt); - - // Saves round 2 data - uint80 roundId2 = roundId; - int256 answer2 = answer; - uint256 startedAt2 = startedAt; - uint256 updatedAt2 = updatedAt; - uint80 answeredInRound2 = answeredInRound; - - // Checks that last round is still returning the correct data - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_optimismSequencerUptimeFeed.getRoundData(1); - assertEq(roundId, 1); - assertEq(answer, 0); - assertEq(answeredInRound, roundId); - assertEq(startedAt, updatedAt); - - // Assert latestRoundData corresponds to latest round id - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_optimismSequencerUptimeFeed.latestRoundData(); - assertEq(roundId2, roundId); - assertEq(answer2, answer); - assertEq(startedAt2, startedAt); - assertEq(updatedAt2, updatedAt); - assertEq(answeredInRound2, answeredInRound); - } - - /// @notice it should revert from #getRoundData when round does not yet exist (future roundId) - function test_RevertGetRoundDataWhenRoundDoesNotExistYet() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); - - // Gets data from a round that has not happened yet - vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); - s_optimismSequencerUptimeFeed.getRoundData(2); - } - - /// @notice it should revert from #getAnswer when round does not yet exist (future roundId) - function test_RevertGetAnswerWhenRoundDoesNotExistYet() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); - - // Gets data from a round that has not happened yet - vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); - s_optimismSequencerUptimeFeed.getAnswer(2); - } - - /// @notice it should revert from #getTimestamp when round does not yet exist (future roundId) - function test_RevertGetTimestampWhenRoundDoesNotExistYet() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); - - // Gets data from a round that has not happened yet - vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); - s_optimismSequencerUptimeFeed.getTimestamp(2); - } -} - -contract OptimismSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions is OptimismSequencerUptimeFeedTest { - /// @notice it should disallow reads on AggregatorV2V3Interface functions when consuming contract is not whitelisted - function test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() public { - // Deploys a FeedConsumer contract - FeedConsumer feedConsumer = new FeedConsumer(address(s_optimismSequencerUptimeFeed)); - - // Sanity - consumer is not whitelisted - assertEq(s_optimismSequencerUptimeFeed.checkEnabled(), true); - assertEq(s_optimismSequencerUptimeFeed.hasAccess(address(feedConsumer), abi.encode("")), false); - - // Asserts reads are not possible from consuming contract - vm.expectRevert("No access"); - feedConsumer.latestAnswer(); - vm.expectRevert("No access"); - feedConsumer.latestRoundData(); - } - - /// @notice it should allow reads on AggregatorV2V3Interface functions when consuming contract is whitelisted - function test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() public { - // Deploys a FeedConsumer contract - FeedConsumer feedConsumer = new FeedConsumer(address(s_optimismSequencerUptimeFeed)); - - // Whitelist consumer - s_optimismSequencerUptimeFeed.addAccess(address(feedConsumer)); - - // Sanity - consumer is whitelisted - assertEq(s_optimismSequencerUptimeFeed.checkEnabled(), true); - assertEq(s_optimismSequencerUptimeFeed.hasAccess(address(feedConsumer), abi.encode("")), true); - - // Asserts reads are possible from consuming contract - (uint80 roundId, int256 answer, , , ) = feedConsumer.latestRoundData(); - assertEq(feedConsumer.latestAnswer(), 0); - assertEq(roundId, 1); - assertEq(answer, 0); + s_optimismSequencerUptimeFeed.validateSenderTestWrapper(s_l1OwnerAddr); } } 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 ba9e3f872f1..48ff1f7778d 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 @@ -9,7 +9,7 @@ import {OptimismSequencerUptimeFeed} from "../../../optimism/OptimismSequencerUp import {OptimismValidator} from "../../../optimism/OptimismValidator.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -contract OptimismValidatorTest is L2EPTest { +contract OptimismValidator_Setup is L2EPTest { /// Helper constants address internal constant L2_SEQ_STATUS_RECORDER_ADDRESS = 0x491B1dDA0A8fa069bbC1125133A975BF4e85a91b; uint32 internal constant INIT_GAS_LIMIT = 1900000; @@ -42,26 +42,16 @@ contract OptimismValidatorTest is L2EPTest { } } -contract OptimismValidator_SetGasLimit is OptimismValidatorTest { - /// @notice it correctly updates the gas limit - function test_CorrectlyUpdatesTheGasLimit() public { - uint32 newGasLimit = 2000000; - assertEq(s_optimismValidator.getGasLimit(), INIT_GAS_LIMIT); - s_optimismValidator.setGasLimit(newGasLimit); - assertEq(s_optimismValidator.getGasLimit(), newGasLimit); - } -} - -contract OptimismValidator_Validate is OptimismValidatorTest { +contract OptimismValidator_Validate is OptimismValidator_Setup { /// @notice it reverts if called by account with no access - function test_RevertsIfCalledByAnAccountWithNoAccess() public { + function test_Validate_RevertWhen_CalledByAccountWithNoAccess() public { vm.startPrank(s_strangerAddr); vm.expectRevert("No access"); s_optimismValidator.validate(0, 0, 1, 1); } - /// @notice it posts sequencer status when there is not status change - function test_PostSequencerStatusWhenThereIsNotStatusChange() public { + /// @notice it posts sequencer status when there is no status change + function test_Validate_PostSequencerStatus_NoStatusChange() public { // Gives access to the s_eoaValidator s_optimismValidator.addAccess(s_eoaValidator); @@ -84,8 +74,8 @@ contract OptimismValidator_Validate is OptimismValidatorTest { s_optimismValidator.validate(0, 0, 0, 0); } - /// @notice it post sequencer offline - function test_PostSequencerOffline() public { + /// @notice it posts sequencer offline + function test_Validate_PostSequencerOffline() public { // Gives access to the s_eoaValidator s_optimismValidator.addAccess(s_eoaValidator); 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 b0ef7df22c1..0025c6b9937 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 @@ -54,7 +54,6 @@ contract ScrollCrossDomainForwarder_Forward is ScrollCrossDomainForwarderTest { /// @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); // Defines the cross domain message to send @@ -74,7 +73,6 @@ contract ScrollCrossDomainForwarder_Forward is ScrollCrossDomainForwarderTest { /// @notice it should revert when contract call reverts function test_ForwardRevert() public { - // Sets msg.sender and tx.origin vm.startPrank(s_strangerAddr); // Sends an invalid message @@ -106,7 +104,6 @@ contract ScrollCrossDomainForwarder_TransferL1Ownership is ScrollCrossDomainForw /// @notice it should be callable by current L1 owner function test_CallableByL1Owner() public { - // Sets msg.sender and tx.origin vm.startPrank(s_strangerAddr); // Defines the cross domain message to send @@ -124,7 +121,6 @@ contract ScrollCrossDomainForwarder_TransferL1Ownership is ScrollCrossDomainForw /// @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); // Defines the cross domain message to send @@ -144,7 +140,6 @@ contract ScrollCrossDomainForwarder_TransferL1Ownership is ScrollCrossDomainForw contract ScrollCrossDomainForwarder_AcceptL1Ownership 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); // Sends the message @@ -159,7 +154,6 @@ contract ScrollCrossDomainForwarder_AcceptL1Ownership is ScrollCrossDomainForwar /// @notice it should be callable by pending L1 owner function test_CallableByPendingL1Owner() public { - // Sets msg.sender and tx.origin vm.startPrank(s_strangerAddr); // Request ownership transfer 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 5eefaddab70..a2523e5feb6 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 @@ -58,7 +58,6 @@ contract ScrollCrossDomainGovernor_Forward is ScrollCrossDomainGovernorTest { /// @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); // Defines the cross domain message to send @@ -78,7 +77,6 @@ contract ScrollCrossDomainGovernor_Forward is ScrollCrossDomainGovernorTest { /// @notice it should revert when contract call reverts function test_ForwardRevert() public { - // Sets msg.sender and tx.origin vm.startPrank(s_strangerAddr); // Sends an invalid message @@ -93,7 +91,6 @@ contract ScrollCrossDomainGovernor_Forward is ScrollCrossDomainGovernorTest { /// @notice it should be callable by L2 owner function test_CallableByL2Owner() public { - // Sets msg.sender and tx.origin vm.startPrank(s_l1OwnerAddr); // Defines the cross domain message to send @@ -120,7 +117,6 @@ contract ScrollCrossDomainGovernor_ForwardDelegate is ScrollCrossDomainGovernorT /// @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); // Sends the message @@ -141,7 +137,6 @@ contract ScrollCrossDomainGovernor_ForwardDelegate is ScrollCrossDomainGovernorT /// @notice it should be callable by L2 owner function test_CallableByL2Owner() public { - // Sets msg.sender and tx.origin vm.startPrank(s_l1OwnerAddr); // Sends the message @@ -162,7 +157,6 @@ contract ScrollCrossDomainGovernor_ForwardDelegate is ScrollCrossDomainGovernorT /// @notice it should revert batch when one call fails function test_RevertsBatchWhenOneCallFails() public { - // Sets msg.sender and tx.origin vm.startPrank(s_strangerAddr); // Sends an invalid message (empty transaction data is not allowed) @@ -184,7 +178,6 @@ contract ScrollCrossDomainGovernor_ForwardDelegate is ScrollCrossDomainGovernorT /// @notice it should bubble up revert when contract call reverts function test_BubbleUpRevert() public { - // Sets msg.sender and tx.origin vm.startPrank(s_strangerAddr); // Sends an invalid message (empty transaction data is not allowed) @@ -220,7 +213,6 @@ contract ScrollCrossDomainGovernor_TransferL1Ownership is ScrollCrossDomainGover /// @notice it should be callable by current L1 owner function test_CallableByL1Owner() public { - // Sets msg.sender and tx.origin vm.startPrank(s_strangerAddr); // Defines the cross domain message to send @@ -238,7 +230,6 @@ contract ScrollCrossDomainGovernor_TransferL1Ownership is ScrollCrossDomainGover /// @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); // Defines the cross domain message to send @@ -258,7 +249,6 @@ contract ScrollCrossDomainGovernor_TransferL1Ownership is ScrollCrossDomainGover contract ScrollCrossDomainGovernor_AcceptL1Ownership 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); // Sends the message @@ -273,7 +263,6 @@ contract ScrollCrossDomainGovernor_AcceptL1Ownership is ScrollCrossDomainGoverno /// @notice it should be callable by pending L1 owner function test_CallableByPendingL1Owner() public { - // Sets msg.sender and tx.origin vm.startPrank(s_strangerAddr); // Request ownership transfer 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 5e4d8a7a20f..1ad4bfd8119 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 @@ -4,18 +4,30 @@ pragma solidity 0.8.24; import {MockScrollL1CrossDomainMessenger} from "../../mocks/scroll/MockScrollL1CrossDomainMessenger.sol"; import {MockScrollL2CrossDomainMessenger} from "../../mocks/scroll/MockScrollL2CrossDomainMessenger.sol"; import {ScrollSequencerUptimeFeed} from "../../../scroll/ScrollSequencerUptimeFeed.sol"; -import {BaseSequencerUptimeFeed} from "../../../shared/BaseSequencerUptimeFeed.sol"; -import {FeedConsumer} from "../../../../tests/FeedConsumer.sol"; +import {BaseSequencerUptimeFeed} from "../../../base/BaseSequencerUptimeFeed.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -contract ScrollSequencerUptimeFeedTest is L2EPTest { +contract ScrollSequencerUptimeFeedTestWrapper is ScrollSequencerUptimeFeed { + constructor( + address l1SenderAddress, + address l2CrossDomainMessengerAddr, + bool initialStatus + ) ScrollSequencerUptimeFeed(l1SenderAddress, l2CrossDomainMessengerAddr, initialStatus) {} + + /// @notice It exposes the internal _validateSender function for testing + function validateSenderTestWrapper(address l1Sender) external view { + super._validateSender(l1Sender); + } +} + +contract ScrollSequencerUptimeFeed_Setup is L2EPTest { /// Constants uint256 internal constant GAS_USED_DEVIATION = 100; /// L2EP contracts MockScrollL1CrossDomainMessenger internal s_mockScrollL1CrossDomainMessenger; MockScrollL2CrossDomainMessenger internal s_mockScrollL2CrossDomainMessenger; - ScrollSequencerUptimeFeed internal s_scrollSequencerUptimeFeed; + ScrollSequencerUptimeFeedTestWrapper internal s_scrollSequencerUptimeFeed; /// Events event UpdateIgnored(bool latestStatus, uint64 latestTimestamp, bool incomingStatus, uint64 incomingTimestamp); @@ -27,7 +39,7 @@ contract ScrollSequencerUptimeFeedTest is L2EPTest { // Deploys contracts s_mockScrollL1CrossDomainMessenger = new MockScrollL1CrossDomainMessenger(); s_mockScrollL2CrossDomainMessenger = new MockScrollL2CrossDomainMessenger(); - s_scrollSequencerUptimeFeed = new ScrollSequencerUptimeFeed( + s_scrollSequencerUptimeFeed = new ScrollSequencerUptimeFeedTestWrapper( s_l1OwnerAddr, address(s_mockScrollL2CrossDomainMessenger), false @@ -38,14 +50,13 @@ contract ScrollSequencerUptimeFeedTest is L2EPTest { } } -contract ScrollSequencerUptimeFeed_Constructor is ScrollSequencerUptimeFeedTest { - /// @notice it should have been deployed with the correct initial state - function test_InitialState() public { +contract ScrollSequencerUptimeFeed_Constructor is ScrollSequencerUptimeFeed_Setup { + /// @notice Reverts when L2 Cross Domain Messenger address is invalid + function test_Constructor_RevertWhen_InvalidL2XDomainMessenger() public { // L2 cross domain messenger address must not be the zero address vm.expectRevert(ScrollSequencerUptimeFeed.ZeroAddress.selector); new ScrollSequencerUptimeFeed(s_l1OwnerAddr, address(0), false); - // Sets msg.sender and tx.origin to a valid address vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); // Checks L1 sender @@ -57,269 +68,50 @@ contract ScrollSequencerUptimeFeed_Constructor is ScrollSequencerUptimeFeedTest assertEq(roundId, 1); assertEq(answer, 0); } -} - -contract ScrollSequencerUptimeFeed_UpdateStatus 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 - vm.startPrank(s_strangerAddr, s_strangerAddr); - - // Tries to update the status from an unauthorized account - vm.expectRevert(BaseSequencerUptimeFeed.InvalidSender.selector); - s_scrollSequencerUptimeFeed.updateStatus(true, uint64(1)); - } - - /// @notice it should revert if called by an address that is not the L2 Cross Domain Messenger and is not the L1 sender - function test_RevertIfNotL2CrossDomainMessengerAddrAndNotL1SenderAddr() public { - // Sets msg.sender and tx.origin to an unauthorized address - vm.startPrank(s_strangerAddr, s_strangerAddr); - - // Sets mock sender in mock L2 messenger contract - s_mockScrollL2CrossDomainMessenger.setSender(s_strangerAddr); - - // Tries to update the status from an unauthorized account - vm.expectRevert(BaseSequencerUptimeFeed.InvalidSender.selector); - s_scrollSequencerUptimeFeed.updateStatus(true, uint64(1)); - } - - /// @notice it should update status when status has not changed and incoming timestamp is the same as latest - function test_UpdateStatusWhenNoChange() public { - // Sets msg.sender and tx.origin to a valid address - address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); - vm.startPrank(l2MessengerAddr, l2MessengerAddr); - - // Fetches the latest timestamp - uint256 timestamp = s_scrollSequencerUptimeFeed.latestTimestamp(); - - // Submits a status update - vm.expectEmit(); - emit AnswerUpdated(1, 2, timestamp); - s_scrollSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_scrollSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Stores the current round data before updating it - ( - uint80 roundIdBeforeUpdate, - int256 answerBeforeUpdate, - uint256 startedAtBeforeUpdate, - , - uint80 answeredInRoundBeforeUpdate - ) = s_scrollSequencerUptimeFeed.latestRoundData(); - - // Submit another status update with the same status - vm.expectEmit(); - emit RoundUpdated(1, uint64(block.timestamp)); - s_scrollSequencerUptimeFeed.updateStatus(true, uint64(timestamp + 200)); - assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_scrollSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Stores the current round data after updating it - ( - uint80 roundIdAfterUpdate, - int256 answerAfterUpdate, - uint256 startedAtAfterUpdate, - uint256 updatedAtAfterUpdate, - uint80 answeredInRoundAfterUpdate - ) = s_scrollSequencerUptimeFeed.latestRoundData(); - - // Verifies the latest round data has been properly updated - assertEq(roundIdAfterUpdate, roundIdBeforeUpdate); - assertEq(answerAfterUpdate, answerBeforeUpdate); - assertEq(startedAtAfterUpdate, startedAtBeforeUpdate); - assertEq(answeredInRoundAfterUpdate, answeredInRoundBeforeUpdate); - assertEq(updatedAtAfterUpdate, block.timestamp); - } - - /// @notice it should update status when status has changed and incoming timestamp is newer than the latest - function test_UpdateStatusWhenStatusChangeAndTimeChange() public { - // Sets msg.sender and tx.origin to a valid address - address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); - vm.startPrank(l2MessengerAddr, l2MessengerAddr); - - // Submits a status update - uint256 timestamp = s_scrollSequencerUptimeFeed.latestTimestamp(); - 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, newer timestamp should update - timestamp = timestamp + 200; - vm.expectEmit(); - emit AnswerUpdated(0, 3, timestamp); - s_scrollSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); - assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 0); - assertEq(s_scrollSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - } - - /// @notice it should update status when status has changed and incoming timestamp is the same as latest - function test_UpdateStatusWhenStatusChangeAndNoTimeChange() public { - // Sets msg.sender and tx.origin to a valid address - address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); - vm.startPrank(l2MessengerAddr, l2MessengerAddr); - - // Fetches the latest timestamp - uint256 timestamp = s_scrollSequencerUptimeFeed.latestTimestamp(); - - // Submits a status update - 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(); - emit AnswerUpdated(0, 3, timestamp); - s_scrollSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); - assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 0); - assertEq(s_scrollSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - } - - /// @notice it should ignore out-of-order updates - function test_IgnoreOutOfOrderUpdates() public { - // Sets msg.sender and tx.origin to a valid address - address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); - vm.startPrank(l2MessengerAddr, l2MessengerAddr); - - // Submits a status update - uint256 timestamp = s_scrollSequencerUptimeFeed.latestTimestamp() + 10000; - vm.expectEmit(); - emit AnswerUpdated(1, 2, timestamp); - s_scrollSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - assertEq(s_scrollSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_scrollSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Update with different status, but stale timestamp, should be ignored - timestamp = timestamp - 1000; - vm.expectEmit(false, false, false, false); - 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)); - } -} - -contract ScrollSequencerUptimeFeed_AggregatorV3Interface 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 - address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); - vm.startPrank(l2MessengerAddr, l2MessengerAddr); - // Defines helper variables - uint80 roundId; - int256 answer; - uint256 startedAt; - uint256 updatedAt; - uint80 answeredInRound; - - // Checks initial state - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_scrollSequencerUptimeFeed.latestRoundData(); - assertEq(roundId, 1); - assertEq(answer, 0); - assertEq(answeredInRound, roundId); - assertEq(startedAt, updatedAt); - - // Submits status update with different status and newer timestamp, should update - uint256 timestamp = startedAt + 1000; - s_scrollSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_scrollSequencerUptimeFeed.getRoundData(2); - assertEq(roundId, 2); - assertEq(answer, 1); - assertEq(answeredInRound, roundId); - assertEq(startedAt, timestamp); - assertLe(updatedAt, startedAt); + /// @notice Tests initial state with valid L2 Cross Domain Messenger + function test_Constructor_InitialState_WhenValidL2XDomainMessenger() public { + vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + ScrollSequencerUptimeFeed scrollSequencerUptimeFeed = new ScrollSequencerUptimeFeed( + s_l1OwnerAddr, + address(s_mockScrollL2CrossDomainMessenger), + false + ); - // Saves round 2 data - uint80 roundId2 = roundId; - int256 answer2 = answer; - uint256 startedAt2 = startedAt; - uint256 updatedAt2 = updatedAt; - uint80 answeredInRound2 = answeredInRound; + // Checks L1 sender + address actualL1Addr = scrollSequencerUptimeFeed.l1Sender(); + assertEq(actualL1Addr, s_l1OwnerAddr); - // Checks that last round is still returning the correct data - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_scrollSequencerUptimeFeed.getRoundData(1); + // Checks latest round data + (uint80 roundId, int256 answer, , , ) = scrollSequencerUptimeFeed.latestRoundData(); assertEq(roundId, 1); assertEq(answer, 0); - assertEq(answeredInRound, roundId); - assertEq(startedAt, updatedAt); - - // Assert latestRoundData corresponds to latest round id - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_scrollSequencerUptimeFeed.latestRoundData(); - assertEq(roundId2, roundId); - assertEq(answer2, answer); - assertEq(startedAt2, startedAt); - assertEq(updatedAt2, updatedAt); - assertEq(answeredInRound2, answeredInRound); - } - - /// @notice it should revert from #getRoundData when round does not yet exist (future roundId) - function test_RevertGetRoundDataWhenRoundDoesNotExistYet() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); - - // Gets data from a round that has not happened yet - vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); - s_scrollSequencerUptimeFeed.getRoundData(2); - } - - /// @notice it should revert from #getAnswer when round does not yet exist (future roundId) - function test_RevertGetAnswerWhenRoundDoesNotExistYet() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); - - // Gets data from a round that has not happened yet - vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); - s_scrollSequencerUptimeFeed.getAnswer(2); - } - - /// @notice it should revert from #getTimestamp when round does not yet exist (future roundId) - function test_RevertGetTimestampWhenRoundDoesNotExistYet() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); - - // Gets data from a round that has not happened yet - vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); - s_scrollSequencerUptimeFeed.getTimestamp(2); } } -contract ScrollSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions is ScrollSequencerUptimeFeedTest { - /// @notice it should disallow reads on AggregatorV2V3Interface functions when consuming contract is not whitelisted - function test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() public { - // Deploys a FeedConsumer contract - FeedConsumer feedConsumer = new FeedConsumer(address(s_scrollSequencerUptimeFeed)); - - // Sanity - consumer is not whitelisted - assertEq(s_scrollSequencerUptimeFeed.checkEnabled(), true); - assertEq(s_scrollSequencerUptimeFeed.hasAccess(address(feedConsumer), abi.encode("")), false); +contract ScrollSequencerUptimeFeed_ValidateSender is ScrollSequencerUptimeFeed_Setup { + /// @notice Reverts when sender is not L2 Cross Domain Messenger address + function test_ValidateSender_RevertWhen_SenderIsNotL2CrossDomainMessengerAddr() public { + vm.startPrank(s_strangerAddr); - // Asserts reads are not possible from consuming contract - vm.expectRevert("No access"); - feedConsumer.latestAnswer(); - vm.expectRevert("No access"); - feedConsumer.latestRoundData(); + vm.expectRevert(BaseSequencerUptimeFeed.InvalidSender.selector); + s_scrollSequencerUptimeFeed.validateSenderTestWrapper(s_l1OwnerAddr); } - /// @notice it should allow reads on AggregatorV2V3Interface functions when consuming contract is whitelisted - function test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() public { - // Deploys a FeedConsumer contract - FeedConsumer feedConsumer = new FeedConsumer(address(s_scrollSequencerUptimeFeed)); + /// @notice Reverts when L1 Cross Domain Messenger address is not L1 sender address + function test_ValidateSender_RevertWhen_L1CrossDomainMessengerAddrIsNotL1SenderAddr() public { + address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); + vm.startPrank(l2MessengerAddr); - // Whitelist consumer - s_scrollSequencerUptimeFeed.addAccess(address(feedConsumer)); + vm.expectRevert(BaseSequencerUptimeFeed.InvalidSender.selector); + s_scrollSequencerUptimeFeed.validateSenderTestWrapper(s_strangerAddr); + } - // Sanity - consumer is whitelisted - assertEq(s_scrollSequencerUptimeFeed.checkEnabled(), true); - assertEq(s_scrollSequencerUptimeFeed.hasAccess(address(feedConsumer), abi.encode("")), true); + /// @notice Updates status when status changes and incoming timestamp is the same as latest + function test_ValidateSender_UpdateStatusWhen_StatusChangeAndNoTimeChange() public { + address l2MessengerAddr = address(s_mockScrollL2CrossDomainMessenger); + vm.startPrank(l2MessengerAddr); - // Asserts reads are possible from consuming contract - (uint80 roundId, int256 answer, , , ) = feedConsumer.latestRoundData(); - assertEq(feedConsumer.latestAnswer(), 0); - assertEq(roundId, 1); - assertEq(answer, 0); + s_scrollSequencerUptimeFeed.validateSenderTestWrapper(s_l1OwnerAddr); } } 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 1a0bcc856f2..b7708889100 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 @@ -10,9 +10,9 @@ import {ScrollSequencerUptimeFeed} from "../../../scroll/ScrollSequencerUptimeFe import {ScrollValidator} from "../../../scroll/ScrollValidator.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -contract ScrollValidatorTest is L2EPTest { +contract ScrollValidator_Setup is L2EPTest { /// Helper constants - address internal constant L2_SEQ_STATUS_RECORDER_ADDRESS = 0x491B1dDA0A8fa069bbC1125133A975BF4e85a91b; + address internal immutable L2_SEQ_STATUS_RECORDER_ADDRESS = makeAddr("L2_SEQ_STATUS_RECORDER_ADDRESS"); uint32 internal constant INIT_GAS_LIMIT = 1900000; /// L2EP contracts @@ -53,26 +53,31 @@ contract ScrollValidatorTest is L2EPTest { } } -contract ScrollValidator_SetGasLimit is ScrollValidatorTest { - /// @notice it correctly updates the gas limit - function test_CorrectlyUpdatesTheGasLimit() public { - uint32 newGasLimit = 2000000; - assertEq(s_scrollValidator.getGasLimit(), INIT_GAS_LIMIT); - s_scrollValidator.setGasLimit(newGasLimit); - assertEq(s_scrollValidator.getGasLimit(), newGasLimit); +contract ScrollValidator_Constructor is ScrollValidator_Setup { + /// @notice Reverts when L1 message queue address is invalid + function test_Constructor_RevertWhen_InvalidL1MessageQueueAddress() public { + vm.startPrank(s_l1OwnerAddr); + + vm.expectRevert("Invalid L1 message queue address"); + new ScrollValidator( + address(s_mockScrollL1CrossDomainMessenger), + address(s_scrollSequencerUptimeFeed), + address(0), + INIT_GAS_LIMIT + ); } } -contract ScrollValidator_Validate is ScrollValidatorTest { - /// @notice it reverts if called by account with no access - function test_RevertsIfCalledByAnAccountWithNoAccess() public { +contract ScrollValidator_Validate is ScrollValidator_Setup { + /// @notice Reverts if called by an account with no access + function test_Validate_RevertWhen_CalledByAccountWithNoAccess() public { vm.startPrank(s_strangerAddr); vm.expectRevert("No access"); s_scrollValidator.validate(0, 0, 1, 1); } - /// @notice it posts sequencer status when there is not status change - function test_PostSequencerStatusWhenThereIsNotStatusChange() public { + /// @notice Posts sequencer status when there is no status change + function test_Validate_PostSequencerStatus_NoStatusChange() public { // Gives access to the s_eoaValidator s_scrollValidator.addAccess(s_eoaValidator); @@ -96,8 +101,8 @@ contract ScrollValidator_Validate is ScrollValidatorTest { s_scrollValidator.validate(0, 0, 0, 0); } - /// @notice it post sequencer offline - function test_PostSequencerOffline() public { + /// @notice Posts sequencer offline status + function test_Validate_PostSequencerOffline() public { // Gives access to the s_eoaValidator s_scrollValidator.addAccess(s_eoaValidator); diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/shared/BaseSequencerUptimeFeed.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/shared/BaseSequencerUptimeFeed.t.sol new file mode 100644 index 00000000000..20553e33bab --- /dev/null +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/shared/BaseSequencerUptimeFeed.t.sol @@ -0,0 +1,377 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {Vm} from "forge-std/Test.sol"; +import {AddressAliasHelper} from "../../../../vendor/arb-bridge-eth/v0.8.0-custom/contracts/libraries/AddressAliasHelper.sol"; +import {BaseSequencerUptimeFeed} from "../../../base/BaseSequencerUptimeFeed.sol"; +import {MockBaseSequencerUptimeFeed} from "../../../test/mocks/MockBaseSequencerUptimeFeed.sol"; +import {FeedConsumer} from "../../../../tests/FeedConsumer.sol"; +import {L2EPTest} from "../L2EPTest.t.sol"; + +contract BaseSequencerUptimeFeed_Setup is L2EPTest { + /// Helper Variables + address internal s_aliasedL1OwnerAddress = AddressAliasHelper.applyL1ToL2Alias(s_l1OwnerAddr); + + /// L2EP contracts + BaseSequencerUptimeFeed internal s_sequencerUptimeFeed; + + /// Events + event UpdateIgnored(bool latestStatus, uint64 latestTimestamp, bool incomingStatus, uint64 incomingTimestamp); + event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt); + event RoundUpdated(int256 status, uint64 updatedAt); + event L1SenderTransferred(address indexed from, address indexed to); + + /// Setup + function setUp() public { + // Deploys contracts + s_sequencerUptimeFeed = new MockBaseSequencerUptimeFeed(s_l1OwnerAddr, false, true); + } +} + +contract BaseSequencerUptimeFeed_Constructor is BaseSequencerUptimeFeed_Setup { + /// @notice Tests initial state of the contract + function test_Constructor_InitialState() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + + // Checks L1 sender + address actualL1Addr = s_sequencerUptimeFeed.l1Sender(); + assertEq(actualL1Addr, s_l1OwnerAddr); + + // Checks latest round data + (uint80 roundId, int256 answer, , , ) = s_sequencerUptimeFeed.latestRoundData(); + assertEq(roundId, 1); + assertEq(answer, 0); + } +} + +contract BaseSequencerUptimeFeed_transferL1Sender is BaseSequencerUptimeFeed_Setup { + /// @notice Tests transferring L1 sender + function test_transferL1Sender_CorrectlyTransfersL1Sender() public { + address initialSender = address(0); + address newSender = makeAddr("newSender"); + + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + + MockBaseSequencerUptimeFeed sequencerUptimeFeed = new MockBaseSequencerUptimeFeed(initialSender, false, true); + + assertEq(sequencerUptimeFeed.l1Sender(), initialSender); + + // Transfers the L1 sender + vm.expectEmit(); + emit L1SenderTransferred(initialSender, newSender); + sequencerUptimeFeed.transferL1Sender(newSender); + assertEq(sequencerUptimeFeed.l1Sender(), newSender); + + vm.recordLogs(); + // Transfers to the same L1 sender should not emit an event + sequencerUptimeFeed.transferL1Sender(newSender); + assertEq(vm.getRecordedLogs().length, 0); + } + + /// @notice Reverts if called by an unauthorized account + function test_transferL1Sender_RevertWhen_CalledByUnauthorizedAccount() public { + address newSender = makeAddr("newSender"); + + // Sets msg.sender and tx.origin to an unauthorized address + vm.startPrank(s_strangerAddr, s_strangerAddr); + + vm.expectRevert("Only callable by owner"); + s_sequencerUptimeFeed.transferL1Sender(newSender); + } +} + +contract BaseSequencerUptimeFeed_UpdateStatus is BaseSequencerUptimeFeed_Setup { + /// @notice Reverts if called by an unauthorized account + function test_updateStatus_RevertWhen_NotL2CrossDomainMessengerAddr() public { + // Sets msg.sender and tx.origin to an unauthorized address + vm.startPrank(s_strangerAddr, s_strangerAddr); + + BaseSequencerUptimeFeed s_sequencerUptimeFeedFailSenderCheck = new MockBaseSequencerUptimeFeed( + s_l1OwnerAddr, + false, + false + ); + + // Tries to update the status from an unauthorized account + vm.expectRevert(BaseSequencerUptimeFeed.InvalidSender.selector); + s_sequencerUptimeFeedFailSenderCheck.updateStatus(true, uint64(1)); + } + + /// @notice Updates status when status has not changed and incoming timestamp is the same as latest + function test_updateStatus_UpdateWhen_NoStatusChangeSameTimestamp() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); + + // Fetches the latest timestamp + uint256 timestamp = s_sequencerUptimeFeed.latestTimestamp(); + + // Submits a status update + vm.expectEmit(); + emit AnswerUpdated(1, 2, timestamp); + s_sequencerUptimeFeed.updateStatus(true, uint64(timestamp)); + assertEq(s_sequencerUptimeFeed.latestAnswer(), 1); + assertEq(s_sequencerUptimeFeed.latestRound(), 2); + assertEq(s_sequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); + + // Stores the current round data before updating it + ( + uint80 roundIdBeforeUpdate, + int256 answerBeforeUpdate, + uint256 startedAtBeforeUpdate, + , + uint80 answeredInRoundBeforeUpdate + ) = s_sequencerUptimeFeed.latestRoundData(); + + // Submit another status update with the same status + vm.expectEmit(); + emit RoundUpdated(1, uint64(block.timestamp)); + s_sequencerUptimeFeed.updateStatus(true, uint64(timestamp + 200)); + assertEq(s_sequencerUptimeFeed.latestAnswer(), 1); + assertEq(s_sequencerUptimeFeed.latestRound(), 2); + assertEq(s_sequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); + + // Stores the current round data after updating it + ( + uint80 roundIdAfterUpdate, + int256 answerAfterUpdate, + uint256 startedAtAfterUpdate, + uint256 updatedAtAfterUpdate, + uint80 answeredInRoundAfterUpdate + ) = s_sequencerUptimeFeed.latestRoundData(); + + // Verifies the latest round data has been properly updated + assertEq(roundIdAfterUpdate, roundIdBeforeUpdate); + assertEq(answerAfterUpdate, answerBeforeUpdate); + assertEq(startedAtAfterUpdate, startedAtBeforeUpdate); + assertEq(answeredInRoundAfterUpdate, answeredInRoundBeforeUpdate); + assertEq(updatedAtAfterUpdate, block.timestamp); + } + + /// @notice Updates status when status has changed and incoming timestamp is newer than the latest + function test_updateStatus_UpdateWhen_StatusChangeAndTimeChange() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); + + // Submits a status update + uint256 timestamp = s_sequencerUptimeFeed.latestTimestamp(); + vm.expectEmit(); + emit AnswerUpdated(1, 2, timestamp); + s_sequencerUptimeFeed.updateStatus(true, uint64(timestamp)); + assertEq(s_sequencerUptimeFeed.latestAnswer(), 1); + assertEq(s_sequencerUptimeFeed.latestRound(), 2); + assertEq(s_sequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); + + // Submit another status update, different status, newer timestamp should update + timestamp = timestamp + 200; + vm.expectEmit(); + emit AnswerUpdated(0, 3, timestamp); + s_sequencerUptimeFeed.updateStatus(false, uint64(timestamp)); + assertEq(s_sequencerUptimeFeed.latestAnswer(), 0); + assertEq(s_sequencerUptimeFeed.latestRound(), 3); + assertEq(s_sequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); + } + + /// @notice Updates status when status has changed and incoming timestamp is the same as latest + function test_updateStatus_UpdateWhen_StatusChangeAndNoTimeChange() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); + + // Fetches the latest timestamp + uint256 timestamp = s_sequencerUptimeFeed.latestTimestamp(); + + // Submits a status update + vm.expectEmit(); + emit AnswerUpdated(1, 2, timestamp); + s_sequencerUptimeFeed.updateStatus(true, uint64(timestamp)); + assertEq(s_sequencerUptimeFeed.latestAnswer(), 1); + assertEq(s_sequencerUptimeFeed.latestRound(), 2); + assertEq(s_sequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); + + // Submit another status update, different status, same timestamp should update + vm.expectEmit(); + emit AnswerUpdated(0, 3, timestamp); + s_sequencerUptimeFeed.updateStatus(false, uint64(timestamp)); + assertEq(s_sequencerUptimeFeed.latestAnswer(), 0); + assertEq(s_sequencerUptimeFeed.latestRound(), 3); + assertEq(s_sequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); + } + + /// @notice Ignores out-of-order updates + function test_updateStatus_IgnoreOutOfOrderUpdates() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); + + // Submits a status update + uint256 timestamp = s_sequencerUptimeFeed.latestTimestamp() + 10000; + vm.expectEmit(); + emit AnswerUpdated(1, 2, timestamp); + s_sequencerUptimeFeed.updateStatus(true, uint64(timestamp)); + assertEq(s_sequencerUptimeFeed.latestAnswer(), 1); + assertEq(s_sequencerUptimeFeed.latestRound(), 2); + assertEq(s_sequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); + + // Update with different status, but stale timestamp, should be ignored + timestamp = timestamp - 1000; + vm.expectEmit(false, false, false, false); + emit UpdateIgnored(true, 0, true, 0); // arguments are dummy values + + vm.recordLogs(); + + // Tries to update with stale timestamp + s_sequencerUptimeFeed.updateStatus(false, uint64(timestamp)); + + Vm.Log[] memory entries = vm.getRecordedLogs(); + + assertEq(entries.length, 1); + assertEq(entries[0].topics[0], keccak256("UpdateIgnored(bool,uint64,bool,uint64)")); + } +} + +contract BaseSequencerUptimeFeed_AggregatorV3Interface is BaseSequencerUptimeFeed_Setup { + /// @notice Returns valid answer from getRoundData and latestRoundData + function test_AggregatorV3Interface_ReturnsValidData() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); + + // Defines helper variables + uint80 roundId; + int256 answer; + uint256 startedAt; + uint256 updatedAt; + uint80 answeredInRound; + + // Checks initial state + (roundId, answer, startedAt, updatedAt, answeredInRound) = s_sequencerUptimeFeed.latestRoundData(); + assertEq(roundId, 1); + assertEq(answer, 0); + assertEq(answeredInRound, roundId); + assertEq(startedAt, updatedAt); + + // Submits status update with different status and newer timestamp, should update + uint256 timestamp = startedAt + 1000; + s_sequencerUptimeFeed.updateStatus(true, uint64(timestamp)); + (roundId, answer, startedAt, updatedAt, answeredInRound) = s_sequencerUptimeFeed.getRoundData(2); + assertEq(roundId, 2); + assertEq(answer, 1); + assertEq(answeredInRound, roundId); + assertEq(startedAt, timestamp); + assertLe(updatedAt, startedAt); + + // Saves round 2 data + uint80 roundId2 = roundId; + int256 answer2 = answer; + uint256 startedAt2 = startedAt; + uint256 updatedAt2 = updatedAt; + uint80 answeredInRound2 = answeredInRound; + + // Checks that last round is still returning the correct data + (roundId, answer, startedAt, updatedAt, answeredInRound) = s_sequencerUptimeFeed.getRoundData(1); + assertEq(roundId, 1); + assertEq(answer, 0); + assertEq(answeredInRound, roundId); + assertEq(startedAt, updatedAt); + + // Assert latestRoundData corresponds to latest round id + (roundId, answer, startedAt, updatedAt, answeredInRound) = s_sequencerUptimeFeed.latestRoundData(); + assertEq(roundId2, roundId); + assertEq(answer2, answer); + assertEq(startedAt2, startedAt); + assertEq(updatedAt2, updatedAt); + assertEq(answeredInRound2, answeredInRound); + } + + /// @notice Reverts when getRoundData is called for a round that does not exist yet + function test_getRoundData_RevertWhen_RoundDoesNotExist() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + + // Gets data from a round that has not happened yet + vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); + s_sequencerUptimeFeed.getRoundData(2); + } + + /// @notice Returns the getAnswer for the latest round + function test_getAnswer_ReturnsValidAnswer() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); + + uint256 startedAt; + (, , startedAt, , ) = s_sequencerUptimeFeed.latestRoundData(); + + s_sequencerUptimeFeed.updateStatus(true, uint64(startedAt + 1000)); + + assertEq(0, s_sequencerUptimeFeed.getAnswer(1)); + } + + /// @notice Reverts when getAnswer is called for a round that does not exist yet + function test_getAnswer_RevertWhen_RoundDoesNotExist() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + + // Gets data from a round that has not happened yet + vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); + s_sequencerUptimeFeed.getAnswer(2); + } + + /// @notice Returns the getTimestamp for the latest round + function test_getTimestamp_ReturnsValidTimestamp() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); + + uint256 startedAt; + (, , startedAt, , ) = s_sequencerUptimeFeed.latestRoundData(); + + s_sequencerUptimeFeed.updateStatus(true, uint64(startedAt + 1000)); + + assertEq(startedAt, s_sequencerUptimeFeed.getTimestamp(1)); + } + + /// @notice Reverts when getTimestamp is called for a round that does not exist yet + function test_getTimestamp_RevertWhen_RoundDoesNotExist() public { + // Sets msg.sender and tx.origin to a valid address + vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); + + // Gets data from a round that has not happened yet + vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); + s_sequencerUptimeFeed.getTimestamp(2); + } +} + +contract BaseSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions is BaseSequencerUptimeFeed_Setup { + /// @notice Disallows reads on AggregatorV2V3Interface functions when consuming contract is not whitelisted + function test_ProtectReads_DisallowWhen_NotWhitelisted() public { + // Deploys a FeedConsumer contract + FeedConsumer feedConsumer = new FeedConsumer(address(s_sequencerUptimeFeed)); + + // Sanity - consumer is not whitelisted + assertEq(s_sequencerUptimeFeed.checkEnabled(), true); + assertEq(s_sequencerUptimeFeed.hasAccess(address(feedConsumer), abi.encode("")), false); + + // Asserts reads are not possible from consuming contract + vm.expectRevert("No access"); + feedConsumer.latestAnswer(); + vm.expectRevert("No access"); + feedConsumer.latestRoundData(); + } + + /// @notice Allows reads on AggregatorV2V3Interface functions when consuming contract is whitelisted + function test_ProtectReads_AllowWhen_Whitelisted() public { + // Deploys a FeedConsumer contract + FeedConsumer feedConsumer = new FeedConsumer(address(s_sequencerUptimeFeed)); + + // Whitelist consumer + s_sequencerUptimeFeed.addAccess(address(feedConsumer)); + + // Sanity - consumer is whitelisted + assertEq(s_sequencerUptimeFeed.checkEnabled(), true); + assertEq(s_sequencerUptimeFeed.hasAccess(address(feedConsumer), abi.encode("")), true); + + // Asserts reads are possible from consuming contract + (uint80 roundId, int256 answer, , , ) = feedConsumer.latestRoundData(); + assertEq(feedConsumer.latestAnswer(), 0); + assertEq(roundId, 1); + assertEq(answer, 0); + } +} diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/shared/BaseValidator.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/shared/BaseValidator.t.sol new file mode 100644 index 00000000000..4b0868c71b3 --- /dev/null +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/shared/BaseValidator.t.sol @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {BaseValidator} from "../../../base/BaseValidator.sol"; +import {MockBaseValidator} from "../../mocks/MockBaseValidator.sol"; +import {L2EPTest} from "../L2EPTest.t.sol"; + +contract BaseValidator_Setup is L2EPTest { + address internal immutable L2_SEQ_STATUS_RECORDER_ADDRESS = makeAddr("L2_SEQ_STATUS_RECORDER_ADDRESS"); + address internal immutable DUMMY_L1_XDOMAIN_MSNGR_ADDR = makeAddr("DUMMY_L1_XDOMAIN_MSNGR_ADDR"); + address internal immutable DUMMY_L2_UPTIME_FEED_ADDR = makeAddr("DUMMY_L2_UPTIME_FEED_ADDR"); + uint32 internal constant INIT_GAS_LIMIT = 1900000; + + BaseValidator internal s_baseValidator; + + /// Fake event that will get emitted when `requestL2TransactionDirect` is called + /// Definition is taken from MockZKSyncL1Bridge + event SentMessage(address indexed sender, bytes message); + + /// Setup + function setUp() public { + s_baseValidator = new MockBaseValidator( + DUMMY_L1_XDOMAIN_MSNGR_ADDR, + L2_SEQ_STATUS_RECORDER_ADDRESS, + INIT_GAS_LIMIT + ); + } +} + +contract BaseValidator_Constructor is BaseValidator_Setup { + /// @notice Reverts when L1 bridge address is zero + function test_Constructor_RevertWhen_L1BridgeAddressIsZero() public { + vm.expectRevert(BaseValidator.L1CrossDomainMessengerAddressZero.selector); + new MockBaseValidator(address(0), DUMMY_L2_UPTIME_FEED_ADDR, INIT_GAS_LIMIT); + } + + /// @notice Reverts when L2 Uptime feed address is zero + function test_Constructor_RevertWhen_L2UptimeFeedAddressIsZero() public { + vm.expectRevert(BaseValidator.L2UptimeFeedAddrZero.selector); + new MockBaseValidator(DUMMY_L1_XDOMAIN_MSNGR_ADDR, address(0), INIT_GAS_LIMIT); + } +} + +contract BaseValidator_GetAndSetGasLimit is BaseValidator_Setup { + /// @notice Verifies the correct retrieval and update of the gas limit + function test_GetAndSetGasLimit_CorrectlyHandlesGasLimit() public { + assertEq(s_baseValidator.getGasLimit(), INIT_GAS_LIMIT); + + uint32 newGasLimit = INIT_GAS_LIMIT + 1; + + vm.expectEmit(); + emit BaseValidator.GasLimitUpdated(newGasLimit); + s_baseValidator.setGasLimit(newGasLimit); + + assertEq(s_baseValidator.getGasLimit(), newGasLimit); + } +} diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/zksync/ZKSyncSequencerUptimeFeed.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/zksync/ZKSyncSequencerUptimeFeed.t.sol index 5b319d32407..8e9c387c875 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/zksync/ZKSyncSequencerUptimeFeed.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/zksync/ZKSyncSequencerUptimeFeed.t.sol @@ -3,289 +3,50 @@ pragma solidity ^0.8.24; import {AddressAliasHelper} from "../../../../vendor/arb-bridge-eth/v0.8.0-custom/contracts/libraries/AddressAliasHelper.sol"; import {ZKSyncSequencerUptimeFeed} from "../../../zksync/ZKSyncSequencerUptimeFeed.sol"; -import {BaseSequencerUptimeFeed} from "../../../shared/BaseSequencerUptimeFeed.sol"; -import {FeedConsumer} from "../../../../tests/FeedConsumer.sol"; +import {BaseSequencerUptimeFeed} from "../../../base/BaseSequencerUptimeFeed.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -contract ZKSyncSequencerUptimeFeedTest is L2EPTest { +contract ZKSyncSequencerUptimeFeed_TestWrapper is ZKSyncSequencerUptimeFeed { + constructor(address l1SenderAddress, bool initialStatus) ZKSyncSequencerUptimeFeed(l1SenderAddress, initialStatus) {} + + /// @notice Exposes the internal _validateSender function for testing + function validateSenderTestWrapper(address l1Sender) external view { + super._validateSender(l1Sender); + } +} + +contract ZKSyncSequencerUptimeFeed_Setup is L2EPTest { /// Helper Variables - address internal s_aliasedL1OwnerAddress = AddressAliasHelper.applyL1ToL2Alias(s_l1OwnerAddr); + address internal l1SenderAddress = address(5); + address internal s_aliasedL1SenderAddress = AddressAliasHelper.applyL1ToL2Alias(l1SenderAddress); /// L2EP contracts - ZKSyncSequencerUptimeFeed internal s_zksyncSequencerUptimeFeed; - - /// Events - event UpdateIgnored(bool latestStatus, uint64 latestTimestamp, bool incomingStatus, uint64 incomingTimestamp); - event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt); - event RoundUpdated(int256 status, uint64 updatedAt); + ZKSyncSequencerUptimeFeed_TestWrapper internal s_zksyncSequencerUptimeFeed; /// Setup function setUp() public { // Deploys contracts - s_zksyncSequencerUptimeFeed = new ZKSyncSequencerUptimeFeed(s_l1OwnerAddr, false); - } -} - -contract ZKSyncSequencerUptimeFeed_Constructor is ZKSyncSequencerUptimeFeedTest { - /// @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 - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); - - // Checks L1 sender - address actualL1Addr = s_zksyncSequencerUptimeFeed.l1Sender(); - assertEq(actualL1Addr, s_l1OwnerAddr); - - // Checks latest round data - (uint80 roundId, int256 answer, , , ) = s_zksyncSequencerUptimeFeed.latestRoundData(); - assertEq(roundId, 1); - assertEq(answer, 0); + s_zksyncSequencerUptimeFeed = new ZKSyncSequencerUptimeFeed_TestWrapper(l1SenderAddress, false); } } -contract ZKSyncSequencerUptimeFeed_UpdateStatus is ZKSyncSequencerUptimeFeedTest { - /// @notice it should revert if called by an unauthorized account - function test_RevertIfNotL2CrossDomainMessengerAddr() public { - // Sets msg.sender and tx.origin to an unauthorized address - vm.startPrank(s_strangerAddr, s_strangerAddr); +contract ZKSyncSequencerUptimeFeed_ValidateSender is ZKSyncSequencerUptimeFeed_Setup { + /// @notice Reverts when pass is not valid + function test_ValidateSender_RevertWhen_PassIsNotValid() public { + // Sets msg.sender and tx.origin to an authorized address + vm.startPrank(s_aliasedL1SenderAddress, s_aliasedL1SenderAddress); // Tries to update the status from an unauthorized account vm.expectRevert(BaseSequencerUptimeFeed.InvalidSender.selector); - s_zksyncSequencerUptimeFeed.updateStatus(true, uint64(1)); - } - - /// @notice it should update status when status has not changed and incoming timestamp is the same as latest - function test_UpdateStatusWhenNoChange() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); - - // Fetches the latest timestamp - uint256 timestamp = s_zksyncSequencerUptimeFeed.latestTimestamp(); - - // Submits a status update - vm.expectEmit(); - emit AnswerUpdated(1, 2, timestamp); - s_zksyncSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - assertEq(s_zksyncSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_zksyncSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Stores the current round data before updating it - ( - uint80 roundIdBeforeUpdate, - int256 answerBeforeUpdate, - uint256 startedAtBeforeUpdate, - , - uint80 answeredInRoundBeforeUpdate - ) = s_zksyncSequencerUptimeFeed.latestRoundData(); - - // Submit another status update with the same status - vm.expectEmit(); - emit RoundUpdated(1, uint64(block.timestamp)); - s_zksyncSequencerUptimeFeed.updateStatus(true, uint64(timestamp + 200)); - assertEq(s_zksyncSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_zksyncSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Stores the current round data after updating it - ( - uint80 roundIdAfterUpdate, - int256 answerAfterUpdate, - uint256 startedAtAfterUpdate, - uint256 updatedAtAfterUpdate, - uint80 answeredInRoundAfterUpdate - ) = s_zksyncSequencerUptimeFeed.latestRoundData(); - - // Verifies the latest round data has been properly updated - assertEq(roundIdAfterUpdate, roundIdBeforeUpdate); - assertEq(answerAfterUpdate, answerBeforeUpdate); - assertEq(startedAtAfterUpdate, startedAtBeforeUpdate); - assertEq(answeredInRoundAfterUpdate, answeredInRoundBeforeUpdate); - assertEq(updatedAtAfterUpdate, block.timestamp); - } - - /// @notice it should update status when status has changed and incoming timestamp is newer than the latest - function test_UpdateStatusWhenStatusChangeAndTimeChange() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); - - // Submits a status update - uint256 timestamp = s_zksyncSequencerUptimeFeed.latestTimestamp(); - vm.expectEmit(); - emit AnswerUpdated(1, 2, timestamp); - s_zksyncSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - assertEq(s_zksyncSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_zksyncSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Submit another status update, different status, newer timestamp should update - timestamp = timestamp + 200; - vm.expectEmit(); - emit AnswerUpdated(0, 3, timestamp); - s_zksyncSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); - assertEq(s_zksyncSequencerUptimeFeed.latestAnswer(), 0); - assertEq(s_zksyncSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - } - - /// @notice it should update status when status has changed and incoming timestamp is the same as latest - function test_UpdateStatusWhenStatusChangeAndNoTimeChange() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); - - // Fetches the latest timestamp - uint256 timestamp = s_zksyncSequencerUptimeFeed.latestTimestamp(); - - // Submits a status update - vm.expectEmit(); - emit AnswerUpdated(1, 2, timestamp); - s_zksyncSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - assertEq(s_zksyncSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_zksyncSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Submit another status update, different status, same timestamp should update - vm.expectEmit(); - emit AnswerUpdated(0, 3, timestamp); - s_zksyncSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); - assertEq(s_zksyncSequencerUptimeFeed.latestAnswer(), 0); - assertEq(s_zksyncSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - } - - /// @notice it should ignore out-of-order updates - function test_IgnoreOutOfOrderUpdates() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); - - // Submits a status update - uint256 timestamp = s_zksyncSequencerUptimeFeed.latestTimestamp() + 10000; - vm.expectEmit(); - emit AnswerUpdated(1, 2, timestamp); - s_zksyncSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - assertEq(s_zksyncSequencerUptimeFeed.latestAnswer(), 1); - assertEq(s_zksyncSequencerUptimeFeed.latestTimestamp(), uint64(timestamp)); - - // Update with different status, but stale timestamp, should be ignored - timestamp = timestamp - 1000; - vm.expectEmit(false, false, false, false); - emit UpdateIgnored(true, 0, true, 0); // arguments are dummy values - // TODO: how can we check that an AnswerUpdated event was NOT emitted - s_zksyncSequencerUptimeFeed.updateStatus(false, uint64(timestamp)); - } -} - -contract ZKSyncSequencerUptimeFeed_AggregatorV3Interface is ZKSyncSequencerUptimeFeedTest { - /// @notice it should return valid answer from getRoundData and latestRoundData - function test_AggregatorV3Interface() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_aliasedL1OwnerAddress, s_aliasedL1OwnerAddress); - - // Defines helper variables - uint80 roundId; - int256 answer; - uint256 startedAt; - uint256 updatedAt; - uint80 answeredInRound; - - // Checks initial state - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_zksyncSequencerUptimeFeed.latestRoundData(); - assertEq(roundId, 1); - assertEq(answer, 0); - assertEq(answeredInRound, roundId); - assertEq(startedAt, updatedAt); - - // Submits status update with different status and newer timestamp, should update - uint256 timestamp = startedAt + 1000; - s_zksyncSequencerUptimeFeed.updateStatus(true, uint64(timestamp)); - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_zksyncSequencerUptimeFeed.getRoundData(2); - assertEq(roundId, 2); - assertEq(answer, 1); - assertEq(answeredInRound, roundId); - assertEq(startedAt, timestamp); - assertLe(updatedAt, startedAt); - - // Saves round 2 data - uint80 roundId2 = roundId; - int256 answer2 = answer; - uint256 startedAt2 = startedAt; - uint256 updatedAt2 = updatedAt; - uint80 answeredInRound2 = answeredInRound; - - // Checks that last round is still returning the correct data - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_zksyncSequencerUptimeFeed.getRoundData(1); - assertEq(roundId, 1); - assertEq(answer, 0); - assertEq(answeredInRound, roundId); - assertEq(startedAt, updatedAt); - - // Assert latestRoundData corresponds to latest round id - (roundId, answer, startedAt, updatedAt, answeredInRound) = s_zksyncSequencerUptimeFeed.latestRoundData(); - assertEq(roundId2, roundId); - assertEq(answer2, answer); - assertEq(startedAt2, startedAt); - assertEq(updatedAt2, updatedAt); - assertEq(answeredInRound2, answeredInRound); - } - - /// @notice it should revert from #getRoundData when round does not yet exist (future roundId) - function test_RevertGetRoundDataWhenRoundDoesNotExistYet() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); - - // Gets data from a round that has not happened yet - vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); - s_zksyncSequencerUptimeFeed.getRoundData(2); - } - - /// @notice it should revert from #getAnswer when round does not yet exist (future roundId) - function test_RevertGetAnswerWhenRoundDoesNotExistYet() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); - - // Gets data from a round that has not happened yet - vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); - s_zksyncSequencerUptimeFeed.getAnswer(2); - } - - /// @notice it should revert from #getTimestamp when round does not yet exist (future roundId) - function test_RevertGetTimestampWhenRoundDoesNotExistYet() public { - // Sets msg.sender and tx.origin to a valid address - vm.startPrank(s_l1OwnerAddr, s_l1OwnerAddr); - - // Gets data from a round that has not happened yet - vm.expectRevert(BaseSequencerUptimeFeed.NoDataPresent.selector); - s_zksyncSequencerUptimeFeed.getTimestamp(2); + s_zksyncSequencerUptimeFeed.validateSenderTestWrapper(address(6)); } -} - -contract ZKSyncSequencerUptimeFeed_ProtectReadsOnAggregatorV2V3InterfaceFunctions is ZKSyncSequencerUptimeFeedTest { - /// @notice it should disallow reads on AggregatorV2V3Interface functions when consuming contract is not whitelisted - function test_AggregatorV2V3InterfaceDisallowReadsIfConsumingContractIsNotWhitelisted() public { - // Deploys a FeedConsumer contract - FeedConsumer feedConsumer = new FeedConsumer(address(s_zksyncSequencerUptimeFeed)); - - // Sanity - consumer is not whitelisted - assertEq(s_zksyncSequencerUptimeFeed.checkEnabled(), true); - assertEq(s_zksyncSequencerUptimeFeed.hasAccess(address(feedConsumer), abi.encode("")), false); - - // Asserts reads are not possible from consuming contract - vm.expectRevert("No access"); - feedConsumer.latestAnswer(); - vm.expectRevert("No access"); - feedConsumer.latestRoundData(); - } - - /// @notice it should allow reads on AggregatorV2V3Interface functions when consuming contract is whitelisted - function test_AggregatorV2V3InterfaceAllowReadsIfConsumingContractIsWhitelisted() public { - // Deploys a FeedConsumer contract - FeedConsumer feedConsumer = new FeedConsumer(address(s_zksyncSequencerUptimeFeed)); - - // Whitelist consumer - s_zksyncSequencerUptimeFeed.addAccess(address(feedConsumer)); - // Sanity - consumer is whitelisted - assertEq(s_zksyncSequencerUptimeFeed.checkEnabled(), true); - assertEq(s_zksyncSequencerUptimeFeed.hasAccess(address(feedConsumer), abi.encode("")), true); + /// @notice Passes when sender is valid + function test_ValidateSender_SuccessWhen_SenderIsValid() public { + // Sets msg.sender and tx.origin to an authorized address + vm.startPrank(s_aliasedL1SenderAddress, s_aliasedL1SenderAddress); - // Asserts reads are possible from consuming contract - (uint80 roundId, int256 answer, , , ) = feedConsumer.latestRoundData(); - assertEq(feedConsumer.latestAnswer(), 0); - assertEq(roundId, 1); - assertEq(answer, 0); + // Tries to update the status from an authorized account + s_zksyncSequencerUptimeFeed.validateSenderTestWrapper(l1SenderAddress); } } diff --git a/contracts/src/v0.8/l2ep/test/v1_0_0/zksync/ZKSyncValidator.t.sol b/contracts/src/v0.8/l2ep/test/v1_0_0/zksync/ZKSyncValidator.t.sol index 1a0f16d6ae0..e36a2732c27 100644 --- a/contracts/src/v0.8/l2ep/test/v1_0_0/zksync/ZKSyncValidator.t.sol +++ b/contracts/src/v0.8/l2ep/test/v1_0_0/zksync/ZKSyncValidator.t.sol @@ -4,13 +4,13 @@ pragma solidity ^0.8.24; import {MockBridgehub} from "../../mocks/zksync/MockZKSyncL1Bridge.sol"; import {ISequencerUptimeFeed} from "../../../interfaces/ISequencerUptimeFeed.sol"; import {ZKSyncValidator} from "../../../zksync/ZKSyncValidator.sol"; -import {BaseValidator} from "../../../shared/BaseValidator.sol"; +import {BaseValidator} from "../../../base/BaseValidator.sol"; import {L2EPTest} from "../L2EPTest.t.sol"; -contract ZKSyncValidatorTest is L2EPTest { - address internal constant L2_SEQ_STATUS_RECORDER_ADDRESS = address(0x491B1dDA0A8fa069bbC1125133A975BF4e85a91b); - address internal constant DUMMY_L1_XDOMAIN_MSNGR_ADDR = address(0xa04Fc18f012B1a5A8231c7Ee4b916Dd6dbd271b6); - address internal constant DUMMY_L2_UPTIME_FEED_ADDR = address(0xFe31891940A2e5f04B76eD8bD1038E44127d1512); +contract ZKSyncValidator_Setup is L2EPTest { + address internal immutable L2_SEQ_STATUS_RECORDER_ADDRESS = makeAddr("L2_SEQ_STATUS_RECORDER_ADDRESS"); + address internal immutable DUMMY_L1_XDOMAIN_MSNGR_ADDR = makeAddr("DUMMY_L1_XDOMAIN_MSNGR_ADDR"); + address internal immutable DUMMY_L2_UPTIME_FEED_ADDR = makeAddr("DUMMY_L2_UPTIME_FEED_ADDR"); uint32 internal constant INIT_GAS_PER_PUBDATA_BYTE_LIMIT = 800; uint32 internal constant INIT_GAS_LIMIT = 1900000; uint32 internal constant MAIN_NET_CHAIN_ID = 300; @@ -38,9 +38,9 @@ contract ZKSyncValidatorTest is L2EPTest { } } -contract ZKSyncValidator_Constructor is ZKSyncValidatorTest { - /// @notice it correctly validates that the chain id is valid - function test_ConstructingRevertedWithInvalidChainId() public { +contract ZKSyncValidator_Constructor is ZKSyncValidator_Setup { + /// @notice Reverts when chain ID is invalid + function test_Constructor_RevertWhen_ChainIdIsInvalid() public { vm.expectRevert(ZKSyncValidator.InvalidChainID.selector); new ZKSyncValidator( DUMMY_L1_XDOMAIN_MSNGR_ADDR, @@ -51,8 +51,8 @@ contract ZKSyncValidator_Constructor is ZKSyncValidatorTest { ); } - /// @notice it correctly validates that the L1 bridge address is not zero - function test_ConstructingRevertedWithZeroL1BridgeAddress() public { + /// @notice Reverts when L1 bridge address is zero + function test_Constructor_RevertWhen_L1BridgeAddressIsZero() public { vm.expectRevert(BaseValidator.L1CrossDomainMessengerAddressZero.selector); new ZKSyncValidator( address(0), @@ -63,8 +63,8 @@ contract ZKSyncValidator_Constructor is ZKSyncValidatorTest { ); } - /// @notice it correctly validates that the L2 Uptime feed address is not zero - function test_ConstructingRevertedWithZeroL2UpdateFeedAddress() public { + /// @notice Reverts when L2 update feed address is zero + function test_Constructor_RevertWhen_L2UpdateFeedAddressIsZero() public { vm.expectRevert(BaseValidator.L2UptimeFeedAddrZero.selector); new ZKSyncValidator( DUMMY_L1_XDOMAIN_MSNGR_ADDR, @@ -76,9 +76,9 @@ contract ZKSyncValidator_Constructor is ZKSyncValidatorTest { } } -contract ZKSyncValidator_GetSetL2GasPerPubdataByteLimit is ZKSyncValidatorTest { - /// @notice it correctly updates the gas limit per pubdata byte - function test_CorrectlyGetsAndUpdatesTheGasPerPubdataByteLimit() public { +contract ZKSyncValidator_GetSetL2GasPerPubdataByteLimit is ZKSyncValidator_Setup { + /// @notice Correctly gets and updates the gas per pubdata byte limit + function test_GetSetL2GasPerPubdataByteLimit_CorrectlyHandlesGasPerPubdataByteLimit() public { assertEq(s_zksyncValidator.getL2GasPerPubdataByteLimit(), INIT_GAS_PER_PUBDATA_BYTE_LIMIT); uint32 newGasPerPubDataByteLimit = 2000000; @@ -87,23 +87,23 @@ contract ZKSyncValidator_GetSetL2GasPerPubdataByteLimit is ZKSyncValidatorTest { } } -contract ZKSyncValidator_GetChainId is ZKSyncValidatorTest { - /// @notice it correctly gets the chain id - function test_CorrectlyGetsTheChainId() public { +contract ZKSyncValidator_GetChainId is ZKSyncValidator_Setup { + /// @notice Correctly gets the chain ID + function test_GetChainId_CorrectlyGetsTheChainId() public view { assertEq(s_zksyncValidator.getChainId(), MAIN_NET_CHAIN_ID); } } -contract ZKSyncValidator_Validate is ZKSyncValidatorTest { - /// @notice it reverts if called by account with no access - function test_RevertsIfCalledByAnAccountWithNoAccess() public { +contract ZKSyncValidator_Validate is ZKSyncValidator_Setup { + /// @notice Reverts if called by an account with no access + function test_Validate_RevertWhen_CalledByAccountWithNoAccess() public { vm.startPrank(s_strangerAddr); vm.expectRevert("No access"); s_zksyncValidator.validate(0, 0, 1, 1); } - /// @notice it posts sequencer status when there is not status change - function test_PostSequencerStatusWhenThereIsNotStatusChange() public { + /// @notice Posts sequencer status when there is no status change + function test_Validate_PostSequencerStatus_NoStatusChange() public { // Gives access to the s_eoaValidator s_zksyncValidator.addAccess(s_eoaValidator); @@ -126,8 +126,8 @@ contract ZKSyncValidator_Validate is ZKSyncValidatorTest { s_zksyncValidator.validate(0, 0, 0, 0); } - /// @notice it post sequencer offline - function test_PostSequencerOffline() public { + /// @notice Posts sequencer offline status + function test_Validate_PostSequencerOffline() public { // Gives access to the s_eoaValidator s_zksyncValidator.addAccess(s_eoaValidator); diff --git a/contracts/src/v0.8/l2ep/zksync/ZKSyncSequencerUptimeFeed.sol b/contracts/src/v0.8/l2ep/zksync/ZKSyncSequencerUptimeFeed.sol index cb520d2d0ac..e464cc7407d 100644 --- a/contracts/src/v0.8/l2ep/zksync/ZKSyncSequencerUptimeFeed.sol +++ b/contracts/src/v0.8/l2ep/zksync/ZKSyncSequencerUptimeFeed.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.19; -import {BaseSequencerUptimeFeed} from "../shared/BaseSequencerUptimeFeed.sol"; +import {BaseSequencerUptimeFeed} from "../base/BaseSequencerUptimeFeed.sol"; import {AddressAliasHelper} from "../../vendor/arb-bridge-eth/v0.8.0-custom/contracts/libraries/AddressAliasHelper.sol"; diff --git a/contracts/src/v0.8/l2ep/zksync/ZKSyncValidator.sol b/contracts/src/v0.8/l2ep/zksync/ZKSyncValidator.sol index 10f68ce286d..39ba0cd839a 100644 --- a/contracts/src/v0.8/l2ep/zksync/ZKSyncValidator.sol +++ b/contracts/src/v0.8/l2ep/zksync/ZKSyncValidator.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.19; import {ISequencerUptimeFeed} from "./../interfaces/ISequencerUptimeFeed.sol"; -import {BaseValidator} from "../shared/BaseValidator.sol"; +import {BaseValidator} from "../base/BaseValidator.sol"; import {IBridgehub, L2TransactionRequestDirect} from "@zksync/contracts/l1-contracts/contracts/bridgehub/IBridgehub.sol";