Skip to content

Commit 6747d38

Browse files
[REVIEW NOT REQUIRED] Update Develop with current Head (#26)
* update .gitignore for repomix * connect stakeManager and JobsManager to use proxy addresses * Update deployment script * differentiate roles from single admin role * nit: spacing * Add github actions config for the repo * Update .gitignore * add prettier config; package contract in yarn * run CI on PR * rename the repo secret * Update Constants.sol * fix testcases for jobs and stake manager * keep version to prevent warning and build error * Update solidity version * add slither report to .gitignore * run forge build before running slither checks * Add deployment to the pipeline * add remappings for correctly using imports * Update imports to not use relative path * Update imports to not use relative path * Update gitmodules and method for dependency installation * remove default module * fix testcases that were broken * Add gas snapshot; update config * don't exit procses on snapshot * remove codecov app * remove --use solc; update .gitignore * fix indent * remove debug flag * nit: stlye * remove codecov app * Add remappings.txt * Update upgradable contracts version * remove remappings forge * reinitialize mappings * remove uploading sarif file * remove lib from git repo * add lib to repo * reset readme * remove initial files * remove initial files * Add unit tests for ACL.sol * Increase stateManager coverage to 100% * Increase jobsManager UT coverage * fix failing testcase for stateManager * Increase stakeManager UT coverage * restrict initializer's visibility to view * skip deployment script in UT coverage * revert overwritten changes
1 parent dbdfca2 commit 6747d38

File tree

5 files changed

+544
-152
lines changed

5 files changed

+544
-152
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ jobs:
6262
--report debug
6363
--optimize
6464
--optimizer-runs 200
65-
--no-auto-detect
65+
--no-auto-detect
66+
--skip script/DeployUpgradableLuminoProtocol.s.sol
6667
id: coverage
6768

6869
# - name: Upload coverage to Codecov

test/ACL.t.sol

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import "forge-std/Test.sol";
5+
import "../src/Core/ACL.sol";
6+
7+
contract ACLTest is Test {
8+
ACL public acl;
9+
address public admin;
10+
address public user1;
11+
address public user2;
12+
13+
// Example role for testing
14+
bytes32 public constant TEST_ROLE = keccak256("TEST_ROLE");
15+
16+
function setUp() public {
17+
admin = address(this);
18+
user1 = address(0x1);
19+
user2 = address(0x2);
20+
21+
acl = new ACL();
22+
}
23+
24+
function testInitialize() public {
25+
acl.initialize(admin);
26+
27+
// Verify admin has DEFAULT_ADMIN_ROLE
28+
assertTrue(acl.hasRole(acl.DEFAULT_ADMIN_ROLE(), admin));
29+
30+
// Verify initialization can't be called twice
31+
bytes memory expectedRevertMessage = abi.encodeWithSignature(
32+
"InvalidInitialization()"
33+
);
34+
vm.expectRevert(expectedRevertMessage);
35+
acl.initialize(user1);
36+
}
37+
38+
function testRoleManagement() public {
39+
acl.initialize(admin);
40+
41+
// Grant role
42+
acl.grantRole(TEST_ROLE, user1);
43+
assertTrue(acl.hasRole(TEST_ROLE, user1));
44+
45+
// Revoke role
46+
acl.revokeRole(TEST_ROLE, user1);
47+
assertFalse(acl.hasRole(TEST_ROLE, user1));
48+
49+
// Test role admin
50+
assertTrue(acl.getRoleAdmin(TEST_ROLE) == acl.DEFAULT_ADMIN_ROLE());
51+
}
52+
53+
function testUnauthorizedAccess() public {
54+
acl.initialize(admin);
55+
56+
// Try to grant role from non-admin account
57+
vm.startPrank(user1);
58+
59+
bytes memory expectedRevertMessage = abi.encodeWithSignature(
60+
"AccessControlUnauthorizedAccount(address,bytes32)",
61+
user1,
62+
acl.DEFAULT_ADMIN_ROLE()
63+
);
64+
vm.expectRevert(expectedRevertMessage);
65+
acl.grantRole(TEST_ROLE, user2);
66+
67+
// Try to revoke role from non-admin account
68+
vm.expectRevert(expectedRevertMessage);
69+
acl.revokeRole(TEST_ROLE, user2);
70+
71+
vm.stopPrank();
72+
}
73+
74+
function testRenounceRole() public {
75+
acl.initialize(admin);
76+
77+
// Grant role to user1
78+
acl.grantRole(TEST_ROLE, user1);
79+
assertTrue(acl.hasRole(TEST_ROLE, user1));
80+
81+
// User1 renounces their role
82+
vm.prank(user1);
83+
acl.renounceRole(TEST_ROLE, user1);
84+
assertFalse(acl.hasRole(TEST_ROLE, user1));
85+
86+
// Try to renounce role for another account (should fail)
87+
vm.prank(user1);
88+
bytes memory expectedRevertMessage = abi.encodeWithSignature(
89+
"AccessControlBadConfirmation()"
90+
);
91+
vm.expectRevert(expectedRevertMessage);
92+
acl.renounceRole(TEST_ROLE, user2);
93+
}
94+
}

0 commit comments

Comments
 (0)