Skip to content

Commit

Permalink
Preparation for efficient consecutive burns 2 (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized authored Feb 16, 2023
1 parent b97b199 commit 249ca1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions contracts/ERC721A.sol
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,14 @@ contract ERC721A is IERC721A {
*
* Tokens start existing when they are minted. See {_mint}.
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return
_startTokenId() <= tokenId &&
tokenId < _currentIndex && // If within bounds,
_packedOwnerships[tokenId] & _BITMASK_BURNED == 0; // and not burned.
function _exists(uint256 tokenId) internal view virtual returns (bool result) {
if (_startTokenId() <= tokenId) {
if (tokenId < _currentIndex) {
uint256 packed;
while ((packed = _packedOwnerships[tokenId]) == 0) --tokenId;
result = packed & _BITMASK_BURNED == 0;
}
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions test/ERC721A.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,10 @@ const createTestSuite = ({ contract, constructorArgs }) =>
if (3 <= i && i < 3 + 2) {
await expect(this.erc721a.ownerOf(this.startTokenId + i))
.to.be.revertedWith('OwnerQueryForNonexistentToken');
await expect(this.erc721a.getApproved(this.startTokenId + i))
.to.be.revertedWith('ApprovalQueryForNonexistentToken');
await expect(this.erc721a.tokenURI(this.startTokenId + i))
.to.be.revertedWith('URIQueryForNonexistentToken');
} else {
expect(await this.erc721a.ownerOf(this.startTokenId + i)).to.eq(owner.address);
}
Expand Down

0 comments on commit 249ca1f

Please sign in to comment.