forked from crytic/properties
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathERC721ExternalBurnableProperties.sol
80 lines (67 loc) · 3.06 KB
/
ERC721ExternalBurnableProperties.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
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.13;
import "../util/ERC721ExternalTestBase.sol";
import "../../../util/Hevm.sol";
abstract contract CryticERC721ExternalBurnableProperties is CryticERC721ExternalTestBase {
using Address for address;
////////////////////////////////////////
// Properties
// The burn function should destroy tokens and reduce the total supply
function test_ERC721_external_burnReducesTotalSupply() public virtual {
require(token.isMintableOrBurnable());
uint256 selfBalance = token.balanceOf(msg.sender);
require(selfBalance > 0);
uint256 oldTotalSupply = token.totalSupply();
for(uint256 i; i < selfBalance; i++) {
uint256 tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
hevm.prank(msg.sender);
token.burn(tokenId);
}
// Check for underflow
assertWithMsg(selfBalance <= oldTotalSupply, "Underflow - user balance larger than total supply");
assertEq(oldTotalSupply - selfBalance, token.totalSupply(), "Incorrect supply update on burn");
}
// A burned token should not be transferrable
function test_ERC721_external_burnRevertOnTransfer(address target) public virtual {
require(token.isMintableOrBurnable());
uint256 selfBalance = token.balanceOf(msg.sender);
require(selfBalance > 0);
uint256 tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
hevm.prank(msg.sender);
token.burn(tokenId);
hevm.prank(msg.sender);
token.transferFrom(msg.sender, target, tokenId);
assertWithMsg(false, "Transferring a burned token didn't revert");
}
function test_ERC721_external_burnRevertOnApprove() public virtual {
require(token.isMintableOrBurnable());
uint256 selfBalance = token.balanceOf(msg.sender);
require(selfBalance > 0);
uint256 tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
hevm.prank(msg.sender);
token.burn(tokenId);
hevm.prank(msg.sender);
token.approve(address(this), tokenId);
assertWithMsg(false, "Approving a burned token didn't revert");
}
function test_ERC721_external_burnRevertOnGetApproved() public virtual {
require(token.isMintableOrBurnable());
uint256 selfBalance = token.balanceOf(msg.sender);
require(selfBalance > 0);
uint256 tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
hevm.prank(msg.sender);
token.burn(tokenId);
token.getApproved(tokenId);
assertWithMsg(false, "getApproved didn't revert for burned token");
}
function test_ERC721_external_burnRevertOnOwnerOf() public virtual {
require(token.isMintableOrBurnable());
uint256 selfBalance = token.balanceOf(msg.sender);
require(selfBalance > 0);
uint256 tokenId = token.tokenOfOwnerByIndex(msg.sender, 0);
hevm.prank(msg.sender);
token.burn(tokenId);
token.ownerOf(tokenId);
assertWithMsg(false, "ownerOf didn't revert for burned token");
}
}