From c49c0e595516720ba878cf5b6bbf3e03a4031b69 Mon Sep 17 00:00:00 2001 From: Yash Date: Tue, 20 Sep 2022 18:59:44 +0530 Subject: [PATCH] (Q-3) TokenERC721 can have empty URI --- contracts/token/TokenERC721.sol | 1 + src/test/token/TokenERC721.t.sol | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/contracts/token/TokenERC721.sol b/contracts/token/TokenERC721.sol index 84065bec7..74f431e6a 100644 --- a/contracts/token/TokenERC721.sol +++ b/contracts/token/TokenERC721.sol @@ -305,6 +305,7 @@ contract TokenERC721 is tokenIdToMint = nextTokenIdToMint; nextTokenIdToMint += 1; + require(bytes(_uri).length > 0, "empty uri."); uri[tokenIdToMint] = _uri; _safeMint(_to, tokenIdToMint); diff --git a/src/test/token/TokenERC721.t.sol b/src/test/token/TokenERC721.t.sol index 75fe2daa8..3253c259b 100644 --- a/src/test/token/TokenERC721.t.sol +++ b/src/test/token/TokenERC721.t.sol @@ -307,6 +307,13 @@ contract TokenERC721Test is BaseTest { tokenContract.mintTo(recipient, _tokenURI); } + function test_revert_mintTo_emptyURI() public { + // mint + vm.prank(deployerSigner); + vm.expectRevert("empty uri."); + tokenContract.mintTo(recipient, ""); + } + function test_event_mintTo() public { string memory _tokenURI = "tokenURI";