Skip to content

Commit

Permalink
ADD: update comments of helpers function and unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredolopez80 committed May 15, 2024
1 parent 250c642 commit d1a0f8f
Show file tree
Hide file tree
Showing 18 changed files with 418 additions and 213 deletions.
269 changes: 134 additions & 135 deletions .gas-snapshot

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion script/DeployKeyperEnv.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ contract DeployKeyperEnv is Script {
// The address https://sepolia.etherscan.io/address/0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1#code, is the address of the CREATE3Factory in Sepolia
CREATE3Factory factory =
CREATE3Factory(0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1);
// Salt is a random number that is used to predict the deployment address
bytes32 salt = keccak256(abi.encode(0xddff)); // need to be unique to avoid collision
address keyperModulePredicted = factory.getDeployed(msg.sender, salt);

// Deploy Safe contracts in goerli
// Deploy Safe contracts in any network
Solenv.config();
address masterCopy = vm.envAddress("MASTER_COPY_ADDRESS");
address proxyFactory = vm.envAddress("PROXY_FACTORY_ADDRESS");
Expand Down
14 changes: 7 additions & 7 deletions script/SkipExecutionOnBehalf.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract SkipSeveralScenarios is Script, SkipSetupEnv {
function setUp() public {
// Set up env
run();
testRevertInvalidGnosisSafeExecTransactionOnBehalf();
testRevertInvalidSignatureExecOnBehalf();
// These are different chain test scenarios, specifically for the execTransactionOnBehalf function in Polygon and Sepolia.
// We test each scenario independently manually and get the results on the Live Mainnet on Polygon and Sepolia.
// testCannot_ExecTransactionOnBehalf_Wrapper_ExecTransactionOnBehalf_ChildSquad_over_RootSafe_With_SAFE(); // ✅
Expand Down Expand Up @@ -424,7 +424,7 @@ contract SkipSeveralScenarios is Script, SkipSetupEnv {

// // ! ********************** REVERT ********************

// Revert: "GS026" execTransactionOnBehalf when is Any EOA, passing the wrong signature of the Root/Super Safe of Target Safe
// Revert: "GS020" execTransactionOnBehalf when is Any EOA, passing the wrong signature of the Root/Super Safe of Target Safe
// Caller: callerEOA
// Caller Type: EOA
// Caller Role: nothing
Expand Down Expand Up @@ -467,7 +467,7 @@ contract SkipSeveralScenarios is Script, SkipSetupEnv {
Enum.Operation(0)
);

// vm.expectRevert("GS020"); // GS020: Invalid signatures provided
// vm.expectRevert("GS020"); // GS020: Signatures data too short
keyperModule.execTransactionOnBehalf(
orgHash,
rootAddr,
Expand All @@ -481,7 +481,7 @@ contract SkipSeveralScenarios is Script, SkipSetupEnv {
vm.stopBroadcast();
}

// Revert: "GS013" execTransactionOnBehalf when is Any EOA, (invalid signatures provided)
// Revert: "GS026" execTransactionOnBehalf when is Any EOA, (invalid signatures provided)
// Caller: callerEOA
// Caller Type: EOA
// Caller Role: nothing
Expand Down Expand Up @@ -523,7 +523,7 @@ contract SkipSeveralScenarios is Script, SkipSetupEnv {
Enum.Operation(0)
);

// vm.expectRevert("GS026"); // GS026: Invalid signatures provided
// vm.expectRevert("GS026"); // GS026: Invalid owner provided
keyperModule.execTransactionOnBehalf(
orgHash,
rootAddr,
Expand Down Expand Up @@ -596,7 +596,7 @@ contract SkipSeveralScenarios is Script, SkipSetupEnv {
vm.stopBroadcast();
}

// Revert "GS013" execTransactionOnBehalf (invalid signatures provided)
// Revert "GS026" execTransactionOnBehalf (invalid signatures provided)
// Caller: rootAddr
// Caller Type: rootSafe
// Caller Role: ROOT_SAFE
Expand Down Expand Up @@ -625,7 +625,7 @@ contract SkipSeveralScenarios is Script, SkipSetupEnv {
Enum.Operation(0)
);

// vm.expectRevert("GS013"); // GS013: Invalid signatures provided
// vm.expectRevert("GS013"); // GS026/GS013: Invalid owner provided
execTransactionOnBehalfTx(
orgHash,
rootAddr,
Expand Down
4 changes: 4 additions & 0 deletions src/KeyperRoles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ contract KeyperRoles is RolesAuthority, ValidAddress {
USER ROLE (OVERRIDE) ASSIGNMENT LOGIC
//////////////////////////////////////////////////////////////*/

/// function to assign a role to a user
/// @param user address of the user
/// @param role uint8 role to assign
/// @param enabled bool enable or disable the role
function setUserRole(address user, uint8 role, bool enabled)
public
virtual
Expand Down
1 change: 1 addition & 0 deletions test/DeploySafe.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract TestDeploySafe is Test, SigningUtils, SignDigestHelper {
gnosisSafeAddr = gnosisHelper.setupSafeEnv();
}

/// @notice Test to transfer funds to safe
function testTransferFundsSafe() public {
bytes memory emptyData;

Expand Down
3 changes: 3 additions & 0 deletions test/EnableGuard.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ contract TestEnableGuard is Test {
GnosisSafeHelper gnosisHelper;
address gnosisSafeAddr;

/// @notice Set up the environment for testing
function setUp() public {
// Init new safe
gnosisHelper = new GnosisSafeHelper();
Expand All @@ -32,6 +33,7 @@ contract TestEnableGuard is Test {
gnosisHelper.setKeyperGuard(address(keyperGuard));
}

/// @notice Test enabling the KeyperModule
function testEnableKeyperModule() public {
bool result = gnosisHelper.enableModuleTx(gnosisSafeAddr);
assertEq(result, true);
Expand All @@ -41,6 +43,7 @@ contract TestEnableGuard is Test {
assertEq(isKeyperModuleEnabled, true);
}

/// @notice Test enabling the KeyperGuard
function testEnableKeyperGuard() public {
bool result = gnosisHelper.enableGuardTx(gnosisSafeAddr);
assertEq(result, true);
Expand Down
3 changes: 3 additions & 0 deletions test/EnableModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract TestEnableModule is Test {
GnosisSafeHelper gnosisHelper;
address gnosisSafeAddr;

/// @notice Set up the environment
function setUp() public {
// Init new safe
gnosisHelper = new GnosisSafeHelper();
Expand All @@ -27,6 +28,7 @@ contract TestEnableModule is Test {
gnosisHelper.setKeyperModule(address(keyperModule));
}

/// @notice Test enable Keyper Module
function testEnableKeyperModule() public {
bool result = gnosisHelper.enableModuleTx(gnosisSafeAddr);
assertEq(result, true);
Expand All @@ -36,6 +38,7 @@ contract TestEnableModule is Test {
assertEq(isKeyperModuleEnabled, true);
}

/// @notice Test disable Keyper Module
function testNewSafeWithKeyperModule() public {
// Create new safe with setup called while creating contract
gnosisHelper.newKeyperSafe(4, 2);
Expand Down
12 changes: 12 additions & 0 deletions test/EventsChecker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ contract EventsChekers is DeployHelper {
owners[4] = address(0xEEE);
}

/// @notice Test Events when Register Root Organization
function testEventWhenRegisterRootOrg() public {
// Register Org through safe tx
address rootAddr = gnosisHelper.newKeyperSafe(4, 2);
Expand All @@ -122,6 +123,7 @@ contract EventsChekers is DeployHelper {
vm.stopPrank();
}

/// @notice Test Events when Add Squad
function testEventWhenAddSquad() public {
// Register Org through safe tx
address rootAddr = gnosisHelper.newKeyperSafe(4, 2);
Expand Down Expand Up @@ -149,6 +151,7 @@ contract EventsChekers is DeployHelper {
keyperModule.addSquad(rootId, squadA1Name);
}

/// @notice Test Events when Remove Squad
function testEventWhenRemoveSquad() public {
// Register Org through safe tx
address rootAddr = gnosisHelper.newKeyperSafe(4, 2);
Expand Down Expand Up @@ -190,6 +193,7 @@ contract EventsChekers is DeployHelper {
keyperModule.removeSquad(squadId);
}

/// @notice Test Events when Register Root Safe
function testEventWhenRegisterRootSafe() public {
// Register Org through safe tx
address rootAddr = gnosisHelper.newKeyperSafe(4, 2);
Expand All @@ -216,6 +220,7 @@ contract EventsChekers is DeployHelper {
keyperModule.createRootSafeSquad(rootSafeAddr, org2Name);
}

/// @notice Test Events when Update Super Safe
function testEventWhenUpdateSuper() public {
// Register Org through safe tx
address rootAddr = gnosisHelper.newKeyperSafe(4, 2);
Expand Down Expand Up @@ -273,6 +278,7 @@ contract EventsChekers is DeployHelper {
keyperModule.updateSuper(squadId, rootsafeId);
}

/// @notice Test Events when Promote Squad to Root Safe
function testEventWhenPromoteRootSafe() public {
// Register Org through safe tx
address rootAddr = gnosisHelper.newKeyperSafe(4, 2);
Expand Down Expand Up @@ -329,6 +335,7 @@ contract EventsChekers is DeployHelper {
keyperModule.promoteRoot(squadId);
}

/// @notice Test Events when Disconnect Safe
function testEventWhenDisconnectSafe() public {
// Register Org through safe tx
address rootAddr = gnosisHelper.newKeyperSafe(4, 2);
Expand Down Expand Up @@ -377,6 +384,7 @@ contract EventsChekers is DeployHelper {
keyperModule.disconnectSafe(squadId);
}

/// @notice Test Events when Call Execution on Behalf
function testEventWhenExecutionOnBehalf() public {
(uint256 rootId, uint256 safeSquadA1) =
keyperSafeBuilder.setupRootOrgAndOneSquad(orgName, squadA1Name);
Expand Down Expand Up @@ -419,6 +427,7 @@ contract EventsChekers is DeployHelper {
vm.stopPrank();
}

/// @notice Test Events when Remove Whole Tree
function testEventWhenRemoveWholeTree() public {
(
uint256 rootId,
Expand All @@ -438,6 +447,7 @@ contract EventsChekers is DeployHelper {
keyperModule.removeWholeTree();
}

/// @notice Test Events when Update New Limit
function testEventWhenUpdateNewLimit() public {
// Register Org through safe tx
address rootAddr = gnosisHelper.newKeyperSafe(4, 2);
Expand Down Expand Up @@ -474,6 +484,7 @@ contract EventsChekers is DeployHelper {
keyperModule.updateDepthTreeLimit(49);
}

/// @notice Test Events when Add Address to Enable/Denied Allow List
function testEventWhenAddToList() public {
address rootAddr = gnosisHelper.newKeyperSafe(4, 2);
vm.startPrank(rootAddr);
Expand All @@ -484,6 +495,7 @@ contract EventsChekers is DeployHelper {
keyperModule.addToList(owners);
}

/// @notice Test Events when Drop Address to Enable/Denied Allow List
function testEventWhenDropFromList() public {
address rootAddr = gnosisHelper.newKeyperSafe(4, 2);
vm.startPrank(rootAddr);
Expand Down
Loading

0 comments on commit d1a0f8f

Please sign in to comment.