From 9f8cc32e8a7f3f670e453c14345be1650040d9ad Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 10:51:06 -0500 Subject: [PATCH 01/27] set up structure --- .../_beforeClaim/_beforeClaim.tree | 12 ++++++ .../_beforeTokenTransfer.tree | 0 .../_canSetFunctions/_canSetFunctions.tree | 41 +++++++++++++++++++ .../drop-erc1155/burnBatch/burnBatch.tree | 17 ++++++++ .../collectPriceOnClaim.tree | 0 .../freezeBatchBaseURI.tree | 0 .../drop-erc1155/initialize/initialize.tree | 0 .../setMaxTotalSupply/setMaxTotalSupply.tree | 0 .../setSaleRecipientForToken.tree | 0 .../transferTokensOnClaim.tree | 0 .../updateBatchBaseURI.tree | 0 11 files changed, 70 insertions(+) create mode 100644 src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree create mode 100644 src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree create mode 100644 src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree create mode 100644 src/test/drop/drop-erc1155/burnBatch/burnBatch.tree create mode 100644 src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree create mode 100644 src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree create mode 100644 src/test/drop/drop-erc1155/initialize/initialize.tree create mode 100644 src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree create mode 100644 src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree create mode 100644 src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree create mode 100644 src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree diff --git a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree new file mode 100644 index 000000000..657436605 --- /dev/null +++ b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree @@ -0,0 +1,12 @@ +function _beforeClaim( + uint256 _tokenId, + address, + uint256 _quantity, + address, + uint256, + AllowlistProof calldata, + bytes memory + ) +# if maxTotalSupply for _tokenId is not zero +## if totalSupply of _tokenId + _quantity is greater than or equal to maxTotalSupply for _tokenId +### it should revert \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree new file mode 100644 index 000000000..0efe366c6 --- /dev/null +++ b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree @@ -0,0 +1,41 @@ +function _canSetPlatformFeeInfo() +# if caller has DEFAULT_ADMIN_ROLE +## it should return true +# if caller does not have DEFAULT_ADMIN_ROLE +## it should return false + +function _canSetPrimarySaleRecipient() +# if caller has DEFAULT_ADMIN_ROLE +## it should return true +# if caller does not have DEFAULT_ADMIN_ROLE +## it should return false + +function _canSetOwner() +# if caller has DEFAULT_ADMIN_ROLE +## it should return true +# if caller does not have DEFAULT_ADMIN_ROLE +## it should return false + +function _canSetRoyaltyInfo() +# if caller has DEFAULT_ADMIN_ROLE +## it should return true +# if caller does not have DEFAULT_ADMIN_ROLE +## it should return false + +function _canSetContractURI() +# if caller has DEFAULT_ADMIN_ROLE +## it should return true +# if caller does not have DEFAULT_ADMIN_ROLE +## it should return false + +function _canSetClaimConditions() +# if caller has DEFAULT_ADMIN_ROLE +## it should return true +# if caller does not have DEFAULT_ADMIN_ROLE +## it should return false + +function _canLazyMint() +# if caller has minterRole +## it should return true +# if caller does not have minterRole +## it should return false \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree b/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree new file mode 100644 index 000000000..0001f4aa9 --- /dev/null +++ b/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree @@ -0,0 +1,17 @@ +function burnBatch( + address account, + uint256[] memory ids, + uint256[] memory values +) +├── if account does not equal _msgSender() and _msgSender() is not an approved operator for account +│ └── it should revert +└── if account is equal to _msgSender() or _msgSender() is an approved operator for account + ├── if ids and values are not the same length + │ └── it should revert + └── if ids and values are the same length + ├── if the balance of account for each id is not greater than or equal to the corresponding value + │ └── it should revert + └── if the balance of account for each id is greater than or equal to the corresponding value + ├── it should reduce the balance of each id for account by the corresponding value + ├── it should reduce the total supply of each id by the corresponding value + └── it should emit TransferBatch with the following parameters: _msgSender(), account, address(0), ids, amounts diff --git a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/drop/drop-erc1155/initialize/initialize.tree b/src/test/drop/drop-erc1155/initialize/initialize.tree new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree b/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree b/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree new file mode 100644 index 000000000..e69de29bb From 23ffac7f6135594b6a6c5736a8b5de61afba161a Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 10:57:59 -0500 Subject: [PATCH 02/27] tree: collectPriceOnClaim --- .../collectPriceOnClaim.tree | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree index e69de29bb..f876f49bc 100644 --- a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree +++ b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree @@ -0,0 +1,21 @@ +function collectPriceOnClaim( + uint256 _tokenId, + address _primarySaleRecipient, + uint256 _quantityToClaim, + address _currency, + uint256 _pricePerToken + ) +├── if _pricePerToken is equal to zero +│ └── if msg.value does not equal to zero +│ └── it should revert +└── if _pricePerToken is not equal to zero + └── if _primarySaleRecipient is equal to address(0) + ├── if _currency is native token + │ ├── if msg.value does not equal to totalPrice + │ │ └── it should revert + │ └── if msg.value does equal to totalPrice + │ ├── it should transfer platformFees to platformFeeRecipient in native token + │ └── it should transfer totalPrice - platformFees to saleRecipient in native token + └── if _currency is not native token + ├── it should transfer platformFees to platformFeeRecipient in _currency token + └── it should transfer totalPrice - platformFees to saleRecipient in _currency token \ No newline at end of file From e7854424b0f352d128bfd864a618956f013cf17a Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 11:06:08 -0500 Subject: [PATCH 03/27] tree: freezeBatchBaseURI --- .../freezeBatchBaseURI/freezeBatchBaseURI.tree | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree index e69de29bb..f8d3951ee 100644 --- a/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree +++ b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree @@ -0,0 +1,12 @@ +function freezeBatchBaseURI(uint256 _index) +├── if the caller does not have metadataRole +│ └── it should revert +└── if the caller has metadataRole + ├── if _index is greater than the number of current batches + │ └── it should revert + └── if _index is equal to or less than the number of current batches + ├── if the baseURI for the batch at _index is not set + │ └── it should revert + └── if the baseURI for the batch at _index is set + ├── it should set batchFrozen[(batchId for _index)] to true + └── it should emit MetadataFrozen \ No newline at end of file From 51f02d7a8021a15b2231ab8696934cbfd7d9ee81 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 11:09:08 -0500 Subject: [PATCH 04/27] tree: setMaxTotalSupply --- .../drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree index e69de29bb..0023edbbe 100644 --- a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree +++ b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree @@ -0,0 +1,6 @@ +function setMaxTotalSupply(uint256 _tokenId, uint256 _maxTotalSupply) +├── if the caller does not have DEFAULT_ADMIN_ROLE +│ └── it should revert +└── if the caller does have DEFAULT_ADMIN_ROLE + ├── it should set maxTotalSupply for _tokenId as _maxTotalSupply + └── it should emit MaxTotalSupplyUpdated with the parameters _tokenId, _maxTotalSupply \ No newline at end of file From 0741b4288664e3c90e55c969f8a2dd22fd500a3c Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 11:11:21 -0500 Subject: [PATCH 05/27] tree: setSaleRecipientForToken --- .../setSaleRecipientForToken/setSaleRecipientForToken.tree | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree b/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree index e69de29bb..4e7bd4ac7 100644 --- a/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree +++ b/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree @@ -0,0 +1,6 @@ +function setSaleRecipientForToken(uint256 _tokenId, address _saleRecipient) +├── when called by a user without DEFAULT_ADMIN_ROLE +│ └── it should revert +└── when called by a user with DEFAULT_ADMIN_ROLE + ├── it should set saleRecipient for _tokenId as _saleRecipient + └── it should emit SaleRecipientForTokenUpdated with the parameters _tokenId, _saleRecipient \ No newline at end of file From f12f2606a5b609e5559079cdbec179751f38f7e4 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 11:21:05 -0500 Subject: [PATCH 06/27] tree: updateBatchBaseURI --- .../updateBatchBaseURI/updateBatchBaseURI.tree | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree b/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree index e69de29bb..ae8b21f5b 100644 --- a/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree +++ b/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree @@ -0,0 +1,9 @@ +function updateBatchBaseURI(uint256 _index, string calldata _uri) +├── when the caller does not have metadataRole +│ └── it should revert +└── when the caller has metadataRole + ├── when batchFrozen[_batchId for _index] is equal to true + │ └── it should revert + └── when batchFrozen[_batchId for _index] is equal to false + ├── it should set baseURI[_batchId for _index] to _uri + └── it should emit BatchMetadataUpdate with the parameters startingTokenId, _batchId \ No newline at end of file From 4d325c477f23240ff3d7ac161ce5561d9d6be6db Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 11:21:15 -0500 Subject: [PATCH 07/27] tree: transferTokensOnClaim --- .../transferTokensOnClaim/transferTokensOnClaim.tree | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree index e69de29bb..9d653e03e 100644 --- a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree +++ b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree @@ -0,0 +1,12 @@ +function transferTokensOnClaim( + address _to, + uint256 _tokenId, + uint256 _quantityBeingClaimed +) +├── when {to} is a smart contract +│ ├── when {to} does not implement onERC1155Received +│ │ └── it should revert +│ └── when {to} does implement onERC1155Received +│ └── it should mint {amount} number of {id} tokens to {to} +└── when {to} is an EOA + └── it should mint {amount} number of {id} tokens to {to} \ No newline at end of file From 5cc53042d749707dc5140213863614a8251c0a5e Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 11:26:35 -0500 Subject: [PATCH 08/27] tree: initialize --- .../drop-erc1155/initialize/initialize.tree | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/test/drop/drop-erc1155/initialize/initialize.tree b/src/test/drop/drop-erc1155/initialize/initialize.tree index e69de29bb..e29c1e463 100644 --- a/src/test/drop/drop-erc1155/initialize/initialize.tree +++ b/src/test/drop/drop-erc1155/initialize/initialize.tree @@ -0,0 +1,50 @@ +function initialize( + address _defaultAdmin, + string memory _name, + string memory _symbol, + string memory _contractURI, + address[] memory _trustedForwarders, + address _saleRecipient, + address _royaltyRecipient, + uint128 _royaltyBps, + uint128 _platformFeeBps, + address _platformFeeRecipient +) +├── when _trustedForwarders.length > 0 +│ └── it should set _trustedForwarder[_trustedForwarders[i]] as true for each address in _trustedForwarders +├── it should set _uri to an empty string +├── it should set contractURI as _contractURI +├── it should emit ContractURIUpdated with the parameters: prevURI, _uri +├── it should set _defaultAdmin as the owner of the contract +├── it should emit OwnerUpdated with the parameters: _prevOwner, _defaultAdmin +├── it should assign the role DEFAULT_ADMIN_ROLE to _defaultAdmin +├── it should emit RoleGranted with the parameters: DEFAULT_ADMIN_ROLE, _defaultAdmin, msg.sender +├── it should assign the role _minterRole to _defaultAdmin +├── it should emit RoleGranted with the parameters: _minterRole, _defaultAdmin, msg.sender +├── it should assign the role _transferRole to _defaultAdmin +├── it should emit RoleGranted with the parameters: _transferRole, _defaultAdmin, msg.sender +├── it should assign the role _transferRole to address(0) +├── it should emit RoleGranted with the parameters: _transferRole, address(0), msg.sender +├── it should assign the role _metadataRole to _defaultAdmin +├── it should emit RoleGranted with the parameters: _metadataRole, _defaultAdmin, msg.sender +├── it should set _getAdminRole[_metadataRole] to equal _metadataRole +├── it should emit RoleAdminChanged with the parameters _metadataRole, previousAdminRole, _metadataRole +├── when _platformFeeBps is greater than 10_000 +│ └── it should revert +├── when _platformFeeBps is less than or equal to 10_000 +│ ├── it should set platformFeeBps to uint16(_platformFeeBps); +│ ├── it should set platformFeeRecipient to _platformFeeRecipient +│ └── it should emit PlatformFeeInfoUpdated with the following parameters: _platformFeeRecipient, _platformFeeBps +├── when _royaltyBps is greater than 10_000 +│ └── it should revert +├── when _royaltyBps is less than or equal to 10_000 +│ ├── it should set royaltyRecipient as _royaltyRecipient +│ ├── it should set royaltyBps as uint16(_royaltyBps) +│ └── it should emit DefaultRoyalty with the parameters _royaltyRecipient, _royaltyBps +├── it should set recipient as _primarySaleRecipient +├── it should emit PrimarySaleRecipientUpdated with the parameters _primarySaleRecipient +├── it should set transferRole as keccak256("TRANSFER_ROLE") +├── it should set minterRole as keccak256("MINTER_ROLE") +├── it should set metadataRole as keccak256("METADATA_ROLE") +├── it should set name as _name +└── it should set symbol as _symbol From aa3b9e869364d42027838dd4ddf75e90c1cc4aac Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 11:38:36 -0500 Subject: [PATCH 09/27] tree: collectPriceOnClaim --- .../collectPriceOnClaim.tree | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree index f876f49bc..0e3ab8c9a 100644 --- a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree +++ b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree @@ -5,17 +5,40 @@ function collectPriceOnClaim( address _currency, uint256 _pricePerToken ) -├── if _pricePerToken is equal to zero -│ └── if msg.value does not equal to zero -│ └── it should revert -└── if _pricePerToken is not equal to zero - └── if _primarySaleRecipient is equal to address(0) - ├── if _currency is native token - │ ├── if msg.value does not equal to totalPrice +├── when _pricePerToken is equal to zero +│ ├── when msg.value does not equal to zero +│ │ └── it should revert +│ └── when msg.value is equal to zero +│ └── it should return +└── when _pricePerToken is not equal to zero + ├── when _primarySaleRecipient is equal to address(0) + │ ├── when saleRecipient for _tokenId is equal to address(0) + │ │ ├── when currency is native token + │ │ │ ├── when msg.value does not equal totalPrice + │ │ │ │ └── it should revert + │ │ │ └── when msg.value does equal totalPrice + │ │ │ ├── it should transfer platformFees to platformFeeRecipient in native token + │ │ │ └── it should transfer totalPrice - platformFees to primarySaleRecipient in native token + │ │ └── when currency is not native token + │ │ ├── it should transfer platformFees to platformFeeRecipient in _currency token + │ │ └── it should transfer totalPrice - platformFees to primarySaleRecipient in _currency token + │ └── when salerecipient for _tokenId is not equal to address(0) + │ ├── when currency is native token + │ │ ├── when msg.value does not equal totalPrice + │ │ │ └── it should revert + │ │ └── when msg.value does equal totalPrice + │ │ ├── it should transfer platformFees to platformFeeRecipient in native token + │ │ └── it should transfer totalPrice - platformFees to saleRecipient for _tokenId in native token + │ └── when currency is not native token + │ ├── it should transfer platformFees to platformFeeRecipient in _currency token + │ └── it should transfer totalPrice - platformFees to saleRecipient for _tokenId in _currency token + └── when _primarySaleRecipient is not equal to address(0) + ├── when currency is native token + │ ├── when msg.value does not equal totalPrice │ │ └── it should revert - │ └── if msg.value does equal to totalPrice + │ └── when msg.value does equal totalPrice │ ├── it should transfer platformFees to platformFeeRecipient in native token - │ └── it should transfer totalPrice - platformFees to saleRecipient in native token - └── if _currency is not native token + │ └── it should transfer totalPrice - platformFees to _primarySaleRecipient in native token + └── when currency is not native token ├── it should transfer platformFees to platformFeeRecipient in _currency token - └── it should transfer totalPrice - platformFees to saleRecipient in _currency token \ No newline at end of file + └── it should transfer totalPrice - platformFees to _primarySaleRecipient in _currency token \ No newline at end of file From b0919e2605ddee54cdb581c0395b678ebc626cc2 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 14:56:20 -0500 Subject: [PATCH 10/27] tree: _beforeTokenTransfer --- .../_beforeClaim/_beforeClaim.tree | 22 ++++---- .../_beforeTokenTransfer.tree | 12 ++++ .../_canSetFunctions/_canSetFunctions.tree | 56 +++++++++---------- 3 files changed, 51 insertions(+), 39 deletions(-) diff --git a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree index 657436605..2bd2d6288 100644 --- a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree +++ b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree @@ -1,12 +1,12 @@ function _beforeClaim( - uint256 _tokenId, - address, - uint256 _quantity, - address, - uint256, - AllowlistProof calldata, - bytes memory - ) -# if maxTotalSupply for _tokenId is not zero -## if totalSupply of _tokenId + _quantity is greater than or equal to maxTotalSupply for _tokenId -### it should revert \ No newline at end of file + uint256 _tokenId, + address, + uint256 _quantity, + address, + uint256, + AllowlistProof calldata, + bytes memory +) +└── if maxTotalSupply for _tokenId is not zero + └── if totalSupply of _tokenId + _quantity is greater than or equal to maxTotalSupply for _tokenId + └── it should revert \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree index e69de29bb..c8fc8ed14 100644 --- a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree +++ b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree @@ -0,0 +1,12 @@ +function _beforeTokenTransfer( + address operator, + address from, + address to, + uint256[] memory ids, + uint256[] memory amounts, + bytes memory data +) +├── when from equals to address(0) +│ └── totalSupply for each id is incremented by the corresponding amounts +└── when to equals address(0) + └── totalSupply for each id is decremented by the corresponding amounts \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree index 0efe366c6..1c0a77f04 100644 --- a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree +++ b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree @@ -1,41 +1,41 @@ function _canSetPlatformFeeInfo() -# if caller has DEFAULT_ADMIN_ROLE -## it should return true -# if caller does not have DEFAULT_ADMIN_ROLE -## it should return false +├── if caller has DEFAULT_ADMIN_ROLE +│ └── it should return true +└── if caller does not have DEFAULT_ADMIN_ROLE + └── it should return false function _canSetPrimarySaleRecipient() -# if caller has DEFAULT_ADMIN_ROLE -## it should return true -# if caller does not have DEFAULT_ADMIN_ROLE -## it should return false +├── if caller has DEFAULT_ADMIN_ROLE +│ └── it should return true +└── if caller does not have DEFAULT_ADMIN_ROLE + └── it should return false function _canSetOwner() -# if caller has DEFAULT_ADMIN_ROLE -## it should return true -# if caller does not have DEFAULT_ADMIN_ROLE -## it should return false +├── if caller has DEFAULT_ADMIN_ROLE +│ └── it should return true +└── if caller does not have DEFAULT_ADMIN_ROLE + └── it should return false function _canSetRoyaltyInfo() -# if caller has DEFAULT_ADMIN_ROLE -## it should return true -# if caller does not have DEFAULT_ADMIN_ROLE -## it should return false +├── if caller has DEFAULT_ADMIN_ROLE +│ └── it should return true +└── if caller does not have DEFAULT_ADMIN_ROLE + └── it should return false function _canSetContractURI() -# if caller has DEFAULT_ADMIN_ROLE -## it should return true -# if caller does not have DEFAULT_ADMIN_ROLE -## it should return false +├── if caller has DEFAULT_ADMIN_ROLE +│ └── it should return true +└── if caller does not have DEFAULT_ADMIN_ROLE + └── it should return false function _canSetClaimConditions() -# if caller has DEFAULT_ADMIN_ROLE -## it should return true -# if caller does not have DEFAULT_ADMIN_ROLE -## it should return false +├── if caller has DEFAULT_ADMIN_ROLE +│ └── it should return true +└── if caller does not have DEFAULT_ADMIN_ROLE + └── it should return false function _canLazyMint() -# if caller has minterRole -## it should return true -# if caller does not have minterRole -## it should return false \ No newline at end of file +├── if caller has minterRole +│ └── it should return true +└── if caller does not have minterRole + └── it should return false \ No newline at end of file From 276f8c53608a38a3797df7b1d5b95af807e84379 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 21:32:34 -0500 Subject: [PATCH 11/27] test: _beforeClaim --- .../_beforeClaim/_beforeClaim.t.sol | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol diff --git a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol new file mode 100644 index 000000000..22d7de23d --- /dev/null +++ b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155, IPermissions, ILazyMint } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; +import "@openzeppelin/contracts/utils/Strings.sol"; + +contract HarnessDropERC1155 is DropERC1155 { + function beforeClaim( + uint256 _tokenId, + address, + uint256 _quantity, + address, + uint256, + AllowlistProof calldata alp, + bytes memory + ) external view { + _beforeClaim(_tokenId, address(0), _quantity, address(0), 0, alp, bytes("")); + } + + function initializeHarness( + address _defaultAdmin, + string memory _contractURI, + address _saleRecipient, + address _royaltyRecipient, + uint128 _royaltyBps, + uint128 _platformFeeBps, + address _platformFeeRecipient + ) external { + bytes32 _transferRole = keccak256("TRANSFER_ROLE"); + bytes32 _minterRole = keccak256("MINTER_ROLE"); + bytes32 _metadataRole = keccak256("METADATA_ROLE"); + + _setupContractURI(_contractURI); + _setupOwner(_defaultAdmin); + + _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); + _setupRole(_minterRole, _defaultAdmin); + _setupRole(_transferRole, _defaultAdmin); + _setupRole(_transferRole, address(0)); + _setupRole(_metadataRole, _defaultAdmin); + _setRoleAdmin(_metadataRole, _metadataRole); + + _setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); + _setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps); + _setupPrimarySaleRecipient(_saleRecipient); + } +} + +contract DropERC1155Test_beforeClaim is BaseTest { + using StringsUpgradeable for uint256; + using StringsUpgradeable for address; + + event TokensLazyMinted(uint256 indexed startTokenId, uint256 endTokenId, string baseURI, bytes encryptedBaseURI); + event TokenURIRevealed(uint256 indexed index, string revealedURI); + event MaxTotalSupplyUpdated(uint256 tokenId, uint256 maxTotalSupply); + + HarnessDropERC1155 public drop; + + bytes private emptyEncodedBytes = abi.encode("", ""); + + using stdStorage for StdStorage; + + function setUp() public override { + super.setUp(); + drop = new HarnessDropERC1155(); + drop.initializeHarness( + address(this), + "https://token-cdn-domain/{id}.json", + deployer, + deployer, + 1000, + 1000, + deployer + ); + drop.setMaxTotalSupply(0, 1); + } + + /*/////////////////////////////////////////////////////////////// + Unit tests: misc. + //////////////////////////////////////////////////////////////*/ + + /** + * note: Tests whether contract reverts when a non-holder renounces a role. + */ + function test_revert_ExceedMaxSupply() public { + DropERC1155.AllowlistProof memory alp; + vm.expectRevert("exceed max total supply"); + drop.beforeClaim(0, address(0), 2, address(0), 0, alp, bytes("")); + } + + function test_NoRevert() public view { + DropERC1155.AllowlistProof memory alp; + drop.beforeClaim(0, address(0), 1, address(0), 0, alp, bytes("")); + } +} From 4ecdb397c48234fe8c72dd3b1e1d9fa9d34195cf Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 21:32:43 -0500 Subject: [PATCH 12/27] test: _beforeTokenTransfer --- .../_beforeTokenTransfer.sol | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol diff --git a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol new file mode 100644 index 000000000..8d913b628 --- /dev/null +++ b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155, IPermissions, ILazyMint } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; +import "@openzeppelin/contracts/utils/Strings.sol"; + +contract HarnessDropERC1155 is DropERC1155 { + function beforeTokenTransfer( + address operator, + address from, + address to, + uint256[] memory ids, + uint256[] memory amounts, + bytes memory data + ) external { + _beforeTokenTransfer(operator, from, to, ids, amounts, data); + } + + function initializeHarness( + address _defaultAdmin, + string memory _contractURI, + address _saleRecipient, + address _royaltyRecipient, + uint128 _royaltyBps, + uint128 _platformFeeBps, + address _platformFeeRecipient + ) external { + bytes32 _transferRole = keccak256("TRANSFER_ROLE"); + bytes32 _minterRole = keccak256("MINTER_ROLE"); + bytes32 _metadataRole = keccak256("METADATA_ROLE"); + + _setupContractURI(_contractURI); + _setupOwner(_defaultAdmin); + + _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); + _setupRole(_minterRole, _defaultAdmin); + _setupRole(_transferRole, _defaultAdmin); + _setupRole(_transferRole, address(0)); + _setupRole(_metadataRole, _defaultAdmin); + _setRoleAdmin(_metadataRole, _metadataRole); + + _setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); + _setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps); + _setupPrimarySaleRecipient(_saleRecipient); + } +} + +contract DropERC1155Test_beforeTokenTransfer is BaseTest { + using StringsUpgradeable for uint256; + using StringsUpgradeable for address; + + event TokensLazyMinted(uint256 indexed startTokenId, uint256 endTokenId, string baseURI, bytes encryptedBaseURI); + event TokenURIRevealed(uint256 indexed index, string revealedURI); + event MaxTotalSupplyUpdated(uint256 tokenId, uint256 maxTotalSupply); + + HarnessDropERC1155 public drop; + + address private beforeTransfer_from = address(0x01); + address private beforeTransfer_to = address(0x01); + uint256[] private beforeTransfer_ids; + uint256[] private beforeTransfer_amounts; + bytes private beforeTransfer_data; + + using stdStorage for StdStorage; + + function setUp() public override { + super.setUp(); + drop = new HarnessDropERC1155(); + drop.initializeHarness( + address(this), + "https://token-cdn-domain/{id}.json", + deployer, + deployer, + 1000, + 1000, + deployer + ); + + beforeTransfer_ids = new uint256[](1); + beforeTransfer_ids[0] = 0; + beforeTransfer_amounts = new uint256[](1); + beforeTransfer_amounts[0] = 1; + beforeTransfer_data = abi.encode("", ""); + } + + modifier fromAddressZero() { + beforeTransfer_from = address(0); + _; + } + + modifier toAddressZero() { + beforeTransfer_to = address(0); + _; + } + + /** + * note: Tests whether contract reverts when a non-holder renounces a role. + */ + function test_state_transferFromZero() public fromAddressZero { + uint256 beforeTokenTotalSupply = drop.totalSupply(0); + drop.beforeTokenTransfer( + deployer, + beforeTransfer_from, + beforeTransfer_to, + beforeTransfer_ids, + beforeTransfer_amounts, + beforeTransfer_data + ); + uint256 afterTokenTotalSupply = drop.totalSupply(0); + assertEq(beforeTokenTotalSupply + beforeTransfer_amounts[0], afterTokenTotalSupply); + } + + function test_state_tranferToZero() public toAddressZero { + drop.beforeTokenTransfer(deployer, beforeTransfer_to, beforeTransfer_from, beforeTransfer_ids, beforeTransfer_amounts, beforeTransfer_data); + uint256 beforeTokenTotalSupply = drop.totalSupply(0); + drop.beforeTokenTransfer( + deployer, + beforeTransfer_from, + beforeTransfer_to, + beforeTransfer_ids, + beforeTransfer_amounts, + beforeTransfer_data + ); + uint256 afterTokenTotalSupply = drop.totalSupply(0); + assertEq(beforeTokenTotalSupply - beforeTransfer_amounts[0], afterTokenTotalSupply); + } +} From eb01028286af3b056b8465dbe8c37bbce7387c5f Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 21:55:06 -0500 Subject: [PATCH 13/27] test: _canSetFunctions --- .../_canSetFunctions/_canSetFunctions.sol | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol diff --git a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol new file mode 100644 index 000000000..b0d88581e --- /dev/null +++ b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155, IPermissions, ILazyMint } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; +import "@openzeppelin/contracts/utils/Strings.sol"; + +contract HarnessDropERC1155 is DropERC1155 { + bytes32 private transferRole; + bytes32 private minterRole; + bytes32 private metadataRole; + + function canSetPlatformFeeInfo() external view returns (bool) { + return _canSetPlatformFeeInfo(); + } + + /// @dev Checks whether primary sale recipient can be set in the given execution context. + function canSetPrimarySaleRecipient() external view returns (bool) { + return _canSetPrimarySaleRecipient(); + } + + /// @dev Checks whether owner can be set in the given execution context. + function canSetOwner() external view returns (bool) { + return _canSetOwner(); + } + + /// @dev Checks whether royalty info can be set in the given execution context. + function canSetRoyaltyInfo() external view returns (bool) { + return _canSetRoyaltyInfo(); + } + + /// @dev Checks whether contract metadata can be set in the given execution context. + function canSetContractURI() external view returns (bool) { + return _canSetContractURI(); + } + + /// @dev Checks whether platform fee info can be set in the given execution context. + function canSetClaimConditions() external view returns (bool) { + return _canSetClaimConditions(); + } + + /// @dev Returns whether lazy minting can be done in the given execution context. + function canLazyMint() external view virtual returns (bool) { + return _canLazyMint(); + } + + function initializeHarness( + address _defaultAdmin, + string memory _contractURI, + address _saleRecipient, + address _royaltyRecipient, + uint128 _royaltyBps, + uint128 _platformFeeBps, + address _platformFeeRecipient + ) external { + bytes32 _transferRole = keccak256("TRANSFER_ROLE"); + bytes32 _minterRole = keccak256("MINTER_ROLE"); + bytes32 _metadataRole = keccak256("METADATA_ROLE"); + + _setupContractURI(_contractURI); + _setupOwner(_defaultAdmin); + + _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); + _setupRole(_minterRole, _defaultAdmin); + _setupRole(_transferRole, _defaultAdmin); + _setupRole(_transferRole, address(0)); + _setupRole(_metadataRole, _defaultAdmin); + _setRoleAdmin(_metadataRole, _metadataRole); + + _setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); + _setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps); + _setupPrimarySaleRecipient(_saleRecipient); + + transferRole = _transferRole; + minterRole = _minterRole; + metadataRole = _metadataRole; + } +} + +contract DropERC1155Test_canSetFunctions is BaseTest { + using StringsUpgradeable for uint256; + using StringsUpgradeable for address; + + HarnessDropERC1155 public drop; + + function setUp() public override { + super.setUp(); + drop = new HarnessDropERC1155(); + drop.initializeHarness( + deployer, + "https://token-cdn-domain/{id}.json", + deployer, + deployer, + 1000, + 1000, + deployer + ); + } + + modifier HasDefaultAdminRole() { + vm.startPrank(deployer); + _; + } + + modifier DoesNotHaveDefaultAdminRole() { + vm.startPrank(address(0x123)); + _; + } + + modifier HasMinterRole() { + vm.startPrank(deployer); + _; + } + + modifier DoesNotHaveMinterRole() { + vm.startPrank(address(0x123)); + _; + } + + /** + * note: Tests whether contract reverts when a non-holder renounces a role. + */ + function test_canSetPlatformFeeInfo_true() public HasDefaultAdminRole { + assertTrue(drop.canSetPlatformFeeInfo()); + } + + function test_canSetPlatformFeeInfo_false() public DoesNotHaveDefaultAdminRole { + assertFalse(drop.canSetPlatformFeeInfo()); + } + + function test_canSetPrimarySaleRecipient_true() public HasDefaultAdminRole { + assertTrue(drop.canSetPrimarySaleRecipient()); + } + + function test_canSetPrimarySaleRecipient_false() public DoesNotHaveDefaultAdminRole { + assertFalse(drop.canSetPrimarySaleRecipient()); + } + + function test_canSetOwner_true() public HasDefaultAdminRole { + assertTrue(drop.canSetOwner()); + } + + function test_canSetOwner_false() public DoesNotHaveDefaultAdminRole { + assertFalse(drop.canSetOwner()); + } + + function test_canSetRoyaltyInfo_true() public HasDefaultAdminRole { + assertTrue(drop.canSetRoyaltyInfo()); + } + + function test_canSetRoyaltyInfo_false() public DoesNotHaveDefaultAdminRole { + assertFalse(drop.canSetRoyaltyInfo()); + } + + function test_canSetContractURI_true() public HasDefaultAdminRole { + assertTrue(drop.canSetContractURI()); + } + + function test_canSetContractURI_false() public DoesNotHaveDefaultAdminRole { + assertFalse(drop.canSetContractURI()); + } + + function test_canSetClaimConditions_true() public HasDefaultAdminRole { + assertTrue(drop.canSetClaimConditions()); + } + + function test_canSetClaimConditions_false() public DoesNotHaveDefaultAdminRole { + assertFalse(drop.canSetClaimConditions()); + } + + function test_canLazyMint_true() public HasMinterRole { + assertTrue(drop.canLazyMint()); + } + + function test_canLazyMint_false() public DoesNotHaveMinterRole { + assertFalse(drop.canLazyMint()); + } +} From ef3ef2ac1766f96f4c1f0af81ae459a033c0b453 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Fri, 6 Oct 2023 22:35:23 -0500 Subject: [PATCH 14/27] test: burnBatch --- .../drop-erc1155/burnBatch/burnBatch.t.sol | 133 ++++++++++++++++++ .../drop-erc1155/burnBatch/burnBatch.tree | 10 +- 2 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 src/test/drop/drop-erc1155/burnBatch/burnBatch.t.sol diff --git a/src/test/drop/drop-erc1155/burnBatch/burnBatch.t.sol b/src/test/drop/drop-erc1155/burnBatch/burnBatch.t.sol new file mode 100644 index 000000000..56b6a649b --- /dev/null +++ b/src/test/drop/drop-erc1155/burnBatch/burnBatch.t.sol @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC2981Upgradeable.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; + +contract DropERC1155Test_burnBatch is BaseTest { + using StringsUpgradeable for uint256; + + DropERC1155 public drop; + + address private unauthorized = address(0x999); + address private account; + uint256[] private ids; + uint256[] private values; + + address private receiver; + bytes private emptyEncodedBytes = abi.encode("", ""); + + event TransferBatch( + address indexed operator, + address indexed from, + address indexed to, + uint256[] ids, + uint256[] values + ); + + function setUp() public override { + super.setUp(); + drop = DropERC1155(getContract("DropERC1155")); + + ids = new uint256[](1); + values = new uint256[](1); + ids[0] = 0; + values[0] = 1; + } + + /*/////////////////////////////////////////////////////////////// + Branch Testing + //////////////////////////////////////////////////////////////*/ + + modifier callerNotApproved() { + vm.startPrank(unauthorized); + _; + } + + modifier callerOwner() { + receiver = getActor(0); + vm.startPrank(receiver); + _; + } + + modifier callerApproved() { + receiver = getActor(0); + vm.prank(receiver); + drop.setApprovalForAll(deployer, true); + vm.startPrank(deployer); + _; + } + + modifier IdValueMismatch() { + values = new uint256[](2); + values[0] = 1; + values[1] = 1; + _; + } + + modifier tokenClaimed() { + vm.warp(1); + + uint256 _tokenId = 0; + receiver = getActor(0); + bytes32[] memory proofs = new bytes32[](0); + + DropERC1155.AllowlistProof memory alp; + alp.proof = proofs; + + DropERC1155.ClaimCondition[] memory conditions = new DropERC1155.ClaimCondition[](1); + conditions[0].maxClaimableSupply = 100; + conditions[0].quantityLimitPerWallet = 100; + + vm.prank(deployer); + drop.lazyMint(100, "ipfs://", emptyEncodedBytes); + vm.prank(deployer); + drop.setClaimConditions(_tokenId, conditions, false); + + vm.prank(getActor(5), getActor(5)); + drop.claim(receiver, _tokenId, 1, address(0), 0, alp, ""); + + _; + } + + function test_revert_callerNotApproved() public tokenClaimed callerNotApproved { + vm.expectRevert("ERC1155: caller is not owner nor approved."); + drop.burnBatch(receiver, ids, values); + } + + function test_state_callerApproved() public tokenClaimed callerApproved { + uint256 beforeBalance = drop.balanceOf(receiver, ids[0]); + drop.burnBatch(receiver, ids, values); + uint256 afterBalance = drop.balanceOf(receiver, ids[0]); + assertEq(beforeBalance - values[0], afterBalance); + } + + function test_state_callerOwner() public tokenClaimed callerOwner { + uint256 beforeBalance = drop.balanceOf(receiver, ids[0]); + drop.burnBatch(receiver, ids, values); + uint256 afterBalance = drop.balanceOf(receiver, ids[0]); + assertEq(beforeBalance - values[0], afterBalance); + } + + function test_revert_IdValueMismatch() public tokenClaimed IdValueMismatch callerOwner { + vm.expectRevert("ERC1155: ids and amounts length mismatch"); + drop.burnBatch(receiver, ids, values); + } + + function test_revert_balanceUnderflow() public tokenClaimed callerOwner { + values[0] = 2; + vm.expectRevert(); + drop.burnBatch(receiver, ids, values); + } + + function test_event() public tokenClaimed callerOwner { + vm.expectEmit(true, true, true, true); + emit TransferBatch(receiver, receiver, address(0), ids, values); + drop.burnBatch(receiver, ids, values); + } +} diff --git a/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree b/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree index 0001f4aa9..3c5760e49 100644 --- a/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree +++ b/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree @@ -4,14 +4,14 @@ function burnBatch( uint256[] memory values ) ├── if account does not equal _msgSender() and _msgSender() is not an approved operator for account -│ └── it should revert +│ └── it should revert ✅ └── if account is equal to _msgSender() or _msgSender() is an approved operator for account ├── if ids and values are not the same length - │ └── it should revert + │ └── it should revert ✅ └── if ids and values are the same length ├── if the balance of account for each id is not greater than or equal to the corresponding value - │ └── it should revert + │ └── it should revert ✅ └── if the balance of account for each id is greater than or equal to the corresponding value - ├── it should reduce the balance of each id for account by the corresponding value - ├── it should reduce the total supply of each id by the corresponding value + ├── it should reduce the balance of each id for account by the corresponding value ✅ + ├── it should reduce the total supply of each id by the corresponding value ✅ └── it should emit TransferBatch with the following parameters: _msgSender(), account, address(0), ids, amounts From 7890dedc23ae4259dcf38fe52f218dcdad2bb300 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sat, 7 Oct 2023 17:33:34 -0500 Subject: [PATCH 15/27] test: freezeBatchBaseURI --- .../drop-erc1155/burnBatch/burnBatch.tree | 2 +- .../freezeBatchBaseURI.t.sol | 88 +++++++++++++++++++ .../freezeBatchBaseURI.tree | 12 +-- 3 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.t.sol diff --git a/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree b/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree index 3c5760e49..d45ff14d6 100644 --- a/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree +++ b/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree @@ -14,4 +14,4 @@ function burnBatch( └── if the balance of account for each id is greater than or equal to the corresponding value ├── it should reduce the balance of each id for account by the corresponding value ✅ ├── it should reduce the total supply of each id by the corresponding value ✅ - └── it should emit TransferBatch with the following parameters: _msgSender(), account, address(0), ids, amounts + └── it should emit TransferBatch with the following parameters: _msgSender(), account, address(0), ids, amounts ✅ diff --git a/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.t.sol b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.t.sol new file mode 100644 index 000000000..42b0a0c4b --- /dev/null +++ b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.t.sol @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC2981Upgradeable.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; + +contract DropERC1155Test_freezeBatchBaseURI is BaseTest { + using StringsUpgradeable for uint256; + + event MetadataFrozen(); + + DropERC1155 public drop; + + address private unauthorized = address(0x123); + + bytes private emptyEncodedBytes = abi.encode("", ""); + + function setUp() public override { + super.setUp(); + drop = DropERC1155(getContract("DropERC1155")); + } + + /*/////////////////////////////////////////////////////////////// + Branch Testing + //////////////////////////////////////////////////////////////*/ + + modifier callerWithoutMetadataRole() { + vm.startPrank(unauthorized); + _; + } + + modifier callerWithMetadataRole() { + vm.startPrank(deployer); + _; + } + + modifier lazyMint() { + vm.prank(deployer); + drop.lazyMint(100, "ipfs://", emptyEncodedBytes); + _; + } + + modifier lazyMintEmptyUri() { + vm.prank(deployer); + drop.lazyMint(100, "", emptyEncodedBytes); + _; + } + + function test_revert_NoMetadataRole() public lazyMint callerWithoutMetadataRole { + bytes32 role = keccak256("METADATA_ROLE"); + vm.expectRevert( + abi.encodePacked( + "Permissions: account ", + TWStrings.toHexString(uint160(unauthorized), 20), + " is missing role ", + TWStrings.toHexString(uint256(role), 32) + ) + ); + drop.freezeBatchBaseURI(0); + } + + function test_revert_IndexTooHigh() public lazyMint callerWithMetadataRole { + vm.expectRevert("Invalid index"); + drop.freezeBatchBaseURI(1); + } + + function test_revert_EmptyBaseURI() public lazyMintEmptyUri callerWithMetadataRole { + vm.expectRevert("Invalid batch"); + drop.freezeBatchBaseURI(0); + } + + function test_state() public lazyMint callerWithMetadataRole { + uint256 batchId = drop.getBatchIdAtIndex(0); + drop.freezeBatchBaseURI(0); + assertEq(drop.batchFrozen(batchId), true); + } + + function test_event() public lazyMint callerWithMetadataRole { + vm.expectEmit(false, false, false, false); + emit MetadataFrozen(); + drop.freezeBatchBaseURI(0); + } +} diff --git a/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree index f8d3951ee..bb5da59eb 100644 --- a/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree +++ b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree @@ -1,12 +1,12 @@ function freezeBatchBaseURI(uint256 _index) -├── if the caller does not have metadataRole -│ └── it should revert +├── if the caller does not have metadataRole +│ └── it should revert ✅ └── if the caller has metadataRole ├── if _index is greater than the number of current batches - │ └── it should revert + │ └── it should revert ✅ └── if _index is equal to or less than the number of current batches ├── if the baseURI for the batch at _index is not set - │ └── it should revert + │ └── it should revert ✅ └── if the baseURI for the batch at _index is set - ├── it should set batchFrozen[(batchId for _index)] to true - └── it should emit MetadataFrozen \ No newline at end of file + ├── it should set batchFrozen[(batchId for _index)] to true ✅ + └── it should emit MetadataFrozen ✅ \ No newline at end of file From b8564bb5c77c9a73b74739cca45889588f4539dd Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sat, 7 Oct 2023 17:33:45 -0500 Subject: [PATCH 16/27] test: setMaxTotalSupply --- .../setMaxTotalSupply/setMaxTotalSupply.t.sol | 67 +++++++++++++++++++ .../setMaxTotalSupply/setMaxTotalSupply.tree | 6 +- 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol diff --git a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol new file mode 100644 index 000000000..9fc4d3bf5 --- /dev/null +++ b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC2981Upgradeable.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; + +contract DropERC1155Test_setMaxTotalSupply is BaseTest { + using StringsUpgradeable for uint256; + + DropERC1155 public drop; + + address private unauthorized = address(0x123); + + uint256 private newMaxSupply = 100; + string private updatedBaseURI = "ipfs://"; + + event MaxTotalSupplyUpdated(uint256 tokenId, uint256 maxTotalSupply); + + function setUp() public override { + super.setUp(); + drop = DropERC1155(getContract("DropERC1155")); + } + + /*/////////////////////////////////////////////////////////////// + Branch Testing + //////////////////////////////////////////////////////////////*/ + + modifier callerWithoutAdminRole() { + vm.startPrank(unauthorized); + _; + } + + modifier callerWithAdminRole() { + vm.startPrank(deployer); + _; + } + + function test_revert_NoAdminRole() public callerWithoutAdminRole { + bytes32 role = keccak256("METADATA_ROLE"); + vm.expectRevert( + abi.encodePacked( + "Permissions: account ", + TWStrings.toHexString(uint160(unauthorized), 20), + " is missing role ", + TWStrings.toHexString(uint256(role), 32) + ) + ); + drop.setMaxTotalSupply(0, newMaxSupply); + } + + function test_state() public callerWithAdminRole { + drop.setMaxTotalSupply(0, newMaxSupply); + uint256 newMaxTotalSupply = drop.maxTotalSupply(0); + assertEq(newMaxSupply, newMaxTotalSupply); + } + + function test_event() public callerWithAdminRole { + vm.expectEmit(false, false, false, true); + emit MaxTotalSupplyUpdated(0, newMaxSupply); + drop.setMaxTotalSupply(0, newMaxSupply); + } +} diff --git a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree index 0023edbbe..82b91bbab 100644 --- a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree +++ b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree @@ -1,6 +1,6 @@ function setMaxTotalSupply(uint256 _tokenId, uint256 _maxTotalSupply) ├── if the caller does not have DEFAULT_ADMIN_ROLE -│ └── it should revert +│ └── it should revert ✅ └── if the caller does have DEFAULT_ADMIN_ROLE - ├── it should set maxTotalSupply for _tokenId as _maxTotalSupply - └── it should emit MaxTotalSupplyUpdated with the parameters _tokenId, _maxTotalSupply \ No newline at end of file + ├── it should set maxTotalSupply for _tokenId as _maxTotalSupply ✅ + └── it should emit MaxTotalSupplyUpdated with the parameters _tokenId, _maxTotalSupply ✅ \ No newline at end of file From 8282a3a06dd2cc240f31a54e780e75ba846e4bab Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sat, 7 Oct 2023 17:33:55 -0500 Subject: [PATCH 17/27] test: transferTokensOnClaim --- .../transferTokensOnClaim.t.sol | 130 ++++++++++++++++++ .../transferTokensOnClaim.tree | 6 +- 2 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol diff --git a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol new file mode 100644 index 000000000..11ac3ba20 --- /dev/null +++ b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155, IPermissions, ILazyMint } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; +import "@openzeppelin/contracts/utils/Strings.sol"; + +contract HarnessDropERC1155 is DropERC1155 { + function transferTokensOnClaimHarness(address to, uint256 _tokenId, uint256 _quantityBeingClaimed) external { + transferTokensOnClaim(to, _tokenId, _quantityBeingClaimed); + } + + function initializeHarness( + address _defaultAdmin, + string memory _contractURI, + address _saleRecipient, + address _royaltyRecipient, + uint128 _royaltyBps, + uint128 _platformFeeBps, + address _platformFeeRecipient + ) external { + bytes32 _transferRole = keccak256("TRANSFER_ROLE"); + bytes32 _minterRole = keccak256("MINTER_ROLE"); + bytes32 _metadataRole = keccak256("METADATA_ROLE"); + + _setupContractURI(_contractURI); + _setupOwner(_defaultAdmin); + + _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); + _setupRole(_minterRole, _defaultAdmin); + _setupRole(_transferRole, _defaultAdmin); + _setupRole(_transferRole, address(0)); + _setupRole(_metadataRole, _defaultAdmin); + _setRoleAdmin(_metadataRole, _metadataRole); + + _setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); + _setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps); + _setupPrimarySaleRecipient(_saleRecipient); + } +} + +contract MockERC1155Receiver { + function onERC1155Received(address, address, uint256, uint256, bytes memory) external pure returns (bytes4) { + return this.onERC1155Received.selector; + } + + function onERC1155BatchReceived( + address, + address, + uint256[] memory, + uint256[] memory, + bytes memory + ) external pure returns (bytes4) { + return this.onERC1155BatchReceived.selector; + } +} + +contract MockERC11555NotReceiver {} + +contract DropERC1155Test_transferTokensOnClaim is BaseTest { + using StringsUpgradeable for uint256; + using StringsUpgradeable for address; + + HarnessDropERC1155 public drop; + + address private to; + MockERC1155Receiver private receiver; + MockERC11555NotReceiver private notReceiver; + + function setUp() public override { + super.setUp(); + drop = new HarnessDropERC1155(); + drop.initializeHarness( + address(this), + "https://token-cdn-domain/{id}.json", + deployer, + deployer, + 1000, + 1000, + deployer + ); + receiver = new MockERC1155Receiver(); + notReceiver = new MockERC11555NotReceiver(); + } + + /*/////////////////////////////////////////////////////////////// + Unit tests: misc. + //////////////////////////////////////////////////////////////*/ + + modifier toEOA() { + to = address(0x01); + _; + } + + modifier toReceiever() { + to = address(receiver); + _; + } + + modifier toNotReceiever() { + to = address(notReceiver); + _; + } + + /** + * note: Tests whether contract reverts when a non-holder renounces a role. + */ + function test_revert_ContractNotERC155Receiver() public toNotReceiever { + vm.expectRevert("ERC1155: transfer to non ERC1155Receiver implementer"); + drop.transferTokensOnClaimHarness(to, 0, 1); + } + + function test_state_ContractERC1155Receiver() public toReceiever { + uint256 beforeBalance = drop.balanceOf(to, 0); + drop.transferTokensOnClaimHarness(to, 0, 1); + uint256 afterBalance = drop.balanceOf(to, 0); + assertEq(beforeBalance + 1, afterBalance); + } + + function test_state_EOAReceiver() public toEOA { + uint256 beforeBalance = drop.balanceOf(to, 0); + drop.transferTokensOnClaimHarness(to, 0, 1); + uint256 afterBalance = drop.balanceOf(to, 0); + assertEq(beforeBalance + 1, afterBalance); + } +} diff --git a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree index 9d653e03e..eb600dbed 100644 --- a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree +++ b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.tree @@ -5,8 +5,8 @@ function transferTokensOnClaim( ) ├── when {to} is a smart contract │ ├── when {to} does not implement onERC1155Received -│ │ └── it should revert +│ │ └── it should revert ✅ │ └── when {to} does implement onERC1155Received -│ └── it should mint {amount} number of {id} tokens to {to} +│ └── it should mint {amount} number of {id} tokens to {to} ✅ └── when {to} is an EOA - └── it should mint {amount} number of {id} tokens to {to} \ No newline at end of file + └── it should mint {amount} number of {id} tokens to {to} ✅ \ No newline at end of file From dcde02a21f22414c192cc41da5e17809577dbc8a Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sat, 7 Oct 2023 17:34:06 -0500 Subject: [PATCH 18/27] test: updateBatchBaseURI --- .../updateBatchBaseURI.t.sol | 98 +++++++++++++++++++ .../updateBatchBaseURI.tree | 8 +- 2 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.t.sol diff --git a/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.t.sol b/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.t.sol new file mode 100644 index 000000000..290f6819b --- /dev/null +++ b/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.t.sol @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC2981Upgradeable.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; + +contract DropERC1155Test_updateBatchBaseURI is BaseTest { + using StringsUpgradeable for uint256; + + event MetadataFrozen(); + + DropERC1155 public drop; + + address private unauthorized = address(0x123); + + bytes private emptyEncodedBytes = abi.encode("", ""); + string private updatedBaseURI = "ipfs://"; + + event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId); + + function setUp() public override { + super.setUp(); + drop = DropERC1155(getContract("DropERC1155")); + } + + /*/////////////////////////////////////////////////////////////// + Branch Testing + //////////////////////////////////////////////////////////////*/ + + modifier callerWithoutMetadataRole() { + vm.startPrank(unauthorized); + _; + } + + modifier callerWithMetadataRole() { + vm.startPrank(deployer); + _; + } + + modifier lazyMint() { + vm.prank(deployer); + drop.lazyMint(100, "ipfs://", emptyEncodedBytes); + _; + } + + modifier lazyMintEmptyUri() { + vm.prank(deployer); + drop.lazyMint(100, "", emptyEncodedBytes); + _; + } + + modifier batchFrozen() { + vm.prank(deployer); + drop.freezeBatchBaseURI(0); + _; + } + + function test_revert_NoMetadataRole() public lazyMint callerWithoutMetadataRole { + bytes32 role = keccak256("METADATA_ROLE"); + vm.expectRevert( + abi.encodePacked( + "Permissions: account ", + TWStrings.toHexString(uint160(unauthorized), 20), + " is missing role ", + TWStrings.toHexString(uint256(role), 32) + ) + ); + drop.updateBatchBaseURI(0, updatedBaseURI); + } + + function test_revert_IndexTooHigh() public lazyMint callerWithMetadataRole { + vm.expectRevert("Invalid index"); + drop.updateBatchBaseURI(1, updatedBaseURI); + } + + function test_revert_BatchFrozen() public lazyMint batchFrozen callerWithMetadataRole { + vm.expectRevert("Batch frozen"); + drop.updateBatchBaseURI(0, updatedBaseURI); + } + + function test_state() public lazyMint callerWithMetadataRole { + drop.updateBatchBaseURI(0, updatedBaseURI); + string memory newBaseURI = drop.uri(0); + console.log("newBaseURI: %s", newBaseURI); + assertEq(newBaseURI, string(abi.encodePacked(updatedBaseURI, "0"))); + } + + function test_event() public lazyMint callerWithMetadataRole { + vm.expectEmit(false, false, false, false); + emit BatchMetadataUpdate(0, 100); + drop.updateBatchBaseURI(0, updatedBaseURI); + } +} diff --git a/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree b/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree index ae8b21f5b..75ffaadcf 100644 --- a/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree +++ b/src/test/drop/drop-erc1155/updateBatchBaseURI/updateBatchBaseURI.tree @@ -1,9 +1,9 @@ function updateBatchBaseURI(uint256 _index, string calldata _uri) ├── when the caller does not have metadataRole -│ └── it should revert +│ └── it should revert ✅ └── when the caller has metadataRole ├── when batchFrozen[_batchId for _index] is equal to true - │ └── it should revert + │ └── it should revert ✅ └── when batchFrozen[_batchId for _index] is equal to false - ├── it should set baseURI[_batchId for _index] to _uri - └── it should emit BatchMetadataUpdate with the parameters startingTokenId, _batchId \ No newline at end of file + ├── it should set baseURI[_batchId for _index] to _uri ✅ + └── it should emit BatchMetadataUpdate with the parameters startingTokenId, _batchId ✅ \ No newline at end of file From d46bd39b3e8c8b366a0183f5a52350531412e136 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sun, 8 Oct 2023 00:02:26 -0500 Subject: [PATCH 19/27] test: setSaleRecipientForToken --- .../setSaleRecipientForToken.t.sol | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.t.sol diff --git a/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.t.sol b/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.t.sol new file mode 100644 index 000000000..9c2ae4f51 --- /dev/null +++ b/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.t.sol @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC2981Upgradeable.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; + +contract DropERC1155Test_setSaleRecipientForToken is BaseTest { + using StringsUpgradeable for uint256; + + DropERC1155 public drop; + + address private unauthorized = address(0x123); + address private recipient = address(0x456); + + event SaleRecipientForTokenUpdated(uint256 indexed tokenId, address saleRecipient); + + function setUp() public override { + super.setUp(); + drop = DropERC1155(getContract("DropERC1155")); + } + + /*/////////////////////////////////////////////////////////////// + Branch Testing + //////////////////////////////////////////////////////////////*/ + + modifier callerWithoutAdminRole() { + vm.startPrank(unauthorized); + _; + } + + modifier callerWithAdminRole() { + vm.startPrank(deployer); + _; + } + + function test_revert_NoAdminRole() public callerWithoutAdminRole { + bytes32 role = bytes32(0x00); + vm.expectRevert( + abi.encodePacked( + "Permissions: account ", + TWStrings.toHexString(uint160(unauthorized), 20), + " is missing role ", + TWStrings.toHexString(uint256(role), 32) + ) + ); + drop.setSaleRecipientForToken(0, recipient); + } + + function test_state() public callerWithAdminRole { + drop.setSaleRecipientForToken(0, recipient); + address newSaleRecipient = drop.saleRecipient(0); + assertEq(newSaleRecipient, recipient); + } + + function test_event() public callerWithAdminRole { + vm.expectEmit(true, true, false, false); + emit SaleRecipientForTokenUpdated(0, recipient); + drop.setSaleRecipientForToken(0, recipient); + } +} From cb508c6ea12989e4e3bda5272719fc4ed0953f71 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sun, 8 Oct 2023 00:35:28 -0500 Subject: [PATCH 20/27] test: initialize --- .../drop-erc1155/initialize/initialize.t.sol | 411 ++++++++++++++++++ 1 file changed, 411 insertions(+) create mode 100644 src/test/drop/drop-erc1155/initialize/initialize.t.sol diff --git a/src/test/drop/drop-erc1155/initialize/initialize.t.sol b/src/test/drop/drop-erc1155/initialize/initialize.t.sol new file mode 100644 index 000000000..7bbd9a342 --- /dev/null +++ b/src/test/drop/drop-erc1155/initialize/initialize.t.sol @@ -0,0 +1,411 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; + +contract DropERC1155Test_initializer is BaseTest { + using StringsUpgradeable for uint256; + + DropERC1155 public newDropContract; + + event ContractURIUpdated(string prevURI, string newURI); + event OwnerUpdated(address indexed prevOwner, address indexed newOwner); + event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); + event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); + event PlatformFeeInfoUpdated(address indexed platformFeeRecipient, uint256 platformFeeBps); + event DefaultRoyalty(address indexed newRoyaltyRecipient, uint256 newRoyaltyBps); + event PrimarySaleRecipientUpdated(address indexed recipient); + + function setUp() public override { + super.setUp(); + } + + modifier royaltyBPSTooHigh() { + uint128 royaltyBps = 10001; + _; + } + + modifier platformFeeBPSTooHigh() { + uint128 platformFeeBps = 10001; + _; + } + + function test_state() public { + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + + newDropContract = DropERC1155(getContract("DropERC1155")); + (address _platformFeeRecipient, uint128 _platformFeeBps) = newDropContract.getPlatformFeeInfo(); + (address _royaltyRecipient, uint128 _royaltyBps) = newDropContract.getDefaultRoyaltyInfo(); + address _saleRecipient = newDropContract.primarySaleRecipient(); + + for (uint256 i = 0; i < forwarders().length; i++) { + assertEq(newDropContract.isTrustedForwarder(forwarders()[i]), true); + } + + assertEq(newDropContract.name(), NAME); + assertEq(newDropContract.symbol(), SYMBOL); + assertEq(newDropContract.contractURI(), CONTRACT_URI); + assertEq(newDropContract.owner(), deployer); + assertEq(_platformFeeRecipient, platformFeeRecipient); + assertEq(_platformFeeBps, platformFeeBps); + assertEq(_royaltyRecipient, royaltyRecipient); + assertEq(_royaltyBps, royaltyBps); + assertEq(_saleRecipient, saleRecipient); + } + + function test_revert_RoyaltyBPSTooHigh() public royaltyBPSTooHigh { + vm.expectRevert("Exceeds max bps"); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + 10001, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_revert_PlatformFeeBPSTooHigh() public platformFeeBPSTooHigh { + vm.expectRevert("Exceeds max bps"); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + 10001, + platformFeeRecipient + ) + ) + ); + } + + function test_event_ContractURIUpdated() public { + vm.expectEmit(false, false, false, true); + emit ContractURIUpdated("", CONTRACT_URI); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_event_OwnerUpdated() public { + vm.expectEmit(true, true, false, false); + emit OwnerUpdated(address(0), deployer); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_event_RoleGrantedDefaultAdminRole() public { + bytes32 role = bytes32(0x00); + vm.expectEmit(true, true, true, false); + emit RoleGranted(role, deployer, 0xf29D12e4c9d593D2887EEDDe076bBe39EDf3cD0F); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_event_RoleGrantedMinterRole() public { + bytes32 role = keccak256("MINTER_ROLE"); + vm.expectEmit(true, true, true, false); + emit RoleGranted(role, deployer, 0xf29D12e4c9d593D2887EEDDe076bBe39EDf3cD0F); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_event_RoleGrantedTransferRole() public { + bytes32 role = keccak256("TRANSFER_ROLE"); + vm.expectEmit(true, true, true, false); + emit RoleGranted(role, deployer, 0xf29D12e4c9d593D2887EEDDe076bBe39EDf3cD0F); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_event_RoleGrantedTransferRoleZeroAddress() public { + bytes32 role = keccak256("TRANSFER_ROLE"); + vm.expectEmit(true, true, true, false); + emit RoleGranted(role, address(0), 0xf29D12e4c9d593D2887EEDDe076bBe39EDf3cD0F); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_event_RoleGrantedMetadataRole() public { + bytes32 role = keccak256("METADATA_ROLE"); + vm.expectEmit(true, true, true, false); + emit RoleGranted(role, deployer, 0xf29D12e4c9d593D2887EEDDe076bBe39EDf3cD0F); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_event_RoleAdminChangedMetadataRole() public { + bytes32 role = keccak256("METADATA_ROLE"); + vm.expectEmit(true, true, true, false); + emit RoleAdminChanged(role, bytes32(0x00), role); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_event_PlatformFeeInfoUpdated() public { + vm.expectEmit(true, false, false, true); + emit PlatformFeeInfoUpdated(platformFeeRecipient, platformFeeBps); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_event_DefaultRoyalty() public { + vm.expectEmit(true, false, false, true); + emit DefaultRoyalty(royaltyRecipient, royaltyBps); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_event_PrimarySaleRecipientUpdated() public { + vm.expectEmit(true, false, false, false); + emit PrimarySaleRecipientUpdated(saleRecipient); + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + } + + function test_roleCheck() public { + deployContractProxy( + "DropERC1155", + abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) + ) + ); + + newDropContract = DropERC1155(getContract("DropERC1155")); + + assertEq(newDropContract.hasRole(bytes32(0x00), deployer), true); + assertEq(newDropContract.hasRole(keccak256("MINTER_ROLE"), deployer), true); + assertEq(newDropContract.hasRole(keccak256("TRANSFER_ROLE"), deployer), true); + assertEq(newDropContract.hasRole(keccak256("TRANSFER_ROLE"), address(0)), true); + assertEq(newDropContract.hasRole(keccak256("METADATA_ROLE"), deployer), true); + + assertEq(newDropContract.getRoleAdmin(keccak256("METADATA_ROLE")), keccak256("METADATA_ROLE")); + } +} \ No newline at end of file From bdb94790601d88f8759a6601f72006be2164d2d9 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sun, 8 Oct 2023 00:44:31 -0500 Subject: [PATCH 21/27] test: collectPriceOnClaim --- .../collectPriceOnClaim.t.sol | 283 ++++++++++++++++++ .../collectPriceOnClaim.tree | 34 +-- 2 files changed, 300 insertions(+), 17 deletions(-) create mode 100644 src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol diff --git a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol new file mode 100644 index 000000000..be442b59d --- /dev/null +++ b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol @@ -0,0 +1,283 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; + +contract HarnessDropERC1155 is DropERC1155 { + function collectPriceOnClaimHarness( + uint256 _tokenId, + address _primarySaleRecipient, + uint256 _quantityToClaim, + address _currency, + uint256 _pricePerToken + ) public payable { + collectPriceOnClaim(_tokenId, _primarySaleRecipient, _quantityToClaim, _currency, _pricePerToken); + } + + function initializeHarness( + address _defaultAdmin, + string memory _contractURI, + address _saleRecipient, + address _royaltyRecipient, + uint128 _royaltyBps, + uint128 _platformFeeBps, + address _platformFeeRecipient + ) external { + bytes32 _transferRole = keccak256("TRANSFER_ROLE"); + bytes32 _minterRole = keccak256("MINTER_ROLE"); + bytes32 _metadataRole = keccak256("METADATA_ROLE"); + + _setupContractURI(_contractURI); + _setupOwner(_defaultAdmin); + + _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); + _setupRole(_minterRole, _defaultAdmin); + _setupRole(_transferRole, _defaultAdmin); + _setupRole(_transferRole, address(0)); + _setupRole(_metadataRole, _defaultAdmin); + _setRoleAdmin(_metadataRole, _metadataRole); + + _setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); + _setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps); + _setupPrimarySaleRecipient(_saleRecipient); + } +} + +contract DropERC1155Test_collectPrice is BaseTest { + using StringsUpgradeable for uint256; + + HarnessDropERC1155 public dropImp; + + address private collectPrice_saleRecipient = address(0x010); + address private collectPrice_royaltyRecipient = address(0x011); + uint128 private collectPrice_royaltyBps = 1000; + uint128 private collectPrice_platformFeeBps = 1000; + address private collectPrice_platformFeeRecipient = address(0x012); + uint256 private collectPrice_quantityToClaim = 1; + uint256 private collectPrice_pricePerToken; + address private collectPrice_currency; + uint256 private collectPrice_msgValue; + address private collectPrice_tokenSaleRecipient = address(0x111); + + function setUp() public override { + super.setUp(); + + dropImp = new HarnessDropERC1155(); + dropImp.initializeHarness( + deployer, + CONTRACT_URI, + collectPrice_saleRecipient, + collectPrice_royaltyRecipient, + collectPrice_royaltyBps, + collectPrice_platformFeeBps, + collectPrice_platformFeeRecipient + ); + } + + modifier pricePerTokenZero() { + collectPrice_pricePerToken = 0; + _; + } + + modifier pricePerTokenNotZero() { + collectPrice_pricePerToken = 1 ether; + _; + } + + modifier msgValueNotZero() { + collectPrice_msgValue = 1 ether; + _; + } + + modifier nativeCurrency() { + collectPrice_currency = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; + _; + } + + modifier erc20Currency() { + collectPrice_currency = address(erc20); + erc20.mint(address(this), 1_000 ether); + _; + } + + modifier primarySaleRecipientZeroAddress() { + collectPrice_saleRecipient = address(0); + _; + } + + modifier primarySaleRecipientNotZeroAddress() { + collectPrice_saleRecipient = address(0x112); + _; + } + + modifier saleRecipientSet() { + vm.prank(deployer); + dropImp.setSaleRecipientForToken(0, address(0x111)); + _; + } + + /*/////////////////////////////////////////////////////////////// + Branch Testing + //////////////////////////////////////////////////////////////*/ + + function test_revert_msgValueNotZero() public nativeCurrency msgValueNotZero pricePerTokenZero { + vm.expectRevert(); + dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + 0, + collectPrice_saleRecipient, + collectPrice_quantityToClaim, + collectPrice_currency, + collectPrice_pricePerToken + ); + } + + function test_msgValueZero_return() public nativeCurrency pricePerTokenZero { + dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + 0, + collectPrice_saleRecipient, + collectPrice_quantityToClaim, + collectPrice_currency, + collectPrice_pricePerToken + ); + } + + + function test_revert_priceValueMismatchNativeCurrency() public nativeCurrency pricePerTokenNotZero { + vm.expectRevert(); + dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + 0, + collectPrice_saleRecipient, + collectPrice_quantityToClaim, + collectPrice_currency, + collectPrice_pricePerToken + ); + } + + function test_transferNativeCurrencyToSaleRecipient() public nativeCurrency pricePerTokenNotZero msgValueNotZero { + uint256 balanceSaleRecipientBefore = address(collectPrice_saleRecipient).balance; + uint256 platformFeeRecipientBefore = address(collectPrice_platformFeeRecipient).balance; + dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + 0, + collectPrice_saleRecipient, + collectPrice_quantityToClaim, + collectPrice_currency, + collectPrice_pricePerToken + ); + + uint256 balanceSaleRecipientAfter = address(collectPrice_saleRecipient).balance; + uint256 platformFeeRecipientAfter = address(collectPrice_platformFeeRecipient).balance; + uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 expectedSaleRecipientProceed = collectPrice_msgValue - expectedPlatformFee; + + assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); + assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); + } + + function test_transferERC20ToSaleRecipient() public erc20Currency pricePerTokenNotZero { + uint256 balanceSaleRecipientBefore = erc20.balanceOf(collectPrice_saleRecipient); + uint256 platformFeeRecipientBefore = erc20.balanceOf(collectPrice_platformFeeRecipient); + erc20.approve(address(dropImp), collectPrice_pricePerToken); + dropImp.collectPriceOnClaimHarness( + 0, + collectPrice_saleRecipient, + collectPrice_quantityToClaim, + collectPrice_currency, + collectPrice_pricePerToken + ); + + uint256 balanceSaleRecipientAfter = erc20.balanceOf(collectPrice_saleRecipient); + uint256 platformFeeRecipientAfter = erc20.balanceOf(collectPrice_platformFeeRecipient); + uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 expectedSaleRecipientProceed = collectPrice_pricePerToken - expectedPlatformFee; + + assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); + assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); + } + + function test_transferNativeCurrencyToTokenIdSaleRecipient() public nativeCurrency pricePerTokenNotZero msgValueNotZero saleRecipientSet primarySaleRecipientZeroAddress { + uint256 balanceSaleRecipientBefore = address(collectPrice_tokenSaleRecipient).balance; + uint256 platformFeeRecipientBefore = address(collectPrice_platformFeeRecipient).balance; + dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + 0, + address(0), + collectPrice_quantityToClaim, + collectPrice_currency, + collectPrice_pricePerToken + ); + + uint256 balanceSaleRecipientAfter = address(collectPrice_tokenSaleRecipient).balance; + uint256 platformFeeRecipientAfter = address(collectPrice_platformFeeRecipient).balance; + uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 expectedSaleRecipientProceed = collectPrice_msgValue - expectedPlatformFee; + + assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); + assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); + } + + function test_transferERc20ToTokenIdSaleRecipient() public erc20Currency pricePerTokenNotZero saleRecipientSet primarySaleRecipientZeroAddress { + uint256 balanceSaleRecipientBefore = erc20.balanceOf(collectPrice_tokenSaleRecipient); + uint256 platformFeeRecipientBefore = erc20.balanceOf(collectPrice_platformFeeRecipient); + erc20.approve(address(dropImp), collectPrice_pricePerToken); + dropImp.collectPriceOnClaimHarness( + 0, + address(0), + collectPrice_quantityToClaim, + collectPrice_currency, + collectPrice_pricePerToken + ); + + uint256 balanceSaleRecipientAfter = erc20.balanceOf(collectPrice_tokenSaleRecipient); + uint256 platformFeeRecipientAfter = erc20.balanceOf(collectPrice_platformFeeRecipient); + uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 expectedSaleRecipientProceed = collectPrice_pricePerToken - expectedPlatformFee; + + assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); + assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); + } + + function test_transferNativeCurrencyToPrimarySaleRecipient() public nativeCurrency pricePerTokenNotZero msgValueNotZero { + uint256 balanceSaleRecipientBefore = address(collectPrice_saleRecipient).balance; + uint256 platformFeeRecipientBefore = address(collectPrice_platformFeeRecipient).balance; + dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + 0, + address(0), + collectPrice_quantityToClaim, + collectPrice_currency, + collectPrice_pricePerToken + ); + + uint256 balanceSaleRecipientAfter = address(collectPrice_saleRecipient).balance; + uint256 platformFeeRecipientAfter = address(collectPrice_platformFeeRecipient).balance; + uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 expectedSaleRecipientProceed = collectPrice_msgValue - expectedPlatformFee; + + assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); + assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); + } + + function test_transferERC20ToPrimarySaleRecipient() public erc20Currency pricePerTokenNotZero { + uint256 balanceSaleRecipientBefore = erc20.balanceOf(collectPrice_saleRecipient); + uint256 platformFeeRecipientBefore = erc20.balanceOf(collectPrice_platformFeeRecipient); + erc20.approve(address(dropImp), collectPrice_pricePerToken); + dropImp.collectPriceOnClaimHarness( + 0, + address(0), + collectPrice_quantityToClaim, + collectPrice_currency, + collectPrice_pricePerToken + ); + + uint256 balanceSaleRecipientAfter = erc20.balanceOf(collectPrice_saleRecipient); + uint256 platformFeeRecipientAfter = erc20.balanceOf(collectPrice_platformFeeRecipient); + uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 expectedSaleRecipientProceed = collectPrice_pricePerToken - expectedPlatformFee; + + assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); + assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); + } +} \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree index 0e3ab8c9a..6cb5cd180 100644 --- a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree +++ b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.tree @@ -7,38 +7,38 @@ function collectPriceOnClaim( ) ├── when _pricePerToken is equal to zero │ ├── when msg.value does not equal to zero -│ │ └── it should revert +│ │ └── it should revert ✅ │ └── when msg.value is equal to zero -│ └── it should return +│ └── it should return ✅ └── when _pricePerToken is not equal to zero ├── when _primarySaleRecipient is equal to address(0) │ ├── when saleRecipient for _tokenId is equal to address(0) │ │ ├── when currency is native token │ │ │ ├── when msg.value does not equal totalPrice - │ │ │ │ └── it should revert + │ │ │ │ └── it should revert ✅ │ │ │ └── when msg.value does equal totalPrice - │ │ │ ├── it should transfer platformFees to platformFeeRecipient in native token - │ │ │ └── it should transfer totalPrice - platformFees to primarySaleRecipient in native token + │ │ │ ├── it should transfer platformFees to platformFeeRecipient in native token ✅ + │ │ │ └── it should transfer totalPrice - platformFees to primarySaleRecipient in native token ✅ │ │ └── when currency is not native token - │ │ ├── it should transfer platformFees to platformFeeRecipient in _currency token - │ │ └── it should transfer totalPrice - platformFees to primarySaleRecipient in _currency token + │ │ ├── it should transfer platformFees to platformFeeRecipient in _currency token ✅ + │ │ └── it should transfer totalPrice - platformFees to primarySaleRecipient in _currency token ✅ │ └── when salerecipient for _tokenId is not equal to address(0) │ ├── when currency is native token │ │ ├── when msg.value does not equal totalPrice - │ │ │ └── it should revert + │ │ │ └── it should revert ✅ │ │ └── when msg.value does equal totalPrice - │ │ ├── it should transfer platformFees to platformFeeRecipient in native token - │ │ └── it should transfer totalPrice - platformFees to saleRecipient for _tokenId in native token + │ │ ├── it should transfer platformFees to platformFeeRecipient in native token ✅ + │ │ └── it should transfer totalPrice - platformFees to saleRecipient for _tokenId in native token ✅ │ └── when currency is not native token - │ ├── it should transfer platformFees to platformFeeRecipient in _currency token - │ └── it should transfer totalPrice - platformFees to saleRecipient for _tokenId in _currency token + │ ├── it should transfer platformFees to platformFeeRecipient in _currency token ✅ + │ └── it should transfer totalPrice - platformFees to saleRecipient for _tokenId in _currency token ✅ └── when _primarySaleRecipient is not equal to address(0) ├── when currency is native token │ ├── when msg.value does not equal totalPrice - │ │ └── it should revert + │ │ └── it should revert ✅ │ └── when msg.value does equal totalPrice - │ ├── it should transfer platformFees to platformFeeRecipient in native token - │ └── it should transfer totalPrice - platformFees to _primarySaleRecipient in native token + │ ├── it should transfer platformFees to platformFeeRecipient in native token ✅ + │ └── it should transfer totalPrice - platformFees to _primarySaleRecipient in native token ✅ └── when currency is not native token - ├── it should transfer platformFees to platformFeeRecipient in _currency token - └── it should transfer totalPrice - platformFees to _primarySaleRecipient in _currency token \ No newline at end of file + ├── it should transfer platformFees to platformFeeRecipient in _currency token ✅ + └── it should transfer totalPrice - platformFees to _primarySaleRecipient in _currency token ✅ \ No newline at end of file From fc826ee3f2ac7686044edbd339b19d0e0c3c4fa5 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sun, 8 Oct 2023 00:44:45 -0500 Subject: [PATCH 22/27] test: setMaxTotalSupply --- .../drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol index 9fc4d3bf5..6239cccf1 100644 --- a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol +++ b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol @@ -41,7 +41,7 @@ contract DropERC1155Test_setMaxTotalSupply is BaseTest { } function test_revert_NoAdminRole() public callerWithoutAdminRole { - bytes32 role = keccak256("METADATA_ROLE"); + bytes32 role = bytes32(0x00); vm.expectRevert( abi.encodePacked( "Permissions: account ", From c4db359db1d5f096100ddeba18808092d0065550 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sun, 8 Oct 2023 00:45:15 -0500 Subject: [PATCH 23/27] lint --- .../_beforeTokenTransfer.sol | 9 +++++- .../collectPriceOnClaim.t.sol | 31 ++++++++++++++----- .../drop-erc1155/initialize/initialize.t.sol | 2 +- .../transferTokensOnClaim.t.sol | 14 +++++++-- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol index 8d913b628..c7f3b692a 100644 --- a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol +++ b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol @@ -116,7 +116,14 @@ contract DropERC1155Test_beforeTokenTransfer is BaseTest { } function test_state_tranferToZero() public toAddressZero { - drop.beforeTokenTransfer(deployer, beforeTransfer_to, beforeTransfer_from, beforeTransfer_ids, beforeTransfer_amounts, beforeTransfer_data); + drop.beforeTokenTransfer( + deployer, + beforeTransfer_to, + beforeTransfer_from, + beforeTransfer_ids, + beforeTransfer_amounts, + beforeTransfer_data + ); uint256 beforeTokenTotalSupply = drop.totalSupply(0); drop.beforeTokenTransfer( deployer, diff --git a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol index be442b59d..835efa75e 100644 --- a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol +++ b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol @@ -10,7 +10,7 @@ import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; contract HarnessDropERC1155 is DropERC1155 { function collectPriceOnClaimHarness( - uint256 _tokenId, + uint256 _tokenId, address _primarySaleRecipient, uint256 _quantityToClaim, address _currency, @@ -119,7 +119,7 @@ contract DropERC1155Test_collectPrice is BaseTest { vm.prank(deployer); dropImp.setSaleRecipientForToken(0, address(0x111)); _; - } + } /*/////////////////////////////////////////////////////////////// Branch Testing @@ -146,7 +146,6 @@ contract DropERC1155Test_collectPrice is BaseTest { ); } - function test_revert_priceValueMismatchNativeCurrency() public nativeCurrency pricePerTokenNotZero { vm.expectRevert(); dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( @@ -199,7 +198,14 @@ contract DropERC1155Test_collectPrice is BaseTest { assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); } - function test_transferNativeCurrencyToTokenIdSaleRecipient() public nativeCurrency pricePerTokenNotZero msgValueNotZero saleRecipientSet primarySaleRecipientZeroAddress { + function test_transferNativeCurrencyToTokenIdSaleRecipient() + public + nativeCurrency + pricePerTokenNotZero + msgValueNotZero + saleRecipientSet + primarySaleRecipientZeroAddress + { uint256 balanceSaleRecipientBefore = address(collectPrice_tokenSaleRecipient).balance; uint256 platformFeeRecipientBefore = address(collectPrice_platformFeeRecipient).balance; dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( @@ -219,7 +225,13 @@ contract DropERC1155Test_collectPrice is BaseTest { assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); } - function test_transferERc20ToTokenIdSaleRecipient() public erc20Currency pricePerTokenNotZero saleRecipientSet primarySaleRecipientZeroAddress { + function test_transferERc20ToTokenIdSaleRecipient() + public + erc20Currency + pricePerTokenNotZero + saleRecipientSet + primarySaleRecipientZeroAddress + { uint256 balanceSaleRecipientBefore = erc20.balanceOf(collectPrice_tokenSaleRecipient); uint256 platformFeeRecipientBefore = erc20.balanceOf(collectPrice_platformFeeRecipient); erc20.approve(address(dropImp), collectPrice_pricePerToken); @@ -240,7 +252,12 @@ contract DropERC1155Test_collectPrice is BaseTest { assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); } - function test_transferNativeCurrencyToPrimarySaleRecipient() public nativeCurrency pricePerTokenNotZero msgValueNotZero { + function test_transferNativeCurrencyToPrimarySaleRecipient() + public + nativeCurrency + pricePerTokenNotZero + msgValueNotZero + { uint256 balanceSaleRecipientBefore = address(collectPrice_saleRecipient).balance; uint256 platformFeeRecipientBefore = address(collectPrice_platformFeeRecipient).balance; dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( @@ -280,4 +297,4 @@ contract DropERC1155Test_collectPrice is BaseTest { assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); } -} \ No newline at end of file +} diff --git a/src/test/drop/drop-erc1155/initialize/initialize.t.sol b/src/test/drop/drop-erc1155/initialize/initialize.t.sol index 7bbd9a342..78ef51f76 100644 --- a/src/test/drop/drop-erc1155/initialize/initialize.t.sol +++ b/src/test/drop/drop-erc1155/initialize/initialize.t.sol @@ -408,4 +408,4 @@ contract DropERC1155Test_initializer is BaseTest { assertEq(newDropContract.getRoleAdmin(keccak256("METADATA_ROLE")), keccak256("METADATA_ROLE")); } -} \ No newline at end of file +} diff --git a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol index 11ac3ba20..a18df9a29 100644 --- a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol +++ b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol @@ -10,7 +10,11 @@ import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; contract HarnessDropERC1155 is DropERC1155 { - function transferTokensOnClaimHarness(address to, uint256 _tokenId, uint256 _quantityBeingClaimed) external { + function transferTokensOnClaimHarness( + address to, + uint256 _tokenId, + uint256 _quantityBeingClaimed + ) external { transferTokensOnClaim(to, _tokenId, _quantityBeingClaimed); } @@ -44,7 +48,13 @@ contract HarnessDropERC1155 is DropERC1155 { } contract MockERC1155Receiver { - function onERC1155Received(address, address, uint256, uint256, bytes memory) external pure returns (bytes4) { + function onERC1155Received( + address, + address, + uint256, + uint256, + bytes memory + ) external pure returns (bytes4) { return this.onERC1155Received.selector; } From d4318fc6de9d68766ff5c5177764b61661ae9412 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sun, 8 Oct 2023 21:34:31 -0500 Subject: [PATCH 24/27] clean --- .../_beforeClaim/_beforeClaim.tree | 2 +- .../_beforeTokenTransfer.tree | 4 +- .../_canSetFunctions/_canSetFunctions.tree | 28 ++++---- .../drop-erc1155/burnBatch/burnBatch.tree | 2 +- .../drop-erc1155/initialize/initialize.tree | 66 +++++++++---------- .../setSaleRecipientForToken.tree | 8 +-- 6 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree index 2bd2d6288..cb31a962d 100644 --- a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree +++ b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree @@ -9,4 +9,4 @@ function _beforeClaim( ) └── if maxTotalSupply for _tokenId is not zero └── if totalSupply of _tokenId + _quantity is greater than or equal to maxTotalSupply for _tokenId - └── it should revert \ No newline at end of file + └── it should revert ✅ \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree index c8fc8ed14..b5e147b76 100644 --- a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree +++ b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.tree @@ -7,6 +7,6 @@ function _beforeTokenTransfer( bytes memory data ) ├── when from equals to address(0) -│ └── totalSupply for each id is incremented by the corresponding amounts +│ └── totalSupply for each id is incremented by the corresponding amounts ✅ └── when to equals address(0) - └── totalSupply for each id is decremented by the corresponding amounts \ No newline at end of file + └── totalSupply for each id is decremented by the corresponding amounts ✅ \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree index 1c0a77f04..d0a041b06 100644 --- a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree +++ b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree @@ -1,41 +1,41 @@ function _canSetPlatformFeeInfo() ├── if caller has DEFAULT_ADMIN_ROLE -│ └── it should return true +│ └── it should return true ✅ └── if caller does not have DEFAULT_ADMIN_ROLE - └── it should return false + └── it should return false ✅ function _canSetPrimarySaleRecipient() ├── if caller has DEFAULT_ADMIN_ROLE -│ └── it should return true +│ └── it should return true ✅ └── if caller does not have DEFAULT_ADMIN_ROLE - └── it should return false + └── it should return false ✅ function _canSetOwner() ├── if caller has DEFAULT_ADMIN_ROLE -│ └── it should return true +│ └── it should return true ✅ └── if caller does not have DEFAULT_ADMIN_ROLE - └── it should return false + └── it should return false ✅ function _canSetRoyaltyInfo() ├── if caller has DEFAULT_ADMIN_ROLE -│ └── it should return true +│ └── it should return true ✅ └── if caller does not have DEFAULT_ADMIN_ROLE - └── it should return false + └── it should return false ✅ function _canSetContractURI() ├── if caller has DEFAULT_ADMIN_ROLE -│ └── it should return true +│ └── it should return true ✅ └── if caller does not have DEFAULT_ADMIN_ROLE - └── it should return false + └── it should return false ✅ function _canSetClaimConditions() ├── if caller has DEFAULT_ADMIN_ROLE -│ └── it should return true +│ └── it should return true ✅ └── if caller does not have DEFAULT_ADMIN_ROLE - └── it should return false + └── it should return false ✅ function _canLazyMint() ├── if caller has minterRole -│ └── it should return true +│ └── it should return true ✅ └── if caller does not have minterRole - └── it should return false \ No newline at end of file + └── it should return false ✅ \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree b/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree index d45ff14d6..5465bb497 100644 --- a/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree +++ b/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree @@ -14,4 +14,4 @@ function burnBatch( └── if the balance of account for each id is greater than or equal to the corresponding value ├── it should reduce the balance of each id for account by the corresponding value ✅ ├── it should reduce the total supply of each id by the corresponding value ✅ - └── it should emit TransferBatch with the following parameters: _msgSender(), account, address(0), ids, amounts ✅ + └── it should emit TransferBatch with the following parameters: _msgSender(), account, address(0), ids, amounts ✅ \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/initialize/initialize.tree b/src/test/drop/drop-erc1155/initialize/initialize.tree index e29c1e463..76c8d15d0 100644 --- a/src/test/drop/drop-erc1155/initialize/initialize.tree +++ b/src/test/drop/drop-erc1155/initialize/initialize.tree @@ -11,40 +11,40 @@ function initialize( address _platformFeeRecipient ) ├── when _trustedForwarders.length > 0 -│ └── it should set _trustedForwarder[_trustedForwarders[i]] as true for each address in _trustedForwarders -├── it should set _uri to an empty string -├── it should set contractURI as _contractURI -├── it should emit ContractURIUpdated with the parameters: prevURI, _uri -├── it should set _defaultAdmin as the owner of the contract -├── it should emit OwnerUpdated with the parameters: _prevOwner, _defaultAdmin -├── it should assign the role DEFAULT_ADMIN_ROLE to _defaultAdmin -├── it should emit RoleGranted with the parameters: DEFAULT_ADMIN_ROLE, _defaultAdmin, msg.sender -├── it should assign the role _minterRole to _defaultAdmin -├── it should emit RoleGranted with the parameters: _minterRole, _defaultAdmin, msg.sender -├── it should assign the role _transferRole to _defaultAdmin -├── it should emit RoleGranted with the parameters: _transferRole, _defaultAdmin, msg.sender -├── it should assign the role _transferRole to address(0) -├── it should emit RoleGranted with the parameters: _transferRole, address(0), msg.sender -├── it should assign the role _metadataRole to _defaultAdmin -├── it should emit RoleGranted with the parameters: _metadataRole, _defaultAdmin, msg.sender -├── it should set _getAdminRole[_metadataRole] to equal _metadataRole -├── it should emit RoleAdminChanged with the parameters _metadataRole, previousAdminRole, _metadataRole +│ └── it should set _trustedForwarder[_trustedForwarders[i]] as true for each address in _trustedForwarders ✅ +├── it should set _uri to an empty string ✅ +├── it should set contractURI as _contractURI ✅ +├── it should emit ContractURIUpdated with the parameters: prevURI, _uri ✅ +├── it should set _defaultAdmin as the owner of the contract ✅ +├── it should emit OwnerUpdated with the parameters: _prevOwner, _defaultAdmin ✅ +├── it should assign the role DEFAULT_ADMIN_ROLE to _defaultAdmin ✅ +├── it should emit RoleGranted with the parameters: DEFAULT_ADMIN_ROLE, _defaultAdmin, msg.sender ✅ +├── it should assign the role _minterRole to _defaultAdmin ✅ +├── it should emit RoleGranted with the parameters: _minterRole, _defaultAdmin, msg.sender ✅ +├── it should assign the role _transferRole to _defaultAdmin ✅ +├── it should emit RoleGranted with the parameters: _transferRole, _defaultAdmin, msg.sender ✅ +├── it should assign the role _transferRole to address(0) ✅ +├── it should emit RoleGranted with the parameters: _transferRole, address(0), msg.sender ✅ +├── it should assign the role _metadataRole to _defaultAdmin ✅ +├── it should emit RoleGranted with the parameters: _metadataRole, _defaultAdmin, msg.sender ✅ +├── it should set _getAdminRole[_metadataRole] to equal _metadataRole ✅ +├── it should emit RoleAdminChanged with the parameters _metadataRole, previousAdminRole, _metadataRole ✅ ├── when _platformFeeBps is greater than 10_000 -│ └── it should revert +│ └── it should revert ✅ ├── when _platformFeeBps is less than or equal to 10_000 -│ ├── it should set platformFeeBps to uint16(_platformFeeBps); -│ ├── it should set platformFeeRecipient to _platformFeeRecipient -│ └── it should emit PlatformFeeInfoUpdated with the following parameters: _platformFeeRecipient, _platformFeeBps +│ ├── it should set platformFeeBps to uint16(_platformFeeBps); ✅ +│ ├── it should set platformFeeRecipient to _platformFeeRecipient ✅ +│ └── it should emit PlatformFeeInfoUpdated with the following parameters: _platformFeeRecipient, _platformFeeBps ✅ ├── when _royaltyBps is greater than 10_000 -│ └── it should revert +│ └── it should revert ✅ ├── when _royaltyBps is less than or equal to 10_000 -│ ├── it should set royaltyRecipient as _royaltyRecipient -│ ├── it should set royaltyBps as uint16(_royaltyBps) -│ └── it should emit DefaultRoyalty with the parameters _royaltyRecipient, _royaltyBps -├── it should set recipient as _primarySaleRecipient -├── it should emit PrimarySaleRecipientUpdated with the parameters _primarySaleRecipient -├── it should set transferRole as keccak256("TRANSFER_ROLE") -├── it should set minterRole as keccak256("MINTER_ROLE") -├── it should set metadataRole as keccak256("METADATA_ROLE") -├── it should set name as _name -└── it should set symbol as _symbol +│ ├── it should set royaltyRecipient as _royaltyRecipient ✅ +│ ├── it should set royaltyBps as uint16(_royaltyBps) ✅ +│ └── it should emit DefaultRoyalty with the parameters _royaltyRecipient, _royaltyBps ✅ +├── it should set recipient as _primarySaleRecipient ✅ +├── it should emit PrimarySaleRecipientUpdated with the parameters _primarySaleRecipient ✅ +├── it should set transferRole as keccak256("TRANSFER_ROLE") ✅ +├── it should set minterRole as keccak256("MINTER_ROLE") ✅ +├── it should set metadataRole as keccak256("METADATA_ROLE") ✅ +├── it should set name as _name ✅ +└── it should set symbol as _symbol ✅ diff --git a/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree b/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree index 4e7bd4ac7..72d7c2cad 100644 --- a/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree +++ b/src/test/drop/drop-erc1155/setSaleRecipientForToken/setSaleRecipientForToken.tree @@ -1,6 +1,6 @@ function setSaleRecipientForToken(uint256 _tokenId, address _saleRecipient) -├── when called by a user without DEFAULT_ADMIN_ROLE -│ └── it should revert +├── when called by a user without DEFAULT_ADMIN_ROLE +│ └── it should revert ✅ └── when called by a user with DEFAULT_ADMIN_ROLE - ├── it should set saleRecipient for _tokenId as _saleRecipient - └── it should emit SaleRecipientForTokenUpdated with the parameters _tokenId, _saleRecipient \ No newline at end of file + ├── it should set saleRecipient for _tokenId as _saleRecipient ✅ + └── it should emit SaleRecipientForTokenUpdated with the parameters _tokenId, _saleRecipient ✅ \ No newline at end of file From 8302ebb0eb92c7514d0bda81492c3eae73d4dc71 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Sun, 8 Oct 2023 21:34:38 -0500 Subject: [PATCH 25/27] test: misc --- .../miscellaneous/miscellaneous.t.sol | 76 +++++++++++++++++++ .../miscellaneous/miscellaneous.tree | 0 2 files changed, 76 insertions(+) create mode 100644 src/test/drop/drop-erc1155/miscellaneous/miscellaneous.t.sol create mode 100644 src/test/drop/drop-erc1155/miscellaneous/miscellaneous.tree diff --git a/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.t.sol b/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.t.sol new file mode 100644 index 000000000..0698b911e --- /dev/null +++ b/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.t.sol @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; + +// Test imports +import "contracts/lib/TWStrings.sol"; +import "../../../utils/BaseTest.sol"; +import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC2981Upgradeable.sol"; +import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC1155Upgradeable.sol"; +import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC1155MetadataURIUpgradeable.sol"; + +import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; + +contract DropERC1155Test_misc is BaseTest { + using StringsUpgradeable for uint256; + + DropERC1155 public drop; + + address private unauthorized = address(0x123); + address private receiver; + + bytes private emptyEncodedBytes = abi.encode("", ""); + + function setUp() public override { + super.setUp(); + drop = DropERC1155(getContract("DropERC1155")); + } + + /*/////////////////////////////////////////////////////////////// + Branch Testing + //////////////////////////////////////////////////////////////*/ + + modifier lazyMint() { + vm.prank(deployer); + drop.lazyMint(10, "ipfs://", emptyEncodedBytes); + _; + } + + function test_nextTokenIdToMint_ZeroLazyMinted() public { + uint256 nextTokenIdToMint = drop.nextTokenIdToMint(); + assertEq(nextTokenIdToMint, 0); + } + + function test_nextTokenIdToMint_TenLazyMinted() public lazyMint { + uint256 nextTokenIdToMint = drop.nextTokenIdToMint(); + assertEq(nextTokenIdToMint, 10); + } + + function test_contractType() public { + assertEq(drop.contractType(), bytes32("DropERC1155")); + } + + function test_contractVersion() public { + assertEq(drop.contractVersion(), uint8(4)); + } + + function test_supportsInterface() public { + assertEq(drop.supportsInterface(type(IERC2981Upgradeable).interfaceId), true); + assertEq(drop.supportsInterface(type(IERC1155Upgradeable).interfaceId), true); + assertEq(drop.supportsInterface(type(IERC1155MetadataURIUpgradeable).interfaceId), true); + } + + function test__msgData() public { + HarnessDropERC1155MsgData msgDataDrop = new HarnessDropERC1155MsgData(); + bytes memory msgData = msgDataDrop.msgData(); + bytes4 expectedData = msgDataDrop.msgData.selector; + assertEq(bytes4(msgData), expectedData); + } +} + +contract HarnessDropERC1155MsgData is DropERC1155 { + function msgData() public view returns (bytes memory) { + return _msgData(); + } +} diff --git a/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.tree b/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.tree new file mode 100644 index 000000000..e69de29bb From 4279dc8b86548ab9c21e871b831bb509ff789665 Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Wed, 11 Oct 2023 11:23:18 -0500 Subject: [PATCH 26/27] remove initializeHarness and set harness to proxy --- .../_beforeClaim/_beforeClaim.t.sol | 78 +++------ .../_beforeTokenTransfer.sol | 83 ++++----- .../_canSetFunctions/_canSetFunctions.sol | 98 ++++------- .../collectPriceOnClaim.t.sol | 160 ++++++++---------- .../transferTokensOnClaim.t.sol | 93 ++++------ 5 files changed, 195 insertions(+), 317 deletions(-) diff --git a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol index 22d7de23d..f7e0c2f6d 100644 --- a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol +++ b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; -import { DropERC1155, IPermissions, ILazyMint } from "contracts/prebuilts/drop/DropERC1155.sol"; +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; +import { TWProxy } from "contracts/infra/TWProxy.sol"; // Test imports import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; -import "@openzeppelin/contracts/utils/Strings.sol"; contract HarnessDropERC1155 is DropERC1155 { function beforeClaim( @@ -21,63 +21,39 @@ contract HarnessDropERC1155 is DropERC1155 { ) external view { _beforeClaim(_tokenId, address(0), _quantity, address(0), 0, alp, bytes("")); } - - function initializeHarness( - address _defaultAdmin, - string memory _contractURI, - address _saleRecipient, - address _royaltyRecipient, - uint128 _royaltyBps, - uint128 _platformFeeBps, - address _platformFeeRecipient - ) external { - bytes32 _transferRole = keccak256("TRANSFER_ROLE"); - bytes32 _minterRole = keccak256("MINTER_ROLE"); - bytes32 _metadataRole = keccak256("METADATA_ROLE"); - - _setupContractURI(_contractURI); - _setupOwner(_defaultAdmin); - - _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); - _setupRole(_minterRole, _defaultAdmin); - _setupRole(_transferRole, _defaultAdmin); - _setupRole(_transferRole, address(0)); - _setupRole(_metadataRole, _defaultAdmin); - _setRoleAdmin(_metadataRole, _metadataRole); - - _setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); - _setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps); - _setupPrimarySaleRecipient(_saleRecipient); - } } contract DropERC1155Test_beforeClaim is BaseTest { using StringsUpgradeable for uint256; using StringsUpgradeable for address; - event TokensLazyMinted(uint256 indexed startTokenId, uint256 endTokenId, string baseURI, bytes encryptedBaseURI); - event TokenURIRevealed(uint256 indexed index, string revealedURI); - event MaxTotalSupplyUpdated(uint256 tokenId, uint256 maxTotalSupply); - - HarnessDropERC1155 public drop; - - bytes private emptyEncodedBytes = abi.encode("", ""); - - using stdStorage for StdStorage; + address public dropImp; + HarnessDropERC1155 public proxy; function setUp() public override { super.setUp(); - drop = new HarnessDropERC1155(); - drop.initializeHarness( - address(this), - "https://token-cdn-domain/{id}.json", - deployer, - deployer, - 1000, - 1000, - deployer + + bytes memory initializeData = abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) ); - drop.setMaxTotalSupply(0, 1); + + dropImp = address(new HarnessDropERC1155()); + proxy = HarnessDropERC1155(address(new TWProxy(dropImp, initializeData))); + + vm.prank(deployer); + proxy.setMaxTotalSupply(0, 1); } /*/////////////////////////////////////////////////////////////// @@ -90,11 +66,11 @@ contract DropERC1155Test_beforeClaim is BaseTest { function test_revert_ExceedMaxSupply() public { DropERC1155.AllowlistProof memory alp; vm.expectRevert("exceed max total supply"); - drop.beforeClaim(0, address(0), 2, address(0), 0, alp, bytes("")); + proxy.beforeClaim(0, address(0), 2, address(0), 0, alp, bytes("")); } function test_NoRevert() public view { DropERC1155.AllowlistProof memory alp; - drop.beforeClaim(0, address(0), 1, address(0), 0, alp, bytes("")); + proxy.beforeClaim(0, address(0), 1, address(0), 0, alp, bytes("")); } } diff --git a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol index c7f3b692a..79ec1ff55 100644 --- a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol +++ b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol @@ -1,13 +1,14 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; -import { DropERC1155, IPermissions, ILazyMint } from "contracts/prebuilts/drop/DropERC1155.sol"; +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; +import { TWProxy } from "contracts/infra/TWProxy.sol"; // Test imports import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; -import "@openzeppelin/contracts/utils/Strings.sol"; + contract HarnessDropERC1155 is DropERC1155 { function beforeTokenTransfer( @@ -20,45 +21,12 @@ contract HarnessDropERC1155 is DropERC1155 { ) external { _beforeTokenTransfer(operator, from, to, ids, amounts, data); } - - function initializeHarness( - address _defaultAdmin, - string memory _contractURI, - address _saleRecipient, - address _royaltyRecipient, - uint128 _royaltyBps, - uint128 _platformFeeBps, - address _platformFeeRecipient - ) external { - bytes32 _transferRole = keccak256("TRANSFER_ROLE"); - bytes32 _minterRole = keccak256("MINTER_ROLE"); - bytes32 _metadataRole = keccak256("METADATA_ROLE"); - - _setupContractURI(_contractURI); - _setupOwner(_defaultAdmin); - - _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); - _setupRole(_minterRole, _defaultAdmin); - _setupRole(_transferRole, _defaultAdmin); - _setupRole(_transferRole, address(0)); - _setupRole(_metadataRole, _defaultAdmin); - _setRoleAdmin(_metadataRole, _metadataRole); - - _setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); - _setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps); - _setupPrimarySaleRecipient(_saleRecipient); - } } contract DropERC1155Test_beforeTokenTransfer is BaseTest { using StringsUpgradeable for uint256; using StringsUpgradeable for address; - event TokensLazyMinted(uint256 indexed startTokenId, uint256 endTokenId, string baseURI, bytes encryptedBaseURI); - event TokenURIRevealed(uint256 indexed index, string revealedURI); - event MaxTotalSupplyUpdated(uint256 tokenId, uint256 maxTotalSupply); - - HarnessDropERC1155 public drop; address private beforeTransfer_from = address(0x01); address private beforeTransfer_to = address(0x01); @@ -66,26 +34,37 @@ contract DropERC1155Test_beforeTokenTransfer is BaseTest { uint256[] private beforeTransfer_amounts; bytes private beforeTransfer_data; - using stdStorage for StdStorage; + address public dropImp; + HarnessDropERC1155 public proxy; function setUp() public override { super.setUp(); - drop = new HarnessDropERC1155(); - drop.initializeHarness( - address(this), - "https://token-cdn-domain/{id}.json", - deployer, - deployer, - 1000, - 1000, - deployer + + bytes memory initializeData = abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) ); + dropImp = address(new HarnessDropERC1155()); + proxy = HarnessDropERC1155(address(new TWProxy(dropImp, initializeData))); + beforeTransfer_ids = new uint256[](1); beforeTransfer_ids[0] = 0; beforeTransfer_amounts = new uint256[](1); beforeTransfer_amounts[0] = 1; beforeTransfer_data = abi.encode("", ""); + } modifier fromAddressZero() { @@ -102,8 +81,8 @@ contract DropERC1155Test_beforeTokenTransfer is BaseTest { * note: Tests whether contract reverts when a non-holder renounces a role. */ function test_state_transferFromZero() public fromAddressZero { - uint256 beforeTokenTotalSupply = drop.totalSupply(0); - drop.beforeTokenTransfer( + uint256 beforeTokenTotalSupply = proxy.totalSupply(0); + proxy.beforeTokenTransfer( deployer, beforeTransfer_from, beforeTransfer_to, @@ -111,12 +90,12 @@ contract DropERC1155Test_beforeTokenTransfer is BaseTest { beforeTransfer_amounts, beforeTransfer_data ); - uint256 afterTokenTotalSupply = drop.totalSupply(0); + uint256 afterTokenTotalSupply = proxy.totalSupply(0); assertEq(beforeTokenTotalSupply + beforeTransfer_amounts[0], afterTokenTotalSupply); } function test_state_tranferToZero() public toAddressZero { - drop.beforeTokenTransfer( + proxy.beforeTokenTransfer( deployer, beforeTransfer_to, beforeTransfer_from, @@ -124,8 +103,8 @@ contract DropERC1155Test_beforeTokenTransfer is BaseTest { beforeTransfer_amounts, beforeTransfer_data ); - uint256 beforeTokenTotalSupply = drop.totalSupply(0); - drop.beforeTokenTransfer( + uint256 beforeTokenTotalSupply = proxy.totalSupply(0); + proxy.beforeTokenTransfer( deployer, beforeTransfer_from, beforeTransfer_to, @@ -133,7 +112,7 @@ contract DropERC1155Test_beforeTokenTransfer is BaseTest { beforeTransfer_amounts, beforeTransfer_data ); - uint256 afterTokenTotalSupply = drop.totalSupply(0); + uint256 afterTokenTotalSupply = proxy.totalSupply(0); assertEq(beforeTokenTotalSupply - beforeTransfer_amounts[0], afterTokenTotalSupply); } } diff --git a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol index b0d88581e..d3359ad42 100644 --- a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol +++ b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol @@ -1,19 +1,15 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; -import { DropERC1155, IPermissions, ILazyMint } from "contracts/prebuilts/drop/DropERC1155.sol"; +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; +import { TWProxy } from "contracts/infra/TWProxy.sol"; // Test imports import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; -import "@openzeppelin/contracts/utils/Strings.sol"; contract HarnessDropERC1155 is DropERC1155 { - bytes32 private transferRole; - bytes32 private minterRole; - bytes32 private metadataRole; - function canSetPlatformFeeInfo() external view returns (bool) { return _canSetPlatformFeeInfo(); } @@ -47,58 +43,36 @@ contract HarnessDropERC1155 is DropERC1155 { function canLazyMint() external view virtual returns (bool) { return _canLazyMint(); } - - function initializeHarness( - address _defaultAdmin, - string memory _contractURI, - address _saleRecipient, - address _royaltyRecipient, - uint128 _royaltyBps, - uint128 _platformFeeBps, - address _platformFeeRecipient - ) external { - bytes32 _transferRole = keccak256("TRANSFER_ROLE"); - bytes32 _minterRole = keccak256("MINTER_ROLE"); - bytes32 _metadataRole = keccak256("METADATA_ROLE"); - - _setupContractURI(_contractURI); - _setupOwner(_defaultAdmin); - - _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); - _setupRole(_minterRole, _defaultAdmin); - _setupRole(_transferRole, _defaultAdmin); - _setupRole(_transferRole, address(0)); - _setupRole(_metadataRole, _defaultAdmin); - _setRoleAdmin(_metadataRole, _metadataRole); - - _setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); - _setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps); - _setupPrimarySaleRecipient(_saleRecipient); - - transferRole = _transferRole; - minterRole = _minterRole; - metadataRole = _metadataRole; - } } contract DropERC1155Test_canSetFunctions is BaseTest { using StringsUpgradeable for uint256; using StringsUpgradeable for address; - HarnessDropERC1155 public drop; + address public dropImp; + HarnessDropERC1155 public proxy; function setUp() public override { super.setUp(); - drop = new HarnessDropERC1155(); - drop.initializeHarness( - deployer, - "https://token-cdn-domain/{id}.json", - deployer, - deployer, - 1000, - 1000, - deployer + + bytes memory initializeData = abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) ); + + dropImp = address(new HarnessDropERC1155()); + proxy = HarnessDropERC1155(address(new TWProxy(dropImp, initializeData))); } modifier HasDefaultAdminRole() { @@ -125,58 +99,58 @@ contract DropERC1155Test_canSetFunctions is BaseTest { * note: Tests whether contract reverts when a non-holder renounces a role. */ function test_canSetPlatformFeeInfo_true() public HasDefaultAdminRole { - assertTrue(drop.canSetPlatformFeeInfo()); + assertTrue(proxy.canSetPlatformFeeInfo()); } function test_canSetPlatformFeeInfo_false() public DoesNotHaveDefaultAdminRole { - assertFalse(drop.canSetPlatformFeeInfo()); + assertFalse(proxy.canSetPlatformFeeInfo()); } function test_canSetPrimarySaleRecipient_true() public HasDefaultAdminRole { - assertTrue(drop.canSetPrimarySaleRecipient()); + assertTrue(proxy.canSetPrimarySaleRecipient()); } function test_canSetPrimarySaleRecipient_false() public DoesNotHaveDefaultAdminRole { - assertFalse(drop.canSetPrimarySaleRecipient()); + assertFalse(proxy.canSetPrimarySaleRecipient()); } function test_canSetOwner_true() public HasDefaultAdminRole { - assertTrue(drop.canSetOwner()); + assertTrue(proxy.canSetOwner()); } function test_canSetOwner_false() public DoesNotHaveDefaultAdminRole { - assertFalse(drop.canSetOwner()); + assertFalse(proxy.canSetOwner()); } function test_canSetRoyaltyInfo_true() public HasDefaultAdminRole { - assertTrue(drop.canSetRoyaltyInfo()); + assertTrue(proxy.canSetRoyaltyInfo()); } function test_canSetRoyaltyInfo_false() public DoesNotHaveDefaultAdminRole { - assertFalse(drop.canSetRoyaltyInfo()); + assertFalse(proxy.canSetRoyaltyInfo()); } function test_canSetContractURI_true() public HasDefaultAdminRole { - assertTrue(drop.canSetContractURI()); + assertTrue(proxy.canSetContractURI()); } function test_canSetContractURI_false() public DoesNotHaveDefaultAdminRole { - assertFalse(drop.canSetContractURI()); + assertFalse(proxy.canSetContractURI()); } function test_canSetClaimConditions_true() public HasDefaultAdminRole { - assertTrue(drop.canSetClaimConditions()); + assertTrue(proxy.canSetClaimConditions()); } function test_canSetClaimConditions_false() public DoesNotHaveDefaultAdminRole { - assertFalse(drop.canSetClaimConditions()); + assertFalse(proxy.canSetClaimConditions()); } function test_canLazyMint_true() public HasMinterRole { - assertTrue(drop.canLazyMint()); + assertTrue(proxy.canLazyMint()); } function test_canLazyMint_false() public DoesNotHaveMinterRole { - assertFalse(drop.canLazyMint()); + assertFalse(proxy.canLazyMint()); } } diff --git a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol index 835efa75e..32cf71881 100644 --- a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol +++ b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.0; import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; +import { TWProxy } from "contracts/infra/TWProxy.sol"; // Test imports import "contracts/lib/TWStrings.sol"; @@ -18,41 +19,11 @@ contract HarnessDropERC1155 is DropERC1155 { ) public payable { collectPriceOnClaim(_tokenId, _primarySaleRecipient, _quantityToClaim, _currency, _pricePerToken); } - - function initializeHarness( - address _defaultAdmin, - string memory _contractURI, - address _saleRecipient, - address _royaltyRecipient, - uint128 _royaltyBps, - uint128 _platformFeeBps, - address _platformFeeRecipient - ) external { - bytes32 _transferRole = keccak256("TRANSFER_ROLE"); - bytes32 _minterRole = keccak256("MINTER_ROLE"); - bytes32 _metadataRole = keccak256("METADATA_ROLE"); - - _setupContractURI(_contractURI); - _setupOwner(_defaultAdmin); - - _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); - _setupRole(_minterRole, _defaultAdmin); - _setupRole(_transferRole, _defaultAdmin); - _setupRole(_transferRole, address(0)); - _setupRole(_metadataRole, _defaultAdmin); - _setRoleAdmin(_metadataRole, _metadataRole); - - _setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); - _setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps); - _setupPrimarySaleRecipient(_saleRecipient); - } } contract DropERC1155Test_collectPrice is BaseTest { using StringsUpgradeable for uint256; - HarnessDropERC1155 public dropImp; - address private collectPrice_saleRecipient = address(0x010); address private collectPrice_royaltyRecipient = address(0x011); uint128 private collectPrice_royaltyBps = 1000; @@ -64,19 +35,30 @@ contract DropERC1155Test_collectPrice is BaseTest { uint256 private collectPrice_msgValue; address private collectPrice_tokenSaleRecipient = address(0x111); + address public dropImp; + HarnessDropERC1155 public proxy; + function setUp() public override { super.setUp(); - dropImp = new HarnessDropERC1155(); - dropImp.initializeHarness( - deployer, - CONTRACT_URI, - collectPrice_saleRecipient, - collectPrice_royaltyRecipient, - collectPrice_royaltyBps, - collectPrice_platformFeeBps, - collectPrice_platformFeeRecipient + bytes memory initializeData = abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) ); + + dropImp = address(new HarnessDropERC1155()); + proxy = HarnessDropERC1155(address(new TWProxy(dropImp, initializeData))); } modifier pricePerTokenZero() { @@ -106,18 +88,18 @@ contract DropERC1155Test_collectPrice is BaseTest { } modifier primarySaleRecipientZeroAddress() { - collectPrice_saleRecipient = address(0); + saleRecipient = address(0); _; } modifier primarySaleRecipientNotZeroAddress() { - collectPrice_saleRecipient = address(0x112); + saleRecipient = address(0x112); _; } modifier saleRecipientSet() { vm.prank(deployer); - dropImp.setSaleRecipientForToken(0, address(0x111)); + proxy.setSaleRecipientForToken(0, address(0x111)); _; } @@ -127,9 +109,9 @@ contract DropERC1155Test_collectPrice is BaseTest { function test_revert_msgValueNotZero() public nativeCurrency msgValueNotZero pricePerTokenZero { vm.expectRevert(); - dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + proxy.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( 0, - collectPrice_saleRecipient, + saleRecipient, collectPrice_quantityToClaim, collectPrice_currency, collectPrice_pricePerToken @@ -137,9 +119,9 @@ contract DropERC1155Test_collectPrice is BaseTest { } function test_msgValueZero_return() public nativeCurrency pricePerTokenZero { - dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + proxy.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( 0, - collectPrice_saleRecipient, + saleRecipient, collectPrice_quantityToClaim, collectPrice_currency, collectPrice_pricePerToken @@ -148,9 +130,9 @@ contract DropERC1155Test_collectPrice is BaseTest { function test_revert_priceValueMismatchNativeCurrency() public nativeCurrency pricePerTokenNotZero { vm.expectRevert(); - dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + proxy.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( 0, - collectPrice_saleRecipient, + saleRecipient, collectPrice_quantityToClaim, collectPrice_currency, collectPrice_pricePerToken @@ -158,19 +140,19 @@ contract DropERC1155Test_collectPrice is BaseTest { } function test_transferNativeCurrencyToSaleRecipient() public nativeCurrency pricePerTokenNotZero msgValueNotZero { - uint256 balanceSaleRecipientBefore = address(collectPrice_saleRecipient).balance; - uint256 platformFeeRecipientBefore = address(collectPrice_platformFeeRecipient).balance; - dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + uint256 balanceSaleRecipientBefore = address(saleRecipient).balance; + uint256 platformFeeRecipientBefore = address(platformFeeRecipient).balance; + proxy.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( 0, - collectPrice_saleRecipient, + saleRecipient, collectPrice_quantityToClaim, collectPrice_currency, collectPrice_pricePerToken ); - uint256 balanceSaleRecipientAfter = address(collectPrice_saleRecipient).balance; - uint256 platformFeeRecipientAfter = address(collectPrice_platformFeeRecipient).balance; - uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 balanceSaleRecipientAfter = address(saleRecipient).balance; + uint256 platformFeeRecipientAfter = address(platformFeeRecipient).balance; + uint256 expectedPlatformFee = (collectPrice_pricePerToken * platformFeeBps) / MAX_BPS; uint256 expectedSaleRecipientProceed = collectPrice_msgValue - expectedPlatformFee; assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); @@ -178,20 +160,20 @@ contract DropERC1155Test_collectPrice is BaseTest { } function test_transferERC20ToSaleRecipient() public erc20Currency pricePerTokenNotZero { - uint256 balanceSaleRecipientBefore = erc20.balanceOf(collectPrice_saleRecipient); - uint256 platformFeeRecipientBefore = erc20.balanceOf(collectPrice_platformFeeRecipient); - erc20.approve(address(dropImp), collectPrice_pricePerToken); - dropImp.collectPriceOnClaimHarness( + uint256 balanceSaleRecipientBefore = erc20.balanceOf(saleRecipient); + uint256 platformFeeRecipientBefore = erc20.balanceOf(platformFeeRecipient); + erc20.approve(address(proxy), collectPrice_pricePerToken); + proxy.collectPriceOnClaimHarness( 0, - collectPrice_saleRecipient, + saleRecipient, collectPrice_quantityToClaim, collectPrice_currency, collectPrice_pricePerToken ); - uint256 balanceSaleRecipientAfter = erc20.balanceOf(collectPrice_saleRecipient); - uint256 platformFeeRecipientAfter = erc20.balanceOf(collectPrice_platformFeeRecipient); - uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 balanceSaleRecipientAfter = erc20.balanceOf(saleRecipient); + uint256 platformFeeRecipientAfter = erc20.balanceOf(platformFeeRecipient); + uint256 expectedPlatformFee = (collectPrice_pricePerToken * platformFeeBps) / MAX_BPS; uint256 expectedSaleRecipientProceed = collectPrice_pricePerToken - expectedPlatformFee; assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); @@ -207,8 +189,8 @@ contract DropERC1155Test_collectPrice is BaseTest { primarySaleRecipientZeroAddress { uint256 balanceSaleRecipientBefore = address(collectPrice_tokenSaleRecipient).balance; - uint256 platformFeeRecipientBefore = address(collectPrice_platformFeeRecipient).balance; - dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + uint256 platformFeeRecipientBefore = address(platformFeeRecipient).balance; + proxy.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( 0, address(0), collectPrice_quantityToClaim, @@ -217,25 +199,19 @@ contract DropERC1155Test_collectPrice is BaseTest { ); uint256 balanceSaleRecipientAfter = address(collectPrice_tokenSaleRecipient).balance; - uint256 platformFeeRecipientAfter = address(collectPrice_platformFeeRecipient).balance; - uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 platformFeeRecipientAfter = address(platformFeeRecipient).balance; + uint256 expectedPlatformFee = (collectPrice_pricePerToken * platformFeeBps) / MAX_BPS; uint256 expectedSaleRecipientProceed = collectPrice_msgValue - expectedPlatformFee; assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); assertEq(platformFeeRecipientAfter - platformFeeRecipientBefore, expectedPlatformFee); } - function test_transferERc20ToTokenIdSaleRecipient() - public - erc20Currency - pricePerTokenNotZero - saleRecipientSet - primarySaleRecipientZeroAddress - { + function test_transferERC20ToTokenIdSaleRecipient() public erc20Currency pricePerTokenNotZero saleRecipientSet { uint256 balanceSaleRecipientBefore = erc20.balanceOf(collectPrice_tokenSaleRecipient); - uint256 platformFeeRecipientBefore = erc20.balanceOf(collectPrice_platformFeeRecipient); - erc20.approve(address(dropImp), collectPrice_pricePerToken); - dropImp.collectPriceOnClaimHarness( + uint256 platformFeeRecipientBefore = erc20.balanceOf(platformFeeRecipient); + erc20.approve(address(proxy), collectPrice_pricePerToken); + proxy.collectPriceOnClaimHarness( 0, address(0), collectPrice_quantityToClaim, @@ -244,8 +220,8 @@ contract DropERC1155Test_collectPrice is BaseTest { ); uint256 balanceSaleRecipientAfter = erc20.balanceOf(collectPrice_tokenSaleRecipient); - uint256 platformFeeRecipientAfter = erc20.balanceOf(collectPrice_platformFeeRecipient); - uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 platformFeeRecipientAfter = erc20.balanceOf(platformFeeRecipient); + uint256 expectedPlatformFee = (collectPrice_pricePerToken * platformFeeBps) / MAX_BPS; uint256 expectedSaleRecipientProceed = collectPrice_pricePerToken - expectedPlatformFee; assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); @@ -258,9 +234,9 @@ contract DropERC1155Test_collectPrice is BaseTest { pricePerTokenNotZero msgValueNotZero { - uint256 balanceSaleRecipientBefore = address(collectPrice_saleRecipient).balance; - uint256 platformFeeRecipientBefore = address(collectPrice_platformFeeRecipient).balance; - dropImp.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( + uint256 balanceSaleRecipientBefore = address(saleRecipient).balance; + uint256 platformFeeRecipientBefore = address(platformFeeRecipient).balance; + proxy.collectPriceOnClaimHarness{ value: collectPrice_msgValue }( 0, address(0), collectPrice_quantityToClaim, @@ -268,9 +244,9 @@ contract DropERC1155Test_collectPrice is BaseTest { collectPrice_pricePerToken ); - uint256 balanceSaleRecipientAfter = address(collectPrice_saleRecipient).balance; - uint256 platformFeeRecipientAfter = address(collectPrice_platformFeeRecipient).balance; - uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 balanceSaleRecipientAfter = address(saleRecipient).balance; + uint256 platformFeeRecipientAfter = address(platformFeeRecipient).balance; + uint256 expectedPlatformFee = (collectPrice_pricePerToken * platformFeeBps) / MAX_BPS; uint256 expectedSaleRecipientProceed = collectPrice_msgValue - expectedPlatformFee; assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); @@ -278,10 +254,10 @@ contract DropERC1155Test_collectPrice is BaseTest { } function test_transferERC20ToPrimarySaleRecipient() public erc20Currency pricePerTokenNotZero { - uint256 balanceSaleRecipientBefore = erc20.balanceOf(collectPrice_saleRecipient); - uint256 platformFeeRecipientBefore = erc20.balanceOf(collectPrice_platformFeeRecipient); - erc20.approve(address(dropImp), collectPrice_pricePerToken); - dropImp.collectPriceOnClaimHarness( + uint256 balanceSaleRecipientBefore = erc20.balanceOf(saleRecipient); + uint256 platformFeeRecipientBefore = erc20.balanceOf(platformFeeRecipient); + erc20.approve(address(proxy), collectPrice_pricePerToken); + proxy.collectPriceOnClaimHarness( 0, address(0), collectPrice_quantityToClaim, @@ -289,9 +265,9 @@ contract DropERC1155Test_collectPrice is BaseTest { collectPrice_pricePerToken ); - uint256 balanceSaleRecipientAfter = erc20.balanceOf(collectPrice_saleRecipient); - uint256 platformFeeRecipientAfter = erc20.balanceOf(collectPrice_platformFeeRecipient); - uint256 expectedPlatformFee = (collectPrice_pricePerToken * collectPrice_platformFeeBps) / MAX_BPS; + uint256 balanceSaleRecipientAfter = erc20.balanceOf(saleRecipient); + uint256 platformFeeRecipientAfter = erc20.balanceOf(platformFeeRecipient); + uint256 expectedPlatformFee = (collectPrice_pricePerToken * platformFeeBps) / MAX_BPS; uint256 expectedSaleRecipientProceed = collectPrice_pricePerToken - expectedPlatformFee; assertEq(balanceSaleRecipientAfter - balanceSaleRecipientBefore, expectedSaleRecipientProceed); diff --git a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol index a18df9a29..7cadd650f 100644 --- a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol +++ b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol @@ -1,60 +1,22 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; -import { DropERC1155, IPermissions, ILazyMint } from "contracts/prebuilts/drop/DropERC1155.sol"; +import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; +import { TWProxy } from "contracts/infra/TWProxy.sol"; // Test imports import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; -import "@openzeppelin/contracts/utils/Strings.sol"; contract HarnessDropERC1155 is DropERC1155 { - function transferTokensOnClaimHarness( - address to, - uint256 _tokenId, - uint256 _quantityBeingClaimed - ) external { + function transferTokensOnClaimHarness(address to, uint256 _tokenId, uint256 _quantityBeingClaimed) external { transferTokensOnClaim(to, _tokenId, _quantityBeingClaimed); } - - function initializeHarness( - address _defaultAdmin, - string memory _contractURI, - address _saleRecipient, - address _royaltyRecipient, - uint128 _royaltyBps, - uint128 _platformFeeBps, - address _platformFeeRecipient - ) external { - bytes32 _transferRole = keccak256("TRANSFER_ROLE"); - bytes32 _minterRole = keccak256("MINTER_ROLE"); - bytes32 _metadataRole = keccak256("METADATA_ROLE"); - - _setupContractURI(_contractURI); - _setupOwner(_defaultAdmin); - - _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); - _setupRole(_minterRole, _defaultAdmin); - _setupRole(_transferRole, _defaultAdmin); - _setupRole(_transferRole, address(0)); - _setupRole(_metadataRole, _defaultAdmin); - _setRoleAdmin(_metadataRole, _metadataRole); - - _setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); - _setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps); - _setupPrimarySaleRecipient(_saleRecipient); - } } contract MockERC1155Receiver { - function onERC1155Received( - address, - address, - uint256, - uint256, - bytes memory - ) external pure returns (bytes4) { + function onERC1155Received(address, address, uint256, uint256, bytes memory) external pure returns (bytes4) { return this.onERC1155Received.selector; } @@ -75,24 +37,35 @@ contract DropERC1155Test_transferTokensOnClaim is BaseTest { using StringsUpgradeable for uint256; using StringsUpgradeable for address; - HarnessDropERC1155 public drop; - address private to; MockERC1155Receiver private receiver; MockERC11555NotReceiver private notReceiver; + address public dropImp; + HarnessDropERC1155 public proxy; + function setUp() public override { super.setUp(); - drop = new HarnessDropERC1155(); - drop.initializeHarness( - address(this), - "https://token-cdn-domain/{id}.json", - deployer, - deployer, - 1000, - 1000, - deployer + + bytes memory initializeData = abi.encodeCall( + DropERC1155.initialize, + ( + deployer, + NAME, + SYMBOL, + CONTRACT_URI, + forwarders(), + saleRecipient, + royaltyRecipient, + royaltyBps, + platformFeeBps, + platformFeeRecipient + ) ); + + dropImp = address(new HarnessDropERC1155()); + proxy = HarnessDropERC1155(address(new TWProxy(dropImp, initializeData))); + receiver = new MockERC1155Receiver(); notReceiver = new MockERC11555NotReceiver(); } @@ -121,20 +94,20 @@ contract DropERC1155Test_transferTokensOnClaim is BaseTest { */ function test_revert_ContractNotERC155Receiver() public toNotReceiever { vm.expectRevert("ERC1155: transfer to non ERC1155Receiver implementer"); - drop.transferTokensOnClaimHarness(to, 0, 1); + proxy.transferTokensOnClaimHarness(to, 0, 1); } function test_state_ContractERC1155Receiver() public toReceiever { - uint256 beforeBalance = drop.balanceOf(to, 0); - drop.transferTokensOnClaimHarness(to, 0, 1); - uint256 afterBalance = drop.balanceOf(to, 0); + uint256 beforeBalance = proxy.balanceOf(to, 0); + proxy.transferTokensOnClaimHarness(to, 0, 1); + uint256 afterBalance = proxy.balanceOf(to, 0); assertEq(beforeBalance + 1, afterBalance); } function test_state_EOAReceiver() public toEOA { - uint256 beforeBalance = drop.balanceOf(to, 0); - drop.transferTokensOnClaimHarness(to, 0, 1); - uint256 afterBalance = drop.balanceOf(to, 0); + uint256 beforeBalance = proxy.balanceOf(to, 0); + proxy.transferTokensOnClaimHarness(to, 0, 1); + uint256 afterBalance = proxy.balanceOf(to, 0); assertEq(beforeBalance + 1, afterBalance); } } From 3d2554d6a6dde9cd0686c473ff9ac2a4d9501bfd Mon Sep 17 00:00:00 2001 From: WhiteOakKong Date: Wed, 11 Oct 2023 11:54:26 -0500 Subject: [PATCH 27/27] clean/lint tests --- .../_beforeClaim/_beforeClaim.t.sol | 5 ---- .../_beforeClaim/_beforeClaim.tree | 4 +-- .../_beforeTokenTransfer.sol | 8 ------ .../_canSetFunctions/_canSetFunctions.sol | 5 ---- .../_canSetFunctions/_canSetFunctions.tree | 28 +++++++++---------- .../drop-erc1155/burnBatch/burnBatch.t.sol | 4 --- .../drop-erc1155/burnBatch/burnBatch.tree | 12 ++++---- .../collectPriceOnClaim.t.sol | 4 --- .../freezeBatchBaseURI.t.sol | 3 -- .../freezeBatchBaseURI.tree | 12 ++++---- .../drop-erc1155/initialize/initialize.t.sol | 4 --- .../miscellaneous/miscellaneous.t.sol | 7 ----- .../miscellaneous/miscellaneous.tree | 8 ++++++ .../setMaxTotalSupply/setMaxTotalSupply.t.sol | 3 -- .../setMaxTotalSupply/setMaxTotalSupply.tree | 4 +-- .../transferTokensOnClaim.t.sol | 14 ++++++++-- 16 files changed, 50 insertions(+), 75 deletions(-) diff --git a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol index f7e0c2f6d..8397c3195 100644 --- a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol +++ b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol @@ -5,9 +5,7 @@ import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; import { TWProxy } from "contracts/infra/TWProxy.sol"; // Test imports -import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; -import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; contract HarnessDropERC1155 is DropERC1155 { function beforeClaim( @@ -24,9 +22,6 @@ contract HarnessDropERC1155 is DropERC1155 { } contract DropERC1155Test_beforeClaim is BaseTest { - using StringsUpgradeable for uint256; - using StringsUpgradeable for address; - address public dropImp; HarnessDropERC1155 public proxy; diff --git a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree index cb31a962d..a5a114d07 100644 --- a/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree +++ b/src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree @@ -7,6 +7,6 @@ function _beforeClaim( AllowlistProof calldata, bytes memory ) -└── if maxTotalSupply for _tokenId is not zero - └── if totalSupply of _tokenId + _quantity is greater than or equal to maxTotalSupply for _tokenId +└── when maxTotalSupply for _tokenId is not zero + └── when totalSupply of _tokenId + _quantity is greater than or equal to maxTotalSupply for _tokenId └── it should revert ✅ \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol index 79ec1ff55..b4c32607c 100644 --- a/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol +++ b/src/test/drop/drop-erc1155/_beforeTokenTransfer/_beforeTokenTransfer.sol @@ -5,10 +5,7 @@ import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; import { TWProxy } from "contracts/infra/TWProxy.sol"; // Test imports -import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; -import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; - contract HarnessDropERC1155 is DropERC1155 { function beforeTokenTransfer( @@ -24,10 +21,6 @@ contract HarnessDropERC1155 is DropERC1155 { } contract DropERC1155Test_beforeTokenTransfer is BaseTest { - using StringsUpgradeable for uint256; - using StringsUpgradeable for address; - - address private beforeTransfer_from = address(0x01); address private beforeTransfer_to = address(0x01); uint256[] private beforeTransfer_ids; @@ -64,7 +57,6 @@ contract DropERC1155Test_beforeTokenTransfer is BaseTest { beforeTransfer_amounts = new uint256[](1); beforeTransfer_amounts[0] = 1; beforeTransfer_data = abi.encode("", ""); - } modifier fromAddressZero() { diff --git a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol index d3359ad42..2be22888c 100644 --- a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol +++ b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol @@ -5,9 +5,7 @@ import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; import { TWProxy } from "contracts/infra/TWProxy.sol"; // Test imports -import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; -import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; contract HarnessDropERC1155 is DropERC1155 { function canSetPlatformFeeInfo() external view returns (bool) { @@ -46,9 +44,6 @@ contract HarnessDropERC1155 is DropERC1155 { } contract DropERC1155Test_canSetFunctions is BaseTest { - using StringsUpgradeable for uint256; - using StringsUpgradeable for address; - address public dropImp; HarnessDropERC1155 public proxy; diff --git a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree index d0a041b06..4b214c4e9 100644 --- a/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree +++ b/src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.tree @@ -1,41 +1,41 @@ function _canSetPlatformFeeInfo() -├── if caller has DEFAULT_ADMIN_ROLE +├── when caller has DEFAULT_ADMIN_ROLE │ └── it should return true ✅ -└── if caller does not have DEFAULT_ADMIN_ROLE +└── when caller does not have DEFAULT_ADMIN_ROLE └── it should return false ✅ function _canSetPrimarySaleRecipient() -├── if caller has DEFAULT_ADMIN_ROLE +├── when caller has DEFAULT_ADMIN_ROLE │ └── it should return true ✅ -└── if caller does not have DEFAULT_ADMIN_ROLE +└── when caller does not have DEFAULT_ADMIN_ROLE └── it should return false ✅ function _canSetOwner() -├── if caller has DEFAULT_ADMIN_ROLE +├── when caller has DEFAULT_ADMIN_ROLE │ └── it should return true ✅ -└── if caller does not have DEFAULT_ADMIN_ROLE +└── when caller does not have DEFAULT_ADMIN_ROLE └── it should return false ✅ function _canSetRoyaltyInfo() -├── if caller has DEFAULT_ADMIN_ROLE +├── when caller has DEFAULT_ADMIN_ROLE │ └── it should return true ✅ -└── if caller does not have DEFAULT_ADMIN_ROLE +└── when caller does not have DEFAULT_ADMIN_ROLE └── it should return false ✅ function _canSetContractURI() -├── if caller has DEFAULT_ADMIN_ROLE +├── when caller has DEFAULT_ADMIN_ROLE │ └── it should return true ✅ -└── if caller does not have DEFAULT_ADMIN_ROLE +└── when caller does not have DEFAULT_ADMIN_ROLE └── it should return false ✅ function _canSetClaimConditions() -├── if caller has DEFAULT_ADMIN_ROLE +├── when caller has DEFAULT_ADMIN_ROLE │ └── it should return true ✅ -└── if caller does not have DEFAULT_ADMIN_ROLE +└── when caller does not have DEFAULT_ADMIN_ROLE └── it should return false ✅ function _canLazyMint() -├── if caller has minterRole +├── when caller has minterRole │ └── it should return true ✅ -└── if caller does not have minterRole +└── when caller does not have minterRole └── it should return false ✅ \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/burnBatch/burnBatch.t.sol b/src/test/drop/drop-erc1155/burnBatch/burnBatch.t.sol index 56b6a649b..86e365f33 100644 --- a/src/test/drop/drop-erc1155/burnBatch/burnBatch.t.sol +++ b/src/test/drop/drop-erc1155/burnBatch/burnBatch.t.sol @@ -4,14 +4,10 @@ pragma solidity ^0.8.0; import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; // Test imports -import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC2981Upgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; contract DropERC1155Test_burnBatch is BaseTest { - using StringsUpgradeable for uint256; - DropERC1155 public drop; address private unauthorized = address(0x999); diff --git a/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree b/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree index 5465bb497..e8685085e 100644 --- a/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree +++ b/src/test/drop/drop-erc1155/burnBatch/burnBatch.tree @@ -3,15 +3,15 @@ function burnBatch( uint256[] memory ids, uint256[] memory values ) -├── if account does not equal _msgSender() and _msgSender() is not an approved operator for account +├── when account does not equal _msgSender() and _msgSender() is not an approved operator for account │ └── it should revert ✅ -└── if account is equal to _msgSender() or _msgSender() is an approved operator for account - ├── if ids and values are not the same length +└── when account is equal to _msgSender() or _msgSender() is an approved operator for account + ├── when ids and values are not the same length │ └── it should revert ✅ - └── if ids and values are the same length - ├── if the balance of account for each id is not greater than or equal to the corresponding value + └── when ids and values are the same length + ├── when the balance of account for each id is not greater than or equal to the corresponding value │ └── it should revert ✅ - └── if the balance of account for each id is greater than or equal to the corresponding value + └── when the balance of account for each id is greater than or equal to the corresponding value ├── it should reduce the balance of each id for account by the corresponding value ✅ ├── it should reduce the total supply of each id by the corresponding value ✅ └── it should emit TransferBatch with the following parameters: _msgSender(), account, address(0), ids, amounts ✅ \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol index 32cf71881..bd2e68b9a 100644 --- a/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol +++ b/src/test/drop/drop-erc1155/collectPriceOnClaim/collectPriceOnClaim.t.sol @@ -5,9 +5,7 @@ import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; import { TWProxy } from "contracts/infra/TWProxy.sol"; // Test imports -import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; -import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; contract HarnessDropERC1155 is DropERC1155 { function collectPriceOnClaimHarness( @@ -22,8 +20,6 @@ contract HarnessDropERC1155 is DropERC1155 { } contract DropERC1155Test_collectPrice is BaseTest { - using StringsUpgradeable for uint256; - address private collectPrice_saleRecipient = address(0x010); address private collectPrice_royaltyRecipient = address(0x011); uint128 private collectPrice_royaltyBps = 1000; diff --git a/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.t.sol b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.t.sol index 42b0a0c4b..cf5e50710 100644 --- a/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.t.sol +++ b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.t.sol @@ -7,11 +7,8 @@ import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC2981Upgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; contract DropERC1155Test_freezeBatchBaseURI is BaseTest { - using StringsUpgradeable for uint256; - event MetadataFrozen(); DropERC1155 public drop; diff --git a/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree index bb5da59eb..7a9a00b7f 100644 --- a/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree +++ b/src/test/drop/drop-erc1155/freezeBatchBaseURI/freezeBatchBaseURI.tree @@ -1,12 +1,12 @@ function freezeBatchBaseURI(uint256 _index) -├── if the caller does not have metadataRole +├── when the caller does not have metadataRole │ └── it should revert ✅ -└── if the caller has metadataRole - ├── if _index is greater than the number of current batches +└── when the caller has metadataRole + ├── when _index is greater than the number of current batches │ └── it should revert ✅ - └── if _index is equal to or less than the number of current batches - ├── if the baseURI for the batch at _index is not set + └── when _index is equal to or less than the number of current batches + ├── when the baseURI for the batch at _index is not set │ └── it should revert ✅ - └── if the baseURI for the batch at _index is set + └── when the baseURI for the batch at _index is set ├── it should set batchFrozen[(batchId for _index)] to true ✅ └── it should emit MetadataFrozen ✅ \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/initialize/initialize.t.sol b/src/test/drop/drop-erc1155/initialize/initialize.t.sol index 78ef51f76..bf4dba6bf 100644 --- a/src/test/drop/drop-erc1155/initialize/initialize.t.sol +++ b/src/test/drop/drop-erc1155/initialize/initialize.t.sol @@ -4,13 +4,9 @@ pragma solidity ^0.8.0; import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; // Test imports -import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; -import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; contract DropERC1155Test_initializer is BaseTest { - using StringsUpgradeable for uint256; - DropERC1155 public newDropContract; event ContractURIUpdated(string prevURI, string newURI); diff --git a/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.t.sol b/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.t.sol index 0698b911e..018bbe081 100644 --- a/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.t.sol +++ b/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.t.sol @@ -10,16 +10,9 @@ import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfac import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC1155Upgradeable.sol"; import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC1155MetadataURIUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; - contract DropERC1155Test_misc is BaseTest { - using StringsUpgradeable for uint256; - DropERC1155 public drop; - address private unauthorized = address(0x123); - address private receiver; - bytes private emptyEncodedBytes = abi.encode("", ""); function setUp() public override { diff --git a/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.tree b/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.tree index e69de29bb..e74189c71 100644 --- a/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.tree +++ b/src/test/drop/drop-erc1155/miscellaneous/miscellaneous.tree @@ -0,0 +1,8 @@ +function nextTokenIdToMint() +└── it should return the next tokenId that is to be lazy minted ✅ + +function contractType() +└── it should return "DropERC1155" in bytes32 format ✅ + +function contractVersion() +└── it should return 4 in uint8 format ✅ \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol index 6239cccf1..ef9b3e158 100644 --- a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol +++ b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.t.sol @@ -7,11 +7,8 @@ import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol"; import "contracts/lib/TWStrings.sol"; import "../../../utils/BaseTest.sol"; import "../../../../../lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC2981Upgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; contract DropERC1155Test_setMaxTotalSupply is BaseTest { - using StringsUpgradeable for uint256; - DropERC1155 public drop; address private unauthorized = address(0x123); diff --git a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree index 82b91bbab..8aa6ad0ef 100644 --- a/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree +++ b/src/test/drop/drop-erc1155/setMaxTotalSupply/setMaxTotalSupply.tree @@ -1,6 +1,6 @@ function setMaxTotalSupply(uint256 _tokenId, uint256 _maxTotalSupply) -├── if the caller does not have DEFAULT_ADMIN_ROLE +├── when the caller does not have DEFAULT_ADMIN_ROLE │ └── it should revert ✅ -└── if the caller does have DEFAULT_ADMIN_ROLE +└── when the caller does have DEFAULT_ADMIN_ROLE ├── it should set maxTotalSupply for _tokenId as _maxTotalSupply ✅ └── it should emit MaxTotalSupplyUpdated with the parameters _tokenId, _maxTotalSupply ✅ \ No newline at end of file diff --git a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol index 7cadd650f..fe68daf78 100644 --- a/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol +++ b/src/test/drop/drop-erc1155/transferTokensOnClaim/transferTokensOnClaim.t.sol @@ -10,13 +10,23 @@ import "../../../utils/BaseTest.sol"; import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; contract HarnessDropERC1155 is DropERC1155 { - function transferTokensOnClaimHarness(address to, uint256 _tokenId, uint256 _quantityBeingClaimed) external { + function transferTokensOnClaimHarness( + address to, + uint256 _tokenId, + uint256 _quantityBeingClaimed + ) external { transferTokensOnClaim(to, _tokenId, _quantityBeingClaimed); } } contract MockERC1155Receiver { - function onERC1155Received(address, address, uint256, uint256, bytes memory) external pure returns (bytes4) { + function onERC1155Received( + address, + address, + uint256, + uint256, + bytes memory + ) external pure returns (bytes4) { return this.onERC1155Received.selector; }