mirror of
https://github.com/lens-protocol/core.git
synced 2026-04-22 03:02:03 -04:00
test: ModuleGlobals (T-1395)
This commit is contained in:
20
TestsList.md
20
TestsList.md
@@ -454,17 +454,17 @@ Collect Module Misc
|
||||
[ ] Should fail to call processCollect directly on a collect module inheriting from the FollowValidationModuleBase contract
|
||||
Module Globals
|
||||
Negatives
|
||||
[ ] User should fail to set the governance address on the module globals
|
||||
[ ] User should fail to set the treasury on the module globals
|
||||
[ ] User should fail to set the treasury fee on the module globals
|
||||
[X] User should fail to set the governance address on the module globals
|
||||
[X] User should fail to set the treasury on the module globals
|
||||
[X] User should fail to set the treasury fee on the module globals
|
||||
Scenarios
|
||||
[ ] Governance should set the governance address on the module globals
|
||||
[ ] Governance should set the treasury on the module globals
|
||||
[ ] Governance should set the treasury fee on the module globals
|
||||
[ ] Governance should fail to whitelist the zero address as a currency
|
||||
[ ] Governance getter should return expected address
|
||||
[ ] Treasury getter should return expected address
|
||||
[ ] Treasury fee getter should return the expected fee
|
||||
[X] Governance should set the governance address on the module globals
|
||||
[X] Governance should set the treasury on the module globals
|
||||
[X] Governance should set the treasury fee on the module globals
|
||||
[X] Governance should fail to whitelist the zero address as a currency
|
||||
[X] Governance getter should return expected address
|
||||
[X] Treasury getter should return expected address
|
||||
[X] Treasury fee getter should return the expected fee
|
||||
UI Data Provider
|
||||
[ ] UI Data Provider should return expected values
|
||||
LensPeriphery
|
||||
|
||||
136
test/foundry/ModuleGlobals.t.sol
Normal file
136
test/foundry/ModuleGlobals.t.sol
Normal file
@@ -0,0 +1,136 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
import './base/BaseTest.t.sol';
|
||||
|
||||
contract ModuleGlobalsTest is BaseTest {
|
||||
function setUp() public override {
|
||||
super.setUp();
|
||||
assertFalse(me == hub.getGovernance(), 'address(this) should not be governance');
|
||||
}
|
||||
|
||||
// Negatives - non Gov caller
|
||||
function testCannotSetGovernanceAddress_ifNotGovernance() public {
|
||||
vm.expectRevert(Errors.NotGovernance.selector);
|
||||
moduleGlobals.setGovernance(address(42));
|
||||
}
|
||||
|
||||
function testCannotSetTreasuryAddress_ifNotGovernance() public {
|
||||
vm.expectRevert(Errors.NotGovernance.selector);
|
||||
moduleGlobals.setTreasury(address(42));
|
||||
}
|
||||
|
||||
function testCannotSetTreasuryFee_ifNotGovernance() public {
|
||||
vm.expectRevert(Errors.NotGovernance.selector);
|
||||
moduleGlobals.setTreasuryFee(0);
|
||||
}
|
||||
|
||||
// Negatives - Gov caller
|
||||
function testCannotSetGovernanceToZeroAddress() public {
|
||||
vm.prank(governance);
|
||||
vm.expectRevert(Errors.InitParamsInvalid.selector);
|
||||
moduleGlobals.setGovernance(address(0));
|
||||
}
|
||||
|
||||
function testCannotSetTreasuryToZeroAddress() public {
|
||||
vm.prank(governance);
|
||||
vm.expectRevert(Errors.InitParamsInvalid.selector);
|
||||
moduleGlobals.setTreasury(address(0));
|
||||
}
|
||||
|
||||
function testCannotWhitelistZeroAddressAsCurrency() public {
|
||||
vm.prank(governance);
|
||||
vm.expectRevert(Errors.InitParamsInvalid.selector);
|
||||
moduleGlobals.whitelistCurrency(address(0), true);
|
||||
}
|
||||
|
||||
function testCannotSetTreasuryFee_largerOrEqualThanHalfOfBPS_MAX() public {
|
||||
vm.prank(governance);
|
||||
vm.expectRevert(Errors.InitParamsInvalid.selector);
|
||||
moduleGlobals.setTreasuryFee(TREASURY_FEE_MAX_BPS / 2);
|
||||
}
|
||||
|
||||
// Scenarios
|
||||
function testSetGovernanceAddress_ifGovernance() public {
|
||||
address governanceBefore = moduleGlobals.getGovernance();
|
||||
address newGovernance = address(uint160(governanceBefore) + 1);
|
||||
|
||||
assertEq(governanceBefore, governance, 'ModuleGlobals Governance is not Governance');
|
||||
|
||||
vm.prank(governance);
|
||||
moduleGlobals.setGovernance(newGovernance);
|
||||
|
||||
address governanceAfter = moduleGlobals.getGovernance();
|
||||
|
||||
assertEq(
|
||||
governanceAfter,
|
||||
newGovernance,
|
||||
"ModuleGlobals Governance didn't change to newGovernance"
|
||||
);
|
||||
assertFalse(governanceBefore == governanceAfter, "ModuleGlobals Governance didn't change");
|
||||
}
|
||||
|
||||
function testSetTreasuryAddress_ifGovernance() public {
|
||||
address treasuryBefore = moduleGlobals.getTreasury();
|
||||
address newTreasury = address(uint160(treasuryBefore) + 1);
|
||||
|
||||
vm.prank(governance);
|
||||
moduleGlobals.setTreasury(newTreasury);
|
||||
|
||||
address treasuryAfter = moduleGlobals.getTreasury();
|
||||
|
||||
assertEq(treasuryAfter, newTreasury, "ModuleGlobals Treasury didn't change to newTreasury");
|
||||
assertFalse(treasuryBefore == treasuryAfter, "ModuleGlobals Treasury didn't change");
|
||||
}
|
||||
|
||||
function testSetTreasuryFee_ifGovernance() public {
|
||||
uint16 treasuryFeeBefore = moduleGlobals.getTreasuryFee();
|
||||
uint16 newTreasuryFee = treasuryFeeBefore + 1;
|
||||
if (newTreasuryFee == TREASURY_FEE_MAX_BPS / 2) newTreasuryFee = 0;
|
||||
|
||||
vm.prank(governance);
|
||||
moduleGlobals.setTreasuryFee(newTreasuryFee);
|
||||
|
||||
uint16 treasuryFeeAfter = moduleGlobals.getTreasuryFee();
|
||||
|
||||
assertEq(
|
||||
treasuryFeeAfter,
|
||||
newTreasuryFee,
|
||||
"ModuleGlobals TreasuryFee didn't change to newTreasuryFee"
|
||||
);
|
||||
assertFalse(
|
||||
treasuryFeeBefore == treasuryFeeAfter,
|
||||
"ModuleGlobals TreasuryFee didn't change"
|
||||
);
|
||||
}
|
||||
|
||||
function testGetGovernance() public {
|
||||
vm.prank(governance);
|
||||
moduleGlobals.setGovernance(address(42));
|
||||
assertEq(
|
||||
moduleGlobals.getGovernance(),
|
||||
address(42),
|
||||
'ModuleGlobals Governance does not match set value'
|
||||
);
|
||||
}
|
||||
|
||||
function testGetTreasury() public {
|
||||
vm.prank(governance);
|
||||
moduleGlobals.setTreasury(address(42));
|
||||
assertEq(
|
||||
moduleGlobals.getTreasury(),
|
||||
address(42),
|
||||
'ModuleGlobals Treasury does not match set value'
|
||||
);
|
||||
}
|
||||
|
||||
function testGetTreasuryFee() public {
|
||||
vm.prank(governance);
|
||||
moduleGlobals.setTreasuryFee(42);
|
||||
assertEq(
|
||||
moduleGlobals.getTreasuryFee(),
|
||||
42,
|
||||
'ModuleGlobals TreasuryFee does not match set value'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -163,6 +163,7 @@ contract TestSetup is Test, ForkManagement {
|
||||
newProfileId = FIRST_PROFILE_ID;
|
||||
deployer = address(1);
|
||||
governance = address(2);
|
||||
treasury = address(3);
|
||||
|
||||
TREASURY_FEE_BPS = 50;
|
||||
|
||||
@@ -195,6 +196,8 @@ contract TestSetup is Test, ForkManagement {
|
||||
// Deploy the MockReferenceModule.
|
||||
mockReferenceModule = new MockReferenceModule();
|
||||
|
||||
moduleGlobals = new ModuleGlobals(governance, treasury, TREASURY_FEE_BPS);
|
||||
|
||||
vm.stopPrank();
|
||||
///////////////////////////////////////// End deployments.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user