Skip to content

Commit 044cd26

Browse files
authored
BTT TokenERC721 (#551)
* test initialize * test burn * test mintTo * test mintWithSignature * test owner * test setContractURI * test setDefaultRoyaltyInfo * test setOwner * test setPlatformFeeInfo * test setPrimarySaleRecipient * test setRoyaltyInfoForToken * test tokenURI * test verify * test other functions * test burn burn-to-claim contract --------- Signed-off-by: Yash <72552910+kumaryash90@users.noreply.github.com>
1 parent 6a6771b commit 044cd26

File tree

30 files changed

+2637
-2
lines changed

30 files changed

+2637
-2
lines changed

src/test/burn-to-claim-drop-BTT/logic/other-functions/other.t.sol

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ contract MyBurnToClaimDrop721Logic is BurnToClaimDrop721Logic {
6565
function beforeClaim(uint256 _quantity, AllowlistProof calldata proof) external {
6666
_beforeClaim(address(0), _quantity, address(0), 0, proof, "");
6767
}
68+
69+
function mintTo(address _recipient) external {
70+
_safeMint(_recipient, 1);
71+
}
6872
}
6973

7074
contract BurnToClaimDrop721Logic_OtherFunctions is BaseTest, IExtension {
7175
MyBurnToClaimDrop721Logic public drop;
7276
address internal caller;
77+
address internal recipient;
7378

7479
function setUp() public override {
7580
super.setUp();
@@ -106,6 +111,7 @@ contract BurnToClaimDrop721Logic_OtherFunctions is BaseTest, IExtension {
106111
);
107112

108113
caller = getActor(5);
114+
recipient = getActor(6);
109115
}
110116

111117
function _setupExtensions() internal returns (Extension[] memory extensions) {
@@ -146,7 +152,7 @@ contract BurnToClaimDrop721Logic_OtherFunctions is BaseTest, IExtension {
146152
implementation: dropLogic
147153
});
148154

149-
extension_drop.functions = new ExtensionFunction[](15);
155+
extension_drop.functions = new ExtensionFunction[](18);
150156
extension_drop.functions[0] = ExtensionFunction(
151157
MyBurnToClaimDrop721Logic.canSetPlatformFeeInfo.selector,
152158
"canSetPlatformFeeInfo()"
@@ -204,6 +210,12 @@ contract BurnToClaimDrop721Logic_OtherFunctions is BaseTest, IExtension {
204210
BurnToClaimDrop721Logic.setMaxTotalMinted.selector,
205211
"setMaxTotalMinted(uint256)"
206212
);
213+
extension_drop.functions[15] = ExtensionFunction(BurnToClaimDrop721Logic.burn.selector, "burn(uint256)");
214+
extension_drop.functions[16] = ExtensionFunction(MyBurnToClaimDrop721Logic.mintTo.selector, "mintTo(address)");
215+
extension_drop.functions[17] = ExtensionFunction(
216+
IERC721.setApprovalForAll.selector,
217+
"setApprovalForAll(address,bool)"
218+
);
207219

208220
extensions[1] = extension_drop;
209221
}
@@ -347,4 +359,41 @@ contract BurnToClaimDrop721Logic_OtherFunctions is BaseTest, IExtension {
347359

348360
drop.beforeClaim(10, proof); // no revert if max total mint cap is set to 0
349361
}
362+
363+
//=========== burn tests =========
364+
365+
function test_burn_whenNotOwnerNorApproved() public {
366+
// mint
367+
drop.mintTo(recipient);
368+
369+
// burn
370+
vm.expectRevert();
371+
drop.burn(0);
372+
}
373+
374+
function test_burn_whenOwner() public {
375+
// mint
376+
drop.mintTo(recipient);
377+
378+
// burn
379+
vm.prank(recipient);
380+
drop.burn(0);
381+
382+
vm.expectRevert(); // checking non-existent token, because burned
383+
drop.ownerOf(0);
384+
}
385+
386+
function test_burn_whenApproved() public {
387+
drop.mintTo(recipient);
388+
389+
vm.prank(recipient);
390+
drop.setApprovalForAll(caller, true);
391+
392+
// burn
393+
vm.prank(caller);
394+
drop.burn(0);
395+
396+
vm.expectRevert(); // checking non-existent token, because burned
397+
drop.ownerOf(0);
398+
}
350399
}

src/test/burn-to-claim-drop-BTT/logic/other-functions/other.tree

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ _canSetBurnToClaim()
4747
└── it should return true ✅
4848

4949
burn(uint256 tokenId)
50-
├── when the caller isn't the owner of `tokenId`
50+
├── when the caller isn't the owner of `tokenId` or token not approved to caller
5151
│ └── it should revert ✅
5252
└── when the caller owns `tokenId`
53+
│ └── it should burn the token ✅
54+
└── when the `tokenId` is approved to caller
5355
└── it should burn the token ✅
5456

5557
_beforeTokenTransfers(
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "../../utils/BaseTest.sol";
5+
6+
import { TWProxy } from "contracts/infra/TWProxy.sol";
7+
8+
contract MyTokenERC721 is TokenERC721 {}
9+
10+
contract TokenERC721Test_Burn is BaseTest {
11+
address public implementation;
12+
address public proxy;
13+
address public caller;
14+
address public recipient;
15+
string public uri;
16+
17+
MyTokenERC721 internal tokenContract;
18+
19+
event MetadataUpdate(uint256 _tokenId);
20+
event TokensMinted(address indexed mintedTo, uint256 indexed tokenIdMinted, string uri);
21+
22+
function setUp() public override {
23+
super.setUp();
24+
25+
// Deploy implementation.
26+
implementation = address(new MyTokenERC721());
27+
caller = getActor(1);
28+
recipient = getActor(2);
29+
30+
// Deploy proxy pointing to implementaion.
31+
vm.prank(deployer);
32+
proxy = address(
33+
new TWProxy(
34+
implementation,
35+
abi.encodeCall(
36+
TokenERC721.initialize,
37+
(
38+
deployer,
39+
NAME,
40+
SYMBOL,
41+
CONTRACT_URI,
42+
forwarders(),
43+
saleRecipient,
44+
royaltyRecipient,
45+
royaltyBps,
46+
platformFeeBps,
47+
platformFeeRecipient
48+
)
49+
)
50+
)
51+
);
52+
53+
tokenContract = MyTokenERC721(proxy);
54+
uri = "uri";
55+
56+
vm.prank(deployer);
57+
tokenContract.grantRole(keccak256("MINTER_ROLE"), caller);
58+
}
59+
60+
function test_burn_whenNotOwnerNorApproved() public {
61+
// state before
62+
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();
63+
64+
// mint
65+
vm.prank(caller);
66+
uint256 _tokenId = tokenContract.mintTo(recipient, uri);
67+
68+
// burn
69+
vm.expectRevert("ERC721Burnable: caller is not owner nor approved");
70+
tokenContract.burn(_tokenId);
71+
}
72+
73+
function test_burn_whenOwner() public {
74+
// state before
75+
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();
76+
77+
// mint
78+
vm.prank(caller);
79+
uint256 _tokenId = tokenContract.mintTo(recipient, uri);
80+
81+
// burn
82+
vm.prank(recipient);
83+
tokenContract.burn(_tokenId);
84+
85+
vm.expectRevert(); // checking non-existent token, because burned
86+
tokenContract.ownerOf(_tokenId);
87+
}
88+
89+
function test_burn_whenApproved() public {
90+
// state before
91+
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();
92+
93+
// mint
94+
vm.prank(caller);
95+
uint256 _tokenId = tokenContract.mintTo(recipient, uri);
96+
97+
vm.prank(recipient);
98+
tokenContract.setApprovalForAll(caller, true);
99+
100+
// burn
101+
vm.prank(caller);
102+
tokenContract.burn(_tokenId);
103+
104+
vm.expectRevert(); // checking non-existent token, because burned
105+
tokenContract.ownerOf(_tokenId);
106+
}
107+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
burn(uint256 tokenId)
2+
├── when the caller isn't the owner of `tokenId` or token not approved to caller
3+
│ └── it should revert ✅
4+
└── when the caller owns `tokenId`
5+
│ └── it should burn the token ✅
6+
└── when the `tokenId` is approved to caller
7+
└── it should burn the token ✅
8+

0 commit comments

Comments
 (0)