Skip to content

Commit 548c428

Browse files
BTT testing for DropERC1155 (#527)
* set up structure * tree: collectPriceOnClaim * tree: freezeBatchBaseURI * tree: setMaxTotalSupply * tree: setSaleRecipientForToken * tree: updateBatchBaseURI * tree: transferTokensOnClaim * tree: initialize * tree: collectPriceOnClaim * tree: _beforeTokenTransfer * test: _beforeClaim * test: _beforeTokenTransfer * test: _canSetFunctions * test: burnBatch * test: freezeBatchBaseURI * test: setMaxTotalSupply * test: transferTokensOnClaim * test: updateBatchBaseURI * test: setSaleRecipientForToken * test: initialize * test: collectPriceOnClaim * test: setMaxTotalSupply * lint * clean * test: misc * remove initializeHarness and set harness to proxy * clean/lint tests --------- Co-authored-by: Joaquim Verges <joaquim.verges@gmail.com>
1 parent 3f4076e commit 548c428

24 files changed

+1873
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol";
5+
import { TWProxy } from "contracts/infra/TWProxy.sol";
6+
7+
// Test imports
8+
import "../../../utils/BaseTest.sol";
9+
10+
contract HarnessDropERC1155 is DropERC1155 {
11+
function beforeClaim(
12+
uint256 _tokenId,
13+
address,
14+
uint256 _quantity,
15+
address,
16+
uint256,
17+
AllowlistProof calldata alp,
18+
bytes memory
19+
) external view {
20+
_beforeClaim(_tokenId, address(0), _quantity, address(0), 0, alp, bytes(""));
21+
}
22+
}
23+
24+
contract DropERC1155Test_beforeClaim is BaseTest {
25+
address public dropImp;
26+
HarnessDropERC1155 public proxy;
27+
28+
function setUp() public override {
29+
super.setUp();
30+
31+
bytes memory initializeData = abi.encodeCall(
32+
DropERC1155.initialize,
33+
(
34+
deployer,
35+
NAME,
36+
SYMBOL,
37+
CONTRACT_URI,
38+
forwarders(),
39+
saleRecipient,
40+
royaltyRecipient,
41+
royaltyBps,
42+
platformFeeBps,
43+
platformFeeRecipient
44+
)
45+
);
46+
47+
dropImp = address(new HarnessDropERC1155());
48+
proxy = HarnessDropERC1155(address(new TWProxy(dropImp, initializeData)));
49+
50+
vm.prank(deployer);
51+
proxy.setMaxTotalSupply(0, 1);
52+
}
53+
54+
/*///////////////////////////////////////////////////////////////
55+
Unit tests: misc.
56+
//////////////////////////////////////////////////////////////*/
57+
58+
/**
59+
* note: Tests whether contract reverts when a non-holder renounces a role.
60+
*/
61+
function test_revert_ExceedMaxSupply() public {
62+
DropERC1155.AllowlistProof memory alp;
63+
vm.expectRevert("exceed max total supply");
64+
proxy.beforeClaim(0, address(0), 2, address(0), 0, alp, bytes(""));
65+
}
66+
67+
function test_NoRevert() public view {
68+
DropERC1155.AllowlistProof memory alp;
69+
proxy.beforeClaim(0, address(0), 1, address(0), 0, alp, bytes(""));
70+
}
71+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function _beforeClaim(
2+
uint256 _tokenId,
3+
address,
4+
uint256 _quantity,
5+
address,
6+
uint256,
7+
AllowlistProof calldata,
8+
bytes memory
9+
)
10+
└── when maxTotalSupply for _tokenId is not zero
11+
└── when totalSupply of _tokenId + _quantity is greater than or equal to maxTotalSupply for _tokenId
12+
└── it should revert ✅
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol";
5+
import { TWProxy } from "contracts/infra/TWProxy.sol";
6+
7+
// Test imports
8+
import "../../../utils/BaseTest.sol";
9+
10+
contract HarnessDropERC1155 is DropERC1155 {
11+
function beforeTokenTransfer(
12+
address operator,
13+
address from,
14+
address to,
15+
uint256[] memory ids,
16+
uint256[] memory amounts,
17+
bytes memory data
18+
) external {
19+
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
20+
}
21+
}
22+
23+
contract DropERC1155Test_beforeTokenTransfer is BaseTest {
24+
address private beforeTransfer_from = address(0x01);
25+
address private beforeTransfer_to = address(0x01);
26+
uint256[] private beforeTransfer_ids;
27+
uint256[] private beforeTransfer_amounts;
28+
bytes private beforeTransfer_data;
29+
30+
address public dropImp;
31+
HarnessDropERC1155 public proxy;
32+
33+
function setUp() public override {
34+
super.setUp();
35+
36+
bytes memory initializeData = abi.encodeCall(
37+
DropERC1155.initialize,
38+
(
39+
deployer,
40+
NAME,
41+
SYMBOL,
42+
CONTRACT_URI,
43+
forwarders(),
44+
saleRecipient,
45+
royaltyRecipient,
46+
royaltyBps,
47+
platformFeeBps,
48+
platformFeeRecipient
49+
)
50+
);
51+
52+
dropImp = address(new HarnessDropERC1155());
53+
proxy = HarnessDropERC1155(address(new TWProxy(dropImp, initializeData)));
54+
55+
beforeTransfer_ids = new uint256[](1);
56+
beforeTransfer_ids[0] = 0;
57+
beforeTransfer_amounts = new uint256[](1);
58+
beforeTransfer_amounts[0] = 1;
59+
beforeTransfer_data = abi.encode("", "");
60+
}
61+
62+
modifier fromAddressZero() {
63+
beforeTransfer_from = address(0);
64+
_;
65+
}
66+
67+
modifier toAddressZero() {
68+
beforeTransfer_to = address(0);
69+
_;
70+
}
71+
72+
/**
73+
* note: Tests whether contract reverts when a non-holder renounces a role.
74+
*/
75+
function test_state_transferFromZero() public fromAddressZero {
76+
uint256 beforeTokenTotalSupply = proxy.totalSupply(0);
77+
proxy.beforeTokenTransfer(
78+
deployer,
79+
beforeTransfer_from,
80+
beforeTransfer_to,
81+
beforeTransfer_ids,
82+
beforeTransfer_amounts,
83+
beforeTransfer_data
84+
);
85+
uint256 afterTokenTotalSupply = proxy.totalSupply(0);
86+
assertEq(beforeTokenTotalSupply + beforeTransfer_amounts[0], afterTokenTotalSupply);
87+
}
88+
89+
function test_state_tranferToZero() public toAddressZero {
90+
proxy.beforeTokenTransfer(
91+
deployer,
92+
beforeTransfer_to,
93+
beforeTransfer_from,
94+
beforeTransfer_ids,
95+
beforeTransfer_amounts,
96+
beforeTransfer_data
97+
);
98+
uint256 beforeTokenTotalSupply = proxy.totalSupply(0);
99+
proxy.beforeTokenTransfer(
100+
deployer,
101+
beforeTransfer_from,
102+
beforeTransfer_to,
103+
beforeTransfer_ids,
104+
beforeTransfer_amounts,
105+
beforeTransfer_data
106+
);
107+
uint256 afterTokenTotalSupply = proxy.totalSupply(0);
108+
assertEq(beforeTokenTotalSupply - beforeTransfer_amounts[0], afterTokenTotalSupply);
109+
}
110+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function _beforeTokenTransfer(
2+
address operator,
3+
address from,
4+
address to,
5+
uint256[] memory ids,
6+
uint256[] memory amounts,
7+
bytes memory data
8+
)
9+
├── when from equals to address(0)
10+
│ └── totalSupply for each id is incremented by the corresponding amounts ✅
11+
└── when to equals address(0)
12+
└── totalSupply for each id is decremented by the corresponding amounts ✅
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import { DropERC1155 } from "contracts/prebuilts/drop/DropERC1155.sol";
5+
import { TWProxy } from "contracts/infra/TWProxy.sol";
6+
7+
// Test imports
8+
import "../../../utils/BaseTest.sol";
9+
10+
contract HarnessDropERC1155 is DropERC1155 {
11+
function canSetPlatformFeeInfo() external view returns (bool) {
12+
return _canSetPlatformFeeInfo();
13+
}
14+
15+
/// @dev Checks whether primary sale recipient can be set in the given execution context.
16+
function canSetPrimarySaleRecipient() external view returns (bool) {
17+
return _canSetPrimarySaleRecipient();
18+
}
19+
20+
/// @dev Checks whether owner can be set in the given execution context.
21+
function canSetOwner() external view returns (bool) {
22+
return _canSetOwner();
23+
}
24+
25+
/// @dev Checks whether royalty info can be set in the given execution context.
26+
function canSetRoyaltyInfo() external view returns (bool) {
27+
return _canSetRoyaltyInfo();
28+
}
29+
30+
/// @dev Checks whether contract metadata can be set in the given execution context.
31+
function canSetContractURI() external view returns (bool) {
32+
return _canSetContractURI();
33+
}
34+
35+
/// @dev Checks whether platform fee info can be set in the given execution context.
36+
function canSetClaimConditions() external view returns (bool) {
37+
return _canSetClaimConditions();
38+
}
39+
40+
/// @dev Returns whether lazy minting can be done in the given execution context.
41+
function canLazyMint() external view virtual returns (bool) {
42+
return _canLazyMint();
43+
}
44+
}
45+
46+
contract DropERC1155Test_canSetFunctions is BaseTest {
47+
address public dropImp;
48+
HarnessDropERC1155 public proxy;
49+
50+
function setUp() public override {
51+
super.setUp();
52+
53+
bytes memory initializeData = abi.encodeCall(
54+
DropERC1155.initialize,
55+
(
56+
deployer,
57+
NAME,
58+
SYMBOL,
59+
CONTRACT_URI,
60+
forwarders(),
61+
saleRecipient,
62+
royaltyRecipient,
63+
royaltyBps,
64+
platformFeeBps,
65+
platformFeeRecipient
66+
)
67+
);
68+
69+
dropImp = address(new HarnessDropERC1155());
70+
proxy = HarnessDropERC1155(address(new TWProxy(dropImp, initializeData)));
71+
}
72+
73+
modifier HasDefaultAdminRole() {
74+
vm.startPrank(deployer);
75+
_;
76+
}
77+
78+
modifier DoesNotHaveDefaultAdminRole() {
79+
vm.startPrank(address(0x123));
80+
_;
81+
}
82+
83+
modifier HasMinterRole() {
84+
vm.startPrank(deployer);
85+
_;
86+
}
87+
88+
modifier DoesNotHaveMinterRole() {
89+
vm.startPrank(address(0x123));
90+
_;
91+
}
92+
93+
/**
94+
* note: Tests whether contract reverts when a non-holder renounces a role.
95+
*/
96+
function test_canSetPlatformFeeInfo_true() public HasDefaultAdminRole {
97+
assertTrue(proxy.canSetPlatformFeeInfo());
98+
}
99+
100+
function test_canSetPlatformFeeInfo_false() public DoesNotHaveDefaultAdminRole {
101+
assertFalse(proxy.canSetPlatformFeeInfo());
102+
}
103+
104+
function test_canSetPrimarySaleRecipient_true() public HasDefaultAdminRole {
105+
assertTrue(proxy.canSetPrimarySaleRecipient());
106+
}
107+
108+
function test_canSetPrimarySaleRecipient_false() public DoesNotHaveDefaultAdminRole {
109+
assertFalse(proxy.canSetPrimarySaleRecipient());
110+
}
111+
112+
function test_canSetOwner_true() public HasDefaultAdminRole {
113+
assertTrue(proxy.canSetOwner());
114+
}
115+
116+
function test_canSetOwner_false() public DoesNotHaveDefaultAdminRole {
117+
assertFalse(proxy.canSetOwner());
118+
}
119+
120+
function test_canSetRoyaltyInfo_true() public HasDefaultAdminRole {
121+
assertTrue(proxy.canSetRoyaltyInfo());
122+
}
123+
124+
function test_canSetRoyaltyInfo_false() public DoesNotHaveDefaultAdminRole {
125+
assertFalse(proxy.canSetRoyaltyInfo());
126+
}
127+
128+
function test_canSetContractURI_true() public HasDefaultAdminRole {
129+
assertTrue(proxy.canSetContractURI());
130+
}
131+
132+
function test_canSetContractURI_false() public DoesNotHaveDefaultAdminRole {
133+
assertFalse(proxy.canSetContractURI());
134+
}
135+
136+
function test_canSetClaimConditions_true() public HasDefaultAdminRole {
137+
assertTrue(proxy.canSetClaimConditions());
138+
}
139+
140+
function test_canSetClaimConditions_false() public DoesNotHaveDefaultAdminRole {
141+
assertFalse(proxy.canSetClaimConditions());
142+
}
143+
144+
function test_canLazyMint_true() public HasMinterRole {
145+
assertTrue(proxy.canLazyMint());
146+
}
147+
148+
function test_canLazyMint_false() public DoesNotHaveMinterRole {
149+
assertFalse(proxy.canLazyMint());
150+
}
151+
}

0 commit comments

Comments
 (0)