Skip to content

Commit

Permalink
deem ineligible if in bad standing
Browse files Browse the repository at this point in the history
  • Loading branch information
spengrah committed Sep 10, 2024
1 parent 91d8ca5 commit af2113f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/HatControlledModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ contract HatControlledModule is HatsEligibilityModule, HatsToggleModule {
/// @inheritdoc HatsEligibilityModule
function getWearerStatus(address _wearer, uint256 _hatId) public view override returns (bool eligible, bool standing) {
IneligibilityData memory data = wearerIneligibility[_hatId][_wearer];
return (!data.ineligible, !data.badStanding);
// bad standing means not eligible, as well
if (data.badStanding) return (false, false);
// good standing but ineligible
if (data.ineligible) return (false, true);
// eligible and in good standing
return (true, true);
}

/*//////////////////////////////////////////////////////////////
Expand Down
23 changes: 11 additions & 12 deletions test/HatControlledModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ contract WithInstanceTest is HatControlledModuleTest {
);
}

function assertWearerStatus(address _wearer, uint256 _hatId, bool _eligible, bool _standing) public view {
(bool eligible, bool standing) = instance.getWearerStatus(_wearer, _hatId);
assertEq(standing, _standing);
if (_standing) assertEq(eligible, _eligible);
else assertFalse(eligible);
}

modifier caller_(address _caller) {
caller = _caller;
vm.prank(caller);
Expand Down Expand Up @@ -104,35 +111,27 @@ contract Eligibility is WithInstanceTest {
vm.prank(controller);
instance.setWearerStatus(_wearer, _hatId, _eligible, _standing);

(bool eligible, bool standing) = instance.getWearerStatus(_wearer, _hatId);
assertEq(eligible, _eligible);
assertEq(standing, _standing);
assertWearerStatus(_wearer, _hatId, _eligible, _standing);

// set the same wearer's status for a different hat
uint256 differentHat = uint256(keccak256(abi.encodePacked(_hatId)));

vm.prank(controller);
instance.setWearerStatus(_wearer, differentHat, _eligible, _standing);

(eligible, standing) = instance.getWearerStatus(_wearer, differentHat);
assertEq(eligible, _eligible);
assertEq(standing, _standing);
assertWearerStatus(_wearer, differentHat, _eligible, _standing);

// set a different wearer's status for the first hat
address otherWearer = address(bytes20(keccak256(abi.encodePacked(_wearer))));

vm.prank(controller);
instance.setWearerStatus(otherWearer, _hatId, _eligible, _standing);

(eligible, standing) = instance.getWearerStatus(otherWearer, _hatId);
assertEq(eligible, _eligible);
assertEq(standing, _standing);
assertWearerStatus(otherWearer, _hatId, _eligible, _standing);
}

function test_default() public view {
(bool eligible, bool standing) = instance.getWearerStatus(wearer, targetHat);
assertTrue(eligible);
assertTrue(standing);
assertWearerStatus(wearer, targetHat, true, true);
}

function test_revert_nonController_cannotSetWearerStatus() public {
Expand Down

0 comments on commit af2113f

Please sign in to comment.