From f8453a4d7d9bd116c45815e54c98a2726cc33a92 Mon Sep 17 00:00:00 2001 From: noel Date: Thu, 9 May 2024 18:03:21 +0900 Subject: [PATCH] test: admin functions --- contracts/test/MachServiceManager.t.sol | 73 +++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/contracts/test/MachServiceManager.t.sol b/contracts/test/MachServiceManager.t.sol index 70596bb..c7da43d 100644 --- a/contracts/test/MachServiceManager.t.sol +++ b/contracts/test/MachServiceManager.t.sol @@ -9,11 +9,47 @@ contract MachServiceManagerTest is AVSDeployer { event OperatorDisallowed(address operator); event AllowlistEnabled(); event AllowlistDisabled(); + event AlertConfirmerChanged(address previousAddress, address newAddress); + event WhitelisterChanged(address previousAddress, address newAddress); + event QuorumThresholdPercentageChanged(uint8 thresholdPercentages); + event RollupChainIdUpdated(uint256 previousRollupChainId, uint256 newRollupChainId); function setUp() public virtual { _deployMockEigenLayerAndAVS(); } + function test_SetConfirmer() public { + address newConfirmer = address(42); + vm.startPrank(proxyAdminOwner); + assertTrue(serviceManager.alertConfirmer() == proxyAdminOwner, "mismatch"); + vm.expectEmit(); + emit AlertConfirmerChanged(proxyAdminOwner, newConfirmer); + serviceManager.setConfirmer(newConfirmer); + assertTrue(serviceManager.alertConfirmer() == newConfirmer, "mismatch"); + vm.stopPrank(); + } + + function test_SetConfirmer_RevertIfNotOwner() public { + vm.expectRevert("Ownable: caller is not the owner"); + serviceManager.setConfirmer(address(42)); + } + + function test_SetWhitelister() public { + address newWhitelister = address(42); + vm.startPrank(proxyAdminOwner); + assertTrue(serviceManager.whitelister() == proxyAdminOwner, "mismatch"); + vm.expectEmit(); + emit WhitelisterChanged(proxyAdminOwner, newWhitelister); + serviceManager.setWhitelister(newWhitelister); + assertTrue(serviceManager.whitelister() == newWhitelister, "mismatch"); + vm.stopPrank(); + } + + function test_SetWhitelister_RevertIfNotOwner() public { + vm.expectRevert("Ownable: caller is not the owner"); + serviceManager.setWhitelister(address(42)); + } + function test_AddToAllowlist() public { vm.startPrank(proxyAdminOwner); assertFalse(serviceManager.allowlist(defaultOperator), "mismatch"); @@ -112,4 +148,41 @@ contract MachServiceManagerTest is AVSDeployer { serviceManager.enableAllowlist(); vm.stopPrank(); } + + function test_UpdateQuorumThresholdPercentage() public { + vm.startPrank(proxyAdminOwner); + assertTrue(serviceManager.quorumThresholdPercentage() == 66, "mismatch"); + vm.expectEmit(); + emit QuorumThresholdPercentageChanged(76); + serviceManager.updateQuorumThresholdPercentage(76); + assertTrue(serviceManager.quorumThresholdPercentage() == 76, "mismatch"); + vm.stopPrank(); + } + + function test_UpdateQuorumThresholdPercentage_RevertIfNotOwner() public { + vm.expectRevert("Ownable: caller is not the owner"); + serviceManager.updateQuorumThresholdPercentage(76); + } + + function test_UpdateQuorumThresholdPercentage_RevertIfInvalidQuorumThresholdPercentage() public { + vm.startPrank(proxyAdminOwner); + vm.expectRevert(InvalidQuorumThresholdPercentage.selector); + serviceManager.updateQuorumThresholdPercentage(101); + vm.stopPrank(); + } + + function test_UpdateRollupChainId() public { + vm.startPrank(proxyAdminOwner); + assertTrue(serviceManager.rollupChainId() == 1, "mismatch"); + vm.expectEmit(); + emit RollupChainIdUpdated(1, 42); + serviceManager.updateRollupChainId(42); + assertTrue(serviceManager.rollupChainId() == 42, "mismatch"); + vm.stopPrank(); + } + + function test_UpdateRollupChainId_RevertIfNotOwner() public { + vm.expectRevert("Ownable: caller is not the owner"); + serviceManager.updateRollupChainId(42); + } }