Skip to content

Commit

Permalink
BTT TokenERC721 (#551)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
kumaryash90 authored Oct 24, 2023
1 parent 6a6771b commit 044cd26
Show file tree
Hide file tree
Showing 30 changed files with 2,637 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ contract MyBurnToClaimDrop721Logic is BurnToClaimDrop721Logic {
function beforeClaim(uint256 _quantity, AllowlistProof calldata proof) external {
_beforeClaim(address(0), _quantity, address(0), 0, proof, "");
}

function mintTo(address _recipient) external {
_safeMint(_recipient, 1);
}
}

contract BurnToClaimDrop721Logic_OtherFunctions is BaseTest, IExtension {
MyBurnToClaimDrop721Logic public drop;
address internal caller;
address internal recipient;

function setUp() public override {
super.setUp();
Expand Down Expand Up @@ -106,6 +111,7 @@ contract BurnToClaimDrop721Logic_OtherFunctions is BaseTest, IExtension {
);

caller = getActor(5);
recipient = getActor(6);
}

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

extension_drop.functions = new ExtensionFunction[](15);
extension_drop.functions = new ExtensionFunction[](18);
extension_drop.functions[0] = ExtensionFunction(
MyBurnToClaimDrop721Logic.canSetPlatformFeeInfo.selector,
"canSetPlatformFeeInfo()"
Expand Down Expand Up @@ -204,6 +210,12 @@ contract BurnToClaimDrop721Logic_OtherFunctions is BaseTest, IExtension {
BurnToClaimDrop721Logic.setMaxTotalMinted.selector,
"setMaxTotalMinted(uint256)"
);
extension_drop.functions[15] = ExtensionFunction(BurnToClaimDrop721Logic.burn.selector, "burn(uint256)");
extension_drop.functions[16] = ExtensionFunction(MyBurnToClaimDrop721Logic.mintTo.selector, "mintTo(address)");
extension_drop.functions[17] = ExtensionFunction(
IERC721.setApprovalForAll.selector,
"setApprovalForAll(address,bool)"
);

extensions[1] = extension_drop;
}
Expand Down Expand Up @@ -347,4 +359,41 @@ contract BurnToClaimDrop721Logic_OtherFunctions is BaseTest, IExtension {

drop.beforeClaim(10, proof); // no revert if max total mint cap is set to 0
}

//=========== burn tests =========

function test_burn_whenNotOwnerNorApproved() public {
// mint
drop.mintTo(recipient);

// burn
vm.expectRevert();
drop.burn(0);
}

function test_burn_whenOwner() public {
// mint
drop.mintTo(recipient);

// burn
vm.prank(recipient);
drop.burn(0);

vm.expectRevert(); // checking non-existent token, because burned
drop.ownerOf(0);
}

function test_burn_whenApproved() public {
drop.mintTo(recipient);

vm.prank(recipient);
drop.setApprovalForAll(caller, true);

// burn
vm.prank(caller);
drop.burn(0);

vm.expectRevert(); // checking non-existent token, because burned
drop.ownerOf(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ _canSetBurnToClaim()
└── it should return true ✅

burn(uint256 tokenId)
├── when the caller isn't the owner of `tokenId`
├── when the caller isn't the owner of `tokenId` or token not approved to caller
│ └── it should revert ✅
└── when the caller owns `tokenId`
│ └── it should burn the token ✅
└── when the `tokenId` is approved to caller
└── it should burn the token ✅

_beforeTokenTransfers(
Expand Down
107 changes: 107 additions & 0 deletions src/test/tokenerc721-BTT/burn/burn.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

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

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

contract MyTokenERC721 is TokenERC721 {}

contract TokenERC721Test_Burn is BaseTest {
address public implementation;
address public proxy;
address public caller;
address public recipient;
string public uri;

MyTokenERC721 internal tokenContract;

event MetadataUpdate(uint256 _tokenId);
event TokensMinted(address indexed mintedTo, uint256 indexed tokenIdMinted, string uri);

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

// Deploy implementation.
implementation = address(new MyTokenERC721());
caller = getActor(1);
recipient = getActor(2);

// Deploy proxy pointing to implementaion.
vm.prank(deployer);
proxy = address(
new TWProxy(
implementation,
abi.encodeCall(
TokenERC721.initialize,
(
deployer,
NAME,
SYMBOL,
CONTRACT_URI,
forwarders(),
saleRecipient,
royaltyRecipient,
royaltyBps,
platformFeeBps,
platformFeeRecipient
)
)
)
);

tokenContract = MyTokenERC721(proxy);
uri = "uri";

vm.prank(deployer);
tokenContract.grantRole(keccak256("MINTER_ROLE"), caller);
}

function test_burn_whenNotOwnerNorApproved() public {
// state before
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();

// mint
vm.prank(caller);
uint256 _tokenId = tokenContract.mintTo(recipient, uri);

// burn
vm.expectRevert("ERC721Burnable: caller is not owner nor approved");
tokenContract.burn(_tokenId);
}

function test_burn_whenOwner() public {
// state before
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();

// mint
vm.prank(caller);
uint256 _tokenId = tokenContract.mintTo(recipient, uri);

// burn
vm.prank(recipient);
tokenContract.burn(_tokenId);

vm.expectRevert(); // checking non-existent token, because burned
tokenContract.ownerOf(_tokenId);
}

function test_burn_whenApproved() public {
// state before
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();

// mint
vm.prank(caller);
uint256 _tokenId = tokenContract.mintTo(recipient, uri);

vm.prank(recipient);
tokenContract.setApprovalForAll(caller, true);

// burn
vm.prank(caller);
tokenContract.burn(_tokenId);

vm.expectRevert(); // checking non-existent token, because burned
tokenContract.ownerOf(_tokenId);
}
}
8 changes: 8 additions & 0 deletions src/test/tokenerc721-BTT/burn/burn.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
burn(uint256 tokenId)
├── when the caller isn't the owner of `tokenId` or token not approved to caller
│ └── it should revert ✅
└── when the caller owns `tokenId`
│ └── it should burn the token ✅
└── when the `tokenId` is approved to caller
└── it should burn the token ✅

Loading

0 comments on commit 044cd26

Please sign in to comment.