Skip to content

Commit

Permalink
feat: can only have one manager badge
Browse files Browse the repository at this point in the history
  • Loading branch information
0xneves committed Jul 15, 2024
1 parent 9f8b4a8 commit b08128c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/resolver/Resolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ contract Resolver is IResolver, AccessControl {
// Maps addresses to booleans to check if a Villager has checked out
mapping(address => bool) private _checkedOutVillagers;

// Maps addresses to booleans to check if a Manager has been revoked
mapping(address => bool) private _receivedManagerBadge;

// Maps allowed attestations (Hashed titles that can be attested)
mapping(bytes32 => bool) private _allowedAttestationTitles;

Expand Down Expand Up @@ -148,12 +151,15 @@ contract Resolver is IResolver, AccessControl {
/// @dev Assign new managers to the contract.
function assignManager(Attestation calldata attestation) internal returns (bool) {
if (hasRole(ROOT_ROLE, attestation.attester) || hasRole(MANAGER_ROLE, attestation.attester)) {
if (hasRole(MANAGER_ROLE, attestation.recipient)) revert InvalidRole();
if (
hasRole(MANAGER_ROLE, attestation.recipient) || _receivedManagerBadge[attestation.recipient]
) revert InvalidRole();
if (!attestation.revocable) revert InvalidRevocability();

string memory role = abi.decode(attestation.data, (string));
if (keccak256(abi.encode(role)) != keccak256(abi.encode("Manager"))) revert InvalidRole();

_receivedManagerBadge[attestation.recipient] = true;
_grantRole(MANAGER_ROLE, attestation.recipient);
return true;
}
Expand Down
21 changes: 21 additions & 0 deletions test/EAS.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ contract ResolverTest is Test {
vm.startPrank(deployer);
attest_manager_revoke(uids[0], assignedManagerUID);
assert(!IAccessControl(address(resolver)).hasRole(MANAGER_ROLE, manager));

// Fail to Revoke Manager a second time
assert(!try_attest_manager_revoke(uids[0], assignedManagerUID));
}

function register_allowed_schemas() public returns (bytes32[] memory) {
Expand Down Expand Up @@ -336,4 +339,22 @@ contract ResolverTest is Test {
})
);
}

function try_attest_manager_revoke(
bytes32 schemaUID,
bytes32 attestationUID
) public returns (bool) {
try
eas.revoke(
RevocationRequest({
schema: schemaUID,
data: RevocationRequestData({ uid: attestationUID, value: 0 })
})
)
{
return true;
} catch {
return false;
}
}
}

0 comments on commit b08128c

Please sign in to comment.