Skip to content

Commit

Permalink
Merge commit 'd257f2dda7f4e4740ccbda079520976fa140f62d'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeyfuss committed Dec 8, 2022
2 parents 2063940 + d257f2d commit d96b47f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
15 changes: 11 additions & 4 deletions contracts/BlockList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ abstract contract BlockList {
}

//================= Setter Functions =================//
/// @notice function to set the block list status
/// @notice function to set the block list status for multiple operators
/// @dev must be called by the blockList owner
/// @dev the blockList owner is likely the same as the owner of the token contract
/// but this could be different under certain applications
function setBlockListStatus(address operator, bool status) external isBlockListOwner {
_blockList[_c][operator] = status;
emit BlockListStatusChange(msg.sender, operator, status);
function setBlockListStatus(address[] calldata operators, bool status) external isBlockListOwner {
for (uint256 i = 0; i < operators.length; i++) {
_setBlockListStatus(operators[i], status);
}
}

/// @notice function to clear the block list status
Expand All @@ -104,4 +105,10 @@ abstract contract BlockList {
blockListOwner = newOwner;
emit BlockListOwnershipTransferred(oldOwner, newOwner);
}

/// @notice internal function to set blockList status for one operator
function _setBlockListStatus(address operator, bool status) internal {
_blockList[_c][operator] = status;
emit BlockListStatusChange(msg.sender, operator, status);
}
}
47 changes: 25 additions & 22 deletions tests/test_blocklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,47 @@ def erc1155():
##################### Set Blocklist Access #####################
def test_setBlockListStatus_non_owner(erc721, erc1155):
with reverts(NOT_BLOCK_LIST_OWNER_ERROR):
erc721.setBlockListStatus(accounts[0].address, True, {"from": accounts[1]})
erc1155.setBlockListStatus(accounts[0].address, True, {"from": accounts[1]})
erc721.setBlockListStatus([accounts[0].address], True, {"from": accounts[1]})
erc1155.setBlockListStatus([accounts[0].address], True, {"from": accounts[1]})

##################### View Function #####################
def test_getBlockListStatus_false(erc721, erc1155):
assert not (erc721.getBlockListStatus(accounts[1].address) and erc1155.getBlockListStatus(accounts[1].address))

def test_getBlockListStatus_true(erc721, erc1155):
erc721.setBlockListStatus(accounts[1].address, True, {"from": accounts[0]})
erc1155.setBlockListStatus(accounts[1].address, True, {"from": accounts[0]})
erc721.setBlockListStatus([accounts[1].address], True, {"from": accounts[0]})
erc1155.setBlockListStatus([accounts[1].address], True, {"from": accounts[0]})

assert erc721.getBlockListStatus(accounts[1].address) and erc1155.getBlockListStatus(accounts[1].address)


##################### Clear Blocklist #####################
def test_clearBlockList_non_owner(erc721, erc1155):
erc721.setBlockListStatus(accounts[1].address, True, {"from": accounts[0]})
erc1155.setBlockListStatus(accounts[1].address, True, {"from": accounts[0]})
erc721.setBlockListStatus([accounts[1].address], True, {"from": accounts[0]})
erc1155.setBlockListStatus([accounts[1].address], True, {"from": accounts[0]})
with reverts(NOT_BLOCK_LIST_OWNER_ERROR):
erc721.clearBlockList({"from": accounts[1]})
erc1155.clearBlockList({"from": accounts[1]})

def test_clearBlockList_owner(erc721, erc1155):
erc721.setBlockListStatus(accounts[1].address, True, {"from": accounts[0]})
erc1155.setBlockListStatus(accounts[1].address, True, {"from": accounts[0]})
erc721.setBlockListStatus(accounts[2].address, True, {"from": accounts[0]})
erc1155.setBlockListStatus(accounts[2].address, True, {"from": accounts[0]})
tx_721 = erc721.setBlockListStatus([accounts[1].address, accounts[2].address], True, {"from": accounts[0]})
tx_1155 = erc1155.setBlockListStatus([accounts[1].address, accounts[2].address], True, {"from": accounts[0]})

erc721.clearBlockList({"from": accounts[0]})
erc1155.clearBlockList({"from": accounts[0]})
tx_721_c = erc721.clearBlockList({"from": accounts[0]})
tx_1155_c = erc1155.clearBlockList({"from": accounts[0]})

assert not (
erc721.getBlockListStatus(accounts[1].address) and
erc721.getBlockListStatus(accounts[2].address) and
erc1155.getBlockListStatus(accounts[1].address) and
erc1155.getBlockListStatus(accounts[2].address)
erc1155.getBlockListStatus(accounts[2].address) and
"BlockListStatusChanged" in tx_721.events and
"BlockListStatusChanged" in tx_1155.events and
"BlockListCleared" in tx_721_c.events and
"BlockListCleared" in tx_1155_c.events
)


##################### Transfer Blocklist Ownership #####################
def test_transferBlockListOwnership_non_owner(erc721, erc1155):
with reverts(NOT_BLOCK_LIST_OWNER_ERROR):
Expand All @@ -81,27 +84,27 @@ def test_transferBlockListOwnership_owner(erc721, erc1155):

##################### ERC721 Approvals & Transfers #####################
def test_approve_not_on_block_list_721(erc721):
erc721.approve(accounts[1], 1, {"from": accounts[0]})
erc721.approve(accounts[1].address, 1, {"from": accounts[0]})
erc721.transferFrom(accounts[0].address, accounts[2].address, 1, {"from": accounts[1]})

def test_approve_on_block_list_721(erc721):
tx = erc721.setBlockListStatus(accounts[1], True, {"from": accounts[0]})
tx = erc721.setBlockListStatus([accounts[1].address], True, {"from": accounts[0]})
with reverts(IS_BLOCKED_OPERATOR_ERROR):
erc721.approve(accounts[1], 1, {"from": accounts[0]})
erc721.approve(accounts[1].address, 1, {"from": accounts[0]})

with reverts():
erc721.transferFrom(accounts[0].address, accounts[2].address, 1, {"from": accounts[1]})

assert "BlockListStatusChange" in tx.events

def test_approveForAll_not_on_block_list_721(erc721):
erc721.setApprovalForAll(accounts[1], True, {"from": accounts[0]})
erc721.setApprovalForAll(accounts[1].address, True, {"from": accounts[0]})
erc721.transferFrom(accounts[0].address, accounts[2].address, 1, {"from": accounts[1]})

def test_approveForAll_on_block_list_721(erc721):
tx = erc721.setBlockListStatus(accounts[1], True, {"from": accounts[0]})
tx = erc721.setBlockListStatus([accounts[1].address], True, {"from": accounts[0]})
with reverts(IS_BLOCKED_OPERATOR_ERROR):
erc721.setApprovalForAll(accounts[1], True, {"from": accounts[0]})
erc721.setApprovalForAll(accounts[1].address, True, {"from": accounts[0]})

with reverts():
erc721.transferFrom(accounts[0].address, accounts[2].address, 1, {"from": accounts[1]})
Expand All @@ -110,13 +113,13 @@ def test_approveForAll_on_block_list_721(erc721):

##################### ERC1155 Approvals & Transfers #####################
def test_approveForAll_not_on_block_list_1155(erc1155):
erc1155.setApprovalForAll(accounts[1], True, {"from": accounts[0]})
erc1155.setApprovalForAll(accounts[1].address, True, {"from": accounts[0]})
erc1155.safeTransferFrom(accounts[0].address, accounts[2].address, 1, 50, "", {"from": accounts[1]})

def test_approveForAll_on_block_list_1155(erc1155):
tx = erc1155.setBlockListStatus(accounts[1], True, {"from": accounts[0]})
tx = erc1155.setBlockListStatus([accounts[1].address], True, {"from": accounts[0]})
with reverts(IS_BLOCKED_OPERATOR_ERROR):
erc1155.setApprovalForAll(accounts[1], True, {"from": accounts[0]})
erc1155.setApprovalForAll(accounts[1].address, True, {"from": accounts[0]})

with reverts():
erc1155.safeTransferFrom(accounts[0].address, accounts[2].address, 1, 50, "", {"from": accounts[1]})
Expand Down

0 comments on commit d96b47f

Please sign in to comment.