It does not effect the protocol that much but it is a good practice to add zero checks. In FestivalPass::uri
if we give 0 as tokenId's value then it will give wrong uri, which is not a good coding practice.
function uri(uint256 tokenId) public view override returns (string memory) {
@> if (tokenId <= BACKSTAGE_PASS) {
return string(abi.encodePacked("ipfs://beatdrop/", Strings.toString(tokenId)));
}
(uint256 collectionId, uint256 itemId) = decodeTokenId(tokenId);
if (collections[collectionId].priceInBeat > 0) {
return string(abi.encodePacked(
collections[collectionId].baseUri,
"/metadata/",
Strings.toString(itemId)
));
}
return super.uri(tokenId);
}
function test_Uri_Pass() public view {
assertEq(festivalPass.uri(0), "ipfs://beatdrop/0");
}
function uri(uint256 tokenId) public view override returns (string memory) {
// Handle regular passes (IDs 1-3)
+ require(tokenId >0, "tokenId cannot be zero");
@> if (tokenId <= BACKSTAGE_PASS) {
return string(abi.encodePacked("ipfs://beatdrop/", Strings.toString(tokenId)));
}
// Decode collection and item IDs
(uint256 collectionId, uint256 itemId) = decodeTokenId(tokenId);
// Check if it's a valid memorabilia token
if (collections[collectionId].priceInBeat > 0) {
// Return specific URI for this item
// e.g., "ipfs://QmXXX/metadata/5" for item #5
return string(abi.encodePacked(
collections[collectionId].baseUri,
"/metadata/",
Strings.toString(itemId)
));
}
return super.uri(tokenId);
}