From c92685ca199a4d6e0d6cf7b1f28da6ac0eb80eab Mon Sep 17 00:00:00 2001 From: Jongwon Park Date: Fri, 5 Apr 2024 15:54:14 -0500 Subject: [PATCH] fix(test): Simplify tests - Use new BaseTest and remove mock deployers - Modify some tests to clarify on caller using vm prank - Minor lint fixes for state variable visibility - Mock royalty policy LAP - Prepare codebase structure to remove some mocks in next PR - Remove unused test files --- test/foundry/IPAccount.t.sol | 12 ++- test/foundry/IPAccountMetaTx.t.sol | 5 +- test/foundry/IPAccountStorage.t.sol | 2 - test/foundry/IPAccountStorageOps.t.sol | 2 - test/foundry/access/AccessControlled.t.sol | 5 +- test/foundry/access/AccessController.t.sol | 60 ++---------- test/foundry/governance/Governance.t.sol | 4 - .../foundry/integration/BaseIntegration.t.sol | 10 -- .../integration/flows/disputes/Disputes.t.sol | 2 +- .../flows/licensing/LicensingScenarios.t.sol | 2 +- .../integration/flows/royalty/Royalty.t.sol | 6 +- .../mocks/policy/MockRoyaltyPolicyLAP.sol | 93 +++++++++++++++++++ test/foundry/modules/ModuleBase.t.sol | 3 - .../modules/dispute/ArbitrationPolicySP.t.sol | 6 -- .../modules/dispute/DisputeModule.t.sol | 11 +-- .../external/TokenWithdrawalModule.t.sol | 17 +--- .../modules/licensing/LicensingModule.t.sol | 35 ++++--- .../PILPolicyFramework.derivation.t.sol | 21 +---- .../PILPolicyFramework.multi-parent.sol | 23 +---- .../licensing/PILPolicyFramework.t.sol | 20 ---- .../modules/metadata/CoreMetadataModule.t.sol | 12 --- .../metadata/CoreMetadataViewModule.t.sol | 19 ---- .../modules/metadata/MetadataModule.t.sol | 14 ++- .../modules/royalty/IpRoyaltyVault.t.sol | 8 +- .../modules/royalty/RoyaltyModule.t.sol | 14 +-- .../modules/royalty/RoyaltyPolicyLAP.t.sol | 6 -- .../registries/IPAccountRegistry.t.sol | 2 - test/foundry/registries/IPAssetRegistry.t.sol | 8 -- test/foundry/registries/ModuleRegistry.t.sol | 3 - test/foundry/utils/BaseTest.t.sol | 10 -- 30 files changed, 165 insertions(+), 270 deletions(-) create mode 100644 test/foundry/mocks/policy/MockRoyaltyPolicyLAP.sol diff --git a/test/foundry/IPAccount.t.sol b/test/foundry/IPAccount.t.sol index 1659f0089..110cb7c24 100644 --- a/test/foundry/IPAccount.t.sol +++ b/test/foundry/IPAccount.t.sol @@ -14,10 +14,12 @@ contract IPAccountTest is BaseTest { function setUp() public override { super.setUp(); - deployConditionally(); - postDeploymentSetup(); module = new MockModule(address(ipAssetRegistry), address(moduleRegistry), "MockModule"); + + vm.startPrank(u.admin); // used twice, name() and registerModule() + moduleRegistry.registerModule(module.name(), address(module)); + vm.stopPrank(); } function test_IPAccount_Idempotency() public { @@ -52,6 +54,12 @@ contract IPAccountTest is BaseTest { IIPAccount ipAccount = IIPAccount(payable(account)); + // Register vm.addr(2) as a valid module to test isValidSigner + bytes32 moduleNameHash = keccak256(abi.encodePacked("MockModuleAddr2")); + bytes32 moduleRegistryStorageLocation = 0xa17d78ae7aee011aefa3f1388acb36741284b44eb3fcffe23ecc3a736eaa2700; + bytes32 entrySlot = keccak256(abi.encodePacked(moduleRegistryStorageLocation, moduleNameHash)); + vm.store(address(moduleRegistry), entrySlot, bytes32(uint256(uint160(vm.addr(2))))); + // Check token and owner functions (uint256 chainId_, address tokenAddress_, uint256 tokenId_) = ipAccount.token(); assertEq(chainId_, block.chainid); diff --git a/test/foundry/IPAccountMetaTx.t.sol b/test/foundry/IPAccountMetaTx.t.sol index 13410026b..3faf686a4 100644 --- a/test/foundry/IPAccountMetaTx.t.sol +++ b/test/foundry/IPAccountMetaTx.t.sol @@ -25,10 +25,7 @@ contract IPAccountMetaTxTest is BaseTest { function setUp() public override { super.setUp(); - buildDeployAccessCondition(DeployAccessCondition({ accessController: true, governance: false })); - buildDeployRegistryCondition(DeployRegistryCondition({ moduleRegistry: true, licenseRegistry: false })); - deployConditionally(); - postDeploymentSetup(); + ownerPrivateKey = 0xA11111; callerPrivateKey = 0xB22222; owner = vm.addr(ownerPrivateKey); diff --git a/test/foundry/IPAccountStorage.t.sol b/test/foundry/IPAccountStorage.t.sol index 0048e4df5..6bba7c0d8 100644 --- a/test/foundry/IPAccountStorage.t.sol +++ b/test/foundry/IPAccountStorage.t.sol @@ -12,8 +12,6 @@ contract IPAccountStorageTest is BaseTest { function setUp() public override { super.setUp(); - deployConditionally(); - postDeploymentSetup(); module = new MockModule(address(ipAssetRegistry), address(moduleRegistry), "MockModule"); diff --git a/test/foundry/IPAccountStorageOps.t.sol b/test/foundry/IPAccountStorageOps.t.sol index 80ac39d3b..8478e7447 100644 --- a/test/foundry/IPAccountStorageOps.t.sol +++ b/test/foundry/IPAccountStorageOps.t.sol @@ -17,8 +17,6 @@ contract IPAccountStorageOpsTest is BaseTest { function setUp() public override { super.setUp(); - deployConditionally(); - postDeploymentSetup(); module = new MockModule(address(ipAssetRegistry), address(moduleRegistry), "MockModule"); diff --git a/test/foundry/access/AccessControlled.t.sol b/test/foundry/access/AccessControlled.t.sol index f7c66922f..2e5fc5753 100644 --- a/test/foundry/access/AccessControlled.t.sol +++ b/test/foundry/access/AccessControlled.t.sol @@ -17,9 +17,6 @@ contract AccessControlledTest is BaseTest { function setUp() public override { super.setUp(); - buildDeployAccessCondition(DeployAccessCondition({ accessController: true, governance: true })); - deployConditionally(); - postDeploymentSetup(); mockNFT.mintId(owner, tokenId); address deployedAccount = ipAccountRegistry.registerIpAccount(block.chainid, address(mockNFT), tokenId); @@ -31,6 +28,8 @@ contract AccessControlledTest is BaseTest { address(moduleRegistry), "MockAccessControlledModule" ); + + vm.prank(u.admin); moduleRegistry.registerModule("MockAccessControlledModule", address(mockModule)); } diff --git a/test/foundry/access/AccessController.t.sol b/test/foundry/access/AccessController.t.sol index a39449ab0..25fb6301e 100644 --- a/test/foundry/access/AccessController.t.sol +++ b/test/foundry/access/AccessController.t.sol @@ -4,8 +4,6 @@ pragma solidity 0.8.23; import { IIPAccount } from "../../../contracts/interfaces/IIPAccount.sol"; import { AccessPermission } from "../../../contracts/lib/AccessPermission.sol"; import { Errors } from "../../../contracts/lib/Errors.sol"; -import { TOKEN_WITHDRAWAL_MODULE_KEY } from "../../../contracts/lib/modules/Module.sol"; -import { TokenWithdrawalModule } from "../../../contracts/modules/external/TokenWithdrawalModule.sol"; import { MockModule } from "../mocks/module/MockModule.sol"; import { MockOrchestratorModule } from "../mocks/module/MockOrchestratorModule.sol"; @@ -24,15 +22,15 @@ contract AccessControllerTest is BaseTest { function setUp() public override { super.setUp(); - buildDeployAccessCondition(DeployAccessCondition({ accessController: true, governance: true })); - deployConditionally(); - postDeploymentSetup(); mockNFT.mintId(owner, tokenId); address deployedAccount = ipAccountRegistry.registerIpAccount(block.chainid, address(mockNFT), tokenId); ipAccount = IIPAccount(payable(deployedAccount)); mockModule = new MockModule(address(ipAccountRegistry), address(moduleRegistry), "MockModule"); + + vm.prank(u.admin); + moduleRegistry.registerModule("MockModule", address(mockModule)); } // test owner can set permission @@ -46,7 +44,6 @@ contract AccessControllerTest is BaseTest { // mock orchestration? function test_AccessController_ipAccountOwnerSetPermission() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -79,7 +76,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_revert_NonOwnerCannotSetPermission() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); address nonOwner = vm.addr(3); vm.prank(nonOwner); @@ -107,7 +103,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_revert_directSetPermission() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(address(ipAccount)); @@ -165,7 +160,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_revert_checkPermission() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -204,7 +198,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_functionPermissionWildcardAllow() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -242,7 +235,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_functionPermissionWildcardDeny() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -288,7 +280,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_toAddressPermissionWildcardAllow() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -325,7 +316,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_toAddressPermissionWildcardDeny() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -371,7 +361,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_overrideFunctionWildcard_allowOverrideDeny() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -423,7 +412,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_overrideFunctionWildcard_DenyOverrideAllow() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -483,7 +471,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_overrideToAddressWildcard_allowOverrideDeny() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -535,7 +522,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_overrideToAddressWildcard_DenyOverrideAllow() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -595,7 +581,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_functionWildcardOverrideToAddressWildcard_allowOverrideDeny() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -652,7 +637,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_functionWildcardOverrideToAddressWildcard_denyOverrideAllow() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -717,8 +701,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_ipAccountOwnerCanCallAnyModuleWithoutPermission() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); - vm.prank(owner); bytes memory result = ipAccount.execute( address(mockModule), @@ -729,12 +711,12 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_moduleCallAnotherModuleViaIpAccount() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); MockModule anotherModule = new MockModule( address(ipAccountRegistry), address(moduleRegistry), "AnotherMockModule" ); + vm.prank(u.admin); moduleRegistry.registerModule("AnotherMockModule", address(anotherModule)); vm.prank(owner); @@ -761,6 +743,7 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_OrchestratorModuleCallIpAccount() public { + vm.startPrank(u.admin); MockOrchestratorModule mockOrchestratorModule = new MockOrchestratorModule( address(ipAccountRegistry), address(moduleRegistry) @@ -787,6 +770,7 @@ contract AccessControllerTest is BaseTest { "Module3WithoutPermission" ); moduleRegistry.registerModule("Module3WithoutPermission", address(module3WithoutPermission)); + vm.stopPrank(); vm.prank(owner); // orchestrator can call any modules through ipAccount @@ -808,6 +792,7 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_revert_OrchestratorModuleCallIpAccountLackSomeModulePermission() public { + vm.startPrank(u.admin); MockOrchestratorModule mockOrchestratorModule = new MockOrchestratorModule( address(ipAccountRegistry), address(moduleRegistry) @@ -834,6 +819,7 @@ contract AccessControllerTest is BaseTest { "Module3WithoutPermission" ); moduleRegistry.registerModule("Module3WithoutPermission", address(module3WithoutPermission)); + vm.stopPrank(); vm.prank(owner); // orchestrator can call any modules through ipAccount @@ -879,6 +865,7 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_OrchestratorModuleWithGlobalPermission() public { + vm.startPrank(u.admin); MockOrchestratorModule mockOrchestratorModule = new MockOrchestratorModule( address(ipAccountRegistry), address(moduleRegistry) @@ -898,6 +885,7 @@ contract AccessControllerTest is BaseTest { "Module2WithPermission" ); moduleRegistry.registerModule("Module2WithPermission", address(module2WithPermission)); + vm.stopPrank(); vm.prank(u.admin); accessController.setGlobalPermission( @@ -942,7 +930,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_ipAccountOwnerSetBatchPermissions() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); AccessPermission.Permission[] memory permissionList = new AccessPermission.Permission[](3); @@ -1036,7 +1023,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_revert_NonIpAccountOwnerSetBatchPermissions() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); AccessPermission.Permission[] memory permissionList = new AccessPermission.Permission[](3); @@ -1081,7 +1067,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_revert_setBatchPermissionsWithZeroIPAccountAddress() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); AccessPermission.Permission[] memory permissionList = new AccessPermission.Permission[](3); @@ -1117,7 +1102,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_revert_setBatchPermissionsWithZeroSignerAddress() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); AccessPermission.Permission[] memory permissionList = new AccessPermission.Permission[](3); @@ -1153,7 +1137,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_revert_setBatchPermissionsWithInvalidIPAccount() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); AccessPermission.Permission[] memory permissionList = new AccessPermission.Permission[](3); @@ -1192,7 +1175,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_revert_setBatchPermissionsWithInvalidPermission() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); AccessPermission.Permission[] memory permissionList = new AccessPermission.Permission[](3); @@ -1229,7 +1211,6 @@ contract AccessControllerTest is BaseTest { } function test_AccessController_revert_setBatchPermissionsButCallerisNotIPAccount() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); AccessPermission.Permission[] memory permissionList = new AccessPermission.Permission[](3); @@ -1262,7 +1243,6 @@ contract AccessControllerTest is BaseTest { // test permission was unset after transfer NFT to another account function test_AccessController_NFTTransfer() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -1301,7 +1281,6 @@ contract AccessControllerTest is BaseTest { // test permission check failure after transfer NFT to another account function test_AccessController_revert_NFTTransferCheckPermissionFailure() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -1344,7 +1323,6 @@ contract AccessControllerTest is BaseTest { // test permission still exist after transfer NFT back function test_AccessController_NFTTransferBack() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -1397,7 +1375,6 @@ contract AccessControllerTest is BaseTest { // test permission check still pass after transfer NFT back function test_AccessController_NFTTransferBackCheckPermission() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -1450,7 +1427,6 @@ contract AccessControllerTest is BaseTest { // test permission was unset after burn NFT function test_AccessController_NFTBurn() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -1487,7 +1463,6 @@ contract AccessControllerTest is BaseTest { // test permission check failed after burn NFT function test_AccessController_revert_NFTBurnCheckPermissionFailure() public { - moduleRegistry.registerModule("MockModule", address(mockModule)); address signer = vm.addr(2); vm.prank(owner); ipAccount.execute( @@ -1527,11 +1502,6 @@ contract AccessControllerTest is BaseTest { address anotherAccount = vm.addr(3); - TokenWithdrawalModule tokenWithdrawalModule = new TokenWithdrawalModule( - address(accessController), - address(ipAccountRegistry) - ); - moduleRegistry.registerModule(TOKEN_WITHDRAWAL_MODULE_KEY, address(tokenWithdrawalModule)); vm.prank(owner); ipAccount.execute( address(accessController), @@ -1567,11 +1537,6 @@ contract AccessControllerTest is BaseTest { address anotherAccount = vm.addr(3); - TokenWithdrawalModule tokenWithdrawalModule = new TokenWithdrawalModule( - address(accessController), - address(ipAccountRegistry) - ); - moduleRegistry.registerModule(TOKEN_WITHDRAWAL_MODULE_KEY, address(tokenWithdrawalModule)); vm.prank(owner); ipAccount.execute( address(accessController), @@ -1605,11 +1570,6 @@ contract AccessControllerTest is BaseTest { address anotherAccount = vm.addr(3); - TokenWithdrawalModule tokenWithdrawalModule = new TokenWithdrawalModule( - address(accessController), - address(ipAccountRegistry) - ); - moduleRegistry.registerModule(TOKEN_WITHDRAWAL_MODULE_KEY, address(tokenWithdrawalModule)); vm.prank(owner); ipAccount.execute( address(accessController), diff --git a/test/foundry/governance/Governance.t.sol b/test/foundry/governance/Governance.t.sol index 5e03632bf..956a877c1 100644 --- a/test/foundry/governance/Governance.t.sol +++ b/test/foundry/governance/Governance.t.sol @@ -21,10 +21,6 @@ contract GovernanceTest is BaseTest { function setUp() public override { super.setUp(); - buildDeployAccessCondition(DeployAccessCondition({ accessController: true, governance: true })); - buildDeployRegistryCondition(DeployRegistryCondition({ moduleRegistry: true, licenseRegistry: false })); - deployConditionally(); - postDeploymentSetup(); mockNFT.mintId(owner, tokenId); diff --git a/test/foundry/integration/BaseIntegration.t.sol b/test/foundry/integration/BaseIntegration.t.sol index 9bd62d283..3a543be49 100644 --- a/test/foundry/integration/BaseIntegration.t.sol +++ b/test/foundry/integration/BaseIntegration.t.sol @@ -20,16 +20,6 @@ contract BaseIntegration is BaseTest { using Strings for *; function setUp() public virtual override(BaseTest) { super.setUp(); - // deploy everything as real contracts - buildDeployAccessCondition(DeployAccessCondition({ governance: true, accessController: true })); - buildDeployRegistryCondition(DeployRegistryCondition({ licenseRegistry: true, moduleRegistry: true })); - buildDeployModuleCondition( - DeployModuleCondition({ disputeModule: true, royaltyModule: true, licensingModule: true }) - ); - buildDeployPolicyCondition(DeployPolicyCondition({ arbitrationPolicySP: true, royaltyPolicyLAP: true })); - - deployConditionally(); - postDeploymentSetup(); dealMockAssets(); diff --git a/test/foundry/integration/flows/disputes/Disputes.t.sol b/test/foundry/integration/flows/disputes/Disputes.t.sol index 4e7440db3..eff1fcbd0 100644 --- a/test/foundry/integration/flows/disputes/Disputes.t.sol +++ b/test/foundry/integration/flows/disputes/Disputes.t.sol @@ -17,7 +17,7 @@ contract Flows_Integration_Disputes is BaseIntegration { using Strings for *; mapping(uint256 tokenId => address ipAccount) internal ipAcct; - uint256 policyId; + uint256 internal policyId; function setUp() public override { super.setUp(); diff --git a/test/foundry/integration/flows/licensing/LicensingScenarios.t.sol b/test/foundry/integration/flows/licensing/LicensingScenarios.t.sol index 90b3dfc85..71b6b1f16 100644 --- a/test/foundry/integration/flows/licensing/LicensingScenarios.t.sol +++ b/test/foundry/integration/flows/licensing/LicensingScenarios.t.sol @@ -17,7 +17,7 @@ contract Licensing_Scenarios is BaseIntegration { using Strings for *; mapping(uint256 tokenId => address ipAccount) internal ipAcct; - uint256 nonCommRemixPoliciyId; + uint256 internal nonCommRemixPoliciyId; function setUp() public override { super.setUp(); diff --git a/test/foundry/integration/flows/royalty/Royalty.t.sol b/test/foundry/integration/flows/royalty/Royalty.t.sol index 262a8993b..7b18fe7ba 100644 --- a/test/foundry/integration/flows/royalty/Royalty.t.sol +++ b/test/foundry/integration/flows/royalty/Royalty.t.sol @@ -54,7 +54,7 @@ contract Flows_Integration_Disputes is BaseIntegration { { vm.startPrank(u.alice); - ipAcct[1] = _getIpId(mockNFT, 1); + ipAcct[1] = ipAccountRegistry.ipAccount(block.chainid, address(mockNFT), 1); vm.label(ipAcct[1], "IPAccount1"); registerIpAccount(mockNFT, 1, u.alice); @@ -67,7 +67,7 @@ contract Flows_Integration_Disputes is BaseIntegration { { vm.startPrank(u.bob); - ipAcct[2] = _getIpId(mockNFT, 2); + ipAcct[2] = ipAccountRegistry.ipAccount(block.chainid, address(mockNFT), 2); vm.label(ipAcct[2], "IPAccount2"); uint256 mintAmount = 3; @@ -98,7 +98,7 @@ contract Flows_Integration_Disputes is BaseIntegration { { vm.startPrank(u.carl); - ipAcct[3] = _getIpId(mockNFT, 3); + ipAcct[3] = ipAccountRegistry.ipAccount(block.chainid, address(mockNFT), 3); vm.label(ipAcct[3], "IPAccount3"); uint256 mintAmount = 1; diff --git a/test/foundry/mocks/policy/MockRoyaltyPolicyLAP.sol b/test/foundry/mocks/policy/MockRoyaltyPolicyLAP.sol new file mode 100644 index 000000000..5e83ee29d --- /dev/null +++ b/test/foundry/mocks/policy/MockRoyaltyPolicyLAP.sol @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.23; + +import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; +import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; + +import { GovernableUpgradeable } from "../../../../contracts/governance/GovernableUpgradeable.sol"; +import { RoyaltyPolicyLAP } from "../../../../contracts/modules/royalty/policies/RoyaltyPolicyLAP.sol"; +import { IRoyaltyPolicyLAP } from "../../../../contracts/interfaces/modules/royalty/policies/IRoyaltyPolicyLAP.sol"; +import { Errors } from "../../../../contracts/lib/Errors.sol"; + +contract MockRoyaltyPolicyLAP is IRoyaltyPolicyLAP, GovernableUpgradeable, ReentrancyGuardUpgradeable, UUPSUpgradeable { + struct RoyaltyPolicyLAPStorage { + address ipRoyaltyVaultBeacon; + uint256 snapshotInterval; + mapping(address ipId => RoyaltyPolicyLAP.LAPRoyaltyData) royaltyData; + } + + bytes32 private constant RoyaltyPolicyLAPStorageLocation = + 0x0c915ba68e2c4e37f19454bb13066f18f9db418fcefbf3c585b4b7d0fb0e0600; + + uint32 public constant TOTAL_RT_SUPPLY = 100000000; + uint256 public constant MAX_PARENTS = 100; + uint256 public constant MAX_ANCESTORS = 100; + address public constant LICENSING_MODULE = address(0); + address public constant ROYALTY_MODULE = address(0); + + constructor() { + _disableInitializers(); + } + + function initialize() external initializer { + __GovernableUpgradeable_init(address(0x1)); + __ReentrancyGuard_init(); + __UUPSUpgradeable_init(); + } + + function setSnapshotInterval(uint256 timestampInterval) public onlyProtocolAdmin { + RoyaltyPolicyLAPStorage storage $ = _getRoyaltyPolicyLAPStorage(); + $.snapshotInterval = timestampInterval; + } + + function setIpRoyaltyVaultBeacon(address beacon) public onlyProtocolAdmin { + if (beacon == address(0)) revert Errors.RoyaltyPolicyLAP__ZeroIpRoyaltyVaultBeacon(); + RoyaltyPolicyLAPStorage storage $ = _getRoyaltyPolicyLAPStorage(); + $.ipRoyaltyVaultBeacon = beacon; + } + + function onLicenseMinting(address ipId, bytes calldata licenseData, bytes calldata externalData) external {} + + function onLinkToParents( + address ipId, + address[] calldata parentIpIds, + bytes[] memory licenseData, + bytes calldata externalData + ) external {} + + function onRoyaltyPayment(address caller, address ipId, address token, uint256 amount) external {} + + function getRoyaltyData( + address ipId + ) external view returns (bool, address, uint32, address[] memory, uint32[] memory) { + RoyaltyPolicyLAPStorage storage $ = _getRoyaltyPolicyLAPStorage(); + RoyaltyPolicyLAP.LAPRoyaltyData memory data = $.royaltyData[ipId]; + return ( + data.isUnlinkableToParents, + data.ipRoyaltyVault, + data.royaltyStack, + data.ancestorsAddresses, + data.ancestorsRoyalties + ); + } + + function getSnapshotInterval() external view returns (uint256) { + RoyaltyPolicyLAPStorage storage $ = _getRoyaltyPolicyLAPStorage(); + return $.snapshotInterval; + } + + function getIpRoyaltyVaultBeacon() external view returns (address) { + RoyaltyPolicyLAPStorage storage $ = _getRoyaltyPolicyLAPStorage(); + return $.ipRoyaltyVaultBeacon; + } + + function _getRoyaltyPolicyLAPStorage() private pure returns (RoyaltyPolicyLAPStorage storage $) { + assembly { + $.slot := RoyaltyPolicyLAPStorageLocation + } + } + + /// @dev Hook to authorize the upgrade according to UUPSUgradeable + /// @param newImplementation The address of the new implementation + function _authorizeUpgrade(address newImplementation) internal override {} +} diff --git a/test/foundry/modules/ModuleBase.t.sol b/test/foundry/modules/ModuleBase.t.sol index b5deeffed..339f908f7 100644 --- a/test/foundry/modules/ModuleBase.t.sol +++ b/test/foundry/modules/ModuleBase.t.sol @@ -15,9 +15,6 @@ abstract contract ModuleBaseTest is BaseTest { function setUp() public virtual override(BaseTest) { super.setUp(); - deployConditionally(); - postDeploymentSetup(); - baseModule = IModule(_deployModule()); } diff --git a/test/foundry/modules/dispute/ArbitrationPolicySP.t.sol b/test/foundry/modules/dispute/ArbitrationPolicySP.t.sol index e7fb3992e..bcc2be82c 100644 --- a/test/foundry/modules/dispute/ArbitrationPolicySP.t.sol +++ b/test/foundry/modules/dispute/ArbitrationPolicySP.t.sol @@ -21,12 +21,6 @@ contract TestArbitrationPolicySP is BaseTest { function setUp() public override { super.setUp(); - buildDeployModuleCondition( - DeployModuleCondition({ disputeModule: true, royaltyModule: false, licensingModule: false }) - ); - buildDeployPolicyCondition(DeployPolicyCondition({ arbitrationPolicySP: true, royaltyPolicyLAP: true })); - deployConditionally(); - postDeploymentSetup(); arbitrationRelayer = u.admin; diff --git a/test/foundry/modules/dispute/DisputeModule.t.sol b/test/foundry/modules/dispute/DisputeModule.t.sol index e650171de..1cd987fce 100644 --- a/test/foundry/modules/dispute/DisputeModule.t.sol +++ b/test/foundry/modules/dispute/DisputeModule.t.sol @@ -42,22 +42,15 @@ contract DisputeModuleTest is BaseTest { function setUp() public override { super.setUp(); - buildDeployModuleCondition( - DeployModuleCondition({ disputeModule: true, royaltyModule: false, licensingModule: false }) - ); - buildDeployPolicyCondition(DeployPolicyCondition({ arbitrationPolicySP: true, royaltyPolicyLAP: true })); - - deployConditionally(); - postDeploymentSetup(); arbitrationRelayer = u.admin; USDC.mint(ipAccount1, 1000 * 10 ** 6); // second arbitration policy - address impl = address(new ArbitrationPolicySP(getDisputeModule(), address(USDC), ARBITRATION_PRICE)); + address impl = address(new ArbitrationPolicySP(address(disputeModule), address(USDC), ARBITRATION_PRICE)); arbitrationPolicySP2 = ArbitrationPolicySP( - TestProxyHelper.deployUUPSProxy(impl, abi.encodeCall(ArbitrationPolicySP.initialize, (getGovernance()))) + TestProxyHelper.deployUUPSProxy(impl, abi.encodeCall(ArbitrationPolicySP.initialize, address(governance))) ); vm.startPrank(u.admin); diff --git a/test/foundry/modules/external/TokenWithdrawalModule.t.sol b/test/foundry/modules/external/TokenWithdrawalModule.t.sol index 171a58412..b52a4220f 100644 --- a/test/foundry/modules/external/TokenWithdrawalModule.t.sol +++ b/test/foundry/modules/external/TokenWithdrawalModule.t.sol @@ -7,9 +7,7 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; // contracts import { IIPAccount } from "../../../../contracts/interfaces/IIPAccount.sol"; import { AccessPermission } from "../../../../contracts/lib/AccessPermission.sol"; -import { TokenWithdrawalModule } from "../../../../contracts/modules/external/TokenWithdrawalModule.sol"; import { Errors } from "../../../../contracts/lib/Errors.sol"; -import { TOKEN_WITHDRAWAL_MODULE_KEY } from "../../../../contracts/lib/modules/Module.sol"; // test import { MockERC20 } from "../../mocks/token/MockERC20.sol"; @@ -24,21 +22,15 @@ contract TokenWithdrawalModuleTest is BaseTest { MockERC721 private tErc721 = new MockERC721("MockERC721"); MockERC1155 private tErc1155 = new MockERC1155("uri"); - TokenWithdrawalModule private tokenWithdrawalModule; - IIPAccount private ipAcct1; IIPAccount private ipAcct2; - uint256 mintAmount20 = 100 * 10 ** tErc20.decimals(); + uint256 private mintAmount20 = 100 * 10 ** tErc20.decimals(); - address randomFrontend = address(0x123); + address private randomFrontend = address(0x123); function setUp() public override { super.setUp(); - buildDeployAccessCondition(DeployAccessCondition({ accessController: true, governance: true })); - buildDeployRegistryCondition(DeployRegistryCondition({ licenseRegistry: false, moduleRegistry: true })); - deployConditionally(); - postDeploymentSetup(); // Create IPAccounts (Alice is the owner) mockNFT.mintId(alice, 1); @@ -49,11 +41,6 @@ contract TokenWithdrawalModuleTest is BaseTest { vm.label(address(ipAcct1), "IPAccount1"); vm.label(address(ipAcct2), "IPAccount2"); - - tokenWithdrawalModule = new TokenWithdrawalModule(address(accessController), address(ipAccountRegistry)); - - vm.prank(u.admin); - moduleRegistry.registerModule(TOKEN_WITHDRAWAL_MODULE_KEY, address(tokenWithdrawalModule)); } modifier testERC20_mintToIpAcct1() { diff --git a/test/foundry/modules/licensing/LicensingModule.t.sol b/test/foundry/modules/licensing/LicensingModule.t.sol index 84d797259..b623ee965 100644 --- a/test/foundry/modules/licensing/LicensingModule.t.sol +++ b/test/foundry/modules/licensing/LicensingModule.t.sol @@ -5,20 +5,22 @@ pragma solidity 0.8.23; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; // contracts -import { IIPAccount } from "contracts/interfaces/IIPAccount.sol"; -import { AccessPermission } from "contracts/lib/AccessPermission.sol"; -import { Errors } from "contracts/lib/Errors.sol"; -import { Licensing } from "contracts/lib/Licensing.sol"; -import { RegisterPILPolicyParams } from "contracts/interfaces/modules/licensing/IPILPolicyFrameworkManager.sol"; -import { PILPolicy } from "contracts/modules/licensing/PILPolicyFrameworkManager.sol"; +import { IIPAccount } from "../../../../contracts/interfaces/IIPAccount.sol"; +import { AccessPermission } from "../../../../contracts/lib/AccessPermission.sol"; +import { Errors } from "../../../../contracts/lib/Errors.sol"; +import { Licensing } from "../../../../contracts/lib/Licensing.sol"; +// solhint-disable-next-line max-line-length +import { RegisterPILPolicyParams } from "../../../../contracts/interfaces/modules/licensing/IPILPolicyFrameworkManager.sol"; +import { PILPolicy } from "../../../../contracts/modules/licensing/PILPolicyFrameworkManager.sol"; +import { IRoyaltyPolicyLAP } from "../../../../contracts/interfaces/modules/royalty/policies/IRoyaltyPolicyLAP.sol"; // test // solhint-disable-next-line max-line-length -import { MockPolicyFrameworkManager, MockPolicyFrameworkConfig, MockPolicy } from "test/foundry/mocks/licensing/MockPolicyFrameworkManager.sol"; -import { MockAccessController } from "test/foundry/mocks/access/MockAccessController.sol"; -import { MockTokenGatedHook } from "test/foundry/mocks/MockTokenGatedHook.sol"; -import { MockERC721 } from "test/foundry/mocks/token/MockERC721.sol"; -import { BaseTest } from "test/foundry/utils/BaseTest.t.sol"; +import { MockPolicyFrameworkManager, MockPolicyFrameworkConfig, MockPolicy } from "../../mocks/licensing/MockPolicyFrameworkManager.sol"; +import { MockAccessController } from "../../mocks/access/MockAccessController.sol"; +import { MockTokenGatedHook } from "../../mocks/MockTokenGatedHook.sol"; +import { MockERC721 } from "../../mocks/token/MockERC721.sol"; +import { BaseTest } from "../../utils/BaseTest.t.sol"; contract LicensingModuleTest is BaseTest { using Strings for *; @@ -38,6 +40,8 @@ contract LicensingModuleTest is BaseTest { address public ipOwner = address(0x100); // use static address, otherwise uri check fails because licensor changes address public licenseHolder = address(0x101); + IRoyaltyPolicyLAP public mockRoyaltyPolicyLAP; + modifier withPolicyFrameworkManager() { licensingModule.registerPolicyFrameworkManager(address(mockPFM)); _; @@ -45,13 +49,6 @@ contract LicensingModuleTest is BaseTest { function setUp() public override { super.setUp(); - buildDeployModuleCondition( - DeployModuleCondition({ disputeModule: false, royaltyModule: false, licensingModule: true }) - ); - buildDeployPolicyCondition(DeployPolicyCondition({ arbitrationPolicySP: false, royaltyPolicyLAP: true })); - buildDeployRegistryCondition(DeployRegistryCondition({ licenseRegistry: true, moduleRegistry: false })); - deployConditionally(); - postDeploymentSetup(); // TODO: Mock this mockRoyaltyPolicyLAP = royaltyPolicyLAP; @@ -78,6 +75,8 @@ contract LicensingModuleTest is BaseTest { vm.label(ipId1, "IPAccount1"); vm.label(ipId2, "IPAccount2"); vm.label(ipId3, "IPAccount3"); + + useMock_RoyaltyPolicyLAP(); } function _createMockPolicy() internal pure returns (bytes memory) { diff --git a/test/foundry/modules/licensing/PILPolicyFramework.derivation.t.sol b/test/foundry/modules/licensing/PILPolicyFramework.derivation.t.sol index f2a330f6c..35475c499 100644 --- a/test/foundry/modules/licensing/PILPolicyFramework.derivation.t.sol +++ b/test/foundry/modules/licensing/PILPolicyFramework.derivation.t.sol @@ -1,9 +1,6 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.23; -import { IAccessController } from "contracts/interfaces/access/IAccessController.sol"; -import { ILicensingModule } from "contracts/interfaces/modules/licensing/ILicensingModule.sol"; -import { IRoyaltyModule } from "contracts/interfaces/modules/royalty/IRoyaltyModule.sol"; import { Errors } from "contracts/lib/Errors.sol"; import { BaseTest } from "test/foundry/utils/BaseTest.t.sol"; @@ -30,20 +27,6 @@ contract PILPolicyFrameworkCompatibilityTest is BaseTest { function setUp() public override { super.setUp(); - buildDeployRegistryCondition(DeployRegistryCondition({ licenseRegistry: true, moduleRegistry: false })); - buildDeployModuleCondition( - DeployModuleCondition({ disputeModule: false, royaltyModule: false, licensingModule: true }) - ); - buildDeployPolicyCondition(DeployPolicyCondition({ royaltyPolicyLAP: true, arbitrationPolicySP: false })); - deployConditionally(); - postDeploymentSetup(); - - // Call `getXXX` here to either deploy mock or use real contracted deploy via the - // deployConditionally() call above. - // TODO: three options, auto/mock/real in deploy condition, so no need to call getXXX - accessController = IAccessController(getAccessController()); - licensingModule = ILicensingModule(getLicensingModule()); - royaltyModule = IRoyaltyModule(getRoyaltyModule()); _setPILPolicyFrameworkManager(); @@ -53,6 +36,8 @@ contract PILPolicyFrameworkCompatibilityTest is BaseTest { ipId2 = ipAccountRegistry.registerIpAccount(block.chainid, address(mockNFT), 2); vm.label(ipId1, "IP1"); vm.label(ipId2, "IP2"); + + useMock_RoyaltyPolicyLAP(); } ///////////////////////////////////////////////////////////// @@ -83,9 +68,11 @@ contract PILPolicyFrameworkCompatibilityTest is BaseTest { // Others can mint licenses to make derivatives of IP1 from each different policy, // as long as they pass the verifications + vm.startPrank(alice); uint256 licenseId1 = licensingModule.mintLicense(_getPilPolicyId("comm_deriv"), ipId1, 1, dan, ""); assertEq(licenseRegistry.balanceOf(dan, licenseId1), 1, "dan doesn't have license1"); + vm.startPrank(dan); uint256 licenseId2 = licensingModule.mintLicense(_getPilPolicyId("comm_non_deriv"), ipId1, 1, dan, ""); assertEq(licenseRegistry.balanceOf(dan, licenseId2), 1, "dan doesn't have license2"); } diff --git a/test/foundry/modules/licensing/PILPolicyFramework.multi-parent.sol b/test/foundry/modules/licensing/PILPolicyFramework.multi-parent.sol index 1bb2be6c8..b17f88505 100644 --- a/test/foundry/modules/licensing/PILPolicyFramework.multi-parent.sol +++ b/test/foundry/modules/licensing/PILPolicyFramework.multi-parent.sol @@ -1,9 +1,6 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.23; -import { IAccessController } from "contracts/interfaces/access/IAccessController.sol"; -import { ILicensingModule } from "contracts/interfaces/modules/licensing/ILicensingModule.sol"; -import { IRoyaltyModule } from "contracts/interfaces/modules/royalty/IRoyaltyModule.sol"; import { Errors } from "contracts/lib/Errors.sol"; import { Licensing } from "contracts/lib/Licensing.sol"; import { PILFrameworkErrors } from "contracts/lib/PILFrameworkErrors.sol"; @@ -40,20 +37,6 @@ contract PILPolicyFrameworkMultiParentTest is BaseTest { function setUp() public override { super.setUp(); - buildDeployRegistryCondition(DeployRegistryCondition({ licenseRegistry: true, moduleRegistry: false })); - buildDeployModuleCondition( - DeployModuleCondition({ disputeModule: false, royaltyModule: false, licensingModule: true }) - ); - buildDeployPolicyCondition(DeployPolicyCondition({ royaltyPolicyLAP: true, arbitrationPolicySP: false })); - deployConditionally(); - postDeploymentSetup(); - - // Call `getXXX` here to either deploy mock or use real contracted deploy via the - // deployConditionally() call above. - // TODO: three options, auto/mock/real in deploy condition, so no need to call getXXX - accessController = IAccessController(getAccessController()); - licensingModule = ILicensingModule(getLicensingModule()); - royaltyModule = IRoyaltyModule(getRoyaltyModule()); _setPILPolicyFrameworkManager(); @@ -76,6 +59,8 @@ contract PILPolicyFrameworkMultiParentTest is BaseTest { vm.label(ipId2, "IP2"); vm.label(ipId3, "IP3"); vm.label(ipId4, "IP4"); + + useMock_RoyaltyPolicyLAP(); } function test_PILPolicyFramework_multiParent_AliceSets3Parents_SamePolicyReciprocal() @@ -404,11 +389,11 @@ contract PILPolicyFrameworkMultiParentTest is BaseTest { RegisterPILPolicyParams memory inputB ) internal returns (uint256 polAId, uint256 polBId) { polAId = _pilFramework().registerPolicy(inputA); - vm.prank(ipId1); + vm.prank(ipIdToOwner[ipId1]); licenses.push(licensingModule.mintLicense(polAId, ipId1, 1, alice, "")); polBId = _pilFramework().registerPolicy(inputB); - vm.prank(ipId2); + vm.prank(ipIdToOwner[ipId2]); licenses.push(licensingModule.mintLicense(polBId, ipId2, 2, alice, "")); } diff --git a/test/foundry/modules/licensing/PILPolicyFramework.t.sol b/test/foundry/modules/licensing/PILPolicyFramework.t.sol index ed08fb1b2..66e1a7f72 100644 --- a/test/foundry/modules/licensing/PILPolicyFramework.t.sol +++ b/test/foundry/modules/licensing/PILPolicyFramework.t.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.23; -import { IAccessController } from "contracts/interfaces/access/IAccessController.sol"; -import { ILicensingModule } from "contracts/interfaces/modules/licensing/ILicensingModule.sol"; import { Errors } from "contracts/lib/Errors.sol"; import { PILFrameworkErrors } from "contracts/lib/PILFrameworkErrors.sol"; // solhint-disable-next-line max-line-length @@ -22,24 +20,6 @@ contract PILPolicyFrameworkTest is BaseTest { function setUp() public override { super.setUp(); - buildDeployRegistryCondition(DeployRegistryCondition({ licenseRegistry: true, moduleRegistry: false })); - buildDeployModuleCondition( - DeployModuleCondition({ disputeModule: false, royaltyModule: false, licensingModule: true }) - ); - buildDeployPolicyCondition( - DeployPolicyCondition({ - arbitrationPolicySP: false, - royaltyPolicyLAP: true // deploy to set address for commercial licenses - }) - ); - deployConditionally(); - postDeploymentSetup(); - - // Call `getXXX` here to either deploy mock or use real contracted deploy via the - // deployConditionally() call above. - // TODO: three options, auto/mock/real in deploy condition, so no need to call getXXX - accessController = IAccessController(getAccessController()); - licensingModule = ILicensingModule(getLicensingModule()); _setPILPolicyFrameworkManager(); diff --git a/test/foundry/modules/metadata/CoreMetadataModule.t.sol b/test/foundry/modules/metadata/CoreMetadataModule.t.sol index 7c968167d..97bc4d9d9 100644 --- a/test/foundry/modules/metadata/CoreMetadataModule.t.sol +++ b/test/foundry/modules/metadata/CoreMetadataModule.t.sol @@ -2,36 +2,24 @@ pragma solidity ^0.8.23; import { IIPAccount } from "../../../../contracts/interfaces/IIPAccount.sol"; -import { CoreMetadataModule } from "../../../../contracts/modules/metadata/CoreMetadataModule.sol"; import { ICoreMetadataModule } from "../../../../contracts/interfaces/modules/metadata/ICoreMetadataModule.sol"; import { Errors } from "../../../../contracts/lib/Errors.sol"; -import { CORE_METADATA_MODULE_KEY } from "../../../../contracts/lib/modules/Module.sol"; import { BaseTest } from "../../utils/BaseTest.t.sol"; import { IPAccountStorageOps } from "../../../../contracts/lib/IPAccountStorageOps.sol"; contract CoreMetadataModuleTest is BaseTest { using IPAccountStorageOps for IIPAccount; - CoreMetadataModule public coreMetadataModule; IIPAccount private ipAccount; function setUp() public override { super.setUp(); - buildDeployAccessCondition(DeployAccessCondition({ accessController: true, governance: true })); - buildDeployRegistryCondition(DeployRegistryCondition({ licenseRegistry: false, moduleRegistry: true })); - deployConditionally(); - postDeploymentSetup(); mockNFT.mintId(alice, 1); ipAccount = IIPAccount(payable(ipAssetRegistry.register(address(mockNFT), 1))); vm.label(address(ipAccount), "IPAccount1"); - - coreMetadataModule = new CoreMetadataModule(address(accessController), address(ipAssetRegistry)); - - vm.prank(u.admin); - moduleRegistry.registerModule(CORE_METADATA_MODULE_KEY, address(coreMetadataModule)); } function test_CoreMetadata_NftTokenURI() public { diff --git a/test/foundry/modules/metadata/CoreMetadataViewModule.t.sol b/test/foundry/modules/metadata/CoreMetadataViewModule.t.sol index f06bba73d..ddf421697 100644 --- a/test/foundry/modules/metadata/CoreMetadataViewModule.t.sol +++ b/test/foundry/modules/metadata/CoreMetadataViewModule.t.sol @@ -4,10 +4,7 @@ pragma solidity ^0.8.23; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol"; import { IIPAccount } from "../../../../contracts/interfaces/IIPAccount.sol"; -import { CoreMetadataModule } from "../../../../contracts/modules/metadata/CoreMetadataModule.sol"; import { CoreMetadataViewModule } from "../../../../contracts/modules/metadata/CoreMetadataViewModule.sol"; -import { CORE_METADATA_MODULE_KEY } from "../../../../contracts/lib/modules/Module.sol"; -import { CORE_METADATA_VIEW_MODULE_KEY } from "../../../../contracts/lib/modules/Module.sol"; import { BaseTest } from "../../utils/BaseTest.t.sol"; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import { IPAccountStorageOps } from "../../../../contracts/lib/IPAccountStorageOps.sol"; @@ -16,32 +13,16 @@ contract CoreMetadataViewModuleTest is BaseTest { using IPAccountStorageOps for IIPAccount; using Strings for *; - CoreMetadataModule public coreMetadataModule; - CoreMetadataViewModule public coreMetadataViewModule; IIPAccount private ipAccount; function setUp() public override { super.setUp(); - buildDeployAccessCondition(DeployAccessCondition({ accessController: true, governance: true })); - buildDeployRegistryCondition(DeployRegistryCondition({ licenseRegistry: false, moduleRegistry: true })); - deployConditionally(); - postDeploymentSetup(); mockNFT.mintId(alice, 99); ipAccount = IIPAccount(payable(ipAssetRegistry.register(address(mockNFT), 99))); vm.label(address(ipAccount), "IPAccount1"); - - coreMetadataModule = new CoreMetadataModule(address(accessController), address(ipAssetRegistry)); - coreMetadataViewModule = new CoreMetadataViewModule(address(ipAssetRegistry), address(moduleRegistry)); - - vm.startPrank(u.admin); - moduleRegistry.registerModule(CORE_METADATA_MODULE_KEY, address(coreMetadataModule)); - moduleRegistry.registerModule(CORE_METADATA_VIEW_MODULE_KEY, address(coreMetadataViewModule)); - vm.stopPrank(); - - coreMetadataViewModule.updateCoreMetadataModule(); } function test_CoreMetadataViewModule_GetAllMetadata() public { diff --git a/test/foundry/modules/metadata/MetadataModule.t.sol b/test/foundry/modules/metadata/MetadataModule.t.sol index a0f6a4109..f79a60d02 100644 --- a/test/foundry/modules/metadata/MetadataModule.t.sol +++ b/test/foundry/modules/metadata/MetadataModule.t.sol @@ -9,19 +9,25 @@ import { BaseTest } from "../../utils/BaseTest.t.sol"; contract MetadataModuleTest is BaseTest { MockModule public module; - MockCoreMetadataViewModule public coreMetadataViewModule; MockAllMetadataViewModule public allMetadataViewModule; MockMetadataModule public metadataModule; function setUp() public override { super.setUp(); - deployConditionally(); - postDeploymentSetup(); metadataModule = new MockMetadataModule(address(accessController), address(ipAssetRegistry)); module = new MockModule(address(ipAssetRegistry), address(moduleRegistry), "MockModule"); - coreMetadataViewModule = new MockCoreMetadataViewModule(address(ipAssetRegistry)); + + vm.etch( + address(coreMetadataViewModule), + address(new MockCoreMetadataViewModule(address(ipAssetRegistry))).code + ); allMetadataViewModule = new MockAllMetadataViewModule(address(ipAssetRegistry), address(metadataModule)); + + vm.startPrank(u.admin); + moduleRegistry.registerModule("MockModule", address(module)); + moduleRegistry.registerModule("MockMetadataModule", address(metadataModule)); + vm.stopPrank(); } function test_Metadata_OptionalMetadata() public { diff --git a/test/foundry/modules/royalty/IpRoyaltyVault.t.sol b/test/foundry/modules/royalty/IpRoyaltyVault.t.sol index 83814cfe2..7eb7a37fb 100644 --- a/test/foundry/modules/royalty/IpRoyaltyVault.t.sol +++ b/test/foundry/modules/royalty/IpRoyaltyVault.t.sol @@ -12,16 +12,10 @@ contract TestIpRoyaltyVault is BaseTest { event RoyaltyTokensCollected(address ancestorIpId, uint256 royaltyTokensCollected); event SnapshotCompleted(uint256 snapshotId, uint256 timestamp, uint32 unclaimedTokens); - IpRoyaltyVault ipRoyaltyVault; + IpRoyaltyVault private ipRoyaltyVault; function setUp() public override { super.setUp(); - buildDeployModuleCondition( - DeployModuleCondition({ disputeModule: false, royaltyModule: true, licensingModule: false }) - ); - buildDeployPolicyCondition(DeployPolicyCondition({ arbitrationPolicySP: false, royaltyPolicyLAP: true })); - deployConditionally(); - postDeploymentSetup(); vm.startPrank(u.admin); // whitelist royalty policy diff --git a/test/foundry/modules/royalty/RoyaltyModule.t.sol b/test/foundry/modules/royalty/RoyaltyModule.t.sol index fc3b45538..b3cac5a40 100644 --- a/test/foundry/modules/royalty/RoyaltyModule.t.sol +++ b/test/foundry/modules/royalty/RoyaltyModule.t.sol @@ -38,18 +38,12 @@ contract TestRoyaltyModule is BaseTest { function setUp() public override { super.setUp(); - buildDeployModuleCondition( - DeployModuleCondition({ disputeModule: false, royaltyModule: true, licensingModule: false }) - ); - buildDeployPolicyCondition(DeployPolicyCondition({ arbitrationPolicySP: false, royaltyPolicyLAP: true })); - deployConditionally(); - postDeploymentSetup(); USDC.mint(ipAccount2, 1000 * 10 ** 6); // 1000 USDC - address impl = address(new RoyaltyPolicyLAP(getRoyaltyModule(), getLicensingModule())); + address impl = address(new RoyaltyPolicyLAP(address(royaltyModule), address(licensingModule))); royaltyPolicyLAP2 = RoyaltyPolicyLAP( - TestProxyHelper.deployUUPSProxy(impl, abi.encodeCall(RoyaltyPolicyLAP.initialize, (getGovernance()))) + TestProxyHelper.deployUUPSProxy(impl, abi.encodeCall(RoyaltyPolicyLAP.initialize, address(governance))) ); vm.startPrank(u.admin); @@ -122,7 +116,7 @@ contract TestRoyaltyModule is BaseTest { function test_RoyaltyModule_setLicensingModule_revert_ZeroLicensingModule() public { address impl = address(new RoyaltyModule()); RoyaltyModule testRoyaltyModule = RoyaltyModule( - TestProxyHelper.deployUUPSProxy(impl, abi.encodeCall(RoyaltyModule.initialize, (address(getGovernance())))) + TestProxyHelper.deployUUPSProxy(impl, abi.encodeCall(RoyaltyModule.initialize, address(governance))) ); vm.expectRevert(Errors.RoyaltyModule__ZeroLicensingModule.selector); vm.prank(u.admin); @@ -133,7 +127,7 @@ contract TestRoyaltyModule is BaseTest { vm.startPrank(u.admin); address impl = address(new RoyaltyModule()); RoyaltyModule testRoyaltyModule = RoyaltyModule( - TestProxyHelper.deployUUPSProxy(impl, abi.encodeCall(RoyaltyModule.initialize, (address(getGovernance())))) + TestProxyHelper.deployUUPSProxy(impl, abi.encodeCall(RoyaltyModule.initialize, address(governance))) ); testRoyaltyModule.setLicensingModule(address(licensingModule)); assertEq(testRoyaltyModule.licensingModule(), address(licensingModule)); diff --git a/test/foundry/modules/royalty/RoyaltyPolicyLAP.t.sol b/test/foundry/modules/royalty/RoyaltyPolicyLAP.t.sol index 41a5cda60..4085e93aa 100644 --- a/test/foundry/modules/royalty/RoyaltyPolicyLAP.t.sol +++ b/test/foundry/modules/royalty/RoyaltyPolicyLAP.t.sol @@ -15,12 +15,6 @@ contract TestRoyaltyPolicyLAP is BaseTest { function setUp() public override { super.setUp(); - buildDeployModuleCondition( - DeployModuleCondition({ disputeModule: false, royaltyModule: true, licensingModule: false }) - ); - buildDeployPolicyCondition(DeployPolicyCondition({ arbitrationPolicySP: false, royaltyPolicyLAP: true })); - deployConditionally(); - postDeploymentSetup(); vm.startPrank(u.admin); // whitelist royalty policy diff --git a/test/foundry/registries/IPAccountRegistry.t.sol b/test/foundry/registries/IPAccountRegistry.t.sol index 6579b1473..471175f12 100644 --- a/test/foundry/registries/IPAccountRegistry.t.sol +++ b/test/foundry/registries/IPAccountRegistry.t.sol @@ -16,8 +16,6 @@ contract IPAccountRegistryTest is BaseTest { function setUp() public override { super.setUp(); - deployConditionally(); - postDeploymentSetup(); } function test_IPAccountRegistry_registerIpAccount() public { diff --git a/test/foundry/registries/IPAssetRegistry.t.sol b/test/foundry/registries/IPAssetRegistry.t.sol index 0cf01ee28..13acf12c7 100644 --- a/test/foundry/registries/IPAssetRegistry.t.sol +++ b/test/foundry/registries/IPAssetRegistry.t.sol @@ -35,14 +35,6 @@ contract IPAssetRegistryTest is BaseTest { /// @notice Initializes the IP asset registry testing contract. function setUp() public virtual override { super.setUp(); - buildDeployRegistryCondition( - DeployRegistryCondition({ - licenseRegistry: false, // don't use - moduleRegistry: false // use mock - }) - ); - deployConditionally(); - postDeploymentSetup(); registry = ipAssetRegistry; diff --git a/test/foundry/registries/ModuleRegistry.t.sol b/test/foundry/registries/ModuleRegistry.t.sol index 747236353..c8b6ef8bc 100644 --- a/test/foundry/registries/ModuleRegistry.t.sol +++ b/test/foundry/registries/ModuleRegistry.t.sol @@ -19,9 +19,6 @@ contract ModuleRegistryTest is BaseTest { function setUp() public override { super.setUp(); - buildDeployRegistryCondition(DeployRegistryCondition({ licenseRegistry: false, moduleRegistry: true })); - deployConditionally(); - postDeploymentSetup(); module = new MockModule(address(ipAccountRegistry), address(moduleRegistry), "MockModule"); customModule = new CustomModule(); diff --git a/test/foundry/utils/BaseTest.t.sol b/test/foundry/utils/BaseTest.t.sol index 639808238..367f0f946 100644 --- a/test/foundry/utils/BaseTest.t.sol +++ b/test/foundry/utils/BaseTest.t.sol @@ -3,18 +3,9 @@ pragma solidity 0.8.23; // external -import { console2 } from "forge-std/console2.sol"; // console to indicate mock deployment calls. import { Test } from "forge-std/Test.sol"; import { ERC6551Registry } from "erc6551/ERC6551Registry.sol"; -// contracts -import { AccessController } from "../../../contracts/access/AccessController.sol"; -// solhint-disable-next-line max-line-length -import { DISPUTE_MODULE_KEY, ROYALTY_MODULE_KEY, LICENSING_MODULE_KEY } from "../../../contracts/lib/modules/Module.sol"; -import { AccessPermission } from "../../../contracts/lib/AccessPermission.sol"; -import { LicenseRegistry } from "../../../contracts/registries/LicenseRegistry.sol"; -import { RoyaltyModule } from "../../../contracts/modules/royalty/RoyaltyModule.sol"; - // test import { DeployHelper } from "../../../script/foundry/utils/DeployHelper.sol"; import { LicensingHelper } from "./LicensingHelper.t.sol"; @@ -22,7 +13,6 @@ import { MockERC20 } from "../mocks/token/MockERC20.sol"; import { MockERC721 } from "../mocks/token/MockERC721.sol"; import { MockRoyaltyPolicyLAP } from "../mocks/policy/MockRoyaltyPolicyLAP.sol"; import { Users, UsersLib } from "./Users.t.sol"; -import { TestProxyHelper } from "./TestProxyHelper.sol"; /// @title Base Test Contract /// @notice This contract provides a set of protocol-related testing utilities