Skip to content

Commit

Permalink
test(l1): Admin facet test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
benceharomi committed Jan 24, 2024
1 parent 6c95526 commit c25e7b4
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 158 deletions.
40 changes: 0 additions & 40 deletions l1-contracts/test/foundry/unit/concrete/Admin/AcceptAdmin.t.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.20;

import {AdminTest, ERROR_ONLY_GOVERNOR} from "./_Admin_Shared.t.sol";
import {AdminTest, ERROR_ONLY_STATE_TRANSITION_MANAGER} from "./_Admin_Shared.t.sol";

import {FeeParams, PubdataPricingMode} from "solpp/state-transition/chain-deps/ZkSyncStateTransitionStorage.sol";

Expand All @@ -24,8 +24,8 @@ contract ChangeFeeParamsTest is AdminTest {
);
}

function test_revertWhen_calledByNonGovernor() public {
address nonGovernor = makeAddr("nonGovernor");
function test_revertWhen_calledByNonStateTransitionManager() public {
address nonStateTransitionManager = makeAddr("nonStateTransitionManager");
FeeParams memory newFeeParams = FeeParams({
pubdataPricingMode: PubdataPricingMode.Rollup,
batchOverheadL1Gas: 1_000_000,
Expand All @@ -35,15 +35,14 @@ contract ChangeFeeParamsTest is AdminTest {
minimalL2GasPrice: 250_000_000
});

vm.startPrank(nonGovernor);
vm.expectRevert(ERROR_ONLY_GOVERNOR);
vm.startPrank(nonStateTransitionManager);
vm.expectRevert(ERROR_ONLY_STATE_TRANSITION_MANAGER);

adminFacet.changeFeeParams(newFeeParams);
}

function test_revertWhen_newMaxPubdataPerBatchIsLessThanMaxPubdataPerTransaction() public {
address governor = adminFacetWrapper.util_getGovernor();
// FeeParams memory oldFeeParams = adminFacetWrapper.util_getFeeParams();
address stateTransitionManager = adminFacetWrapper.util_getStateTransitionManager();
uint32 priorityTxMaxPubdata = 88_000;
uint32 maxPubdataPerBatch = priorityTxMaxPubdata - 1;
FeeParams memory newFeeParams = FeeParams({
Expand All @@ -57,12 +56,12 @@ contract ChangeFeeParamsTest is AdminTest {

vm.expectRevert(bytes.concat("n6"));

vm.startPrank(governor);
vm.startPrank(stateTransitionManager);
adminFacet.changeFeeParams(newFeeParams);
}

function test_successfulChange() public {
address governor = adminFacetWrapper.util_getGovernor();
address stateTransitionManager = adminFacetWrapper.util_getStateTransitionManager();
FeeParams memory oldFeeParams = adminFacetWrapper.util_getFeeParams();
FeeParams memory newFeeParams = FeeParams({
pubdataPricingMode: PubdataPricingMode.Rollup,
Expand All @@ -76,7 +75,7 @@ contract ChangeFeeParamsTest is AdminTest {
vm.expectEmit(true, true, true, true, address(adminFacet));
emit NewFeeParams(oldFeeParams, newFeeParams);

vm.startPrank(governor);
vm.startPrank(stateTransitionManager);
adminFacet.changeFeeParams(newFeeParams);

bytes32 newFeeParamsHash = keccak256(abi.encode(newFeeParams));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,42 @@

pragma solidity 0.8.20;

import {AdminTest, ERROR_ONLY_GOVERNOR} from "./_Admin_Shared.t.sol";
import {AdminTest, ERROR_ONLY_STATE_TRANSITION_MANAGER} from "./_Admin_Shared.t.sol";

import {MAX_GAS_PER_TRANSACTION} from "solpp/common/Config.sol";

contract SetPriorityTxMaxGasLimitTest is AdminTest {
event NewPriorityTxMaxGasLimit(uint256 oldPriorityTxMaxGasLimit, uint256 newPriorityTxMaxGasLimit);

function test_revertWhen_calledByNonGovernor() public {
address nonGovernor = makeAddr("nonGovernor");
function test_revertWhen_calledByNonStateTransitionManager() public {
address nonStateTransitionManager = makeAddr("nonStateTransitionManager");
uint256 newPriorityTxMaxGasLimit = 100;

vm.startPrank(nonGovernor);
vm.expectRevert(ERROR_ONLY_GOVERNOR);
vm.startPrank(nonStateTransitionManager);
vm.expectRevert(ERROR_ONLY_STATE_TRANSITION_MANAGER);

adminFacet.setPriorityTxMaxGasLimit(newPriorityTxMaxGasLimit);
}

function test_revertWhen_newPriorityTxMaxGasLimitIsGreaterThanMaxGasPerTransaction() public {
address governor = adminFacetWrapper.util_getGovernor();
address stateTransitionManager = adminFacetWrapper.util_getStateTransitionManager();
uint256 newPriorityTxMaxGasLimit = MAX_GAS_PER_TRANSACTION + 1;

vm.expectRevert(bytes.concat("n5"));

vm.startPrank(governor);
vm.startPrank(stateTransitionManager);
adminFacet.setPriorityTxMaxGasLimit(newPriorityTxMaxGasLimit);
}

function test_successfulSet() public {
address governor = adminFacetWrapper.util_getGovernor();
address stateTransitionManager = adminFacetWrapper.util_getStateTransitionManager();
uint256 oldPriorityTxMaxGasLimit = adminFacetWrapper.util_getPriorityTxMaxGasLimit();
uint256 newPriorityTxMaxGasLimit = 100;

vm.expectEmit(true, true, true, true, address(adminFacet));
emit NewPriorityTxMaxGasLimit(oldPriorityTxMaxGasLimit, newPriorityTxMaxGasLimit);

vm.startPrank(governor);
vm.startPrank(stateTransitionManager);
adminFacet.setPriorityTxMaxGasLimit(newPriorityTxMaxGasLimit);

assertEq(adminFacetWrapper.util_getPriorityTxMaxGasLimit(), newPriorityTxMaxGasLimit);
Expand Down
46 changes: 9 additions & 37 deletions l1-contracts/test/foundry/unit/concrete/Admin/SetValidator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,24 @@

pragma solidity 0.8.20;

import {AdminTest, ERROR_ONLY_ADMIN_OR_GOVERNOR} from "./_Admin_Shared.t.sol";
import {AdminTest, ERROR_ONLY_STATE_TRANSITION_MANAGER} from "./_Admin_Shared.t.sol";

contract SetValidatorTest is AdminTest {
event ValidatorStatusUpdate(address indexed validatorAddress, bool isActive);

function test_revertWhen_calledByNonAdminOrGovernor() public {
address nonAdminOrGovernor = makeAddr("nonAdminOrGovernor");
function test_revertWhen_calledByNonStateTransitionManager() public {
address nonStateTransitionManager = makeAddr("nonStateTransitionManager");
address validator = makeAddr("validator");
bool isActive = true;

vm.expectRevert(ERROR_ONLY_ADMIN_OR_GOVERNOR);
vm.expectRevert(ERROR_ONLY_STATE_TRANSITION_MANAGER);

vm.startPrank(nonAdminOrGovernor);
vm.startPrank(nonStateTransitionManager);
adminFacet.setValidator(validator, isActive);
}

function test_calledByGovernor() public {
address governor = adminFacetWrapper.util_getGovernor();
address validator = makeAddr("validator");
bool isActive = true;

vm.expectEmit(true, true, true, true, address(adminFacet));
emit ValidatorStatusUpdate(validator, isActive);

vm.startPrank(governor);
adminFacet.setValidator(validator, isActive);

assertEq(adminFacetWrapper.util_getValidator(validator), isActive);
}

function test_calledByAdmin() public {
address admin = adminFacetWrapper.util_getAdmin();
address validator = makeAddr("validator");
bool isActive = true;

vm.expectEmit(true, true, true, true, address(adminFacet));
emit ValidatorStatusUpdate(validator, isActive);

vm.startPrank(admin);
adminFacet.setValidator(validator, isActive);

assertEq(adminFacetWrapper.util_getValidator(validator), isActive);
}

function test_deactivateValidator() public {
address admin = adminFacetWrapper.util_getAdmin();
address stateTransitionManager = adminFacetWrapper.util_getStateTransitionManager();
address validator = makeAddr("validator");
bool isActive = false;

Expand All @@ -56,14 +28,14 @@ contract SetValidatorTest is AdminTest {
vm.expectEmit(true, true, true, true, address(adminFacet));
emit ValidatorStatusUpdate(validator, isActive);

vm.startPrank(admin);
vm.startPrank(stateTransitionManager);
adminFacet.setValidator(validator, isActive);

assertEq(adminFacetWrapper.util_getValidator(validator), isActive);
}

function test_reactivateValidator() public {
address admin = adminFacetWrapper.util_getAdmin();
address stateTransitionManager = adminFacetWrapper.util_getStateTransitionManager();
address validator = makeAddr("validator");
bool isActive = true;

Expand All @@ -72,7 +44,7 @@ contract SetValidatorTest is AdminTest {
vm.expectEmit(true, true, true, true, address(adminFacet));
emit ValidatorStatusUpdate(validator, isActive);

vm.startPrank(admin);
vm.startPrank(stateTransitionManager);
adminFacet.setValidator(validator, isActive);

assertEq(adminFacetWrapper.util_getValidator(validator), isActive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

pragma solidity 0.8.20;

import {AdminTest, ERROR_ONLY_ADMIN_OR_GOVERNOR} from "./_Admin_Shared.t.sol";
import {AdminTest, ERROR_ONLY_GOVERNOR_OR_STATE_TRANSITION_MANAGER} from "./_Admin_Shared.t.sol";

contract UnfreezeDiamondTest is AdminTest {
event Unfreeze();

function test_revertWhen_calledByNonGovernorOrAdmin() public {
address nonGovernorOrAdmin = makeAddr("nonGovernorOrAdmin");
function test_revertWhen_calledByNonGovernorOrStateTransitionManager() public {
address nonGovernorOrStateTransitionManager = makeAddr("nonGovernorOrStateTransitionManager");

vm.expectRevert(ERROR_ONLY_ADMIN_OR_GOVERNOR);
vm.expectRevert(ERROR_ONLY_GOVERNOR_OR_STATE_TRANSITION_MANAGER);

vm.startPrank(nonGovernorOrAdmin);
vm.startPrank(nonGovernorOrStateTransitionManager);
adminFacet.unfreezeDiamond();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ contract UpgradeChainFromVersionTest is AdminTest {

function test_revertWhen_calledByNonGovernorOrStateTransitionManager() public {
address nonGovernorOrStateTransitionManager = makeAddr("nonGovernorOrStateTransitionManager");
uint256 chainId = 1337;
uint256 oldProtocolVersion = 1;
Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({
facetCuts: new Diamond.FacetCut[](0),
Expand All @@ -23,14 +22,13 @@ contract UpgradeChainFromVersionTest is AdminTest {
vm.expectRevert(ERROR_ONLY_GOVERNOR_OR_STATE_TRANSITION_MANAGER);

vm.startPrank(nonGovernorOrStateTransitionManager);
adminFacet.upgradeChainFromVersion(chainId, oldProtocolVersion, diamondCutData);
adminFacet.upgradeChainFromVersion(oldProtocolVersion, diamondCutData);
}

function test_revertWhen_cutHashMismatch() public {
address governor = adminFacetWrapper.util_getGovernor();
address stateTransitionManager = makeAddr("stateTransitionManager");

uint256 chainId = 1337;
uint256 oldProtocolVersion = 1;
Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({
facetCuts: new Diamond.FacetCut[](0),
Expand All @@ -50,14 +48,13 @@ contract UpgradeChainFromVersionTest is AdminTest {
vm.expectRevert("StateTransition: cutHash mismatch");

vm.startPrank(governor);
adminFacet.upgradeChainFromVersion(chainId, oldProtocolVersion, diamondCutData);
adminFacet.upgradeChainFromVersion(oldProtocolVersion, diamondCutData);
}

function test_revertWhen_ProtocolVersionMismatchWhenUpgrading() public {
address governor = adminFacetWrapper.util_getGovernor();
address stateTransitionManager = makeAddr("stateTransitionManager");

uint256 chainId = 1337;
uint256 oldProtocolVersion = 1;
Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({
facetCuts: new Diamond.FacetCut[](0),
Expand All @@ -78,14 +75,13 @@ contract UpgradeChainFromVersionTest is AdminTest {
vm.expectRevert("StateTransition: protocolVersion mismatch in STC when upgrading");

vm.startPrank(governor);
adminFacet.upgradeChainFromVersion(chainId, oldProtocolVersion, diamondCutData);
adminFacet.upgradeChainFromVersion(oldProtocolVersion, diamondCutData);
}

function test_revertWhen_ProtocolVersionMismatchAfterUpgrading() public {
address governor = adminFacetWrapper.util_getGovernor();
address stateTransitionManager = makeAddr("stateTransitionManager");

uint256 chainId = 1337;
uint256 oldProtocolVersion = 1;
Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({
facetCuts: new Diamond.FacetCut[](0),
Expand All @@ -109,7 +105,7 @@ contract UpgradeChainFromVersionTest is AdminTest {
emit ExecuteUpgrade(diamondCutData);

vm.startPrank(governor);
adminFacet.upgradeChainFromVersion(chainId, oldProtocolVersion, diamondCutData);
adminFacet.upgradeChainFromVersion(oldProtocolVersion, diamondCutData);
}

// TODO
Expand Down
20 changes: 4 additions & 16 deletions l1-contracts/test/foundry/unit/concrete/Admin/_Admin_Shared.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ contract AdminWrapper is AdminFacet {
return s.governor;
}

function util_setPendingAdmin(address _pendingAdmin) external {
s.pendingAdmin = _pendingAdmin;
}

function util_getPendingAdmin() external view returns (address) {
return s.pendingAdmin;
}

function util_setAdmin(address _admin) external {
s.admin = _admin;
}

function util_getAdmin() external view returns (address) {
return s.admin;
}

function util_setValidator(address _validator, bool _active) external {
s.validators[_validator] = _active;
}
Expand Down Expand Up @@ -112,5 +96,9 @@ contract AdminTest is Test {
function setUp() public virtual {
adminFacetWrapper = new AdminWrapper();
adminFacet = IAdmin(adminFacetWrapper);

adminFacetWrapper.util_setGovernor(makeAddr("governor"));
adminFacetWrapper.util_setPendingGovernor(makeAddr("pendingGovernor"));
adminFacetWrapper.util_setStateTransitionManager(makeAddr("stateTransitionManager"));
}
}

0 comments on commit c25e7b4

Please sign in to comment.