From a825cb40eb3b1b1105591bef89664f6e47149c85 Mon Sep 17 00:00:00 2001 From: Vectorized Date: Thu, 16 Feb 2023 00:28:39 +0000 Subject: [PATCH] Add code and tests --- contracts/ERC721A.sol | 13 ++++++++----- test/ERC721A.test.js | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/contracts/ERC721A.sol b/contracts/ERC721A.sol index 580f480e0..c0230ef45 100644 --- a/contracts/ERC721A.sol +++ b/contracts/ERC721A.sol @@ -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; + } + } } /** diff --git a/test/ERC721A.test.js b/test/ERC721A.test.js index 07b62fb24..d32cdc5e9 100644 --- a/test/ERC721A.test.js +++ b/test/ERC721A.test.js @@ -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); }