diff --git a/Makefile b/Makefile index 550ac828e..46bafe6d4 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,6 @@ abi: @$(call generate_abi,"LicenseToken",".") @$(call generate_abi,"AccessController","./access") @$(call generate_abi,"DisputeModule","./modules/dispute") - @$(call generate_abi,"ArbitrationPolicySP","./modules/dispute/policies") @$(call generate_abi,"LicensingModule","./modules/licensing") @$(call generate_abi,"PILicenseTemplate","./modules/licensing") @$(call generate_abi,"CoreMetadataModule","./modules/metadata") diff --git a/contracts/interfaces/modules/dispute/policies/IArbitrationPolicy.sol b/contracts/interfaces/modules/dispute/policies/IArbitrationPolicy.sol index 191f122bc..b00c69280 100644 --- a/contracts/interfaces/modules/dispute/policies/IArbitrationPolicy.sol +++ b/contracts/interfaces/modules/dispute/policies/IArbitrationPolicy.sol @@ -3,11 +3,6 @@ pragma solidity 0.8.26; /// @title Arbitration Policy Interface interface IArbitrationPolicy { - /// @notice Allows governance set the treasury address - /// @dev Enforced to be only callable by the governance protocol admin - /// @param newTreasury The new address of the treasury - function setTreasury(address newTreasury) external; - /// @notice Executes custom logic on raising dispute. /// @dev Enforced to be only callable by the DisputeModule. /// @param caller Address of the caller @@ -34,7 +29,4 @@ interface IArbitrationPolicy { /// @param disputeId The dispute id /// @param data The arbitrary data used to resolve the dispute function onResolveDispute(address caller, uint256 disputeId, bytes calldata data) external; - - /// @notice Returns the treasury address - function treasury() external view returns (address); } diff --git a/contracts/lib/Errors.sol b/contracts/lib/Errors.sol index 8c74d2822..2808c3b31 100644 --- a/contracts/lib/Errors.sol +++ b/contracts/lib/Errors.sol @@ -414,25 +414,6 @@ library Errors { /// @notice Provided parent dispute has not been resolved. error DisputeModule__ParentDisputeNotResolved(); - //////////////////////////////////////////////////////////////////////////// - // ArbitrationPolicy SP // - //////////////////////////////////////////////////////////////////////////// - - /// @notice Zero address provided for Access Manager in initializer. - error ArbitrationPolicySP__ZeroAccessManager(); - - /// @notice Zero address provided for Dispute Module. - error ArbitrationPolicySP__ZeroDisputeModule(); - - /// @notice Zero address provided for Treasury. - error ArbitrationPolicySP__ZeroTreasury(); - - /// @notice Zero address provided for Payment Token. - error ArbitrationPolicySP__ZeroPaymentToken(); - - /// @notice Caller is not the Dispute Module. - error ArbitrationPolicySP__NotDisputeModule(); - //////////////////////////////////////////////////////////////////////////// // Royalty Module // //////////////////////////////////////////////////////////////////////////// diff --git a/contracts/modules/dispute/policies/ArbitrationPolicySP.sol b/contracts/modules/dispute/policies/ArbitrationPolicySP.sol deleted file mode 100644 index 1d4ca2f51..000000000 --- a/contracts/modules/dispute/policies/ArbitrationPolicySP.sol +++ /dev/null @@ -1,141 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.26; - -import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; -// solhint-disable-next-line max-line-length -import { AccessManagedUpgradeable } from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol"; - -import { IDisputeModule } from "../../../interfaces/modules/dispute/IDisputeModule.sol"; -import { IArbitrationPolicy } from "../../../interfaces/modules/dispute/policies/IArbitrationPolicy.sol"; -import { Errors } from "../../../lib/Errors.sol"; - -/// @title Story Protocol Arbitration Policy -/// @notice The Story Protocol arbitration policy is a simple policy that requires the dispute initiator to pay a fixed -/// amount of tokens to raise a dispute and refunds that amount if the dispute initiator wins the dispute. -contract ArbitrationPolicySP is IArbitrationPolicy, AccessManagedUpgradeable, UUPSUpgradeable { - using SafeERC20 for IERC20; - - /// @notice Returns the protocol-wide dispute module address - /// @custom:oz-upgrades-unsafe-allow state-variable-immutable - address public immutable DISPUTE_MODULE; - /// @notice Returns the payment token address - /// @custom:oz-upgrades-unsafe-allow state-variable-immutable - address public immutable PAYMENT_TOKEN; - /// @notice Returns the arbitration price - /// @custom:oz-upgrades-unsafe-allow state-variable-immutable - uint256 public immutable ARBITRATION_PRICE; - - /// @dev Storage structure for the ArbitrationPolicySP - /// @custom:storage-location erc7201:story-protocol.ArbitrationPolicySP - struct ArbitrationPolicySPStorage { - address treasury; - } - - // keccak256(abi.encode(uint256(keccak256("story-protocol.ArbitrationPolicySP")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 private constant ArbitrationPolicySPStorageLocation = - 0x8b56c510cd155da0a5980302e158a4f212510ffd8eb3a4388303109171a91800; - - /// @notice Restricts the calls to the DisputeModule - modifier onlyDisputeModule() { - if (msg.sender != DISPUTE_MODULE) revert Errors.ArbitrationPolicySP__NotDisputeModule(); - _; - } - - /// Constructor - /// @param disputeModule The dispute module address - /// @param paymentToken The ERC20 payment token address - /// @param arbitrationPrice The arbitration price - /// @custom:oz-upgrades-unsafe-allow constructor - constructor(address disputeModule, address paymentToken, uint256 arbitrationPrice) { - if (disputeModule == address(0)) revert Errors.ArbitrationPolicySP__ZeroDisputeModule(); - if (paymentToken == address(0)) revert Errors.ArbitrationPolicySP__ZeroPaymentToken(); - - DISPUTE_MODULE = disputeModule; - PAYMENT_TOKEN = paymentToken; - ARBITRATION_PRICE = arbitrationPrice; - - _disableInitializers(); - } - - /// @notice Allows governance set the treasury address - /// @dev Enforced to be only callable by the governance protocol admin - /// @param newTreasury The new address of the treasury - function setTreasury(address newTreasury) external restricted { - if (newTreasury == address(0)) revert Errors.ArbitrationPolicySP__ZeroTreasury(); - - ArbitrationPolicySPStorage storage $ = _getArbitrationPolicySPStorage(); - $.treasury = newTreasury; - } - - /// @notice Initializer for this implementation contract - /// @param accessManager The address of the protocol admin roles contract - /// @param newTreasury The new address of the treasury - function initialize(address accessManager, address newTreasury) public initializer { - if (accessManager == address(0)) revert Errors.ArbitrationPolicySP__ZeroAccessManager(); - if (newTreasury == address(0)) revert Errors.ArbitrationPolicySP__ZeroTreasury(); - - __AccessManaged_init(accessManager); - __UUPSUpgradeable_init(); - - ArbitrationPolicySPStorage storage $ = _getArbitrationPolicySPStorage(); - $.treasury = newTreasury; - } - - /// @notice Executes custom logic on raising dispute - /// @dev Enforced to be only callable by the DisputeModule - /// @param caller Address of the caller - /// @param data The arbitrary data used to raise the dispute - function onRaiseDispute(address caller, bytes calldata data) external onlyDisputeModule { - // requires that the caller has given approve() to this contract - IERC20(PAYMENT_TOKEN).safeTransferFrom(caller, address(this), ARBITRATION_PRICE); - } - - /// @notice Executes custom logic on disputing judgement - /// @dev Enforced to be only callable by the DisputeModule - /// @param disputeId The dispute id - /// @param decision The decision of the dispute - /// @param data The arbitrary data used to set the dispute judgement - function onDisputeJudgement(uint256 disputeId, bool decision, bytes calldata data) external onlyDisputeModule { - if (decision) { - (, address disputeInitiator, , , , , ) = IDisputeModule(DISPUTE_MODULE).disputes(disputeId); - IERC20(PAYMENT_TOKEN).safeTransfer(disputeInitiator, ARBITRATION_PRICE); - } else { - ArbitrationPolicySPStorage storage $ = _getArbitrationPolicySPStorage(); - IERC20(PAYMENT_TOKEN).safeTransfer($.treasury, ARBITRATION_PRICE); - } - } - - /// @notice Executes custom logic on disputing cancel - /// @dev Enforced to be only callable by the DisputeModule and purposedly left empty - /// @param caller Address of the caller - /// @param disputeId The dispute id - /// @param data The arbitrary data used to cancel the dispute - function onDisputeCancel(address caller, uint256 disputeId, bytes calldata data) external onlyDisputeModule {} - - /// @notice Executes custom logic on resolving dispute - /// @dev Enforced to be only callable by the DisputeModule and purposedly left empty - /// @param caller Address of the caller - /// @param disputeId The dispute id - /// @param data The arbitrary data used to resolve the dispute - function onResolveDispute(address caller, uint256 disputeId, bytes calldata data) external onlyDisputeModule {} - - /// @notice Returns the treasury address - /// @return The treasury address - function treasury() external view returns (address) { - ArbitrationPolicySPStorage storage $ = _getArbitrationPolicySPStorage(); - return $.treasury; - } - - /// @dev Hook to authorize the upgrade according to UUPSUpgradeable - /// @param newImplementation The address of the new implementation - function _authorizeUpgrade(address newImplementation) internal override restricted {} - - /// @dev Returns the storage struct of ArbitrationPolicySP - function _getArbitrationPolicySPStorage() private pure returns (ArbitrationPolicySPStorage storage $) { - assembly { - $.slot := ArbitrationPolicySPStorageLocation - } - } -} diff --git a/script/foundry/utils/DeployHelper.sol b/script/foundry/utils/DeployHelper.sol index d7395bfb0..9babf50a5 100644 --- a/script/foundry/utils/DeployHelper.sol +++ b/script/foundry/utils/DeployHelper.sol @@ -36,7 +36,6 @@ import { RoyaltyPolicyLAP } from "contracts/modules/royalty/policies/LAP/Royalty import { RoyaltyPolicyLRP } from "contracts/modules/royalty/policies/LRP/RoyaltyPolicyLRP.sol"; import { VaultController } from "contracts/modules/royalty/policies/VaultController.sol"; import { DisputeModule } from "contracts/modules/dispute/DisputeModule.sol"; -import { ArbitrationPolicySP } from "contracts/modules/dispute/policies/ArbitrationPolicySP.sol"; import { MODULE_TYPE_HOOK } from "contracts/lib/modules/Module.sol"; import { IModule } from "contracts/interfaces/modules/base/IModule.sol"; import { IHookModule } from "contracts/interfaces/modules/base/IHookModule.sol"; @@ -90,7 +89,6 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag CoreMetadataViewModule internal coreMetadataViewModule; // Policy - ArbitrationPolicySP internal arbitrationPolicySP; RoyaltyPolicyLAP internal royaltyPolicyLAP; RoyaltyPolicyLRP internal royaltyPolicyLRP; UpgradeableBeacon internal ipRoyaltyVaultBeacon; @@ -511,27 +509,6 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag // Story-specific Non-Core Contracts // - _predeploy("ArbitrationPolicySP"); - impl = address(new ArbitrationPolicySP(address(disputeModule), address(erc20), ARBITRATION_PRICE)); - arbitrationPolicySP = ArbitrationPolicySP( - TestProxyHelper.deployUUPSProxy( - create3Deployer, - _getSalt(type(ArbitrationPolicySP).name), - impl, - abi.encodeCall(ArbitrationPolicySP.initialize, (address(protocolAccessManager), TREASURY_ADDRESS)) - ) - ); - require( - _getDeployedAddress(type(ArbitrationPolicySP).name) == address(arbitrationPolicySP), - "Deploy: Arbitration Policy Address Mismatch" - ); - require( - _loadProxyImpl(address(arbitrationPolicySP)) == impl, - "ArbitrationPolicySP Proxy Implementation Mismatch" - ); - impl = address(0); - _postdeploy("ArbitrationPolicySP", address(arbitrationPolicySP)); - _predeploy("RoyaltyPolicyLAP"); impl = address(new RoyaltyPolicyLAP( address(royaltyModule), @@ -718,11 +695,7 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag ipRoyaltyVaultBeacon.transferOwnership(address(royaltyModule)); // Dispute Module and SP Dispute Policy - address arbitrationRelayer = relayer; disputeModule.whitelistDisputeTag("PLAGIARISM", true); - disputeModule.whitelistArbitrationPolicy(address(arbitrationPolicySP), true); - disputeModule.whitelistArbitrationRelayer(address(arbitrationPolicySP), arbitrationRelayer, true); - disputeModule.setBaseArbitrationPolicy(address(arbitrationPolicySP)); // Core Metadata Module coreMetadataViewModule.updateCoreMetadataModule(); @@ -754,11 +727,6 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag protocolAccessManager.setTargetFunctionRole(address(licenseToken), selectors, ProtocolAdmin.UPGRADER_ROLE); protocolAccessManager.setTargetFunctionRole(address(accessController), selectors, ProtocolAdmin.UPGRADER_ROLE); protocolAccessManager.setTargetFunctionRole(address(disputeModule), selectors, ProtocolAdmin.UPGRADER_ROLE); - protocolAccessManager.setTargetFunctionRole( - address(arbitrationPolicySP), - selectors, - ProtocolAdmin.UPGRADER_ROLE - ); protocolAccessManager.setTargetFunctionRole(address(licensingModule), selectors, ProtocolAdmin.UPGRADER_ROLE); protocolAccessManager.setTargetFunctionRole(address(royaltyPolicyLAP), selectors, ProtocolAdmin.UPGRADER_ROLE); protocolAccessManager.setTargetFunctionRole(address(royaltyPolicyLRP), selectors, ProtocolAdmin.UPGRADER_ROLE); diff --git a/test/foundry/invariants/DisputeModule.t.sol b/test/foundry/invariants/DisputeModule.t.sol index d939bc7ee..b56a02f59 100644 --- a/test/foundry/invariants/DisputeModule.t.sol +++ b/test/foundry/invariants/DisputeModule.t.sol @@ -147,7 +147,7 @@ contract DisputeInvariants is BaseTest { mockToken.mint(address(harness), 1000 ether); vm.startPrank(address(harness)); - mockToken.approve(address(arbitrationPolicySP), type(uint256).max); + mockToken.approve(address(mockArbitrationPolicy), type(uint256).max); vm.stopPrank(); mockNFT.transferFrom(address(this), address(harness), 300); mockNFT.transferFrom(address(this), address(harness), 301); diff --git a/test/foundry/mocks/dispute/MockArbitrationPolicy.sol b/test/foundry/mocks/dispute/MockArbitrationPolicy.sol new file mode 100644 index 000000000..2771ca5b6 --- /dev/null +++ b/test/foundry/mocks/dispute/MockArbitrationPolicy.sol @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.26; + +import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +import { IDisputeModule } from "../../../../contracts/interfaces/modules/dispute/IDisputeModule.sol"; +import { IArbitrationPolicy } from "../../../../contracts/interfaces/modules/dispute/policies/IArbitrationPolicy.sol"; + +contract MockArbitrationPolicy is IArbitrationPolicy { + using SafeERC20 for IERC20; + + address public immutable DISPUTE_MODULE; + address public immutable PAYMENT_TOKEN; + uint256 public immutable ARBITRATION_PRICE; + + address treasury; + + error MockArbitrationPolicy__NotDisputeModule(); + + /// @notice Restricts the calls to the DisputeModule + modifier onlyDisputeModule() { + if (msg.sender != DISPUTE_MODULE) revert MockArbitrationPolicy__NotDisputeModule(); + _; + } + + constructor(address disputeModule, address paymentToken, uint256 arbitrationPrice) { + DISPUTE_MODULE = disputeModule; + PAYMENT_TOKEN = paymentToken; + ARBITRATION_PRICE = arbitrationPrice; + } + + function setTreasury(address newTreasury) external { + treasury = newTreasury; + } + + function onRaiseDispute(address caller, bytes calldata data) external onlyDisputeModule { + IERC20(PAYMENT_TOKEN).safeTransferFrom(caller, address(this), ARBITRATION_PRICE); + } + + function onDisputeJudgement(uint256 disputeId, bool decision, bytes calldata data) external onlyDisputeModule { + if (decision) { + (, address disputeInitiator, , , , , ) = IDisputeModule(DISPUTE_MODULE).disputes(disputeId); + IERC20(PAYMENT_TOKEN).safeTransfer(disputeInitiator, ARBITRATION_PRICE); + } else { + IERC20(PAYMENT_TOKEN).safeTransfer(treasury, ARBITRATION_PRICE); + } + } + + function onDisputeCancel(address caller, uint256 disputeId, bytes calldata data) external onlyDisputeModule {} + + function onResolveDispute(address caller, uint256 disputeId, bytes calldata data) external onlyDisputeModule {} +} diff --git a/test/foundry/modules/dispute/ArbitrationPolicySP.t.sol b/test/foundry/modules/dispute/ArbitrationPolicySP.t.sol deleted file mode 100644 index d354caaf7..000000000 --- a/test/foundry/modules/dispute/ArbitrationPolicySP.t.sol +++ /dev/null @@ -1,229 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.26; - -// external -import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import { ERC6551AccountLib } from "erc6551/lib/ERC6551AccountLib.sol"; -// contracts -import { Errors } from "contracts/lib/Errors.sol"; -import { ArbitrationPolicySP } from "contracts/modules/dispute/policies/ArbitrationPolicySP.sol"; -// test -import { BaseTest } from "test/foundry/utils/BaseTest.t.sol"; -import { TestProxyHelper } from "test/foundry/utils/TestProxyHelper.sol"; - -contract TestArbitrationPolicySP is BaseTest { - event GovernanceWithdrew(uint256 amount); - - address internal ipAccount1 = address(0x111000aaa); - - address public ipAddr; - address internal arbitrationRelayer; - - function setUp() public override { - super.setUp(); - - arbitrationRelayer = u.relayer; - - USDC.mint(ipAccount1, 10000 * 10 ** 6); - - registerSelectedPILicenseTerms_Commercial({ - selectionName: "cheap_flexible", - transferable: true, - derivatives: true, - reciprocal: false, - commercialRevShare: 10, - mintingFee: 0 - }); - - mockNFT.mintId(u.admin, 0); - - address expectedAddr = ERC6551AccountLib.computeAddress( - address(erc6551Registry), - address(ipAccountImpl), - ipAccountRegistry.IP_ACCOUNT_SALT(), - block.chainid, - address(mockNFT), - 0 - ); - vm.label(expectedAddr, "IPAccount0"); - - vm.startPrank(u.admin); - ipAddr = ipAssetRegistry.register(block.chainid, address(mockNFT), 0); - - licensingModule.attachLicenseTerms(ipAddr, address(pilTemplate), getSelectedPILicenseTermsId("cheap_flexible")); - - // set arbitration policy - vm.startPrank(ipAddr); - disputeModule.setArbitrationPolicy(ipAddr, address(arbitrationPolicySP)); - vm.stopPrank(); - } - - function test_ArbitrationPolicySP_constructor_ZeroDisputeModule() public { - address disputeModule = address(0); - address paymentToken = address(1); - uint256 arbitrationPrice = 1000; - address governance = address(3); - - vm.expectRevert(Errors.ArbitrationPolicySP__ZeroDisputeModule.selector); - // NOTE: Not using proxy since error is thrown in constructor - new ArbitrationPolicySP(disputeModule, paymentToken, arbitrationPrice); - } - - function test_ArbitrationPolicySP_constructor_ZeroPaymentToken() public { - address disputeModule = address(1); - address paymentToken = address(0); - uint256 arbitrationPrice = 1000; - address governance = address(3); - - vm.expectRevert(Errors.ArbitrationPolicySP__ZeroPaymentToken.selector); - // NOTE: Not using proxy since error is thrown in constructor - new ArbitrationPolicySP(disputeModule, paymentToken, arbitrationPrice); - } - - function test_ArbitrationPolicySP_constructor() public { - address disputeModule = address(1); - address paymentToken = address(2); - uint256 arbitrationPrice = 1000; - - // NOTE: Not using proxy since error is thrown in constructor - ArbitrationPolicySP arbitrationPolicySP = new ArbitrationPolicySP( - disputeModule, - paymentToken, - arbitrationPrice - ); - - assertEq(address(arbitrationPolicySP.DISPUTE_MODULE()), disputeModule); - assertEq(address(arbitrationPolicySP.PAYMENT_TOKEN()), paymentToken); - assertEq(arbitrationPolicySP.ARBITRATION_PRICE(), arbitrationPrice); - } - - function test_ArbitrationPolicySP_initialize_revert_ZeroAccessManager() public { - address disputeModule = address(1); - address paymentToken = address(2); - uint256 arbitrationPrice = 1000; - - address impl = address(new ArbitrationPolicySP(address(disputeModule), paymentToken, arbitrationPrice)); - - vm.expectRevert(Errors.ArbitrationPolicySP__ZeroAccessManager.selector); - arbitrationPolicySP = ArbitrationPolicySP( - TestProxyHelper.deployUUPSProxy( - impl, - abi.encodeCall(ArbitrationPolicySP.initialize, (address(0), TREASURY_ADDRESS)) - ) - ); - } - - function test_ArbitrationPolicySP_initialize_revert_ZeroTreasury() public { - address disputeModule = address(1); - address paymentToken = address(2); - address accessManager = address(3); - uint256 arbitrationPrice = 1000; - - address impl = address(new ArbitrationPolicySP(address(disputeModule), paymentToken, arbitrationPrice)); - - vm.expectRevert(Errors.ArbitrationPolicySP__ZeroTreasury.selector); - arbitrationPolicySP = ArbitrationPolicySP( - TestProxyHelper.deployUUPSProxy( - impl, - abi.encodeCall(ArbitrationPolicySP.initialize, (accessManager, address(0))) - ) - ); - } - - function test_ArbitrationPolicySP_setTreasury_revert_ZeroTreasury() public { - vm.startPrank(u.admin); - vm.expectRevert(Errors.ArbitrationPolicySP__ZeroTreasury.selector); - arbitrationPolicySP.setTreasury(address(0)); - } - - function test_ArbitrationPolicySP_setTreasury() public { - address newTreasuryAddress = address(1); - - vm.startPrank(u.admin); - assertEq(arbitrationPolicySP.treasury(), TREASURY_ADDRESS); - arbitrationPolicySP.setTreasury(newTreasuryAddress); - assertEq(arbitrationPolicySP.treasury(), newTreasuryAddress); - } - - function test_ArbitrationPolicySP_onRaiseDispute_NotDisputeModule() public { - vm.expectRevert(Errors.ArbitrationPolicySP__NotDisputeModule.selector); - arbitrationPolicySP.onRaiseDispute(address(1), new bytes(0)); - } - - function test_ArbitrationPolicySP_onRaiseDispute() public { - address caller = ipAccount1; - vm.startPrank(caller); - USDC.approve(address(arbitrationPolicySP), ARBITRATION_PRICE); - vm.stopPrank(); - - USDC.mint(caller, 10000 * 10 ** 6); - - vm.startPrank(address(disputeModule)); - - uint256 userUSDCBalBefore = USDC.balanceOf(caller); - uint256 arbitrationContractBalBefore = USDC.balanceOf(address(arbitrationPolicySP)); - - arbitrationPolicySP.onRaiseDispute(caller, new bytes(0)); - - uint256 userUSDCBalAfter = USDC.balanceOf(caller); - uint256 arbitrationContractBalAfter = USDC.balanceOf(address(arbitrationPolicySP)); - - assertEq(userUSDCBalBefore - userUSDCBalAfter, ARBITRATION_PRICE); - assertEq(arbitrationContractBalAfter - arbitrationContractBalBefore, ARBITRATION_PRICE); - } - - function test_ArbitrationPolicySP_onDisputeJudgement_NotDisputeModule() public { - vm.expectRevert(Errors.ArbitrationPolicySP__NotDisputeModule.selector); - arbitrationPolicySP.onDisputeJudgement(1, true, new bytes(0)); - } - - function test_ArbitrationPolicySP_onDisputeJudgement_True() public { - // raise dispute - vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); - disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); - vm.stopPrank(); - - // set dispute judgement - uint256 ipAccount1USDCBalanceBefore = USDC.balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceBefore = USDC.balanceOf(address(arbitrationPolicySP)); - - vm.startPrank(arbitrationRelayer); - disputeModule.setDisputeJudgement(1, true, ""); - - uint256 ipAccount1USDCBalanceAfter = USDC.balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceAfter = USDC.balanceOf(address(arbitrationPolicySP)); - - assertEq(ipAccount1USDCBalanceAfter - ipAccount1USDCBalanceBefore, ARBITRATION_PRICE); - assertEq(arbitrationPolicySPUSDCBalanceBefore - arbitrationPolicySPUSDCBalanceAfter, ARBITRATION_PRICE); - } - - function test_ArbitrationPolicySP_onDisputeJudgement_False() public { - // raise dispute - vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); - disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); - vm.stopPrank(); - - // set dispute judgement - uint256 ipAccount1USDCBalanceBefore = USDC.balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceBefore = USDC.balanceOf(address(arbitrationPolicySP)); - uint256 treasuryUSDCBalanceBefore = USDC.balanceOf(TREASURY_ADDRESS); - - vm.startPrank(arbitrationRelayer); - disputeModule.setDisputeJudgement(1, false, ""); - - uint256 ipAccount1USDCBalanceAfter = USDC.balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceAfter = USDC.balanceOf(address(arbitrationPolicySP)); - uint256 treasuryUSDCBalanceAfter = USDC.balanceOf(TREASURY_ADDRESS); - - assertEq(ipAccount1USDCBalanceAfter - ipAccount1USDCBalanceBefore, 0); - assertEq(arbitrationPolicySPUSDCBalanceBefore - arbitrationPolicySPUSDCBalanceAfter, ARBITRATION_PRICE); - assertEq(treasuryUSDCBalanceAfter - treasuryUSDCBalanceBefore, ARBITRATION_PRICE); - } - - function test_ArbitrationPolicySP_onDisputeCancel_NotDisputeModule() public { - vm.expectRevert(Errors.ArbitrationPolicySP__NotDisputeModule.selector); - arbitrationPolicySP.onDisputeCancel(address(1), 1, new bytes(0)); - } -} diff --git a/test/foundry/modules/dispute/DisputeModule.t.sol b/test/foundry/modules/dispute/DisputeModule.t.sol index 3b766cc44..df32fb0b2 100644 --- a/test/foundry/modules/dispute/DisputeModule.t.sol +++ b/test/foundry/modules/dispute/DisputeModule.t.sol @@ -5,16 +5,14 @@ pragma solidity 0.8.26; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { ERC6551AccountLib } from "erc6551/lib/ERC6551AccountLib.sol"; import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; - // contracts import { Errors } from "contracts/lib/Errors.sol"; import { IModule } from "contracts/interfaces/modules/base/IModule.sol"; -import { ArbitrationPolicySP } from "contracts/modules/dispute/policies/ArbitrationPolicySP.sol"; import { ShortStringOps } from "contracts/lib/ShortStringOps.sol"; import { IDisputeModule } from "contracts/interfaces/modules/dispute/IDisputeModule.sol"; // test import { BaseTest } from "test/foundry/utils/BaseTest.t.sol"; -import { TestProxyHelper } from "test/foundry/utils/TestProxyHelper.sol"; +import { MockArbitrationPolicy } from "test/foundry/mocks/dispute/MockArbitrationPolicy.sol"; contract DisputeModuleTest is BaseTest { event TagWhitelistUpdated(bytes32 tag, bool allowed); @@ -41,7 +39,7 @@ contract DisputeModuleTest is BaseTest { address internal ipAddr; address internal ipAddr2; address internal arbitrationRelayer; - ArbitrationPolicySP internal arbitrationPolicySP2; + MockArbitrationPolicy internal mockArbitrationPolicy2; function setUp() public override { super.setUp(); @@ -51,17 +49,11 @@ contract DisputeModuleTest is BaseTest { USDC.mint(ipAccount1, 1000 * 10 ** 6); // second arbitration policy - address impl = address(new ArbitrationPolicySP(address(disputeModule), address(USDC), ARBITRATION_PRICE)); - arbitrationPolicySP2 = ArbitrationPolicySP( - TestProxyHelper.deployUUPSProxy( - impl, - abi.encodeCall(ArbitrationPolicySP.initialize, (address(protocolAccessManager), TREASURY_ADDRESS)) - ) - ); + mockArbitrationPolicy2 = new MockArbitrationPolicy(address(disputeModule), address(USDC), ARBITRATION_PRICE); vm.startPrank(u.admin); - disputeModule.whitelistArbitrationPolicy(address(arbitrationPolicySP2), true); - disputeModule.setBaseArbitrationPolicy(address(arbitrationPolicySP2)); + disputeModule.whitelistArbitrationPolicy(address(mockArbitrationPolicy2), true); + disputeModule.setBaseArbitrationPolicy(address(mockArbitrationPolicy2)); vm.stopPrank(); registerSelectedPILicenseTerms_Commercial({ @@ -115,12 +107,12 @@ contract DisputeModuleTest is BaseTest { // set arbitration policy vm.startPrank(ipAddr); - disputeModule.setArbitrationPolicy(ipAddr, address(arbitrationPolicySP)); + disputeModule.setArbitrationPolicy(ipAddr, address(mockArbitrationPolicy)); vm.stopPrank(); // set arbitration policy vm.startPrank(ipAddr2); - disputeModule.setArbitrationPolicy(ipAddr2, address(arbitrationPolicySP)); + disputeModule.setArbitrationPolicy(ipAddr2, address(mockArbitrationPolicy)); vm.stopPrank(); } @@ -171,17 +163,17 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_whitelistArbitrationRelayer_revert_ZeroArbitrationRelayer() public { vm.startPrank(u.admin); vm.expectRevert(Errors.DisputeModule__ZeroArbitrationRelayer.selector); - disputeModule.whitelistArbitrationRelayer(address(arbitrationPolicySP), address(0), true); + disputeModule.whitelistArbitrationRelayer(address(mockArbitrationPolicy), address(0), true); } function test_DisputeModule_whitelistArbitrationRelayer() public { vm.startPrank(u.admin); vm.expectEmit(true, true, true, true, address(disputeModule)); - emit ArbitrationRelayerWhitelistUpdated(address(arbitrationPolicySP), address(1), true); + emit ArbitrationRelayerWhitelistUpdated(address(mockArbitrationPolicy), address(1), true); - disputeModule.whitelistArbitrationRelayer(address(arbitrationPolicySP), address(1), true); + disputeModule.whitelistArbitrationRelayer(address(mockArbitrationPolicy), address(1), true); - assertEq(disputeModule.isWhitelistedArbitrationRelayer(address(arbitrationPolicySP), address(1)), true); + assertEq(disputeModule.isWhitelistedArbitrationRelayer(address(mockArbitrationPolicy), address(1)), true); } function test_DisputeModule_setBaseArbitrationPolicy_revert_NotWhitelistedArbitrationPolicy() public { @@ -193,11 +185,11 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_setBaseArbitrationPolicy() public { vm.startPrank(u.admin); vm.expectEmit(true, true, true, true, address(disputeModule)); - emit DefaultArbitrationPolicyUpdated(address(arbitrationPolicySP2)); + emit DefaultArbitrationPolicyUpdated(address(mockArbitrationPolicy2)); - disputeModule.setBaseArbitrationPolicy(address(arbitrationPolicySP2)); + disputeModule.setBaseArbitrationPolicy(address(mockArbitrationPolicy2)); - assertEq(disputeModule.baseArbitrationPolicy(), address(arbitrationPolicySP2)); + assertEq(disputeModule.baseArbitrationPolicy(), address(mockArbitrationPolicy2)); } function test_DisputeModule_setArbitrationPolicy_revert_UnauthorizedAccess() public { @@ -210,31 +202,31 @@ contract DisputeModuleTest is BaseTest { disputeModule.setArbitrationPolicy.selector ) ); - disputeModule.setArbitrationPolicy(ipAddr, address(arbitrationPolicySP2)); + disputeModule.setArbitrationPolicy(ipAddr, address(mockArbitrationPolicy2)); } function test_DisputeModule_setArbitrationPolicy_revert_NotWhitelistedArbitrationPolicy() public { vm.startPrank(u.admin); - disputeModule.whitelistArbitrationPolicy(address(arbitrationPolicySP2), false); + disputeModule.whitelistArbitrationPolicy(address(mockArbitrationPolicy2), false); vm.stopPrank(); vm.startPrank(ipAddr); vm.expectRevert(Errors.DisputeModule__NotWhitelistedArbitrationPolicy.selector); - disputeModule.setArbitrationPolicy(ipAddr, address(arbitrationPolicySP2)); + disputeModule.setArbitrationPolicy(ipAddr, address(mockArbitrationPolicy2)); } function test_DisputeModule_setArbitrationPolicy() public { vm.startPrank(u.admin); - disputeModule.whitelistArbitrationPolicy(address(arbitrationPolicySP2), true); + disputeModule.whitelistArbitrationPolicy(address(mockArbitrationPolicy2), true); vm.stopPrank(); vm.startPrank(ipAddr); vm.expectEmit(true, true, true, true, address(disputeModule)); - emit ArbitrationPolicySet(ipAddr, address(arbitrationPolicySP2)); + emit ArbitrationPolicySet(ipAddr, address(mockArbitrationPolicy2)); - disputeModule.setArbitrationPolicy(ipAddr, address(arbitrationPolicySP2)); - assertEq(disputeModule.arbitrationPolicies(ipAddr), address(arbitrationPolicySP2)); + disputeModule.setArbitrationPolicy(ipAddr, address(mockArbitrationPolicy2)); + assertEq(disputeModule.arbitrationPolicies(ipAddr), address(mockArbitrationPolicy2)); } function test_DisputeModule_raiseDispute_revert_NotRegisteredIpId() public { @@ -257,7 +249,7 @@ contract DisputeModuleTest is BaseTest { disputeModule.pause(); vm.startPrank(u.bob); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); vm.expectRevert(abi.encodeWithSelector(PausableUpgradeable.EnforcedPause.selector)); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -265,22 +257,22 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_PolicySP_raiseDispute_BlacklistedPolicy() public { vm.startPrank(u.admin); - disputeModule.whitelistArbitrationPolicy(address(arbitrationPolicySP), false); + disputeModule.whitelistArbitrationPolicy(address(mockArbitrationPolicy), false); vm.stopPrank(); vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP2), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy2), ARBITRATION_PRICE); uint256 disputeIdBefore = disputeModule.disputeCounter(); uint256 ipAccount1USDCBalanceBefore = IERC20(USDC).balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceBefore = IERC20(USDC).balanceOf(address(arbitrationPolicySP2)); + uint256 mockArbitrationPolicyUSDCBalanceBefore = IERC20(USDC).balanceOf(address(mockArbitrationPolicy2)); vm.expectEmit(true, true, true, true, address(disputeModule)); emit DisputeRaised( disputeIdBefore + 1, ipAddr, ipAccount1, - address(arbitrationPolicySP2), + address(mockArbitrationPolicy2), ShortStringOps.stringToBytes32("urlExample"), bytes32("PLAGIARISM"), "" @@ -290,7 +282,7 @@ contract DisputeModuleTest is BaseTest { uint256 disputeIdAfter = disputeModule.disputeCounter(); uint256 ipAccount1USDCBalanceAfter = IERC20(USDC).balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceAfter = IERC20(USDC).balanceOf(address(arbitrationPolicySP2)); + uint256 mockArbitrationPolicyUSDCBalanceAfter = IERC20(USDC).balanceOf(address(mockArbitrationPolicy2)); ( address targetIpId, @@ -305,10 +297,10 @@ contract DisputeModuleTest is BaseTest { assertEq(disputeIdAfter, 1); assertEq(disputeIdAfter - disputeIdBefore, 1); assertEq(ipAccount1USDCBalanceBefore - ipAccount1USDCBalanceAfter, ARBITRATION_PRICE); - assertEq(arbitrationPolicySPUSDCBalanceAfter - arbitrationPolicySPUSDCBalanceBefore, ARBITRATION_PRICE); + assertEq(mockArbitrationPolicyUSDCBalanceAfter - mockArbitrationPolicyUSDCBalanceBefore, ARBITRATION_PRICE); assertEq(targetIpId, ipAddr); assertEq(disputeInitiator, ipAccount1); - assertEq(arbitrationPolicy, address(arbitrationPolicySP2)); + assertEq(arbitrationPolicy, address(mockArbitrationPolicy2)); assertEq(linkToDisputeEvidence, ShortStringOps.stringToBytes32("urlExample")); assertEq(targetTag, bytes32("PLAGIARISM")); assertEq(currentTag, bytes32("IN_DISPUTE")); @@ -317,18 +309,18 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_raiseDispute() public { vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); uint256 disputeIdBefore = disputeModule.disputeCounter(); uint256 ipAccount1USDCBalanceBefore = USDC.balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceBefore = USDC.balanceOf(address(arbitrationPolicySP)); + uint256 mockArbitrationPolicyUSDCBalanceBefore = USDC.balanceOf(address(mockArbitrationPolicy)); vm.expectEmit(true, true, true, true, address(disputeModule)); emit DisputeRaised( disputeIdBefore + 1, ipAddr, ipAccount1, - address(arbitrationPolicySP), + address(mockArbitrationPolicy), ShortStringOps.stringToBytes32("urlExample"), bytes32("PLAGIARISM"), "" @@ -338,7 +330,7 @@ contract DisputeModuleTest is BaseTest { uint256 disputeIdAfter = disputeModule.disputeCounter(); uint256 ipAccount1USDCBalanceAfter = USDC.balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceAfter = USDC.balanceOf(address(arbitrationPolicySP)); + uint256 mockArbitrationPolicyUSDCBalanceAfter = USDC.balanceOf(address(mockArbitrationPolicy)); ( address targetIpId, @@ -352,10 +344,10 @@ contract DisputeModuleTest is BaseTest { assertEq(disputeIdAfter - disputeIdBefore, 1); assertEq(ipAccount1USDCBalanceBefore - ipAccount1USDCBalanceAfter, ARBITRATION_PRICE); - assertEq(arbitrationPolicySPUSDCBalanceAfter - arbitrationPolicySPUSDCBalanceBefore, ARBITRATION_PRICE); + assertEq(mockArbitrationPolicyUSDCBalanceAfter - mockArbitrationPolicyUSDCBalanceBefore, ARBITRATION_PRICE); assertEq(targetIpId, ipAddr); assertEq(disputeInitiator, ipAccount1); - assertEq(arbitrationPolicy, address(arbitrationPolicySP)); + assertEq(arbitrationPolicy, address(mockArbitrationPolicy)); assertEq(linkToDisputeEvidence, ShortStringOps.stringToBytes32("urlExample")); assertEq(targetTag, bytes32("PLAGIARISM")); assertEq(currentTag, bytes32("IN_DISPUTE")); @@ -370,7 +362,7 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_setDisputeJudgement_revert_NotWhitelistedArbitrationRelayer() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -381,14 +373,14 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_setDisputeJudgement_True() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); // set dispute judgement (, , , , , bytes32 currentTagBefore, ) = disputeModule.disputes(1); uint256 ipAccount1USDCBalanceBefore = USDC.balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceBefore = USDC.balanceOf(address(arbitrationPolicySP)); + uint256 mockArbitrationPolicyUSDCBalanceBefore = USDC.balanceOf(address(mockArbitrationPolicy)); vm.expectEmit(true, true, true, true, address(disputeModule)); emit DisputeJudgementSet(1, true, ""); @@ -398,10 +390,10 @@ contract DisputeModuleTest is BaseTest { (, , , , , bytes32 currentTagAfter, ) = disputeModule.disputes(1); uint256 ipAccount1USDCBalanceAfter = USDC.balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceAfter = USDC.balanceOf(address(arbitrationPolicySP)); + uint256 mockArbitrationPolicyUSDCBalanceAfter = USDC.balanceOf(address(mockArbitrationPolicy)); assertEq(ipAccount1USDCBalanceAfter - ipAccount1USDCBalanceBefore, ARBITRATION_PRICE); - assertEq(arbitrationPolicySPUSDCBalanceBefore - arbitrationPolicySPUSDCBalanceAfter, ARBITRATION_PRICE); + assertEq(mockArbitrationPolicyUSDCBalanceBefore - mockArbitrationPolicyUSDCBalanceAfter, ARBITRATION_PRICE); assertEq(currentTagBefore, bytes32("IN_DISPUTE")); assertEq(currentTagAfter, bytes32("PLAGIARISM")); assertTrue(disputeModule.isIpTagged(ipAddr)); @@ -410,14 +402,14 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_setDisputeJudgement_False() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); // set dispute judgement (, , , , , bytes32 currentTagBefore, ) = disputeModule.disputes(1); uint256 ipAccount1USDCBalanceBefore = USDC.balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceBefore = USDC.balanceOf(address(arbitrationPolicySP)); + uint256 mockArbitrationPolicyUSDCBalanceBefore = USDC.balanceOf(address(mockArbitrationPolicy)); vm.expectEmit(true, true, true, true, address(disputeModule)); emit DisputeJudgementSet(1, false, ""); @@ -427,10 +419,10 @@ contract DisputeModuleTest is BaseTest { (, , , , , bytes32 currentTagAfter, ) = disputeModule.disputes(1); uint256 ipAccount1USDCBalanceAfter = USDC.balanceOf(ipAccount1); - uint256 arbitrationPolicySPUSDCBalanceAfter = USDC.balanceOf(address(arbitrationPolicySP)); + uint256 mockArbitrationPolicyUSDCBalanceAfter = USDC.balanceOf(address(mockArbitrationPolicy)); assertEq(ipAccount1USDCBalanceAfter - ipAccount1USDCBalanceBefore, 0); - assertEq(arbitrationPolicySPUSDCBalanceBefore - arbitrationPolicySPUSDCBalanceAfter, ARBITRATION_PRICE); + assertEq(mockArbitrationPolicyUSDCBalanceBefore - mockArbitrationPolicyUSDCBalanceAfter, ARBITRATION_PRICE); assertEq(currentTagBefore, bytes32("IN_DISPUTE")); assertEq(currentTagAfter, bytes32(0)); assertFalse(disputeModule.isIpTagged(ipAddr)); @@ -438,7 +430,7 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_PolicySP_revert_paused() public { vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -455,7 +447,7 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_PolicySP_cancelDispute_revert_NotDisputeInitiator() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -471,7 +463,7 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_cancelDispute() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -507,7 +499,7 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_tagDerivativeIfParentInfringed_revert_ParentNotTagged() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -518,7 +510,7 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_tagDerivativeIfParentInfringed_revert_NotDerivative() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -534,7 +526,7 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_tagDerivativeIfParentInfringed() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -571,7 +563,7 @@ contract DisputeModuleTest is BaseTest { assertTrue(disputeModule.isIpTagged(ipAddr2)); assertEq(targetIpId, ipAddr2); assertEq(disputeInitiator, address(1)); - assertEq(arbitrationPolicy, address(arbitrationPolicySP)); + assertEq(arbitrationPolicy, address(mockArbitrationPolicy)); assertEq(linkToDisputeEvidence, bytes32(0)); assertEq(targetTag, bytes32("PLAGIARISM")); assertEq(currentTag, bytes32("PLAGIARISM")); @@ -586,7 +578,7 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_resolveDispute_revert_NotAbleToResolve() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -598,7 +590,7 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_resolveDispute_revert_ParentDisputeNotResolved() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -617,7 +609,7 @@ contract DisputeModuleTest is BaseTest { function test_DisputeModule_resolveDispute() public { // raise dispute vm.startPrank(ipAccount1); - IERC20(USDC).approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + IERC20(USDC).approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); diff --git a/test/foundry/modules/dispute/btt/ArbitrationPolicySP.tree b/test/foundry/modules/dispute/btt/ArbitrationPolicySP.tree deleted file mode 100644 index a065b81c4..000000000 --- a/test/foundry/modules/dispute/btt/ArbitrationPolicySP.tree +++ /dev/null @@ -1,22 +0,0 @@ -ArbitrationPolicySP.sol -├── when caller is not DisputeModule -│ └── it should revert -├── when caller is DisputeModule -│ ├── when raise dispute callback is called -│ │ ├── given the allowance is lower than arbitration price -│ │ │ └── it should revert -│ │ └── given the allowance is equal to or higher than arbitration price -│ │ ├── it should safe transfer arbitration price (in the payment token) from dispute raiser -│ │ └── it should safe transfer arbitration price (in the payment token) to the policy -│ ├── when dispute judgement callback is called -│ │ ├── given the decision is false -│ │ │ └── it should do nothing -│ │ └── given the decision is true -│ │ ├── it should safe transfer arbitration price (in the payment token) from the policy -│ │ └── it should safe transfer arbitration price (in the payment token) to dispute initiator -│ └── when dispute cancel callback is called -│ └── it should do nothing -└── when caller is protocol governance - └── when governance withdraw is called - ├── it should safe transfer total balance of payment token to the governance - └── it should emit an event \ No newline at end of file diff --git a/test/foundry/modules/royalty/RoyaltyModule.t.sol b/test/foundry/modules/royalty/RoyaltyModule.t.sol index 4412ea09a..7fa7271bc 100644 --- a/test/foundry/modules/royalty/RoyaltyModule.t.sol +++ b/test/foundry/modules/royalty/RoyaltyModule.t.sol @@ -97,7 +97,7 @@ contract TestRoyaltyModule is BaseTest { // set arbitration policy vm.startPrank(ipAddr); - disputeModule.setArbitrationPolicy(ipAddr, address(arbitrationPolicySP)); + disputeModule.setArbitrationPolicy(ipAddr, address(mockArbitrationPolicy)); vm.stopPrank(); // grouping @@ -827,7 +827,7 @@ contract TestRoyaltyModule is BaseTest { function test_RoyaltyModule_payRoyaltyOnBehalf_revert_IpIsTagged() public { // raise dispute vm.startPrank(ipAccount1); - USDC.approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + USDC.approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); @@ -968,7 +968,7 @@ contract TestRoyaltyModule is BaseTest { function test_RoyaltyModule_payLicenseMintingFee_revert_IpIsTagged() public { // raise dispute vm.startPrank(ipAccount1); - USDC.approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + USDC.approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeModule.raiseDispute(ipAddr, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank(); diff --git a/test/foundry/upgrades/Upgrades.t.sol b/test/foundry/upgrades/Upgrades.t.sol index 10aea71a7..2bf959b80 100644 --- a/test/foundry/upgrades/Upgrades.t.sol +++ b/test/foundry/upgrades/Upgrades.t.sol @@ -162,21 +162,6 @@ contract UpgradesTest is BaseTest { ProtocolAdmin.UPGRADER_ROLE ); - (immediate, delay) = protocolAccessManager.canCall( - multisig, - address(arbitrationPolicySP), - UUPSUpgradeable.upgradeToAndCall.selector - ); - assertFalse(immediate); - assertEq(delay, execDelay); - assertEq( - protocolAccessManager.getTargetFunctionRole( - address(arbitrationPolicySP), - UUPSUpgradeable.upgradeToAndCall.selector - ), - ProtocolAdmin.UPGRADER_ROLE - ); - (immediate, delay) = protocolAccessManager.canCall( multisig, address(licensingModule), diff --git a/test/foundry/utils/BaseTest.t.sol b/test/foundry/utils/BaseTest.t.sol index c6e8d116f..f974c9b52 100644 --- a/test/foundry/utils/BaseTest.t.sol +++ b/test/foundry/utils/BaseTest.t.sol @@ -19,6 +19,7 @@ import { MockRoyaltyPolicyLAP } from "../mocks/policy/MockRoyaltyPolicyLAP.sol"; import { Users, UsersLib } from "./Users.t.sol"; import { LicenseRegistryHarness } from "../mocks/module/LicenseRegistryHarness.sol"; import { MockIPGraph } from "../mocks/MockIPGraph.sol"; +import { MockArbitrationPolicy } from "../mocks/dispute/MockArbitrationPolicy.sol"; /// @title Base Test Contract /// @notice This contract provides a set of protocol-related testing utilities @@ -54,6 +55,7 @@ contract BaseTest is Test, DeployHelper, LicensingHelper { address internal lrHarnessImpl; MockIPGraph ipGraph = MockIPGraph(address(0x1B)); + MockArbitrationPolicy mockArbitrationPolicy; constructor() DeployHelper( @@ -101,6 +103,14 @@ contract BaseTest is Test, DeployHelper, LicensingHelper { lrHarnessImpl = address( new LicenseRegistryHarness(address(licensingModule), address(disputeModule), address(ipGraphACL)) ); + + mockArbitrationPolicy = new MockArbitrationPolicy(address(disputeModule), address(USDC), ARBITRATION_PRICE); + vm.startPrank(u.admin); + disputeModule.whitelistArbitrationPolicy(address(mockArbitrationPolicy), true); + disputeModule.whitelistArbitrationRelayer(address(mockArbitrationPolicy), address(u.relayer), true); + disputeModule.setBaseArbitrationPolicy(address(mockArbitrationPolicy)); + mockArbitrationPolicy.setTreasury(TREASURY_ADDRESS); + vm.stopPrank(); } function dealMockAssets() public { @@ -122,7 +132,7 @@ contract BaseTest is Test, DeployHelper, LicensingHelper { function _disputeIp(address disputeInitiator, address ipAddrToDispute) internal returns (uint256 disputeId) { vm.startPrank(disputeInitiator); - USDC.approve(address(arbitrationPolicySP), ARBITRATION_PRICE); + USDC.approve(address(mockArbitrationPolicy), ARBITRATION_PRICE); disputeId = disputeModule.raiseDispute(ipAddrToDispute, string("urlExample"), "PLAGIARISM", ""); vm.stopPrank();