Skip to content

Commit

Permalink
whitelist/blacklist mutually exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
iethena committed Nov 16, 2024
1 parent 9fcc6da commit 25d7b6d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
5 changes: 2 additions & 3 deletions contracts/ustb/UStb.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ contract UStb is
*/
function addBlacklistAddress(address[] calldata users) external onlyRole(BLACKLIST_MANAGER_ROLE) {
for (uint8 i = 0; i < users.length; i++) {
if (hasRole(WHITELISTED_ROLE, users[i])) _revokeRole(WHITELISTED_ROLE, users[i]);
_grantRole(BLACKLISTED_ROLE, users[i]);
}
}
Expand All @@ -90,7 +91,7 @@ contract UStb is
*/
function addWhitelistAddress(address[] calldata users) external onlyRole(WHITELIST_MANAGER_ROLE) {
for (uint8 i = 0; i < users.length; i++) {
_grantRole(WHITELISTED_ROLE, users[i]);
if (!hasRole(BLACKLISTED_ROLE, users[i])) _grantRole(WHITELISTED_ROLE, users[i]);
}
}

Expand Down Expand Up @@ -190,9 +191,7 @@ contract UStb is
// whitelisted user can burn
} else if (
hasRole(WHITELISTED_ROLE, msg.sender) && hasRole(WHITELISTED_ROLE, from) && hasRole(WHITELISTED_ROLE, to)
&& !hasRole(BLACKLISTED_ROLE, msg.sender) && !hasRole(BLACKLISTED_ROLE, from) && !hasRole(BLACKLISTED_ROLE, to)
) {
// n.b. an address can be whitelisted and blacklisted at the same time
// normal case
} else {
revert OperationNotAllowed();
Expand Down
13 changes: 0 additions & 13 deletions test/foundry/UStb.transfers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1401,19 +1401,6 @@ contract UStbTransferTest is UStbBaseSetup {
}

function testTransferStateWhitelistEnabledFail3() public {
vm.startPrank(newOwner);
UStbContract.updateTransferState(IUStbDefinitions.TransferState.WHITELIST_ENABLED);
UStbContract.grantRole(WHITELISTED_ROLE, bob);
UStbContract.grantRole(WHITELISTED_ROLE, greg);
UStbContract.grantRole(BLACKLISTED_ROLE, bob);
UStbContract.grantRole(BLACKLISTED_ROLE, greg);
vm.stopPrank();
vm.startPrank(bob);
vm.expectRevert();
UStbContract.transfer(greg, _transferAmount);
}

function testTransferStateWhitelistEnabledFail4() public {
vm.startPrank(newOwner);
UStbContract.updateTransferState(IUStbDefinitions.TransferState.WHITELIST_ENABLED);
UStbContract.grantRole(BLACKLISTED_ROLE, bob);
Expand Down

0 comments on commit 25d7b6d

Please sign in to comment.