From 8fae755fab308e9f34eda45503ac2ff18cb12a03 Mon Sep 17 00:00:00 2001 From: soloseng <102702451+soloseng@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:38:17 -0500 Subject: [PATCH 1/4] Passing L1 test using TestWithUtils --- .../governance/network/GovernanceSlasher.t.sol | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol b/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol index 32cfa375cb8..ee7e9919038 100644 --- a/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol +++ b/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.5.13; -import "celo-foundry/Test.sol"; -import { TestConstants } from "@test-sol/constants.sol"; +import { TestWithUtils } from "@test-sol/TestWithUtils.sol"; +import "@test-sol/utils/WhenL2.sol"; import "@celo-contracts/common/Accounts.sol"; import "@celo-contracts/common/FixidityLib.sol"; -import "@celo-contracts/common/interfaces/IRegistry.sol"; + import "@celo-contracts/governance/Proposals.sol"; import "@celo-contracts/governance/test/MockLockedGold.sol"; import "@celo-contracts/governance/test/MockValidators.sol"; @@ -14,14 +14,13 @@ import { L2MakerAbstract } from "@test-sol/utils/L2MakerAbstract.sol"; import "@celo-contracts/governance/GovernanceSlasher.sol"; -contract GovernanceSlasherTest is Test, TestConstants { +contract GovernanceSlasherTest is TestWithUtils { event SlashingApproved(address indexed account, uint256 amount); event GovernanceSlashPerformed(address indexed account, uint256 amount); event GovernanceSlashL2Performed(address indexed account, address indexed group, uint256 amount); event HavelSlashingMultiplierHalved(address validator); event ValidatorDeaffiliatedCalled(address validator); - IRegistry registry; Accounts accounts; MockLockedGold mockLockedGold; @@ -37,6 +36,7 @@ contract GovernanceSlasherTest is Test, TestConstants { address internal slasherExecuter; function setUp() public { + super.setUp(); owner = address(this); nonOwner = actor("nonOwner"); validator = actor("validator"); @@ -47,8 +47,6 @@ contract GovernanceSlasherTest is Test, TestConstants { mockLockedGold = new MockLockedGold(); governanceSlasher = new GovernanceSlasher(true); - deployCodeTo("Registry.sol", abi.encode(false), REGISTRY_ADDRESS); - registry = IRegistry(REGISTRY_ADDRESS); registry.setAddressFor("Accounts", address(accounts)); registry.setAddressFor("LockedGold", address(mockLockedGold)); @@ -57,6 +55,8 @@ contract GovernanceSlasherTest is Test, TestConstants { } } +contract GovernanceSlasherTest_L2 is GovernanceSlasherTest, WhenL2 {} + contract GovernanceSlasherTest_initialize is GovernanceSlasherTest { function test_shouldHaveSetOwner() public { assertEq(governanceSlasher.owner(), owner); @@ -68,7 +68,7 @@ contract GovernanceSlasherTest_initialize is GovernanceSlasherTest { } } -contract GovernanceSlasherTest_approveSlashingTest is GovernanceSlasherTest { +contract GovernanceSlasherTest_approveSlashing is GovernanceSlasherTest { function test_ShouldSetSlashableAmount() public { governanceSlasher.approveSlashing(slashedAddress, 1000); assertEq(governanceSlasher.getApprovedSlashing(slashedAddress), 1000); From 605c39620a30ba31edd6606a53fed2f4c7851ae9 Mon Sep 17 00:00:00 2001 From: soloseng <102702451+soloseng@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:31:42 -0500 Subject: [PATCH 2/4] passing L2 tests --- .../network/GovernanceSlasher.t.sol | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol b/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol index ee7e9919038..f75b2dca3b6 100644 --- a/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol +++ b/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol @@ -10,8 +10,6 @@ import "@celo-contracts/common/FixidityLib.sol"; import "@celo-contracts/governance/Proposals.sol"; import "@celo-contracts/governance/test/MockLockedGold.sol"; import "@celo-contracts/governance/test/MockValidators.sol"; -import { L2MakerAbstract } from "@test-sol/utils/L2MakerAbstract.sol"; - import "@celo-contracts/governance/GovernanceSlasher.sol"; contract GovernanceSlasherTest is TestWithUtils { @@ -99,7 +97,14 @@ contract GovernanceSlasherTest_approveSlashing is GovernanceSlasherTest { } } -contract GovernanceSlasherTest_slash is GovernanceSlasherTest, L2MakerAbstract { +contract GovernanceSlasherTest_approveSlashing_L2 is + GovernanceSlasherTest_L2, + GovernanceSlasherTest_approveSlashing +{} + +// contract GovernanceSlasherTest_slash_setup is GovernanceSlasherTest {} + +contract GovernanceSlasherTest_slash is GovernanceSlasherTest { function test_ShouldFailIfThereIsNothingToSlash() public { vm.expectRevert("No penalty given by governance"); governanceSlasher.slash(validator, lessers, greaters, indices); @@ -123,9 +128,10 @@ contract GovernanceSlasherTest_slash is GovernanceSlasherTest, L2MakerAbstract { emit GovernanceSlashPerformed(validator, 1000); governanceSlasher.slash(validator, lessers, greaters, indices); } +} +contract GovernanceSlasherTest_slash_L2 is GovernanceSlasherTest_L2 { function test_Reverts_WhenL2() public { - _whenL2(); governanceSlasher.approveSlashing(validator, 1000); vm.expectRevert("This method is no longer supported in L2."); governanceSlasher.slash(validator, lessers, greaters, indices); @@ -147,17 +153,9 @@ contract GovernanceSlasherTest_slashL2_WhenL1 is GovernanceSlasherTest { } // should work just like the deprecated version -contract GovernanceSlasherTest_slashL2_WhenL2_WhenNotGroup is - GovernanceSlasherTest, - L2MakerAbstract -{ +contract GovernanceSlasherTest_slashL2_WhenNotGroup_L2 is GovernanceSlasherTest_L2 { address group = address(0); - function setUp() public { - super.setUp(); - _whenL2(); - } - // only onwer or multisig can call function test_ShouldDecrementCelo() public { @@ -181,13 +179,12 @@ contract GovernanceSlasherTest_slashL2_WhenL2_WhenNotGroup is } // should work just like the deprecated version -contract GovernanceSlasherTest_slashL2_WhenL2_WhenGroup is GovernanceSlasherTest, L2MakerAbstract { +contract GovernanceSlasherTest_slashL2_WhenGroup_L2 is GovernanceSlasherTest_L2 { address group; MockValidators validators; function setUp() public { super.setUp(); - _whenL2(); validators = new MockValidators(); registry.setAddressFor("Validators", address(validators)); @@ -249,7 +246,7 @@ contract GovernanceSlasherTest_slashL2_WhenL2_WhenGroup is GovernanceSlasherTest } } -contract SlasherExecuterTest_setSlasherExecuter is GovernanceSlasherTest { +contract GovernanceSlasherTest_setSlasherExecuter is GovernanceSlasherTest { function test_onlyOwnwerCanSetSlasherExecuter() public { vm.prank(nonOwner); vm.expectRevert("Ownable: caller is not the owner"); @@ -261,3 +258,8 @@ contract SlasherExecuterTest_setSlasherExecuter is GovernanceSlasherTest { assertEq(governanceSlasher.getSlasherExecuter(), nonOwner, "Score Manager not set"); } } + +contract GovernanceSlasherTest_setSlasherExecuter_L2 is + GovernanceSlasherTest_L2, + GovernanceSlasherTest_setSlasherExecuter +{} From c395c3827fb16ecd636a48ac87e965b92a4d6d83 Mon Sep 17 00:00:00 2001 From: soloseng <102702451+soloseng@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:33:28 -0500 Subject: [PATCH 3/4] -- unused contract --- .../unit/governance/network/GovernanceSlasher.t.sol | 1 - packages/protocol/test-sol/utils/L2MakerAbstract.sol | 11 ----------- 2 files changed, 12 deletions(-) delete mode 100644 packages/protocol/test-sol/utils/L2MakerAbstract.sol diff --git a/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol b/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol index f75b2dca3b6..0ff30db3fae 100644 --- a/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol +++ b/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol @@ -6,7 +6,6 @@ import "@test-sol/utils/WhenL2.sol"; import "@celo-contracts/common/Accounts.sol"; import "@celo-contracts/common/FixidityLib.sol"; - import "@celo-contracts/governance/Proposals.sol"; import "@celo-contracts/governance/test/MockLockedGold.sol"; import "@celo-contracts/governance/test/MockValidators.sol"; diff --git a/packages/protocol/test-sol/utils/L2MakerAbstract.sol b/packages/protocol/test-sol/utils/L2MakerAbstract.sol deleted file mode 100644 index 8553ef254e6..00000000000 --- a/packages/protocol/test-sol/utils/L2MakerAbstract.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.5.13; - -import "celo-foundry/Test.sol"; -import { TestConstants } from "@test-sol/constants.sol"; - -contract L2MakerAbstract is Test, TestConstants { - function _whenL2() public { - deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS); - } -} From 5d26d1d348fd0faad48277bc1fa59463eea802bd Mon Sep 17 00:00:00 2001 From: soloseng <102702451+soloseng@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:11:20 -0500 Subject: [PATCH 4/4] -- commented line --- .../test-sol/unit/governance/network/GovernanceSlasher.t.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol b/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol index 0ff30db3fae..eb8e8599c95 100644 --- a/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol +++ b/packages/protocol/test-sol/unit/governance/network/GovernanceSlasher.t.sol @@ -101,8 +101,6 @@ contract GovernanceSlasherTest_approveSlashing_L2 is GovernanceSlasherTest_approveSlashing {} -// contract GovernanceSlasherTest_slash_setup is GovernanceSlasherTest {} - contract GovernanceSlasherTest_slash is GovernanceSlasherTest { function test_ShouldFailIfThereIsNothingToSlash() public { vm.expectRevert("No penalty given by governance");