Skip to content

Fix: SPGNFT metadata hash setter#233

Merged
romain-mg merged 6 commits intostoryprotocol:mainfrom
romain-mg:fix-token-id-metadata
Jul 15, 2025
Merged

Fix: SPGNFT metadata hash setter#233
romain-mg merged 6 commits intostoryprotocol:mainfrom
romain-mg:fix-token-id-metadata

Conversation

@romain-mg
Copy link

@romain-mg romain-mg commented Jun 26, 2025

Description

This PR adds functionality to allow NFT owners to update the metadata (both URI and hash) of their tokens in SPGNFT collections.

Changes Made

Core Functionality

  • Added setTokenURI(uint256 tokenId, string memory tokenUri, bytes32 nftMetadataHash) external function in SPGNFT.sol -> allows token owners to update both metadata URI and metadata hash for their tokens
  • Validates caller is the token owner using ownerOf() check
  • Calls _setTokenURI() to update the token's URI
  • Updates the nftMetadataHashToTokenId mapping

Interface Updates

  • Added setTokenURI(uint256 tokenId, string memory tokenUri, bytes32 nftMetadataHash) function declaration in ISPGNFT.sol
  • Marked the existing setTokenURI(uint256 tokenId, string memory tokenUri) function as deprecated

Error Handling

  • Reuses existing SPGNFT__CallerNotOwner error for access control validation

Testing

  • Added comprehensive test coverage in SPGNFT.t.sol:
  • test_SPGNFT_setTokenURI() - successful metadata update (both URI and hash)
  • test_SPGNFT_setTokenURI_revert_callerNotOwner() - access control validation
  • Marked the tests of the old existing setTokenURI() function as deprecated, avoiding duplicated tests issues

Related Issues

Closes #232

@romain-mg romain-mg force-pushed the fix-token-id-metadata branch 2 times, most recently from e77bc78 to b342ee1 Compare June 26, 2025 00:34
@romain-mg romain-mg force-pushed the fix-token-id-metadata branch from b342ee1 to 06763ea Compare June 26, 2025 00:38
@romain-mg romain-mg force-pushed the fix-token-id-metadata branch from 06763ea to e633964 Compare June 26, 2025 00:57
@romain-mg romain-mg force-pushed the fix-token-id-metadata branch 4 times, most recently from 8df29f0 to 5e724b8 Compare July 7, 2025 18:00
@romain-mg romain-mg force-pushed the fix-token-id-metadata branch from 5e724b8 to a5827b9 Compare July 7, 2025 18:01
@romain-mg romain-mg force-pushed the fix-token-id-metadata branch 2 times, most recently from 6a47545 to 93a3517 Compare July 15, 2025 17:14
@romain-mg romain-mg force-pushed the fix-token-id-metadata branch from 93a3517 to a07f11a Compare July 15, 2025 18:27
@romain-mg romain-mg force-pushed the fix-token-id-metadata branch from a07f11a to e10bc9b Compare July 15, 2025 18:29
@romain-mg romain-mg force-pushed the fix-token-id-metadata branch from e10bc9b to e56346e Compare July 15, 2025 19:29
Copy link
Member

@sebsadface sebsadface left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@romain-mg romain-mg merged commit 4e283eb into storyprotocol:main Jul 15, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getTokenIdByMetadataHash() may return stale data if metadata hash is updated

2 participants