forked from crytic/properties
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathERC721BurnableProperties.sol
105 lines (85 loc) · 3.62 KB
/
ERC721BurnableProperties.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.13;
import "../util/ERC721TestBase.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
abstract contract CryticERC721BurnableProperties is CryticERC721TestBase, ERC721Burnable {
using Address for address;
////////////////////////////////////////
// Properties
// The burn function should destroy tokens and reduce the total supply
function test_ERC721_burnReducesTotalSupply() public virtual {
require(isMintableOrBurnable);
uint256 selfBalance = balanceOf(msg.sender);
require(selfBalance > 0);
uint256 oldTotalSupply = totalSupply();
for(uint256 i; i < selfBalance; i++) {
uint256 tokenId = tokenOfOwnerByIndex(msg.sender, 0);
burn(tokenId);
}
assertWithMsg(selfBalance <= oldTotalSupply, "Underflow - user balance larger than total supply");
assertEq(oldTotalSupply - selfBalance, totalSupply(), "Incorrect supply update on burn");
}
// A burned token should not be transferrable
function test_ERC721_burnRevertOnTransferFromPreviousOwner(address target) public virtual {
require(isMintableOrBurnable);
uint256 selfBalance = balanceOf(msg.sender);
require(selfBalance > 0);
uint256 tokenId = tokenOfOwnerByIndex(msg.sender, 0);
burn(tokenId);
transferFrom(msg.sender, target, tokenId);
assertWithMsg(false, "Transferring a burned token didn't revert");
}
function test_ERC721_burnRevertOnTransferFromZeroAddress(address target) public virtual {
require(isMintableOrBurnable);
uint256 selfBalance = balanceOf(msg.sender);
require(selfBalance > 0);
uint256 tokenId = tokenOfOwnerByIndex(msg.sender, 0);
burn(tokenId);
transferFrom(address(0), target, tokenId);
assertWithMsg(false, "Transferring a burned token didn't revert");
}
function test_ERC721_burnRevertOnApprove() public virtual {
require(isMintableOrBurnable);
uint256 selfBalance = balanceOf(msg.sender);
require(selfBalance > 0);
uint256 tokenId = tokenOfOwnerByIndex(msg.sender, 0);
burn(tokenId);
approve(address(this), tokenId);
assertWithMsg(false, "Approving a burned token didn't revert");
}
function test_ERC721_burnRevertOnGetApproved() public virtual {
require(isMintableOrBurnable);
uint256 selfBalance = balanceOf(msg.sender);
require(selfBalance > 0);
uint256 tokenId = tokenOfOwnerByIndex(msg.sender, 0);
burn(tokenId);
getApproved(tokenId);
assertWithMsg(false, "getApproved didn't revert for burned token");
}
function test_ERC721_burnRevertOnOwnerOf() public virtual {
require(isMintableOrBurnable);
uint256 selfBalance = balanceOf(msg.sender);
require(selfBalance > 0);
uint256 tokenId = tokenOfOwnerByIndex(msg.sender, 0);
burn(tokenId);
ownerOf(tokenId);
assertWithMsg(false, "ownerOf didn't revert for burned token");
}
// The following functions are overrides required by Solidity.
function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
internal
virtual
override(ERC721, CryticERC721TestBase)
{
super._beforeTokenTransfer(from, to, tokenId, batchSize);
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721, CryticERC721TestBase)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}