Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect and Revert Duplicate License Terms #75

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ library Errors {
error LicenseRegistry__IndexOutOfBounds(address ipId, uint256 index, uint256 length);
error LicenseRegistry__LicenseTermsAlreadyAttached(address ipId, address licenseTemplate, uint256 licenseTermsId);
error LicenseRegistry__UnmatchedLicenseTemplate(address ipId, address licenseTemplate, address newLicenseTemplate);

error LicenseRegistry__DuplicateLicense(address ipId, address licenseTemplate, uint256 licenseTermsId);
////////////////////////////////////////////////////////////////////////////
// LicenseToken //
////////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 6 additions & 2 deletions contracts/registries/LicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@ contract LicenseRegistry is ILicenseRegistry, AccessManagedUpgradeable, UUPSUpgr

for (uint256 i = 0; i < parentIpIds.length; i++) {
_verifyDerivativeFromParent(parentIpIds[i], childIpId, licenseTemplate, licenseTermsIds[i]);
$.parentIps[childIpId].add(parentIpIds[i]);
$.childIps[parentIpIds[i]].add(childIpId);
$.attachedLicenseTerms[childIpId].add(licenseTermsIds[i]);
// determine if duplicate license terms
LeoHChen marked this conversation as resolved.
Show resolved Hide resolved
bool isNewParent = $.parentIps[childIpId].add(parentIpIds[i]);
bool isNewTerms = $.attachedLicenseTerms[childIpId].add(licenseTermsIds[i]);
if (!isNewParent && !isNewTerms) {
revert Errors.LicenseRegistry__DuplicateLicense(parentIpIds[i], licenseTemplate, licenseTermsIds[i]);
}
}

$.licenseTemplates[childIpId] = licenseTemplate;
Expand Down
9 changes: 8 additions & 1 deletion test/foundry/integration/flows/royalty/Royalty.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ contract Flows_Integration_Disputes is BaseIntegration {

ipAcct[2] = registerIpAccount(address(mockNFT), 2, u.bob);

vm.expectRevert(Errors.RoyaltyPolicyLAP__AboveParentLimit.selector);
vm.expectRevert(
abi.encodeWithSelector(
Errors.LicenseRegistry__DuplicateLicense.selector,
ipAcct[1],
address(pilTemplate),
commRemixTermsId
)
);
licensingModule.registerDerivativeWithLicenseTokens(ipAcct[2], licenseIds, "");

// can link max two
Expand Down
40 changes: 40 additions & 0 deletions test/foundry/registries/LicenseRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,46 @@ contract LicenseRegistryTest is BaseTest {
licenseRegistry.getParentIp(ipId2, 1);
}

function test_LicenseRegistry_registerDerivativeIp() public {
uint256 socialRemixTermsId = pilTemplate.registerLicenseTerms(PILFlavors.nonCommercialSocialRemixing());
vm.prank(ipOwner1);
licensingModule.attachLicenseTerms(ipId1, address(pilTemplate), socialRemixTermsId);
vm.prank(ipOwner2);
licensingModule.attachLicenseTerms(ipId2, address(pilTemplate), socialRemixTermsId);

address[] memory parentIpIds = new address[](2);
parentIpIds[0] = ipId1;
parentIpIds[1] = ipId2;
uint256[] memory licenseTermsIds = new uint256[](2);
licenseTermsIds[0] = socialRemixTermsId;
licenseTermsIds[1] = socialRemixTermsId;
vm.prank(address(licensingModule));
licenseRegistry.registerDerivativeIp(ipId3, parentIpIds, address(pilTemplate), licenseTermsIds);
}

function test_LicenseRegistry_registerDerivativeIp_revert_DuplicateLicense() public {
uint256 socialRemixTermsId = pilTemplate.registerLicenseTerms(PILFlavors.nonCommercialSocialRemixing());
vm.prank(ipOwner1);
licensingModule.attachLicenseTerms(ipId1, address(pilTemplate), socialRemixTermsId);

address[] memory parentIpIds = new address[](2);
parentIpIds[0] = ipId1;
parentIpIds[1] = ipId1;
uint256[] memory licenseTermsIds = new uint256[](2);
licenseTermsIds[0] = socialRemixTermsId;
licenseTermsIds[1] = socialRemixTermsId;
vm.expectRevert(
abi.encodeWithSelector(
Errors.LicenseRegistry__DuplicateLicense.selector,
ipId1,
address(pilTemplate),
socialRemixTermsId
)
);
vm.prank(address(licensingModule));
licenseRegistry.registerDerivativeIp(ipId2, parentIpIds, address(pilTemplate), licenseTermsIds);
}

function onERC721Received(address, address, uint256, bytes memory) public pure returns (bytes4) {
return this.onERC721Received.selector;
}
Expand Down
Loading