Skip to content

Commit 0c6e930

Browse files
committed
fix(registration): update dedup behavior
1 parent 248667d commit 0c6e930

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

contracts/lib/Errors.sol

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ library Errors {
1414
/// @notice Zero address provided as a param to the RegistrationWorkflows.
1515
error RegistrationWorkflows__ZeroAddressParam();
1616

17+
/// @notice Error thrown when attempting to mint an NFT with a metadata hash that already exists.
18+
/// @param spgNftContract The address of the SPGNFT collection contract where the duplicate was detected.
19+
/// @param tokenId The ID of the original NFT that was first minted with this metadata hash.
20+
/// @param ipId The identifier of the registered IP associated with this NFT.
21+
/// @param nftMetadataHash The hash of the NFT metadata that caused the duplication error.
22+
error RegistrationWorkflows__DuplicatedNFTMetadataHash(
23+
address spgNftContract,
24+
uint256 tokenId,
25+
address ipId,
26+
bytes32 nftMetadataHash
27+
);
28+
1729
////////////////////////////////////////////////////////////////////////////
1830
// LicenseAttachmentWorkflows //
1931
////////////////////////////////////////////////////////////////////////////

contracts/workflows/RegistrationWorkflows.sol

+7-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@ contract RegistrationWorkflows is
125125
dedup: dedup
126126
});
127127

128-
if (deduped) return (_getIpId(spgNftContract, tokenId), tokenId);
128+
if (deduped)
129+
revert Errors.RegistrationWorkflows__DuplicatedNFTMetadataHash({
130+
spgNftContract: spgNftContract,
131+
tokenId: tokenId,
132+
ipId: _getIpId(spgNftContract, tokenId),
133+
nftMetadataHash: ipMetadata.nftMetadataHash
134+
});
129135

130136
ipId = IP_ASSET_REGISTRY.register(block.chainid, spgNftContract, tokenId);
131137
MetadataHelper.setMetadata(ipId, address(CORE_METADATA_MODULE), ipMetadata);

test/workflows/RegistrationWorkflows.t.sol

+15-8
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ contract RegistrationWorkflowsTest is BaseTest {
6767
});
6868
}
6969

70-
function test_RegistrationWorkflows_mintAndRegisterIP_dedup() public withCollection whenCallerHasMinterRole {
70+
function test_RegistrationWorkflows_revert_duplicatedNftMetadataHash()
71+
public
72+
withCollection
73+
whenCallerHasMinterRole
74+
{
7175
mockToken.mint(address(caller), 1000 * 10 ** mockToken.decimals());
7276
mockToken.approve(address(nftContract), 1000 * 10 ** mockToken.decimals());
7377

@@ -82,18 +86,21 @@ contract RegistrationWorkflowsTest is BaseTest {
8286
assertEq(nftContract.tokenURI(tokenId1), string.concat(testBaseURI, ipMetadataDefault.nftMetadataURI));
8387
assertMetadata(ipId1, ipMetadataDefault);
8488

85-
(address ipId2, uint256 tokenId2) = registrationWorkflows.mintAndRegisterIp({
89+
vm.expectRevert(
90+
abi.encodeWithSelector(
91+
Errors.RegistrationWorkflows__DuplicatedNFTMetadataHash.selector,
92+
address(nftContract),
93+
tokenId1,
94+
ipId1,
95+
ipMetadataDefault.nftMetadataHash
96+
)
97+
);
98+
registrationWorkflows.mintAndRegisterIp({
8699
spgNftContract: address(nftContract),
87100
recipient: u.bob,
88101
ipMetadata: ipMetadataDefault,
89102
dedup: true
90103
});
91-
92-
// check that the tokenId is the same as the first one
93-
assertEq(tokenId2, tokenId1);
94-
assertTrue(ipAssetRegistry.isRegistered(ipId2));
95-
assertEq(nftContract.tokenURI(tokenId2), string.concat(testBaseURI, ipMetadataDefault.nftMetadataURI));
96-
assertMetadata(ipId2, ipMetadataDefault);
97104
}
98105

99106
function test_RegistrationWorkflows_mintAndRegisterIp_publicMint() public {

0 commit comments

Comments
 (0)