From 0aa11959f00336b30c87c0f328f36c8f4b48ca71 Mon Sep 17 00:00:00 2001 From: Jongwon Park Date: Thu, 22 Feb 2024 17:28:19 -0800 Subject: [PATCH] test: add license minting fee test in integration --- .../integration/flows/royalty/Royalty.t.sol | 30 +++++++++++++-- test/foundry/utils/LicensingHelper.t.sol | 38 +++++++++++++++++-- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/test/foundry/integration/flows/royalty/Royalty.t.sol b/test/foundry/integration/flows/royalty/Royalty.t.sol index afdad1599..4a963474e 100644 --- a/test/foundry/integration/flows/royalty/Royalty.t.sol +++ b/test/foundry/integration/flows/royalty/Royalty.t.sol @@ -7,6 +7,7 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; // contract +import { IRoyaltyModule } from "contracts/interfaces/modules/royalty/IRoyaltyModule.sol"; import { IRoyaltyPolicyLAP } from "contracts/interfaces/modules/royalty/policies/IRoyaltyPolicyLAP.sol"; // test @@ -30,7 +31,10 @@ contract Flows_Integration_Disputes is BaseIntegration { }) ); + address internal royaltyPolicyAddr; // must be assigned AFTER super.setUp() + address internal mintingFeeToken; // must be assigned AFTER super.setUp() uint32 internal defaultCommRevShare = 100; + uint256 internal mintingFee = 7 ether; function setUp() public override { super.setUp(); @@ -38,13 +42,18 @@ contract Flows_Integration_Disputes is BaseIntegration { // Register PIL Framework _deployLFM_PIL(); + royaltyPolicyAddr = address(royaltyPolicyLAP); + mintingFeeToken = address(erc20); + // Register a License - _mapPILPolicySimple({ + _mapPILPolicyCommercial({ name: "commercial-remix", - commercial: true, derivatives: true, reciprocal: true, - commercialRevShare: defaultCommRevShare + commercialRevShare: defaultCommRevShare, + royaltyPolicy: royaltyPolicyAddr, + mintingFeeToken: mintingFeeToken, + mintingFee: mintingFee }); _registerPILPolicyFromMapping("commercial-remix"); @@ -74,11 +83,17 @@ contract Flows_Integration_Disputes is BaseIntegration { ipAcct[2] = _getIpId(mockNFT, 2); vm.label(ipAcct[2], "IPAccount2"); + uint256 mintAmount = 3; + erc20.approve(address(royaltyPolicyAddr), mintAmount * mintingFee); + uint256[] memory licenseIds = new uint256[](1); + + vm.expectEmit(address(royaltyModule)); + emit IRoyaltyModule.LicenseMintingFeePaid(ipAcct[1], u.bob, address(erc20), mintAmount * mintingFee); licenseIds[0] = licensingModule.mintLicense( _getPilPolicyId("commercial-remix"), ipAcct[1], - 1, + mintAmount, u.bob, emptyRoyaltyPolicyLAPInitParams ); @@ -116,8 +131,13 @@ contract Flows_Integration_Disputes is BaseIntegration { ipAcct[3] = _getIpId(mockNFT, 3); vm.label(ipAcct[3], "IPAccount3"); + uint256 mintAmount = 1; uint256[] memory licenseIds = new uint256[](2); + erc20.approve(address(royaltyPolicyAddr), 2 * mintAmount * mintingFee); + + vm.expectEmit(address(royaltyModule)); + emit IRoyaltyModule.LicenseMintingFeePaid(ipAcct[1], u.carl, address(erc20), mintAmount * mintingFee); licenseIds[0] = licensingModule.mintLicense( _getPilPolicyId("commercial-remix"), ipAcct[1], // grandparent, root IP @@ -137,6 +157,8 @@ contract Flows_Integration_Disputes is BaseIntegration { params1.targetAncestors[0] = ipAcct[1]; params1.targetRoyaltyAmount[0] = defaultCommRevShare; + vm.expectEmit(address(royaltyModule)); + emit IRoyaltyModule.LicenseMintingFeePaid(ipAcct[2], u.carl, address(erc20), mintAmount * mintingFee); licenseIds[1] = licensingModule.mintLicense( _getPilPolicyId("commercial-remix"), ipAcct[2], // parent, is child IP of ipAcct[1] diff --git a/test/foundry/utils/LicensingHelper.t.sol b/test/foundry/utils/LicensingHelper.t.sol index d8c05ac90..1af87de6d 100644 --- a/test/foundry/utils/LicensingHelper.t.sol +++ b/test/foundry/utils/LicensingHelper.t.sol @@ -121,10 +121,9 @@ contract LicensingHelper { string memory pName = string(abi.encodePacked("pil_", name)); policies[pName] = RegisterPILPolicyParams({ transferable: true, - // TODO: use mock or real based on condition royaltyPolicy: commercial ? address(ROYALTY_POLICY_LAP) : address(0), - mintingFee: 0, - mintingFeeToken: address(0), + mintingFee: commercial ? 1 ether : 0, + mintingFeeToken: address(0), // TODO: set to a valid token if commercial policy: PILPolicy({ attribution: true, commercialUse: commercial, @@ -143,6 +142,39 @@ contract LicensingHelper { }); } + function _mapPILPolicyCommercial( + string memory name, + bool derivatives, + bool reciprocal, + uint32 commercialRevShare, + address royaltyPolicy, + uint256 mintingFee, + address mintingFeeToken + ) internal { + string memory pName = string(abi.encodePacked("pil_", name)); + policies[pName] = RegisterPILPolicyParams({ + transferable: true, + royaltyPolicy: royaltyPolicy, + mintingFee: mintingFee, + mintingFeeToken: mintingFeeToken, + policy: PILPolicy({ + attribution: true, + commercialUse: true, + commercialAttribution: false, + commercializerChecker: address(0), + commercializerCheckerData: "", + commercialRevShare: commercialRevShare, + derivativesAllowed: derivatives, + derivativesAttribution: false, + derivativesApproval: false, + derivativesReciprocal: reciprocal, + territories: emptyStringArray, + distributionChannels: emptyStringArray, + contentRestrictions: emptyStringArray + }) + }); + } + function _addPILPolicyFromMapping(string memory name, address pilFramework) internal returns (uint256) { string memory pName = string(abi.encodePacked("pil_", name)); policyIds[pName] = PILPolicyFrameworkManager(pilFramework).registerPolicy(policies[pName]);