Skip to content

Commit 4cc7fc5

Browse files
BTT Test Coverage: DropERC721 (#526)
* rip solady * tree: reveal * tree: updateBatchBaseURI * tree: freezeBatchBaseURI * tree: setMaxTotalSupply * tree: _beforeClaim * tree: _collectPriceOnClaim * tree: _canSetFunctions * tree: _transferTokensOnClaim * tree: miscellaneous * test: lazyMint.t.sol * correct BatchMintMetadata natspec decription * test: lazyMint * test: reveal * test: misc * test: _canSetFunctions * tree cleanup * test: freeze * test: setMaxTotalSupply * test: updateBatchBaseURI * test: _beforeClaim * test: _collectPriceOnClaim * tree: initializer * test: initializer * lint * test: misd * test: _transferTokensOnClaim * clean and lint * remove harness initializer * _transferTokensOnClaim redo harness on TWProxy * clean/lint * update lazyMint.tree * update tree file with checks * run lint/prettier --------- Co-authored-by: Joaquim Verges <[email protected]>
1 parent 548c428 commit 4cc7fc5

23 files changed

+1911
-1
lines changed

contracts/extension/BatchMintMetadata.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pragma solidity ^0.8.0;
1111
*/
1212

1313
contract BatchMintMetadata {
14-
/// @dev Largest tokenId of each batch of tokens with the same baseURI.
14+
/// @dev Largest tokenId of each batch of tokens with the same baseURI + 1 {ex: batchId 100 at position 0 includes tokens 0-99}
1515
uint256[] private batchIds;
1616

1717
/// @dev Mapping from id of a batch of tokens => to base URI for the respective batch of tokens.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import { DropERC721 } from "contracts/prebuilts/drop/DropERC721.sol";
5+
6+
// Test imports
7+
import "../../../utils/BaseTest.sol";
8+
9+
contract DropERC721Test_beforeClaim is BaseTest {
10+
event TokenURIRevealed(uint256 indexed index, string revealedURI);
11+
12+
DropERC721 public drop;
13+
14+
bytes private beforeClaim_data;
15+
string private beforeClaim_baseURI;
16+
uint256 private beforeClaim_amount;
17+
address private receiver = address(0x92Bb439374a091c7507bE100183d8D1Ed2c9dAD3);
18+
19+
DropERC721.AllowlistProof private alp;
20+
21+
function setUp() public override {
22+
super.setUp();
23+
drop = DropERC721(getContract("DropERC721"));
24+
25+
string[] memory inputs = new string[](5);
26+
27+
inputs[0] = "node";
28+
inputs[1] = "src/test/scripts/generateRoot.ts";
29+
inputs[2] = "300";
30+
inputs[3] = "0";
31+
inputs[4] = Strings.toHexString(uint160(address(erc20)));
32+
33+
bytes memory result = vm.ffi(inputs);
34+
// revert();
35+
bytes32 root = abi.decode(result, (bytes32));
36+
37+
inputs[1] = "src/test/scripts/getProof.ts";
38+
result = vm.ffi(inputs);
39+
bytes32[] memory proofs = abi.decode(result, (bytes32[]));
40+
41+
alp.proof = proofs;
42+
alp.quantityLimitPerWallet = 300;
43+
alp.pricePerToken = 0;
44+
alp.currency = address(erc20);
45+
46+
vm.warp(1);
47+
48+
DropERC721.ClaimCondition[] memory conditions = new DropERC721.ClaimCondition[](1);
49+
conditions[0].maxClaimableSupply = 500;
50+
conditions[0].quantityLimitPerWallet = 10;
51+
conditions[0].merkleRoot = root;
52+
conditions[0].pricePerToken = 10;
53+
conditions[0].currency = address(erc20);
54+
55+
vm.prank(deployer);
56+
drop.setClaimConditions(conditions, false);
57+
}
58+
59+
/*///////////////////////////////////////////////////////////////
60+
Branch Testing
61+
//////////////////////////////////////////////////////////////*/
62+
63+
modifier lazyMintUnEncrypted() {
64+
beforeClaim_amount = 10;
65+
beforeClaim_baseURI = "ipfs://";
66+
vm.prank(deployer);
67+
drop.lazyMint(beforeClaim_amount, beforeClaim_baseURI, beforeClaim_data);
68+
_;
69+
}
70+
71+
modifier setMaxSupply() {
72+
vm.prank(deployer);
73+
drop.setMaxTotalSupply(5);
74+
_;
75+
}
76+
77+
function test_revert_greaterThanNextTokenIdToLazyMint() public lazyMintUnEncrypted {
78+
vm.prank(receiver, receiver);
79+
vm.expectRevert("!Tokens");
80+
drop.claim(receiver, 11, address(erc20), 0, alp, "");
81+
}
82+
83+
function test_revert_greaterThanMaxTotalSupply() public lazyMintUnEncrypted setMaxSupply {
84+
vm.prank(receiver, receiver);
85+
vm.expectRevert("!Supply");
86+
drop.claim(receiver, 6, address(erc20), 0, alp, "");
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function _beforeClaim(
2+
address,
3+
uint256 _quantity,
4+
address,
5+
uint256,
6+
AllowlistProof calldata,
7+
bytes memory
8+
)
9+
├── when _current index + _quantity are greater than nextTokenIdToLazyMint
10+
│ └── it should revert ✅
11+
└── when maxTotalSupply does not equal zero and _currentIndex + _quantity is greater than maxTotalSupply
12+
└── it should revert ✅
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import { DropERC721 } from "contracts/prebuilts/drop/DropERC721.sol";
5+
6+
// Test imports
7+
import "../../../utils/BaseTest.sol";
8+
9+
contract DropERC721Test_canSetFunctions is BaseTest {
10+
DropERC721 public drop;
11+
12+
bytes private canset_data;
13+
string private canset_baseURI;
14+
uint256 private canset_amount;
15+
bytes private canset_encryptedURI;
16+
bytes32 private canset_provenanceHash;
17+
address private unauthorized = address(0x123);
18+
19+
function setUp() public override {
20+
super.setUp();
21+
drop = DropERC721(getContract("DropERC721"));
22+
}
23+
24+
/*///////////////////////////////////////////////////////////////
25+
Branch Testing
26+
//////////////////////////////////////////////////////////////*/
27+
28+
modifier callerNotAdmin() {
29+
vm.startPrank(unauthorized);
30+
_;
31+
}
32+
33+
modifier callerAdmin() {
34+
vm.startPrank(deployer);
35+
_;
36+
}
37+
38+
modifier callerNotMinter() {
39+
vm.startPrank(unauthorized);
40+
_;
41+
}
42+
43+
modifier callerMinter() {
44+
vm.startPrank(deployer);
45+
_;
46+
}
47+
48+
function test__canSetPlatformFeeInfo_revert_callerNotAdmin() public callerNotAdmin {
49+
vm.expectRevert("Not authorized");
50+
drop.setPlatformFeeInfo(address(0x1), 1);
51+
}
52+
53+
function test__canSetPlatformFeeInfo_callerAdmin() public callerAdmin {
54+
drop.setPlatformFeeInfo(address(0x1), 1);
55+
(address recipient, uint16 bps) = drop.getPlatformFeeInfo();
56+
assertEq(recipient, address(0x1));
57+
assertEq(bps, 1);
58+
}
59+
60+
function test__canSetPrimarySaleRecipient_revert_callerNotAdmin() public callerNotAdmin {
61+
vm.expectRevert("Not authorized");
62+
drop.setPrimarySaleRecipient(address(0x1));
63+
}
64+
65+
function test__canSetPrimarySaleRecipient_callerAdmin() public callerAdmin {
66+
drop.setPrimarySaleRecipient(address(0x1));
67+
assertEq(drop.primarySaleRecipient(), address(0x1));
68+
}
69+
70+
function test__canSetOwner_revert_callerNotAdmin() public callerNotAdmin {
71+
vm.expectRevert("Not authorized");
72+
drop.setOwner(address(0x1));
73+
}
74+
75+
function test__canSetOwner_callerAdmin() public callerAdmin {
76+
drop.setOwner(address(0x1));
77+
assertEq(drop.owner(), address(0x1));
78+
}
79+
80+
function test__canSetRoyaltyInfo_revert_callerNotAdmin() public callerNotAdmin {
81+
vm.expectRevert("Not authorized");
82+
drop.setDefaultRoyaltyInfo(address(0x1), 1);
83+
}
84+
85+
function test__canSetRoyaltyInfo_callerAdmin() public callerAdmin {
86+
drop.setDefaultRoyaltyInfo(address(0x1), 1);
87+
(address recipient, uint16 bps) = drop.getDefaultRoyaltyInfo();
88+
assertEq(recipient, address(0x1));
89+
assertEq(bps, 1);
90+
}
91+
92+
function test__canSetContractURI_revert_callerNotAdmin() public callerNotAdmin {
93+
vm.expectRevert("Not authorized");
94+
drop.setContractURI("ipfs://");
95+
}
96+
97+
function test__canSetContractURI_callerAdmin() public callerAdmin {
98+
drop.setContractURI("ipfs://");
99+
assertEq(drop.contractURI(), "ipfs://");
100+
}
101+
102+
function test__canSetClaimConditions_revert_callerNotAdmin() public callerNotAdmin {
103+
DropERC721.ClaimCondition[] memory conditions = new DropERC721.ClaimCondition[](1);
104+
conditions[0].maxClaimableSupply = 500;
105+
conditions[0].quantityLimitPerWallet = 10;
106+
conditions[0].merkleRoot = bytes32(0);
107+
conditions[0].pricePerToken = 10;
108+
conditions[0].currency = address(0x111);
109+
vm.expectRevert("Not authorized");
110+
drop.setClaimConditions(conditions, true);
111+
}
112+
113+
function test__canSetClaimConditions_callerAdmin() public callerAdmin {
114+
DropERC721.ClaimCondition[] memory conditions = new DropERC721.ClaimCondition[](1);
115+
conditions[0].maxClaimableSupply = 500;
116+
conditions[0].quantityLimitPerWallet = 10;
117+
conditions[0].merkleRoot = bytes32(0);
118+
conditions[0].pricePerToken = 10;
119+
conditions[0].currency = address(0x111);
120+
drop.setClaimConditions(conditions, true);
121+
}
122+
123+
function test__canLazyMint_revert_callerNotMinter() public callerNotMinter {
124+
canset_amount = 10;
125+
canset_baseURI = "ipfs://";
126+
canset_data = abi.encode(canset_encryptedURI, canset_provenanceHash);
127+
vm.expectRevert("Not authorized");
128+
drop.lazyMint(canset_amount, canset_baseURI, canset_data);
129+
}
130+
131+
function test__canLazyMint_callerMinter() public callerMinter {
132+
canset_amount = 10;
133+
canset_baseURI = "ipfs://";
134+
canset_data = abi.encode(canset_encryptedURI, canset_provenanceHash);
135+
drop.lazyMint(canset_amount, canset_baseURI, canset_data);
136+
}
137+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function _canSetPlatformFeeInfo()
2+
├── when caller has DEFAULT_ADMIN_ROLE
3+
│ └── it should return true ✅
4+
└── when caller does not have DEFAULT_ADMIN_ROLE
5+
└── it should return false ✅
6+
7+
function _canSetPrimarySaleRecipient()
8+
├── when caller has DEFAULT_ADMIN_ROLE
9+
│ └── it should return true ✅
10+
└── when caller does not have DEFAULT_ADMIN_ROLE
11+
└── it should return false ✅
12+
13+
function _canSetOwner()
14+
├── when caller has DEFAULT_ADMIN_ROLE
15+
│ └── it should return true ✅
16+
└── when caller does not have DEFAULT_ADMIN_ROLE
17+
└── it should return false ✅
18+
19+
function _canSetRoyaltyInfo()
20+
├── when caller has DEFAULT_ADMIN_ROLE
21+
│ └── it should return true ✅
22+
└── when caller does not have DEFAULT_ADMIN_ROLE
23+
└── it should return false ✅
24+
25+
function _canSetContractURI()
26+
├── when caller has DEFAULT_ADMIN_ROLE
27+
│ └── it should return true ✅
28+
└── when caller does not have DEFAULT_ADMIN_ROLE
29+
└── it should return false ✅
30+
31+
function _canSetClaimConditions()
32+
├── when caller has DEFAULT_ADMIN_ROLE
33+
│ └── it should return true ✅
34+
└── when caller does not have DEFAULT_ADMIN_ROLE
35+
└── it should return false ✅
36+
37+
function _canLazyMint()
38+
├── when caller has minterRole
39+
│ └── it should return true ✅
40+
└── when caller does not have minterRole
41+
└── it should return false ✅

0 commit comments

Comments
 (0)