Skip to content

Commit

Permalink
Check derivativesReciprocal of derivative (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster-will authored Jun 27, 2024
1 parent fb14509 commit fe9b8e1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions contracts/modules/licensing/PILicenseTemplate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ contract PILicenseTemplate is
return false;
}

// reciprocal derivatives must be true, if want to allow derivatives of derivatives
if (LICENSE_REGISTRY.isDerivativeIp(parentIpId)) {
if (!terms.derivativesReciprocal) {
return false;
}
}

// If the policy defines the licensor must approve derivatives, check if the
// derivative is approved by the licensor
if (terms.derivativesApproval && !isDerivativeApproved(parentIpId, licenseTermsId, childIpId)) {
Expand Down
31 changes: 31 additions & 0 deletions test/foundry/modules/licensing/LicensingModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,37 @@ contract LicensingModuleTest is BaseTest {
licensingModule.registerDerivative(ipId3, parentIpIds, licenseTermsIds, address(pilTemplate), "");
}

function test_LicensingModule_registerDerivative_revert_NotAllowDerivativesReciprocal() public {
// register license terms allow derivative but not allow derivative of derivative
PILTerms memory terms = PILFlavors.nonCommercialSocialRemixing();
// not allow derivative of derivative
terms.derivativesReciprocal = false;
uint256 socialRemixTermsId = pilTemplate.registerLicenseTerms(terms);

// register derivative
vm.prank(ipOwner1);
licensingModule.attachLicenseTerms(ipId1, address(pilTemplate), socialRemixTermsId);

address[] memory parentIpIds = new address[](1);
parentIpIds[0] = ipId1;

uint256[] memory licenseTermsIds = new uint256[](1);
licenseTermsIds[0] = socialRemixTermsId;

vm.prank(ipOwner2);
licensingModule.registerDerivative(ipId2, parentIpIds, licenseTermsIds, address(pilTemplate), "");

// register derivative of derivative, should revert
parentIpIds = new address[](1);
parentIpIds[0] = ipId2;

vm.expectRevert(
abi.encodeWithSelector(Errors.LicensingModule__LicenseNotCompatibleForDerivative.selector, ipId3)
);
vm.prank(ipOwner3);
licensingModule.registerDerivative(ipId3, parentIpIds, licenseTermsIds, address(pilTemplate), "");
}

function test_LicensingModule_setLicensingConfig() public {
uint256 socialRemixTermsId = pilTemplate.registerLicenseTerms(PILFlavors.nonCommercialSocialRemixing());
MockLicensingHook licensingHook = new MockLicensingHook();
Expand Down
22 changes: 22 additions & 0 deletions test/foundry/modules/licensing/PILicenseTemplate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,28 @@ contract PILicenseTemplateTest is BaseTest {
assertTrue(result);
}

// test verifyRegisterDerivative
function test_PILicenseTemplate_verifyRegisterDerivative_NotDerivativesReciprocal() public {
// register license terms allow derivative but not allow derivative of derivative
PILTerms memory terms = PILFlavors.nonCommercialSocialRemixing();
terms.derivativesReciprocal = false;
uint256 socialRemixTermsId = pilTemplate.registerLicenseTerms(terms);

// register derivative
vm.prank(ipOwner[1]);
licensingModule.attachLicenseTerms(ipAcct[1], address(pilTemplate), socialRemixTermsId);
address[] memory parentIpIds = new address[](1);
parentIpIds[0] = ipAcct[1];
uint256[] memory licenseTermsIds = new uint256[](1);
licenseTermsIds[0] = socialRemixTermsId;
vm.prank(ipOwner[2]);
licensingModule.registerDerivative(ipAcct[2], parentIpIds, licenseTermsIds, address(pilTemplate), "");

// checking register derivative of derivative, expect false
bool result = pilTemplate.verifyRegisterDerivative(ipAcct[3], ipAcct[2], socialRemixTermsId, ipOwner[3]);
assertFalse(result);
}

function test_PILicenseTemplate_verifyRegisterDerivative_WithApproval() public {
PILTerms memory terms = PILFlavors.nonCommercialSocialRemixing();
terms.derivativesApproval = true;
Expand Down

0 comments on commit fe9b8e1

Please sign in to comment.