Skip to content

Commit

Permalink
Not support link more parents (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster-will authored Mar 28, 2024
1 parent 5ae90f6 commit ee1030d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ library Errors {
// LicensingModule //
////////////////////////////////////////////////////////////////////////////

error LicensingModule__IpAlreadyLinked();
error LicensingModule__PolicyAlreadySetForIpId();
error LicensingModule__FrameworkNotFound();
error LicensingModule__EmptyLicenseUrl();
Expand Down
5 changes: 5 additions & 0 deletions contracts/modules/licensing/LicensingModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ contract LicensingModule is
address childIpId,
bytes calldata royaltyContext
) external nonReentrant verifyPermission(childIpId) {
LicensingModuleStorage storage $ = _getLicensingModuleStorage();
if ($.ipIdParents[childIpId].length() > 0) {
revert Errors.LicensingModule__IpAlreadyLinked();
}

_verifyIpNotDisputed(childIpId);
address holder = IIPAccount(payable(childIpId)).owner();
address[] memory licensors = new address[](licenseIds.length);
Expand Down
30 changes: 30 additions & 0 deletions test/foundry/modules/licensing/LicensingModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contract LicensingModuleTest is BaseTest {
string public licenseUrl = "https://example.com/license";
address public ipId1;
address public ipId2;
address public ipId3;
address public ipOwner = address(0x100); // use static address, otherwise uri check fails because licensor changes
address public licenseHolder = address(0x101);

Expand Down Expand Up @@ -68,12 +69,15 @@ contract LicensingModuleTest is BaseTest {
// Create IPAccounts
nft.mintId(ipOwner, 1);
nft.mintId(ipOwner, 2);
nft.mintId(ipOwner, 3);

ipId1 = ipAccountRegistry.registerIpAccount(block.chainid, address(nft), 1);
ipId2 = ipAccountRegistry.registerIpAccount(block.chainid, address(nft), 2);
ipId3 = ipAccountRegistry.registerIpAccount(block.chainid, address(nft), 3);

vm.label(ipId1, "IPAccount1");
vm.label(ipId2, "IPAccount2");
vm.label(ipId3, "IPAccount3");
}

function _createMockPolicy() internal pure returns (bytes memory) {
Expand Down Expand Up @@ -504,6 +508,32 @@ contract LicensingModuleTest is BaseTest {
vm.stopPrank();
}

function test_LicensingModule_linkIpToParents_revert_linkTwice() public withPolicyFrameworkManager {
vm.prank(address(mockPFM));
uint256 policyId = licensingModule.registerPolicy(_createPolicyFrameworkData());

vm.startPrank(ipOwner);
uint256 indexOnIpId = licensingModule.addPolicyToIp(ipId1, policyId);
assertEq(policyId, 1);

uint256 licenseId = licensingModule.mintLicense(policyId, ipId1, 2, ipOwner, "");
assertEq(licenseId, 1);

uint256[] memory licenseIds = new uint256[](1);
licenseIds[0] = licenseId;

licensingModule.linkIpToParents(licenseIds, ipId3, "");

indexOnIpId = licensingModule.addPolicyToIp(ipId2, policyId);
licenseId = licensingModule.mintLicense(policyId, ipId2, 2, ipOwner, "");
licenseIds = new uint256[](1);
licenseIds[0] = licenseId;

vm.expectRevert(Errors.LicensingModule__IpAlreadyLinked.selector);
licensingModule.linkIpToParents(licenseIds, ipId3, "");
vm.stopPrank();
}

function test_LicensingModule_linkIpToParents_revert_notLicensee() public withPolicyFrameworkManager {
vm.prank(address(mockPFM));
uint256 policyId = licensingModule.registerPolicy(_createPolicyFrameworkData());
Expand Down

0 comments on commit ee1030d

Please sign in to comment.