Skip to content

BTT testing for DropERC1155 #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9f8cc32
set up structure
WhiteOakKong Oct 6, 2023
23ffac7
tree: collectPriceOnClaim
WhiteOakKong Oct 6, 2023
e785442
tree: freezeBatchBaseURI
WhiteOakKong Oct 6, 2023
51f02d7
tree: setMaxTotalSupply
WhiteOakKong Oct 6, 2023
0741b42
tree: setSaleRecipientForToken
WhiteOakKong Oct 6, 2023
f12f260
tree: updateBatchBaseURI
WhiteOakKong Oct 6, 2023
4d325c4
tree: transferTokensOnClaim
WhiteOakKong Oct 6, 2023
5cc5304
tree: initialize
WhiteOakKong Oct 6, 2023
aa3b9e8
tree: collectPriceOnClaim
WhiteOakKong Oct 6, 2023
b0919e2
tree: _beforeTokenTransfer
WhiteOakKong Oct 6, 2023
276f8c5
test: _beforeClaim
WhiteOakKong Oct 7, 2023
4ecdb39
test: _beforeTokenTransfer
WhiteOakKong Oct 7, 2023
eb01028
test: _canSetFunctions
WhiteOakKong Oct 7, 2023
ef3ef2a
test: burnBatch
WhiteOakKong Oct 7, 2023
7890ded
test: freezeBatchBaseURI
WhiteOakKong Oct 7, 2023
b8564bb
test: setMaxTotalSupply
WhiteOakKong Oct 7, 2023
8282a3a
test: transferTokensOnClaim
WhiteOakKong Oct 7, 2023
dcde02a
test: updateBatchBaseURI
WhiteOakKong Oct 7, 2023
d46bd39
test: setSaleRecipientForToken
WhiteOakKong Oct 8, 2023
cb508c6
test: initialize
WhiteOakKong Oct 8, 2023
bdb9479
test: collectPriceOnClaim
WhiteOakKong Oct 8, 2023
fc826ee
test: setMaxTotalSupply
WhiteOakKong Oct 8, 2023
c4db359
lint
WhiteOakKong Oct 8, 2023
d4318fc
clean
WhiteOakKong Oct 9, 2023
8302ebb
test: misc
WhiteOakKong Oct 9, 2023
5a4d9f2
Merge branch 'thirdweb-dev:main' into BTT-drop-1155
WhiteOakKong Oct 10, 2023
4279dc8
remove initializeHarness and set harness to proxy
WhiteOakKong Oct 11, 2023
3d2554d
clean/lint tests
WhiteOakKong Oct 11, 2023
7d6cfb2
Merge branch 'thirdweb-dev:main' into BTT-drop-1155
WhiteOakKong Oct 16, 2023
58b8b88
Merge branch 'main' into BTT-drop-1155
WhiteOakKong Oct 16, 2023
98eccd4
Merge branch 'main' into BTT-drop-1155
joaquim-verges Oct 16, 2023
315e923
Merge branch 'main' into BTT-drop-1155
WhiteOakKong Oct 16, 2023
793c67b
Merge branch 'main' into BTT-drop-1155
joaquim-verges Oct 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol";
import { TWProxy } from "contracts/infra/TWProxy.sol";

// Test imports
import "../../../utils/BaseTest.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(""));
}
}

contract DropERC1155Test_beforeClaim is BaseTest {
address public dropImp;
HarnessDropERC1155 public proxy;

function setUp() public override {
super.setUp();

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)));

vm.prank(deployer);
proxy.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");
proxy.beforeClaim(0, address(0), 2, address(0), 0, alp, bytes(""));
}

function test_NoRevert() public view {
DropERC1155.AllowlistProof memory alp;
proxy.beforeClaim(0, address(0), 1, address(0), 0, alp, bytes(""));
}
}
12 changes: 12 additions & 0 deletions src/test/drop/drop-erc1155/_beforeClaim/_beforeClaim.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function _beforeClaim(
uint256 _tokenId,
address,
uint256 _quantity,
address,
uint256,
AllowlistProof calldata,
bytes memory
)
└── when maxTotalSupply for _tokenId is not zero
└── when totalSupply of _tokenId + _quantity is greater than or equal to maxTotalSupply for _tokenId
└── it should revert ✅
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol";
import { TWProxy } from "contracts/infra/TWProxy.sol";

// Test imports
import "../../../utils/BaseTest.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);
}
}

contract DropERC1155Test_beforeTokenTransfer is BaseTest {
address private beforeTransfer_from = address(0x01);
address private beforeTransfer_to = address(0x01);
uint256[] private beforeTransfer_ids;
uint256[] private beforeTransfer_amounts;
bytes private beforeTransfer_data;

address public dropImp;
HarnessDropERC1155 public proxy;

function setUp() public override {
super.setUp();

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() {
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 = proxy.totalSupply(0);
proxy.beforeTokenTransfer(
deployer,
beforeTransfer_from,
beforeTransfer_to,
beforeTransfer_ids,
beforeTransfer_amounts,
beforeTransfer_data
);
uint256 afterTokenTotalSupply = proxy.totalSupply(0);
assertEq(beforeTokenTotalSupply + beforeTransfer_amounts[0], afterTokenTotalSupply);
}

function test_state_tranferToZero() public toAddressZero {
proxy.beforeTokenTransfer(
deployer,
beforeTransfer_to,
beforeTransfer_from,
beforeTransfer_ids,
beforeTransfer_amounts,
beforeTransfer_data
);
uint256 beforeTokenTotalSupply = proxy.totalSupply(0);
proxy.beforeTokenTransfer(
deployer,
beforeTransfer_from,
beforeTransfer_to,
beforeTransfer_ids,
beforeTransfer_amounts,
beforeTransfer_data
);
uint256 afterTokenTotalSupply = proxy.totalSupply(0);
assertEq(beforeTokenTotalSupply - beforeTransfer_amounts[0], afterTokenTotalSupply);
}
}
Original file line number Diff line number Diff line change
@@ -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 ✅
151 changes: 151 additions & 0 deletions src/test/drop/drop-erc1155/_canSetFunctions/_canSetFunctions.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol";
import { TWProxy } from "contracts/infra/TWProxy.sol";

// Test imports
import "../../../utils/BaseTest.sol";

contract HarnessDropERC1155 is DropERC1155 {
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();
}
}

contract DropERC1155Test_canSetFunctions is BaseTest {
address public dropImp;
HarnessDropERC1155 public proxy;

function setUp() public override {
super.setUp();

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() {
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(proxy.canSetPlatformFeeInfo());
}

function test_canSetPlatformFeeInfo_false() public DoesNotHaveDefaultAdminRole {
assertFalse(proxy.canSetPlatformFeeInfo());
}

function test_canSetPrimarySaleRecipient_true() public HasDefaultAdminRole {
assertTrue(proxy.canSetPrimarySaleRecipient());
}

function test_canSetPrimarySaleRecipient_false() public DoesNotHaveDefaultAdminRole {
assertFalse(proxy.canSetPrimarySaleRecipient());
}

function test_canSetOwner_true() public HasDefaultAdminRole {
assertTrue(proxy.canSetOwner());
}

function test_canSetOwner_false() public DoesNotHaveDefaultAdminRole {
assertFalse(proxy.canSetOwner());
}

function test_canSetRoyaltyInfo_true() public HasDefaultAdminRole {
assertTrue(proxy.canSetRoyaltyInfo());
}

function test_canSetRoyaltyInfo_false() public DoesNotHaveDefaultAdminRole {
assertFalse(proxy.canSetRoyaltyInfo());
}

function test_canSetContractURI_true() public HasDefaultAdminRole {
assertTrue(proxy.canSetContractURI());
}

function test_canSetContractURI_false() public DoesNotHaveDefaultAdminRole {
assertFalse(proxy.canSetContractURI());
}

function test_canSetClaimConditions_true() public HasDefaultAdminRole {
assertTrue(proxy.canSetClaimConditions());
}

function test_canSetClaimConditions_false() public DoesNotHaveDefaultAdminRole {
assertFalse(proxy.canSetClaimConditions());
}

function test_canLazyMint_true() public HasMinterRole {
assertTrue(proxy.canLazyMint());
}

function test_canLazyMint_false() public DoesNotHaveMinterRole {
assertFalse(proxy.canLazyMint());
}
}
Loading