Skip to content
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

BTT Test Coverage: DropERC721 #526

Merged
merged 42 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0a0f1de
rip solady
WhiteOakKong Oct 4, 2023
c3ba102
tree: reveal
WhiteOakKong Oct 4, 2023
ba447c7
tree: updateBatchBaseURI
WhiteOakKong Oct 4, 2023
6e08734
tree: freezeBatchBaseURI
WhiteOakKong Oct 4, 2023
8422721
tree: setMaxTotalSupply
WhiteOakKong Oct 4, 2023
eb4528c
tree: _beforeClaim
WhiteOakKong Oct 4, 2023
0b733f6
tree: _collectPriceOnClaim
WhiteOakKong Oct 4, 2023
3b94c8b
tree: _canSetFunctions
WhiteOakKong Oct 4, 2023
98ef816
tree: _transferTokensOnClaim
WhiteOakKong Oct 4, 2023
5f9d306
tree: miscellaneous
WhiteOakKong Oct 4, 2023
39489fc
test: lazyMint.t.sol
WhiteOakKong Oct 4, 2023
d1b9322
correct BatchMintMetadata natspec decription
WhiteOakKong Oct 5, 2023
f3494a4
test: lazyMint
WhiteOakKong Oct 5, 2023
17b180d
test: reveal
WhiteOakKong Oct 5, 2023
1dd0714
test: misc
WhiteOakKong Oct 5, 2023
4495b39
test: _canSetFunctions
WhiteOakKong Oct 5, 2023
2e04cda
tree cleanup
WhiteOakKong Oct 5, 2023
8598a66
test: freeze
WhiteOakKong Oct 5, 2023
95ba9ce
test: setMaxTotalSupply
WhiteOakKong Oct 5, 2023
04c9fc8
test: updateBatchBaseURI
WhiteOakKong Oct 5, 2023
04220bf
test: _beforeClaim
WhiteOakKong Oct 6, 2023
80dce70
test: _collectPriceOnClaim
WhiteOakKong Oct 6, 2023
bc9c2d0
tree: initializer
WhiteOakKong Oct 6, 2023
32dee8c
test: initializer
WhiteOakKong Oct 6, 2023
88a8be4
lint
WhiteOakKong Oct 6, 2023
76cb657
test: misd
WhiteOakKong Oct 6, 2023
a63f50d
test: _transferTokensOnClaim
WhiteOakKong Oct 6, 2023
6561e56
clean and lint
WhiteOakKong Oct 6, 2023
a745dc0
Merge branch 'main' into btt-drop-erc721
WhiteOakKong Oct 6, 2023
d8a1fb9
Merge branch 'thirdweb-dev:main' into btt-drop-erc721
WhiteOakKong Oct 10, 2023
cf4fc16
remove harness initializer
WhiteOakKong Oct 10, 2023
5624be7
_transferTokensOnClaim redo harness on TWProxy
WhiteOakKong Oct 11, 2023
96a8bd4
clean/lint
WhiteOakKong Oct 11, 2023
053a188
Merge branch 'thirdweb-dev:main' into btt-drop-erc721
WhiteOakKong Oct 16, 2023
07bf30b
Merge branch 'main' into btt-drop-erc721
WhiteOakKong Oct 16, 2023
bc6e7ec
update lazyMint.tree
WhiteOakKong Oct 16, 2023
64be2aa
Merge branch 'main' into btt-drop-erc721
joaquim-verges Oct 16, 2023
ebabf1e
update tree file with checks
WhiteOakKong Oct 16, 2023
7ab434c
Merge branch 'main' into btt-drop-erc721
WhiteOakKong Oct 16, 2023
86b9fc2
run lint/prettier
WhiteOakKong Oct 16, 2023
51e54e4
Merge branch 'main' into btt-drop-erc721
joaquim-verges Oct 16, 2023
7cf78fe
Merge branch 'main' into btt-drop-erc721
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
2 changes: 1 addition & 1 deletion contracts/extension/BatchMintMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pragma solidity ^0.8.0;
*/

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

/// @dev Mapping from id of a batch of tokens => to base URI for the respective batch of tokens.
Expand Down
89 changes: 89 additions & 0 deletions src/test/drop/drop-erc721/_beforeClaim/_beforeClaim.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { DropERC721 } from "contracts/prebuilts/drop/DropERC721.sol";

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

contract DropERC721Test_beforeClaim is BaseTest {

event TokenURIRevealed(uint256 indexed index, string revealedURI);

DropERC721 public drop;

bytes private beforeClaim_data;
string private beforeClaim_baseURI;
uint256 private beforeClaim_amount;
address private receiver = address(0x92Bb439374a091c7507bE100183d8D1Ed2c9dAD3);

DropERC721.AllowlistProof private alp;

function setUp() public override {
super.setUp();
drop = DropERC721(getContract("DropERC721"));

string[] memory inputs = new string[](5);

inputs[0] = "node";
inputs[1] = "src/test/scripts/generateRoot.ts";
inputs[2] = "300";
inputs[3] = "0";
inputs[4] = Strings.toHexString(uint160(address(erc20)));

bytes memory result = vm.ffi(inputs);
// revert();
bytes32 root = abi.decode(result, (bytes32));

inputs[1] = "src/test/scripts/getProof.ts";
result = vm.ffi(inputs);
bytes32[] memory proofs = abi.decode(result, (bytes32[]));

alp.proof = proofs;
alp.quantityLimitPerWallet = 300;
alp.pricePerToken = 0;
alp.currency = address(erc20);

vm.warp(1);

DropERC721.ClaimCondition[] memory conditions = new DropERC721.ClaimCondition[](1);
conditions[0].maxClaimableSupply = 500;
conditions[0].quantityLimitPerWallet = 10;
conditions[0].merkleRoot = root;
conditions[0].pricePerToken = 10;
conditions[0].currency = address(erc20);

vm.prank(deployer);
drop.setClaimConditions(conditions, false);
}

/*///////////////////////////////////////////////////////////////
Branch Testing
//////////////////////////////////////////////////////////////*/

modifier lazyMintUnEncrypted() {
beforeClaim_amount = 10;
beforeClaim_baseURI = "ipfs://";
vm.prank(deployer);
drop.lazyMint(beforeClaim_amount, beforeClaim_baseURI, beforeClaim_data);
_;
}

modifier setMaxSupply() {
vm.prank(deployer);
drop.setMaxTotalSupply(5);
_;
}

function test_revert_greaterThanNextTokenIdToLazyMint() public lazyMintUnEncrypted {
vm.prank(receiver, receiver);
vm.expectRevert("!Tokens");
drop.claim(receiver, 11, address(erc20), 0, alp, "");
}

function test_revert_greaterThanMaxTotalSupply() public lazyMintUnEncrypted setMaxSupply {
vm.prank(receiver, receiver);
vm.expectRevert("!Supply");
drop.claim(receiver, 6, address(erc20), 0, alp, "");
}
}
12 changes: 12 additions & 0 deletions src/test/drop/drop-erc721/_beforeClaim/_beforeClaim.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function _beforeClaim(
address,
uint256 _quantity,
address,
uint256,
AllowlistProof calldata,
bytes memory
)
├── when _current index + _quantity are greater than nextTokenIdToLazyMint
│ └── it should revert ✅
└── when maxTotalSupply does not equal zero and _currentIndex + _quantity is greater than maxTotalSupply
└── it should revert ✅
138 changes: 138 additions & 0 deletions src/test/drop/drop-erc721/_canSetFunctions/_canSetFunctions.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { DropERC721 } from "contracts/prebuilts/drop/DropERC721.sol";

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

contract DropERC721Test_canSetFunctions is BaseTest {

DropERC721 public drop;

bytes private canset_data;
string private canset_baseURI;
uint256 private canset_amount;
bytes private canset_encryptedURI;
bytes32 private canset_provenanceHash;
address private unauthorized = address(0x123);

function setUp() public override {
super.setUp();
drop = DropERC721(getContract("DropERC721"));
}

/*///////////////////////////////////////////////////////////////
Branch Testing
//////////////////////////////////////////////////////////////*/

modifier callerNotAdmin() {
vm.startPrank(unauthorized);
_;
}

modifier callerAdmin() {
vm.startPrank(deployer);
_;
}

modifier callerNotMinter() {
vm.startPrank(unauthorized);
_;
}

modifier callerMinter() {
vm.startPrank(deployer);
_;
}

function test__canSetPlatformFeeInfo_revert_callerNotAdmin() public callerNotAdmin {
vm.expectRevert("Not authorized");
drop.setPlatformFeeInfo(address(0x1), 1);
}

function test__canSetPlatformFeeInfo_callerAdmin() public callerAdmin {
drop.setPlatformFeeInfo(address(0x1), 1);
(address recipient, uint16 bps) = drop.getPlatformFeeInfo();
assertEq(recipient, address(0x1));
assertEq(bps, 1);
}

function test__canSetPrimarySaleRecipient_revert_callerNotAdmin() public callerNotAdmin {
vm.expectRevert("Not authorized");
drop.setPrimarySaleRecipient(address(0x1));
}

function test__canSetPrimarySaleRecipient_callerAdmin() public callerAdmin {
drop.setPrimarySaleRecipient(address(0x1));
assertEq(drop.primarySaleRecipient(), address(0x1));
}

function test__canSetOwner_revert_callerNotAdmin() public callerNotAdmin {
vm.expectRevert("Not authorized");
drop.setOwner(address(0x1));
}

function test__canSetOwner_callerAdmin() public callerAdmin {
drop.setOwner(address(0x1));
assertEq(drop.owner(), address(0x1));
}

function test__canSetRoyaltyInfo_revert_callerNotAdmin() public callerNotAdmin {
vm.expectRevert("Not authorized");
drop.setDefaultRoyaltyInfo(address(0x1), 1);
}

function test__canSetRoyaltyInfo_callerAdmin() public callerAdmin {
drop.setDefaultRoyaltyInfo(address(0x1), 1);
(address recipient, uint16 bps) = drop.getDefaultRoyaltyInfo();
assertEq(recipient, address(0x1));
assertEq(bps, 1);
}

function test__canSetContractURI_revert_callerNotAdmin() public callerNotAdmin {
vm.expectRevert("Not authorized");
drop.setContractURI("ipfs://");
}

function test__canSetContractURI_callerAdmin() public callerAdmin {
drop.setContractURI("ipfs://");
assertEq(drop.contractURI(), "ipfs://");
}

function test__canSetClaimConditions_revert_callerNotAdmin() public callerNotAdmin {
DropERC721.ClaimCondition[] memory conditions = new DropERC721.ClaimCondition[](1);
conditions[0].maxClaimableSupply = 500;
conditions[0].quantityLimitPerWallet = 10;
conditions[0].merkleRoot = bytes32(0);
conditions[0].pricePerToken = 10;
conditions[0].currency = address(0x111);
vm.expectRevert("Not authorized");
drop.setClaimConditions(conditions, true);
}

function test__canSetClaimConditions_callerAdmin() public callerAdmin {
DropERC721.ClaimCondition[] memory conditions = new DropERC721.ClaimCondition[](1);
conditions[0].maxClaimableSupply = 500;
conditions[0].quantityLimitPerWallet = 10;
conditions[0].merkleRoot = bytes32(0);
conditions[0].pricePerToken = 10;
conditions[0].currency = address(0x111);
drop.setClaimConditions(conditions, true);
}

function test__canLazyMint_revert_callerNotMinter() public callerNotMinter {
canset_amount = 10;
canset_baseURI = "ipfs://";
canset_data = abi.encode(canset_encryptedURI, canset_provenanceHash);
vm.expectRevert("Not authorized");
drop.lazyMint(canset_amount, canset_baseURI, canset_data);
}

function test__canLazyMint_callerMinter() public callerMinter {
canset_amount = 10;
canset_baseURI = "ipfs://";
canset_data = abi.encode(canset_encryptedURI, canset_provenanceHash);
drop.lazyMint(canset_amount, canset_baseURI, canset_data);
}
}
41 changes: 41 additions & 0 deletions src/test/drop/drop-erc721/_canSetFunctions/_canSetFunctions.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function _canSetPlatformFeeInfo()
├── when caller has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when caller does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅

function _canSetPrimarySaleRecipient()
├── when caller has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when caller does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅

function _canSetOwner()
├── when caller has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when caller does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅

function _canSetRoyaltyInfo()
├── when caller has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when caller does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅

function _canSetContractURI()
├── when caller has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when caller does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅

function _canSetClaimConditions()
├── when caller has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when caller does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅

function _canLazyMint()
├── when caller has minterRole
│ └── it should return true ✅
└── when caller does not have minterRole
└── it should return false ✅
Loading