From eac2e44acb9c75bfaad3934f17ed8c058497eb40 Mon Sep 17 00:00:00 2001 From: Satyajeet Kolhapure <77279246+satyajeetkolhapure@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:19:19 +0000 Subject: [PATCH] chore(contracts): Stop supporting deprecated Portal functions (#810) --- contracts/src/DefaultPortalV2.sol | 20 ++ contracts/src/ModuleRegistry.sol | 5 +- contracts/src/PortalRegistry.sol | 16 +- contracts/src/abstracts/AbstractModule.sol | 2 +- contracts/src/abstracts/AbstractPortal.sol | 4 +- contracts/src/abstracts/AbstractPortalV2.sol | 278 +++++++++++++++++ contracts/src/examples/portals/EASPortal.sol | 12 +- contracts/src/examples/portals/NFTPortal.sol | 16 +- .../src/examples/portals/PausablePortal.sol | 29 +- contracts/test/DefaultPortal.t.sol | 4 +- contracts/test/DefaultPortalV2.t.sol | 289 ++++++++++++++++++ contracts/test/ModuleRegistry.t.sol | 55 +--- contracts/test/PortalRegistry.t.sol | 61 ++-- .../test/examples/portals/EASPortal.t.sol | 4 +- .../test/examples/portals/NFTPortal.t.sol | 6 +- .../examples/portals/PausablePortal.t.sol | 113 ++----- .../integration/AttestationRegistryMass.t.sol | 6 +- .../test/integration/IssuersPortal.t.sol | 18 +- .../test/integration/IssuersPortalV2.t.sol | 146 --------- .../test/mocks/IPortalImplementation.sol | 21 -- ...oduleMock.sol => OldVersionModuleMock.sol} | 6 +- contracts/test/mocks/OldVersionPortalMock.sol | 12 + contracts/test/mocks/ValidPortalMock.sol | 6 +- 23 files changed, 712 insertions(+), 417 deletions(-) create mode 100644 contracts/src/DefaultPortalV2.sol create mode 100644 contracts/src/abstracts/AbstractPortalV2.sol create mode 100644 contracts/test/DefaultPortalV2.t.sol delete mode 100644 contracts/test/integration/IssuersPortalV2.t.sol delete mode 100644 contracts/test/mocks/IPortalImplementation.sol rename contracts/test/mocks/{CorrectModuleMock.sol => OldVersionModuleMock.sol} (76%) create mode 100644 contracts/test/mocks/OldVersionPortalMock.sol diff --git a/contracts/src/DefaultPortalV2.sol b/contracts/src/DefaultPortalV2.sol new file mode 100644 index 00000000..3a22357b --- /dev/null +++ b/contracts/src/DefaultPortalV2.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.21; + +import { AbstractPortalV2 } from "./abstracts/AbstractPortalV2.sol"; + +/** + * @title Default Portal V2 + * @author Consensys + * @notice This contract aims to provide a default portal compatible with the V2 version of Abstract Portal + * @dev This Portal does not add any logic to the AbstractPortalV2 + */ +contract DefaultPortalV2 is AbstractPortalV2 { + /** + * @notice Contract constructor + * @param modules list of modules to use for the portal (can be empty). The modules should be based on AbstractModuleV2 + * @param router the Router's address + * @dev This sets the addresses for the AttestationRegistry, ModuleRegistry and PortalRegistry + */ + constructor(address[] memory modules, address router) AbstractPortalV2(modules, router) {} +} diff --git a/contracts/src/ModuleRegistry.sol b/contracts/src/ModuleRegistry.sol index c0e2bcce..b7d5132b 100644 --- a/contracts/src/ModuleRegistry.sol +++ b/contracts/src/ModuleRegistry.sol @@ -107,10 +107,7 @@ contract ModuleRegistry is OwnableUpgradeable { // Check if moduleAddress is a smart contract address if (!isContractAddress(moduleAddress)) revert ModuleAddressInvalid(); // Check if module has implemented AbstractModule or AbstractModuleV2 - if ( - !ERC165CheckerUpgradeable.supportsInterface(moduleAddress, type(AbstractModule).interfaceId) && - !ERC165CheckerUpgradeable.supportsInterface(moduleAddress, type(AbstractModuleV2).interfaceId) - ) { + if (!ERC165CheckerUpgradeable.supportsInterface(moduleAddress, type(AbstractModuleV2).interfaceId)) { revert ModuleInvalid(); } // Module address is used to identify uniqueness of the module diff --git a/contracts/src/PortalRegistry.sol b/contracts/src/PortalRegistry.sol index 0e771981..799c6a3f 100644 --- a/contracts/src/PortalRegistry.sol +++ b/contracts/src/PortalRegistry.sol @@ -4,11 +4,11 @@ pragma solidity 0.8.21; import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; // solhint-disable-next-line max-line-length import { ERC165CheckerUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165CheckerUpgradeable.sol"; -import { AbstractPortal } from "./abstracts/AbstractPortal.sol"; -import { DefaultPortal } from "./DefaultPortal.sol"; +import { AbstractPortalV2 } from "./abstracts/AbstractPortalV2.sol"; +import { DefaultPortalV2 } from "./DefaultPortalV2.sol"; import { Portal } from "./types/Structs.sol"; import { IRouter } from "./interfaces/IRouter.sol"; -import { IPortal } from "./interfaces/IPortal.sol"; +import { uncheckedInc256 } from "./Common.sol"; /** * @title Portal Registry @@ -161,11 +161,11 @@ contract PortalRegistry is OwnableUpgradeable { // Check if the owner's name is not empty if (bytes(ownerName).length == 0) revert PortalOwnerNameMissing(); - // Check if portal has implemented AbstractPortal - if (!ERC165CheckerUpgradeable.supportsInterface(id, type(IPortal).interfaceId)) revert PortalInvalid(); + // Check if portal has implemented AbstractPortalV2 + if (!ERC165CheckerUpgradeable.supportsInterface(id, type(AbstractPortalV2).interfaceId)) revert PortalInvalid(); // Get the array of modules implemented by the portal - address[] memory modules = AbstractPortal(id).getModules(); + address[] memory modules = AbstractPortalV2(id).getModules(); // Add portal to mapping Portal memory newPortal = Portal(id, msg.sender, modules, isRevocable, name, description, ownerName); @@ -189,7 +189,7 @@ contract PortalRegistry is OwnableUpgradeable { } /** - * @notice Deploys and registers a clone of default portal + * @notice Deploys and registers a clone of default portal V2 * @param modules the modules addresses * @param name the portal name * @param description the portal description @@ -202,7 +202,7 @@ contract PortalRegistry is OwnableUpgradeable { bool isRevocable, string calldata ownerName ) external onlyAllowlisted(msg.sender) { - DefaultPortal defaultPortal = new DefaultPortal(modules, address(router)); + DefaultPortalV2 defaultPortal = new DefaultPortalV2(modules, address(router)); register(address(defaultPortal), name, description, isRevocable, ownerName); } diff --git a/contracts/src/abstracts/AbstractModule.sol b/contracts/src/abstracts/AbstractModule.sol index 0e0d817e..f604dbe0 100644 --- a/contracts/src/abstracts/AbstractModule.sol +++ b/contracts/src/abstracts/AbstractModule.sol @@ -7,7 +7,7 @@ import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol /** * @title Abstract Module * @author Consensys - * @notice Defines the minimal Module interface + * @notice Deprecated. Use the AbstractModuleV2 contract instead. */ abstract contract AbstractModule is IERC165 { /// @notice Error thrown when someone else than the portal's owner is trying to revoke diff --git a/contracts/src/abstracts/AbstractPortal.sol b/contracts/src/abstracts/AbstractPortal.sol index 388a283c..4c46ae1d 100644 --- a/contracts/src/abstracts/AbstractPortal.sol +++ b/contracts/src/abstracts/AbstractPortal.sol @@ -13,9 +13,7 @@ import { IPortal } from "../interfaces/IPortal.sol"; /** * @title Abstract Portal * @author Consensys - * @notice This contract is an abstracts contract with basic Portal logic - * to be inherited. We strongly encourage all Portals to implement - * this contract. + * @notice Deprecated. Use the AbstractPortalV2 contract instead. */ abstract contract AbstractPortal is IPortal { IRouter public router; diff --git a/contracts/src/abstracts/AbstractPortalV2.sol b/contracts/src/abstracts/AbstractPortalV2.sol new file mode 100644 index 00000000..614ff33b --- /dev/null +++ b/contracts/src/abstracts/AbstractPortalV2.sol @@ -0,0 +1,278 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.21; + +import { AttestationRegistry } from "../AttestationRegistry.sol"; +import { ModuleRegistry } from "../ModuleRegistry.sol"; +import { PortalRegistry } from "../PortalRegistry.sol"; +import { OperationType } from "../types/Enums.sol"; +import { AttestationPayload } from "../types/Structs.sol"; +import { IERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol"; +import { IRouter } from "../interfaces/IRouter.sol"; +import { IPortal } from "../interfaces/IPortal.sol"; + +/** + * @title Abstract Portal V2 + * @author Consensys + * @notice This contract is an abstracts contract with basic Portal logic + * to be inherited. We strongly encourage all Portals to implement + * this contract. + */ +abstract contract AbstractPortalV2 is IPortal { + IRouter public router; + address[] public modules; + ModuleRegistry public moduleRegistry; + AttestationRegistry public attestationRegistry; + PortalRegistry public portalRegistry; + + /// @notice Error thrown when someone else than the portal's owner is trying to revoke + error OnlyPortalOwner(); + + /// @notice Error thrown when withdrawing funds fails + error WithdrawFail(); + + /** + * @notice Contract constructor + * @param _modules list of modules to use for the portal (can be empty) + * @param _router Router's address + * @dev This sets the addresses for the AttestationRegistry, ModuleRegistry and PortalRegistry + */ + constructor(address[] memory _modules, address _router) { + modules = _modules; + router = IRouter(_router); + attestationRegistry = AttestationRegistry(router.getAttestationRegistry()); + moduleRegistry = ModuleRegistry(router.getModuleRegistry()); + portalRegistry = PortalRegistry(router.getPortalRegistry()); + } + + /** + * @notice Withdraw funds from the Portal + * @param to the address to send the funds to + * @param amount the amount to withdraw + * @dev Only the Portal owner can withdraw funds + */ + function withdraw(address payable to, uint256 amount) external virtual { + if (msg.sender != portalRegistry.getPortalByAddress(address(this)).ownerAddress) revert OnlyPortalOwner(); + (bool s, ) = to.call{ value: amount }(""); + if (!s) revert WithdrawFail(); + } + + /** + * @notice Attest the schema with given attestationPayload and validationPayload + * @param attestationPayload the payload to attest + * @param validationPayloads the payloads to validate via the modules to issue the attestations + * @dev Runs all modules for the portal and registers the attestation using AttestationRegistry + */ + function attest(AttestationPayload memory attestationPayload, bytes[] memory validationPayloads) public payable { + moduleRegistry.runModulesV2( + modules, + attestationPayload, + validationPayloads, + msg.value, + msg.sender, + getAttester(), + OperationType.Attest + ); + + _onAttest(attestationPayload, validationPayloads, msg.value); + + attestationRegistry.attest(attestationPayload, getAttester()); + } + + /** + * @notice Bulk attest the schema with payloads to attest and validation payloads + * @param attestationPayloads the payloads to attest + * @param validationPayloads the payloads to validate via the modules to issue the attestations + * @dev DISCLAIMER: This method may have unexpected behavior if one of the Module checks is done on the attestation ID + * as this ID won't be incremented before the end of the transaction. + * If you need to check the attestation ID, please use the `attestV2` method. + */ + function bulkAttest(AttestationPayload[] memory attestationPayloads, bytes[][] memory validationPayloads) public { + moduleRegistry.bulkRunModulesV2( + modules, + attestationPayloads, + validationPayloads, + msg.sender, + getAttester(), + OperationType.BulkAttest + ); + + _onBulkAttest(attestationPayloads, validationPayloads); + + attestationRegistry.bulkAttest(attestationPayloads, getAttester()); + } + + /** + * @notice Replaces the attestation for the given identifier and replaces it with a new attestation + * @param attestationId the ID of the attestation to replace + * @param attestationPayload the attestation payload to create the new attestation and register it + * @param validationPayloads the payloads to validate via the modules to issue the attestation + * @dev Runs all modules for the portal and registers the attestation using AttestationRegistry + */ + function replace( + bytes32 attestationId, + AttestationPayload memory attestationPayload, + bytes[] memory validationPayloads + ) public payable { + moduleRegistry.runModulesV2( + modules, + attestationPayload, + validationPayloads, + msg.value, + msg.sender, + getAttester(), + OperationType.Replace + ); + + _onReplace(attestationId, attestationPayload, getAttester(), msg.value); + + attestationRegistry.replace(attestationId, attestationPayload, getAttester()); + } + + /** + * @notice Bulk replaces the attestation for the given identifiers and replaces them with new attestations + * @param attestationIds the list of IDs of the attestations to replace + * @param attestationsPayloads the list of attestation payloads to create the new attestations and register them + * @param validationPayloads the payloads to validate via the modules to issue the attestations + * @dev DISCLAIMER: This method may have unexpected behavior if one of the Module checks is done on the attestation ID + * as this ID won't be incremented before the end of the transaction. + * If you need to check the attestation ID, please use the `replaceV2` method. + */ + function bulkReplace( + bytes32[] memory attestationIds, + AttestationPayload[] memory attestationsPayloads, + bytes[][] memory validationPayloads + ) public { + moduleRegistry.bulkRunModulesV2( + modules, + attestationsPayloads, + validationPayloads, + msg.sender, + getAttester(), + OperationType.BulkReplace + ); + + _onBulkReplace(attestationIds, attestationsPayloads, validationPayloads); + + attestationRegistry.bulkReplace(attestationIds, attestationsPayloads, getAttester()); + } + + /** + * @notice Revokes an attestation for the given identifier + * @param attestationId the ID of the attestation to revoke + * @dev By default, revocation is only possible by the portal owner + * We strongly encourage implementing such a rule in your Portal if you intend on overriding this method + */ + function revoke(bytes32 attestationId) public { + _onRevoke(attestationId); + + attestationRegistry.revoke(attestationId); + } + + /** + * @notice Bulk revokes a list of attestations for the given identifiers + * @param attestationIds the IDs of the attestations to revoke + */ + function bulkRevoke(bytes32[] memory attestationIds) public { + _onBulkRevoke(attestationIds); + + attestationRegistry.bulkRevoke(attestationIds); + } + + /** + * @notice Get all the modules addresses used by the Portal + * @return The list of modules addresses linked to the Portal + */ + function getModules() external view returns (address[] memory) { + return modules; + } + + /** + * @notice Verifies that a specific interface is implemented by the Portal, following ERC-165 specification + * @param interfaceID the interface identifier checked in this call + * @return The list of modules addresses linked to the Portal + */ + function supportsInterface(bytes4 interfaceID) public pure virtual override returns (bool) { + return + interfaceID == type(AbstractPortalV2).interfaceId || + interfaceID == type(IPortal).interfaceId || + interfaceID == type(IERC165).interfaceId; + } + + /** + * @notice Defines the address of the entity issuing attestations to the subject + * @dev We strongly encourage a reflection when overriding this rule: who should be set as the attester? + */ + function getAttester() public view virtual returns (address) { + return msg.sender; + } + + /** + * @notice Optional method run before a payload is attested + * @param attestationPayload the attestation payload to attest + * @param validationPayloads the payloads to validate via the modules + * @param value the value sent with the attestation + */ + function _onAttest( + AttestationPayload memory attestationPayload, + bytes[] memory validationPayloads, + uint256 value + ) internal virtual {} + + /** + * @notice Optional method run when an attestation is replaced + * @dev IMPORTANT NOTE: By default, replacement is only possible by the portal owner + * @param attestationId the ID of the attestation being replaced + * @param attestationPayload the attestation payload to create attestation and register it + * @param attester the address of the attester + * @param value the value sent with the attestation + */ + function _onReplace( + bytes32 attestationId, + AttestationPayload memory attestationPayload, + address attester, + uint256 value + ) internal virtual { + if (msg.sender != portalRegistry.getPortalByAddress(address(this)).ownerAddress) revert OnlyPortalOwner(); + } + + /** + * @notice Optional method run when attesting a batch of payloads + * @param attestationsPayloads the payloads to attest + * @param validationPayloads the payloads to validate in order to issue the attestations + */ + function _onBulkAttest( + AttestationPayload[] memory attestationsPayloads, + bytes[][] memory validationPayloads + ) internal virtual {} + + /** + * @notice Optional method run when replacing a batch of payloads + * @dev IMPORTANT NOTE: By default, bulk replacement is only possible by the portal owner + * @param attestationIds the IDs of the attestations being replaced + * @param attestationsPayloads the payloads to replace + * @param validationPayloads the payloads to validate in order to replace the attestations + */ + function _onBulkReplace( + bytes32[] memory attestationIds, + AttestationPayload[] memory attestationsPayloads, + bytes[][] memory validationPayloads + ) internal virtual { + if (msg.sender != portalRegistry.getPortalByAddress(address(this)).ownerAddress) revert OnlyPortalOwner(); + } + + /** + * @notice Optional method run when an attestation is revoked or replaced + * @dev IMPORTANT NOTE: By default, revocation is only possible by the portal owner + */ + function _onRevoke(bytes32 /*attestationId*/) internal virtual { + if (msg.sender != portalRegistry.getPortalByAddress(address(this)).ownerAddress) revert OnlyPortalOwner(); + } + + /** + * @notice Optional method run when a batch of attestations are revoked or replaced + * @dev IMPORTANT NOTE: By default, revocation is only possible by the portal owner + */ + function _onBulkRevoke(bytes32[] memory /*attestationIds*/) internal virtual { + if (msg.sender != portalRegistry.getPortalByAddress(address(this)).ownerAddress) revert OnlyPortalOwner(); + } +} diff --git a/contracts/src/examples/portals/EASPortal.sol b/contracts/src/examples/portals/EASPortal.sol index b36271b6..56bd8c57 100644 --- a/contracts/src/examples/portals/EASPortal.sol +++ b/contracts/src/examples/portals/EASPortal.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { AbstractPortal } from "../../abstracts/AbstractPortal.sol"; +import { AbstractPortalV2 } from "../../abstracts/AbstractPortalV2.sol"; import { AttestationPayload } from "../../types/Structs.sol"; import { uncheckedInc256 } from "../../Common.sol"; @@ -10,7 +10,7 @@ import { uncheckedInc256 } from "../../Common.sol"; * @author Consensys * @notice This is an example of how to maintain interoperability with EAS - https://attest.sh */ -contract EASPortal is AbstractPortal { +contract EASPortal is AbstractPortalV2 { // @notice This struct is defined in EAS's src' codebase // solhint-disable-next-line max-line-length // this definition was taken from: https://github.com/ethereum-attestation-service/eas-contracts/blob/master/contracts/IEAS.sol#L9 @@ -46,9 +46,9 @@ contract EASPortal is AbstractPortal { * @param router Router's address * @dev This sets the addresses for the AttestationRegistry, ModuleRegistry and PortalRegistry */ - constructor(address[] memory modules, address router) AbstractPortal(modules, router) {} + constructor(address[] memory modules, address router) AbstractPortalV2(modules, router) {} - /// @inheritdoc AbstractPortal + /// @inheritdoc AbstractPortalV2 function withdraw(address payable to, uint256 amount) external override {} /** @@ -98,7 +98,7 @@ contract EASPortal is AbstractPortal { } /** - * @inheritdoc AbstractPortal + * @inheritdoc AbstractPortalV2 * @notice This portal doesn't allow for an attestation to be revoked */ function _onRevoke(bytes32 /*attestationId*/) internal pure override { @@ -106,7 +106,7 @@ contract EASPortal is AbstractPortal { } /** - * @inheritdoc AbstractPortal + * @inheritdoc AbstractPortalV2 * @notice This portal doesn't allow for attestations to be revoked */ function _onBulkRevoke(bytes32[] memory /*attestationIds*/) internal pure override { diff --git a/contracts/src/examples/portals/NFTPortal.sol b/contracts/src/examples/portals/NFTPortal.sol index f0f1ee20..e4abb7a2 100644 --- a/contracts/src/examples/portals/NFTPortal.sol +++ b/contracts/src/examples/portals/NFTPortal.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.21; import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import { IERC721, ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import { IERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol"; -import { AbstractPortal } from "../../abstracts/AbstractPortal.sol"; +import { AbstractPortalV2 } from "../../abstracts/AbstractPortalV2.sol"; import { Attestation, AttestationPayload } from "../../types/Structs.sol"; import { IPortal } from "../../interfaces/IPortal.sol"; @@ -14,7 +14,7 @@ import { IPortal } from "../../interfaces/IPortal.sol"; * @notice This contract aims to provide ERC 721 compatibility * @dev This Portal implements parts of ERC 721 - balanceOf and ownerOf functions */ -contract NFTPortal is AbstractPortal, ERC721 { +contract NFTPortal is AbstractPortalV2, ERC721 { mapping(bytes owner => uint256 numberOfAttestations) private numberOfAttestationsPerOwner; /** @@ -26,7 +26,7 @@ contract NFTPortal is AbstractPortal, ERC721 { constructor( address[] memory modules, address router - ) AbstractPortal(modules, router) ERC721("NFTPortal", "NFTPortal") {} + ) AbstractPortalV2(modules, router) ERC721("NFTPortal", "NFTPortal") {} /** * @notice Count all attestations assigned to an owner @@ -49,17 +49,17 @@ contract NFTPortal is AbstractPortal, ERC721 { } /** - * @inheritdoc AbstractPortal + * @inheritdoc AbstractPortalV2 */ function _onAttest( AttestationPayload memory attestationPayload, - address /*attester*/, + bytes[] memory /*validationPayloads*/, uint256 /*value*/ ) internal override { numberOfAttestationsPerOwner[attestationPayload.subject]++; } - /// @inheritdoc AbstractPortal + /// @inheritdoc AbstractPortalV2 function withdraw(address payable to, uint256 amount) external override {} /** @@ -67,9 +67,9 @@ contract NFTPortal is AbstractPortal, ERC721 { * @param interfaceID the interface identifier checked in this call * @return The list of modules addresses linked to the Portal */ - function supportsInterface(bytes4 interfaceID) public pure virtual override(AbstractPortal, ERC721) returns (bool) { + function supportsInterface(bytes4 interfaceID) public pure virtual override(AbstractPortalV2, ERC721) returns (bool) { return - interfaceID == type(AbstractPortal).interfaceId || + interfaceID == type(AbstractPortalV2).interfaceId || interfaceID == type(IPortal).interfaceId || interfaceID == type(IERC165).interfaceId || interfaceID == type(IERC721).interfaceId; diff --git a/contracts/src/examples/portals/PausablePortal.sol b/contracts/src/examples/portals/PausablePortal.sol index 9b01e6fb..75fae50d 100644 --- a/contracts/src/examples/portals/PausablePortal.sol +++ b/contracts/src/examples/portals/PausablePortal.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.21; import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; -import { AbstractPortal } from "../../abstracts/AbstractPortal.sol"; +import { AbstractPortalV2 } from "../../abstracts/AbstractPortalV2.sol"; import { AttestationPayload } from "../../types/Structs.sol"; /** @@ -11,14 +11,14 @@ import { AttestationPayload } from "../../types/Structs.sol"; * @author Consensys * @notice This Portal aims to be pausable to prevent any attestation to be added in case of emergency */ -contract PausablePortal is AbstractPortal, Pausable, Ownable { +contract PausablePortal is AbstractPortalV2, Pausable, Ownable { /** * @notice Contract constructor * @param modules list of modules to use for the portal (can be empty) * @param router Router's address * @dev This sets the addresses for the AttestationRegistry, ModuleRegistry and PortalRegistry */ - constructor(address[] memory modules, address router) AbstractPortal(modules, router) Ownable() {} + constructor(address[] memory modules, address router) AbstractPortalV2(modules, router) Ownable() {} /** * @dev Pauses the contract. @@ -39,31 +39,22 @@ contract PausablePortal is AbstractPortal, Pausable, Ownable { } /** - * @inheritdoc AbstractPortal + * @inheritdoc AbstractPortalV2 * @dev By default, this Portal does not have any withdrawal logic */ function withdraw(address payable to, uint256 amount) external virtual override {} /** - * @inheritdoc AbstractPortal + * @inheritdoc AbstractPortalV2 */ function _onAttest( - AttestationPayload memory attestationPayload, - address attester, - uint256 value - ) internal virtual override whenNotPaused {} - - /** - * @inheritdoc AbstractPortal - */ - function _onAttestV2( AttestationPayload memory attestationPayload, bytes[] memory validationPayloads, uint256 value ) internal virtual override whenNotPaused {} /** - * @inheritdoc AbstractPortal + * @inheritdoc AbstractPortalV2 */ function _onBulkAttest( AttestationPayload[] memory attestationsPayloads, @@ -71,7 +62,7 @@ contract PausablePortal is AbstractPortal, Pausable, Ownable { ) internal virtual override whenNotPaused {} /** - * @inheritdoc AbstractPortal + * @inheritdoc AbstractPortalV2 * @dev Only the owner of the portal can replace an attestation */ function _onReplace( @@ -84,7 +75,7 @@ contract PausablePortal is AbstractPortal, Pausable, Ownable { } /** - * @inheritdoc AbstractPortal + * @inheritdoc AbstractPortalV2 * @dev Only the owner of the portal can bulk replace attestations */ function _onBulkReplace( @@ -96,7 +87,7 @@ contract PausablePortal is AbstractPortal, Pausable, Ownable { } /** - * @inheritdoc AbstractPortal + * @inheritdoc AbstractPortalV2 * @dev Only the owner of the portal can revoke an attestation */ function _onRevoke(bytes32 /*attestationId*/) internal virtual override whenNotPaused { @@ -104,7 +95,7 @@ contract PausablePortal is AbstractPortal, Pausable, Ownable { } /** - * @inheritdoc AbstractPortal + * @inheritdoc AbstractPortalV2 * @dev Only the owner of the portal can bulk revoke attestations */ function _onBulkRevoke(bytes32[] memory /*attestationIds*/) internal virtual override whenNotPaused { diff --git a/contracts/test/DefaultPortal.t.sol b/contracts/test/DefaultPortal.t.sol index 515585b6..0863b517 100644 --- a/contracts/test/DefaultPortal.t.sol +++ b/contracts/test/DefaultPortal.t.sol @@ -5,7 +5,7 @@ import { Test } from "forge-std/Test.sol"; import { AbstractPortal } from "../src/abstracts/AbstractPortal.sol"; import { DefaultPortal } from "../src/DefaultPortal.sol"; import { AttestationPayload } from "../src/types/Structs.sol"; -import { CorrectModule } from "./mocks/CorrectModuleMock.sol"; +import { OldVersionModule } from "./mocks/OldVersionModuleMock.sol"; import { AttestationRegistryMock } from "./mocks/AttestationRegistryMock.sol"; import { ModuleRegistryMock } from "./mocks/ModuleRegistryMock.sol"; import { PortalRegistryMock } from "./mocks/PortalRegistryMock.sol"; @@ -13,7 +13,7 @@ import { ERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/int import { Router } from "./../src/Router.sol"; contract DefaultPortalTest is Test { - CorrectModule public correctModule = new CorrectModule(); + OldVersionModule public correctModule = new OldVersionModule(); address[] public modules = new address[](1); DefaultPortal public defaultPortal; ModuleRegistryMock public moduleRegistryMock = new ModuleRegistryMock(); diff --git a/contracts/test/DefaultPortalV2.t.sol b/contracts/test/DefaultPortalV2.t.sol new file mode 100644 index 00000000..89e46b17 --- /dev/null +++ b/contracts/test/DefaultPortalV2.t.sol @@ -0,0 +1,289 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.21; + +import { Test } from "forge-std/Test.sol"; +import { AbstractPortalV2 } from "../src/abstracts/AbstractPortalV2.sol"; +import { DefaultPortalV2 } from "../src/DefaultPortalV2.sol"; +import { AttestationPayload } from "../src/types/Structs.sol"; +import { OldVersionModule } from "./mocks/OldVersionModuleMock.sol"; +import { AttestationRegistryMock } from "./mocks/AttestationRegistryMock.sol"; +import { ModuleRegistryMock } from "./mocks/ModuleRegistryMock.sol"; +import { PortalRegistryMock } from "./mocks/PortalRegistryMock.sol"; +import { ERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol"; +import { Router } from "./../src/Router.sol"; + +contract DefaultPortalV2Test is Test { + OldVersionModule public correctModule = new OldVersionModule(); + address[] public modules = new address[](1); + DefaultPortalV2 public defaultPortal; + ModuleRegistryMock public moduleRegistryMock = new ModuleRegistryMock(); + PortalRegistryMock public portalRegistryMock = new PortalRegistryMock(); + AttestationRegistryMock public attestationRegistryMock = new AttestationRegistryMock(); + Router public router = new Router(); + address public portalOwner = makeAddr("portalOwner"); + address public recipient = makeAddr("recipient"); + + event Initialized(uint8 version); + event PortalRegistered(string name, string description, address portalAddress); + event AttestationRegistered(); + event BulkAttestationsRegistered(); + event ModulesRunForAttestation(); + event ModulesBulkRunForAttestation(); + event ModulesBulkRunForAttestationV2(); + event AttestationRevoked(bytes32 attestationId); + event BulkAttestationsRevoked(bytes32[] attestationId); + + function setUp() public { + router.initialize(); + router.updateModuleRegistry(address(moduleRegistryMock)); + router.updateAttestationRegistry(address(attestationRegistryMock)); + router.updatePortalRegistry(address(portalRegistryMock)); + + modules.push(address(correctModule)); + defaultPortal = new DefaultPortalV2(modules, address(router)); + + vm.prank(portalOwner); + portalRegistryMock.register(address(defaultPortal), "Name", "Description", true, "Owner name"); + } + + function test_setup() public view { + assertEq(address(defaultPortal.modules(0)), address(modules[0])); + assertEq(address(defaultPortal.moduleRegistry()), address(moduleRegistryMock)); + assertEq(address(defaultPortal.attestationRegistry()), address(attestationRegistryMock)); + assertEq(address(defaultPortal.portalRegistry()), address(portalRegistryMock)); + assertEq(portalRegistryMock.getPortalByAddress(address(defaultPortal)).ownerAddress, portalOwner); + } + + function test_getModules() public view { + address[] memory _modules = defaultPortal.getModules(); + assertEq(_modules, modules); + } + + function test_attest() public { + // Create attestation payload + AttestationPayload memory attestationPayload = AttestationPayload( + bytes32(uint256(1)), + uint64(block.timestamp + 1 days), + bytes("subject"), + new bytes(1) + ); + // Create validation payload + bytes[] memory validationPayload = new bytes[](2); + vm.expectEmit(true, true, true, true); + emit AttestationRegistered(); + defaultPortal.attest(attestationPayload, validationPayload); + } + + function test_bulkAttest(AttestationPayload[2] memory attestationsPayloads) public { + vm.assume(bytes32(attestationsPayloads[0].schemaId) != 0); + vm.assume(bytes32(attestationsPayloads[1].schemaId) != 0); + // Create attestations payloads + AttestationPayload[] memory payloadsToAttest = new AttestationPayload[](2); + payloadsToAttest[0] = attestationsPayloads[0]; + payloadsToAttest[1] = attestationsPayloads[1]; + + // Create validation payloads + bytes[] memory validationPayload1 = new bytes[](1); + bytes[] memory validationPayload2 = new bytes[](1); + + bytes[][] memory validationPayloads = new bytes[][](2); + validationPayloads[0] = validationPayload1; + validationPayloads[1] = validationPayload2; + + vm.expectEmit(true, true, true, true); + emit ModulesBulkRunForAttestationV2(); + vm.expectEmit(true, true, true, true); + emit BulkAttestationsRegistered(); + defaultPortal.bulkAttest(payloadsToAttest, validationPayloads); + } + + function test_replace() public { + // Create attestation payload + AttestationPayload memory attestationPayload = AttestationPayload( + bytes32(uint256(1)), + uint64(block.timestamp + 1 days), + bytes("subject"), + new bytes(1) + ); + // Create validation payload + bytes[] memory validationPayload = new bytes[](2); + vm.expectEmit(true, true, true, true); + emit AttestationRegistered(); + defaultPortal.attest(attestationPayload, validationPayload); + vm.prank(portalOwner); + defaultPortal.replace(bytes32(abi.encode(1)), attestationPayload, validationPayload); + } + + function test_replaceFail_OnlyOwner() public { + // Create attestation payload + AttestationPayload memory attestationPayload = AttestationPayload( + bytes32(uint256(1)), + uint64(block.timestamp + 1 days), + bytes("subject"), + new bytes(1) + ); + // Create validation payload + bytes[] memory validationPayload = new bytes[](2); + vm.expectEmit(true, true, true, true); + emit AttestationRegistered(); + defaultPortal.attest(attestationPayload, validationPayload); + vm.prank(makeAddr("random")); + vm.expectRevert(AbstractPortalV2.OnlyPortalOwner.selector); + defaultPortal.replace(bytes32(abi.encode(1)), attestationPayload, validationPayload); + } + + function test_bulkReplace(AttestationPayload[2] memory attestationPayloads) public { + vm.assume(bytes32(attestationPayloads[0].schemaId) != 0); + vm.assume(bytes32(attestationPayloads[1].schemaId) != 0); + // Create attestations payloads + AttestationPayload[] memory payloadsToAttest = new AttestationPayload[](2); + payloadsToAttest[0] = attestationPayloads[0]; + payloadsToAttest[1] = attestationPayloads[1]; + + // Create validation payloads + bytes[] memory validationPayload1 = new bytes[](1); + bytes[] memory validationPayload2 = new bytes[](1); + + bytes[][] memory validationPayloads = new bytes[][](2); + validationPayloads[0] = validationPayload1; + validationPayloads[1] = validationPayload2; + + bytes32[] memory attestationIds = new bytes32[](2); + attestationIds[0] = bytes32(abi.encode(1)); + attestationIds[1] = bytes32(abi.encode(2)); + + defaultPortal.bulkAttest(payloadsToAttest, validationPayloads); + vm.prank(portalOwner); + defaultPortal.bulkReplace(attestationIds, payloadsToAttest, validationPayloads); + } + + function test_bulkReplaceFail_OnlyOwner(AttestationPayload[2] memory attestationPayloads) public { + vm.assume(bytes32(attestationPayloads[0].schemaId) != 0); + vm.assume(bytes32(attestationPayloads[1].schemaId) != 0); + // Create attestations payloads + AttestationPayload[] memory payloadsToAttest = new AttestationPayload[](2); + payloadsToAttest[0] = attestationPayloads[0]; + payloadsToAttest[1] = attestationPayloads[1]; + + // Create validation payloads + bytes[] memory validationPayload1 = new bytes[](1); + bytes[] memory validationPayload2 = new bytes[](1); + + bytes[][] memory validationPayloads = new bytes[][](2); + validationPayloads[0] = validationPayload1; + validationPayloads[1] = validationPayload2; + + bytes32[] memory attestationIds = new bytes32[](2); + attestationIds[0] = bytes32(abi.encode(1)); + attestationIds[1] = bytes32(abi.encode(2)); + + defaultPortal.bulkAttest(payloadsToAttest, validationPayloads); + vm.prank(makeAddr("random")); + vm.expectRevert(AbstractPortalV2.OnlyPortalOwner.selector); + defaultPortal.bulkReplace(attestationIds, payloadsToAttest, validationPayloads); + } + + function test_revoke_byPortalOwner() public { + // Create attestation payload + AttestationPayload memory attestationPayload = AttestationPayload( + bytes32(uint256(1)), + uint64(block.timestamp + 1 days), + bytes("subject"), + new bytes(1) + ); + + // Create validation payload + bytes[] memory validationPayload = new bytes[](2); + + // Do register the attestation + vm.prank(makeAddr("attester")); + vm.expectEmit(true, true, true, true); + emit AttestationRegistered(); + defaultPortal.attest(attestationPayload, validationPayload); + + // Revoke the attestation as portal owner + vm.prank(portalOwner); + vm.expectEmit(true, true, true, true); + emit AttestationRevoked(bytes32(abi.encode(1))); + defaultPortal.revoke(bytes32(abi.encode(1))); + } + + function test_revokeFail_OnlyOwner() public { + // Create attestation payload + AttestationPayload memory attestationPayload = AttestationPayload( + bytes32(uint256(1)), + uint64(block.timestamp + 1 days), + bytes("subject"), + new bytes(1) + ); + + // Create validation payload + bytes[] memory validationPayload = new bytes[](2); + + // Do register the attestation + vm.prank(makeAddr("attester")); + vm.expectEmit(true, true, true, true); + emit AttestationRegistered(); + defaultPortal.attest(attestationPayload, validationPayload); + + // Revoke the attestation as a random user + vm.prank(makeAddr("random")); + vm.expectRevert(AbstractPortalV2.OnlyPortalOwner.selector); + defaultPortal.revoke(bytes32(abi.encode(1))); + } + + function test_bulkRevoke() public { + bytes32[] memory attestationsToRevoke = new bytes32[](2); + attestationsToRevoke[0] = bytes32("1"); + attestationsToRevoke[1] = bytes32("2"); + + vm.expectEmit(true, true, true, true); + emit BulkAttestationsRevoked(attestationsToRevoke); + vm.prank(portalOwner); + defaultPortal.bulkRevoke(attestationsToRevoke); + } + + function test_supportsInterface() public view { + bool isIERC165Supported = defaultPortal.supportsInterface(type(ERC165Upgradeable).interfaceId); + assertEq(isIERC165Supported, true); + bool isAbstractPortalV2Supported = defaultPortal.supportsInterface(type(AbstractPortalV2).interfaceId); + assertEq(isAbstractPortalV2Supported, true); + } + + function test_withdraw_byOwner() public { + // Fund the portal contract with 1 ether + vm.deal(address(defaultPortal), 1 ether); + + // Set the amount to withdraw + uint256 withdrawAmount = 0.5 ether; + uint256 recipientInitialBalance = recipient.balance; + + // Attempt withdrawal by the owner + vm.prank(portalOwner); + defaultPortal.withdraw(payable(recipient), withdrawAmount); + + // Verify the recipient's balance has increased by the withdrawal amount + assertEq(recipient.balance, recipientInitialBalance + withdrawAmount); + } + + function test_withdrawFail_OnlyPortalOwner() public { + // Attempt withdrawal by a non-owner address + uint256 withdrawAmount = 0.5 ether; + vm.prank(makeAddr("nonOwner")); + vm.expectRevert(AbstractPortalV2.OnlyPortalOwner.selector); + + defaultPortal.withdraw(payable(recipient), withdrawAmount); + } + + function test_withdrawFail_InsufficientBalance() public { + // Fund the portal contract with less than the requested amount + vm.deal(address(defaultPortal), 0.25 ether); + + // Attempt withdrawal of 0.5 ether + uint256 withdrawAmount = 0.5 ether; + vm.prank(portalOwner); + vm.expectRevert(AbstractPortalV2.WithdrawFail.selector); + + defaultPortal.withdraw(payable(recipient), withdrawAmount); + } +} diff --git a/contracts/test/ModuleRegistry.t.sol b/contracts/test/ModuleRegistry.t.sol index e2e493cd..ece92133 100644 --- a/contracts/test/ModuleRegistry.t.sol +++ b/contracts/test/ModuleRegistry.t.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.21; import { Test } from "forge-std/Test.sol"; import { ModuleRegistry } from "../src/ModuleRegistry.sol"; -import { CorrectModule } from "./mocks/CorrectModuleMock.sol"; +import { OldVersionModule } from "./mocks/OldVersionModuleMock.sol"; import { CorrectModuleV2 } from "./mocks/CorrectModuleV2Mock.sol"; import { IncorrectModule } from "./mocks/IncorrectModuleMock.sol"; import { PortalRegistryMock } from "./mocks/PortalRegistryMock.sol"; @@ -18,7 +18,7 @@ contract ModuleRegistryTest is Test { address public portalRegistryAddress; string private expectedName = "Name"; string private expectedDescription = "Description"; - address private expectedAddress = address(new CorrectModule()); + address private expectedAddress = address(new CorrectModuleV2()); address private user = makeAddr("user"); AttestationPayload private attestationPayload; @@ -124,6 +124,13 @@ contract ModuleRegistryTest is Test { moduleRegistry.register(expectedName, expectedDescription, address(incorrectModule)); } + function test_register_old_version_ModuleInvalid() public { + OldVersionModule oldVersionModule = new OldVersionModule(); + vm.expectRevert(ModuleRegistry.ModuleInvalid.selector); + vm.prank(user); + moduleRegistry.register(expectedName, expectedDescription, address(oldVersionModule)); + } + function test_register_ModuleAlreadyExists() public { vm.prank(user); moduleRegistry.register(expectedName, expectedDescription, expectedAddress); @@ -132,21 +139,6 @@ contract ModuleRegistryTest is Test { moduleRegistry.register(expectedName, expectedDescription, expectedAddress); } - function test_runModules() public { - // Register 2 modules - address[] memory moduleAddresses = new address[](2); - moduleAddresses[0] = address(new CorrectModule()); - moduleAddresses[1] = address(new CorrectModule()); - vm.startPrank(user); - moduleRegistry.register("Module1", "Description1", moduleAddresses[0]); - moduleRegistry.register("Module2", "Description2", moduleAddresses[1]); - vm.stopPrank(); - // Create validation payload - bytes[] memory validationPayload = new bytes[](2); - - moduleRegistry.runModules(moduleAddresses, attestationPayload, validationPayload, 0); - } - function test_runModulesV2() public { // Register 2 modules address[] memory moduleAddresses = new address[](2); @@ -243,8 +235,8 @@ contract ModuleRegistryTest is Test { function test_runModules_ModuleNotRegistered() public { // Create 2 modules without registration address[] memory moduleAddresses = new address[](2); - moduleAddresses[0] = address(new CorrectModule()); - moduleAddresses[1] = address(new CorrectModule()); + moduleAddresses[0] = address(new OldVersionModule()); + moduleAddresses[1] = address(new OldVersionModule()); // Create validation payload bytes[] memory validationPayload = new bytes[](2); @@ -276,31 +268,6 @@ contract ModuleRegistryTest is Test { ); } - function test_bulkRunModules() public { - // Register 2 modules - address[] memory moduleAddresses = new address[](2); - moduleAddresses[0] = address(new CorrectModule()); - moduleAddresses[1] = address(new CorrectModule()); - vm.startPrank(user); - moduleRegistry.register("Module1", "Description1", moduleAddresses[0]); - moduleRegistry.register("Module2", "Description2", moduleAddresses[1]); - - // Create validation payloads - bytes[] memory validationPayload1 = new bytes[](2); - bytes[] memory validationPayload2 = new bytes[](2); - - bytes[][] memory validationPayloads = new bytes[][](2); - validationPayloads[0] = validationPayload1; - validationPayloads[1] = validationPayload2; - - AttestationPayload[] memory attestationPayloads = new AttestationPayload[](2); - attestationPayloads[0] = attestationPayload; - attestationPayloads[1] = attestationPayload; - - moduleRegistry.bulkRunModules(moduleAddresses, attestationPayloads, validationPayloads); - vm.stopPrank(); - } - function test_bulkRunModulesV2() public { // Register 2 modules address[] memory moduleAddresses = new address[](2); diff --git a/contracts/test/PortalRegistry.t.sol b/contracts/test/PortalRegistry.t.sol index 6d039f8b..dab4e06a 100644 --- a/contracts/test/PortalRegistry.t.sol +++ b/contracts/test/PortalRegistry.t.sol @@ -3,15 +3,15 @@ pragma solidity 0.8.21; import { Test } from "forge-std/Test.sol"; import { PortalRegistry } from "../src/PortalRegistry.sol"; -import { CorrectModule } from "./mocks/CorrectModuleMock.sol"; +import { CorrectModuleV2 } from "./mocks/CorrectModuleV2Mock.sol"; import { Portal } from "../src/types/Structs.sol"; import { Router } from "../src/Router.sol"; import { AttestationRegistryMock } from "./mocks/AttestationRegistryMock.sol"; import { SchemaRegistryMock } from "./mocks/SchemaRegistryMock.sol"; import { ModuleRegistryMock } from "./mocks/ModuleRegistryMock.sol"; import { ValidPortalMock } from "./mocks/ValidPortalMock.sol"; +import { OldVersionPortalMock } from "./mocks/OldVersionPortalMock.sol"; import { InvalidPortalMock } from "./mocks/InvalidPortalMock.sol"; -import { IPortalImplementation } from "./mocks/IPortalImplementation.sol"; contract PortalRegistryTest is Test { address public user = makeAddr("user"); @@ -24,8 +24,8 @@ contract PortalRegistryTest is Test { string public expectedDescription = "Description"; string public expectedOwnerName = "Owner Name"; ValidPortalMock public validPortalMock; + OldVersionPortalMock public oldVersionPortalMock; InvalidPortalMock public invalidPortalMock = new InvalidPortalMock(); - IPortalImplementation public iPortalImplementation = new IPortalImplementation(); event Initialized(uint8 version); event PortalRegistered(string name, string description, address portalAddress); @@ -55,6 +55,7 @@ contract PortalRegistryTest is Test { portalRegistry.setIssuer(user); validPortalMock = new ValidPortalMock(new address[](0), address(router)); + oldVersionPortalMock = new OldVersionPortalMock(new address[](1), address(router)); } function test_initialize_ContractAlreadyInitialized() public { @@ -180,21 +181,6 @@ contract PortalRegistryTest is Test { bool isRegistered = portalRegistry.isRegistered(address(validPortalMock)); assertEq(isRegistered, true); - // Register a portal implementing IPortal - vm.expectEmit(); - emit PortalRegistered("IPortalImplementation", "IPortalImplementation description", address(iPortalImplementation)); - vm.prank(user); - portalRegistry.register( - address(iPortalImplementation), - "IPortalImplementation", - "IPortalImplementation description", - true, - expectedOwnerName - ); - - isRegistered = portalRegistry.isRegistered(address(iPortalImplementation)); - assertEq(isRegistered, true); - Portal memory expectedPortal = Portal( address(validPortalMock), user, @@ -257,44 +243,43 @@ contract PortalRegistryTest is Test { portalRegistry.register(address(invalidPortalMock), expectedName, expectedDescription, true, expectedOwnerName); } + function test_register_old_version_PortalInvalid() public { + vm.expectRevert(PortalRegistry.PortalInvalid.selector); + vm.prank(user); + portalRegistry.register(address(oldVersionPortalMock), expectedName, expectedDescription, true, expectedOwnerName); + } + function test_revoke() public { - address portalAddress = address(iPortalImplementation); vm.expectEmit(); - emit PortalRegistered("IPortalImplementation", "IPortalImplementation description", portalAddress); + emit PortalRegistered(expectedName, expectedDescription, address(validPortalMock)); vm.prank(user); - portalRegistry.register( - portalAddress, - "IPortalImplementation", - "IPortalImplementation description", - true, - expectedOwnerName - ); + portalRegistry.register(address(validPortalMock), expectedName, expectedDescription, true, expectedOwnerName); - bool isRegistered = portalRegistry.isRegistered(portalAddress); + bool isRegistered = portalRegistry.isRegistered(address(validPortalMock)); assertEq(isRegistered, true); Portal memory expectedPortal = Portal( - portalAddress, + address(validPortalMock), user, new address[](0), true, - "IPortalImplementation", - "IPortalImplementation description", + expectedName, + expectedDescription, expectedOwnerName ); - Portal memory registeredPortal = portalRegistry.getPortalByAddress(portalAddress); + Portal memory registeredPortal = portalRegistry.getPortalByAddress(address(validPortalMock)); _assertPortal(registeredPortal, expectedPortal); vm.prank(address(0)); - emit PortalRevoked(portalAddress); - portalRegistry.revoke(portalAddress); + emit PortalRevoked(address(validPortalMock)); + portalRegistry.revoke(address(validPortalMock)); - isRegistered = portalRegistry.isRegistered(portalAddress); + isRegistered = portalRegistry.isRegistered(address(validPortalMock)); assertEq(isRegistered, false); vm.expectRevert(PortalRegistry.PortalNotRegistered.selector); - portalRegistry.getPortalByAddress(portalAddress); + portalRegistry.getPortalByAddress(address(validPortalMock)); } function test_revoke_OnlyOwner() public { @@ -310,7 +295,7 @@ contract PortalRegistryTest is Test { } function test_deployDefaultPortal() public { - CorrectModule correctModule = new CorrectModule(); + CorrectModuleV2 correctModule = new CorrectModuleV2(); address[] memory modules = new address[](1); modules[0] = address(correctModule); vm.prank(user); @@ -318,7 +303,7 @@ contract PortalRegistryTest is Test { } function test_deployDefaultPortal_OnlyAllowlisted() public { - CorrectModule correctModule = new CorrectModule(); + CorrectModuleV2 correctModule = new CorrectModuleV2(); address[] memory modules = new address[](1); modules[0] = address(correctModule); vm.expectRevert(PortalRegistry.OnlyAllowlisted.selector); diff --git a/contracts/test/examples/portals/EASPortal.t.sol b/contracts/test/examples/portals/EASPortal.t.sol index 081d260b..771191e4 100644 --- a/contracts/test/examples/portals/EASPortal.t.sol +++ b/contracts/test/examples/portals/EASPortal.t.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.21; import { Test } from "forge-std/Test.sol"; import { EASPortal } from "../../../src/examples/portals/EASPortal.sol"; import { Router } from "../../../src/Router.sol"; -import { AbstractPortal } from "../../../src/abstracts/AbstractPortal.sol"; +import { AbstractPortalV2 } from "../../../src/abstracts/AbstractPortalV2.sol"; import { AttestationRegistryMock } from "../../mocks/AttestationRegistryMock.sol"; import { ModuleRegistryMock } from "../../mocks/ModuleRegistryMock.sol"; import { ERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol"; @@ -153,7 +153,7 @@ contract EASPortalTest is Test { function test_supportsInterface() public view { bool isIERC165Supported = easPortal.supportsInterface(type(ERC165Upgradeable).interfaceId); assertEq(isIERC165Supported, true); - bool isEASAbstractPortalSupported = easPortal.supportsInterface(type(AbstractPortal).interfaceId); + bool isEASAbstractPortalSupported = easPortal.supportsInterface(type(AbstractPortalV2).interfaceId); assertEq(isEASAbstractPortalSupported, true); } } diff --git a/contracts/test/examples/portals/NFTPortal.t.sol b/contracts/test/examples/portals/NFTPortal.t.sol index ae2e52df..19a8b5f0 100644 --- a/contracts/test/examples/portals/NFTPortal.t.sol +++ b/contracts/test/examples/portals/NFTPortal.t.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.21; import { Test } from "forge-std/Test.sol"; import { NFTPortal } from "../../../src/examples/portals/NFTPortal.sol"; import { Router } from "../../../src/Router.sol"; -import { AbstractPortal } from "../../../src/abstracts/AbstractPortal.sol"; +import { AbstractPortalV2 } from "../../../src/abstracts/AbstractPortalV2.sol"; import { AttestationPayload } from "../../../src/types/Structs.sol"; import { AttestationRegistryMock } from "../../mocks/AttestationRegistryMock.sol"; import { ModuleRegistryMock } from "../../mocks/ModuleRegistryMock.sol"; @@ -65,7 +65,7 @@ contract NFTPortalTest is Test { assertTrue(isIERC165Supported); bool isIERC721Supported = nftPortal.supportsInterface(type(IERC721).interfaceId); assertTrue(isIERC721Supported); - bool isEASAbstractPortalSupported = nftPortal.supportsInterface(type(AbstractPortal).interfaceId); - assertTrue(isEASAbstractPortalSupported); + bool isEASAbstractPortalV2Supported = nftPortal.supportsInterface(type(AbstractPortalV2).interfaceId); + assertTrue(isEASAbstractPortalV2Supported); } } diff --git a/contracts/test/examples/portals/PausablePortal.t.sol b/contracts/test/examples/portals/PausablePortal.t.sol index e0dc3475..ab4d4af4 100644 --- a/contracts/test/examples/portals/PausablePortal.t.sol +++ b/contracts/test/examples/portals/PausablePortal.t.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.21; import { Test } from "forge-std/Test.sol"; import { PausablePortal } from "../../../src/examples/portals/PausablePortal.sol"; import { Router } from "../../../src/Router.sol"; -import { AbstractPortal } from "../../../src/abstracts/AbstractPortal.sol"; +import { AbstractPortalV2 } from "../../../src/abstracts/AbstractPortalV2.sol"; import { AttestationPayload } from "../../../src/types/Structs.sol"; import { AttestationRegistryMock } from "../../mocks/AttestationRegistryMock.sol"; import { PortalRegistryMock } from "../../mocks/PortalRegistryMock.sol"; @@ -103,36 +103,6 @@ contract PausablePortalTest is Test { pausablePortal.attest(attestationPayload, validationPayload); } - function test_attestV2_unpaused() public { - AttestationPayload memory attestationPayload = AttestationPayload( - bytes32(uint256(1)), - uint64(block.timestamp + 30 days), - abi.encode(makeAddr("user")), - new bytes(1) - ); - bytes[] memory validationPayload = new bytes[](0); - - vm.expectEmit(true, true, true, true); - emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); - } - - function test_attestV2_paused() public { - AttestationPayload memory attestationPayload = AttestationPayload( - bytes32(uint256(1)), - uint64(block.timestamp + 30 days), - abi.encode(makeAddr("user")), - new bytes(1) - ); - bytes[] memory validationPayload = new bytes[](0); - - vm.prank(address(this)); - pausablePortal.pause(); - - vm.expectRevert("Pausable: paused"); - pausablePortal.attestV2(attestationPayload, validationPayload); - } - function test_bulkAttest_unpaused() public { AttestationPayload memory attestationPayload = AttestationPayload( bytes32(uint256(1)), @@ -178,51 +148,6 @@ contract PausablePortalTest is Test { pausablePortal.bulkAttest(attestationPayloads, validationPayloads); } - function test_bulkAttestV2_unpaused() public { - AttestationPayload memory attestationPayload = AttestationPayload( - bytes32(uint256(1)), - uint64(block.timestamp + 30 days), - abi.encode(makeAddr("user")), - new bytes(1) - ); - AttestationPayload[] memory attestationPayloads = new AttestationPayload[](2); - attestationPayloads[0] = attestationPayload; - attestationPayloads[1] = attestationPayload; - - bytes[] memory validationPayload = new bytes[](2); - bytes[][] memory validationPayloads = new bytes[][](2); - validationPayloads[0] = validationPayload; - validationPayloads[1] = validationPayload; - - vm.prank(address(0)); - vm.expectEmit(true, true, true, true); - emit BulkAttestationsRegistered(); - pausablePortal.bulkAttestV2(attestationPayloads, validationPayloads); - } - - function test_bulkAttestV2_paused() public { - AttestationPayload memory attestationPayload = AttestationPayload( - bytes32(uint256(1)), - uint64(block.timestamp + 30 days), - abi.encode(makeAddr("user")), - new bytes(1) - ); - AttestationPayload[] memory attestationPayloads = new AttestationPayload[](2); - attestationPayloads[0] = attestationPayload; - attestationPayloads[1] = attestationPayload; - - bytes[] memory validationPayload = new bytes[](2); - bytes[][] memory validationPayloads = new bytes[][](2); - validationPayloads[0] = validationPayload; - validationPayloads[1] = validationPayload; - - vm.prank(address(this)); - pausablePortal.pause(); - - vm.expectRevert("Pausable: paused"); - pausablePortal.bulkAttestV2(attestationPayloads, validationPayloads); - } - function test_replace_unpaused() public { AttestationPayload memory attestationPayload = AttestationPayload( bytes32(uint256(1)), @@ -234,7 +159,7 @@ contract PausablePortalTest is Test { vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); vm.prank(portalOwner); vm.expectEmit(true, true, true, true); @@ -253,7 +178,7 @@ contract PausablePortalTest is Test { vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); vm.prank(address(this)); pausablePortal.pause(); @@ -274,10 +199,10 @@ contract PausablePortalTest is Test { vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); vm.prank(makeAddr("wrongOwner")); - vm.expectRevert(AbstractPortal.OnlyPortalOwner.selector); + vm.expectRevert(AbstractPortalV2.OnlyPortalOwner.selector); pausablePortal.replace(bytes32(uint256(1)), attestationPayload, validationPayload); } @@ -356,7 +281,7 @@ contract PausablePortalTest is Test { attestationIds[1] = bytes32(uint256(2)); vm.prank(makeAddr("wrongOwner")); - vm.expectRevert(AbstractPortal.OnlyPortalOwner.selector); + vm.expectRevert(AbstractPortalV2.OnlyPortalOwner.selector); pausablePortal.bulkReplace(attestationIds, attestationPayloads, validationPayloads); } @@ -371,7 +296,7 @@ contract PausablePortalTest is Test { vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); vm.prank(portalOwner); vm.expectEmit(true, true, true, true); @@ -390,7 +315,7 @@ contract PausablePortalTest is Test { vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); vm.prank(address(this)); pausablePortal.pause(); @@ -411,10 +336,10 @@ contract PausablePortalTest is Test { vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); vm.prank(makeAddr("wrongOwner")); - vm.expectRevert(AbstractPortal.OnlyPortalOwner.selector); + vm.expectRevert(AbstractPortalV2.OnlyPortalOwner.selector); pausablePortal.revoke(bytes32(uint256(1))); } @@ -429,10 +354,10 @@ contract PausablePortalTest is Test { vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); bytes32[] memory attestationIds = new bytes32[](2); attestationIds[0] = bytes32(uint256(1)); @@ -455,10 +380,10 @@ contract PausablePortalTest is Test { vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); bytes32[] memory attestationIds = new bytes32[](2); attestationIds[0] = bytes32(uint256(1)); @@ -483,24 +408,24 @@ contract PausablePortalTest is Test { vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); vm.expectEmit(true, true, true, true); emit AttestationRegistered(); - pausablePortal.attestV2(attestationPayload, validationPayload); + pausablePortal.attest(attestationPayload, validationPayload); bytes32[] memory attestationIds = new bytes32[](2); attestationIds[0] = bytes32(uint256(1)); attestationIds[1] = bytes32(uint256(2)); vm.prank(makeAddr("wrongOwner")); - vm.expectRevert(AbstractPortal.OnlyPortalOwner.selector); + vm.expectRevert(AbstractPortalV2.OnlyPortalOwner.selector); pausablePortal.bulkRevoke(attestationIds); } function testSupportsInterface() public view { bool isIERC165Supported = pausablePortal.supportsInterface(type(IERC165).interfaceId); assertTrue(isIERC165Supported); - bool isEASAbstractPortalSupported = pausablePortal.supportsInterface(type(AbstractPortal).interfaceId); - assertTrue(isEASAbstractPortalSupported); + bool isEASAbstractPortalV2Supported = pausablePortal.supportsInterface(type(AbstractPortalV2).interfaceId); + assertTrue(isEASAbstractPortalV2Supported); } } diff --git a/contracts/test/integration/AttestationRegistryMass.t.sol b/contracts/test/integration/AttestationRegistryMass.t.sol index 0b8acd91..cd0a8ae6 100644 --- a/contracts/test/integration/AttestationRegistryMass.t.sol +++ b/contracts/test/integration/AttestationRegistryMass.t.sol @@ -6,7 +6,7 @@ import { AttestationRegistry } from "../../src/AttestationRegistry.sol"; import { PortalRegistry } from "../../src/PortalRegistry.sol"; import { SchemaRegistry } from "../../src/SchemaRegistry.sol"; import { ModuleRegistry } from "../../src/ModuleRegistry.sol"; -import { DefaultPortal } from "../../src/DefaultPortal.sol"; +import { DefaultPortalV2 } from "../../src/DefaultPortalV2.sol"; import { Attestation, AttestationPayload } from "../../src/types/Structs.sol"; import { Router } from "../../src/Router.sol"; @@ -20,7 +20,7 @@ contract AttestationRegistryMassTest is Test { bytes32 public schemaId; AttestationPayload[] public payloadsToAttest; bytes[][] public validationPayloads; - DefaultPortal public defaultPortal; + DefaultPortalV2 public defaultPortal; event Initialized(uint8 version); event AttestationRegistered(bytes32 indexed attestationId); @@ -57,7 +57,7 @@ contract AttestationRegistryMassTest is Test { portalRegistry.setIssuer(portalOwner); vm.prank(portalOwner); address[] memory modules = new address[](0); - defaultPortal = new DefaultPortal(modules, address(router)); + defaultPortal = new DefaultPortalV2(modules, address(router)); vm.prank(portalOwner); portalRegistry.register(address(defaultPortal), "Name", "Description", true, "Linea"); diff --git a/contracts/test/integration/IssuersPortal.t.sol b/contracts/test/integration/IssuersPortal.t.sol index 1f4bb59f..0b310565 100644 --- a/contracts/test/integration/IssuersPortal.t.sol +++ b/contracts/test/integration/IssuersPortal.t.sol @@ -8,9 +8,9 @@ import { AttestationRegistry } from "../../src/AttestationRegistry.sol"; import { ModuleRegistry } from "../../src/ModuleRegistry.sol"; import { SchemaRegistry } from "../../src/SchemaRegistry.sol"; import { PortalRegistry } from "../../src/PortalRegistry.sol"; -import { IssuersModule } from "../../src/stdlib/IssuersModule.sol"; -import { SenderModule } from "../../src/stdlib/SenderModule.sol"; -import { DefaultPortal } from "../../src/DefaultPortal.sol"; +import { IssuersModuleV2 } from "../../src/stdlib/IssuersModuleV2.sol"; +import { SenderModuleV2 } from "../../src/stdlib/SenderModuleV2.sol"; +import { DefaultPortalV2 } from "../../src/DefaultPortalV2.sol"; contract IssuersPortalTest is Test { address public issuerAddress = makeAddr("issuer"); @@ -19,10 +19,10 @@ contract IssuersPortalTest is Test { PortalRegistry public portalRegistry = new PortalRegistry(false); ModuleRegistry public moduleRegistry = new ModuleRegistry(); AttestationRegistry public attestationRegistry = new AttestationRegistry(); - IssuersModule public issuersModule; - SenderModule public senderModule; + IssuersModuleV2 public issuersModule; + SenderModuleV2 public senderModule; bytes32 public schemaId = bytes32(0); - DefaultPortal public issuersPortal; + DefaultPortalV2 public issuersPortal; event Initialized(uint8 version); event AttestationRegistered(bytes32 indexed attestationId); @@ -42,8 +42,8 @@ contract IssuersPortalTest is Test { moduleRegistry.updateRouter(address(router)); attestationRegistry.updateRouter(address(router)); - issuersModule = new IssuersModule(address(portalRegistry)); - senderModule = new SenderModule(address(portalRegistry)); + issuersModule = new IssuersModuleV2(address(portalRegistry)); + senderModule = new SenderModuleV2(address(portalRegistry)); portalRegistry.setIssuer(issuerAddress); vm.stopPrank(); @@ -72,7 +72,7 @@ contract IssuersPortalTest is Test { // Get the address of the Portal that was just deployed and registered (, , address portalAddress) = abi.decode(entries[0].data, (string, string, address)); - issuersPortal = DefaultPortal(portalAddress); + issuersPortal = DefaultPortalV2(portalAddress); address[] memory senders = new address[](1); senders[0] = address(0); diff --git a/contracts/test/integration/IssuersPortalV2.t.sol b/contracts/test/integration/IssuersPortalV2.t.sol deleted file mode 100644 index bb7d1a73..00000000 --- a/contracts/test/integration/IssuersPortalV2.t.sol +++ /dev/null @@ -1,146 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.21; - -import { Test, Vm } from "forge-std/Test.sol"; -import { Router } from "../../src/Router.sol"; -import { AttestationPayload } from "../../src/types/Structs.sol"; -import { AttestationRegistry } from "../../src/AttestationRegistry.sol"; -import { ModuleRegistry } from "../../src/ModuleRegistry.sol"; -import { SchemaRegistry } from "../../src/SchemaRegistry.sol"; -import { PortalRegistry } from "../../src/PortalRegistry.sol"; -import { IssuersModuleV2 } from "../../src/stdlib/IssuersModuleV2.sol"; -import { SenderModuleV2 } from "../../src/stdlib/SenderModuleV2.sol"; -import { DefaultPortal } from "../../src/DefaultPortal.sol"; - -contract IssuersPortalTest is Test { - address public issuerAddress = makeAddr("issuer"); - Router public router = new Router(); - SchemaRegistry public schemaRegistry = new SchemaRegistry(); - PortalRegistry public portalRegistry = new PortalRegistry(false); - ModuleRegistry public moduleRegistry = new ModuleRegistry(); - AttestationRegistry public attestationRegistry = new AttestationRegistry(); - IssuersModuleV2 public issuersModule; - SenderModuleV2 public senderModule; - bytes32 public schemaId = bytes32(0); - DefaultPortal public issuersPortal; - - event Initialized(uint8 version); - event AttestationRegistered(bytes32 indexed attestationId); - event BulkAttestationsRegistered(); - - function setUp() public { - vm.startPrank(address(0)); - - router.initialize(); - router.updateSchemaRegistry(address(schemaRegistry)); - router.updatePortalRegistry(address(portalRegistry)); - router.updateModuleRegistry(address(moduleRegistry)); - router.updateAttestationRegistry(address(attestationRegistry)); - - schemaRegistry.updateRouter(address(router)); - portalRegistry.updateRouter(address(router)); - moduleRegistry.updateRouter(address(router)); - attestationRegistry.updateRouter(address(router)); - - issuersModule = new IssuersModuleV2(address(portalRegistry)); - senderModule = new SenderModuleV2(address(portalRegistry)); - - portalRegistry.setIssuer(issuerAddress); - vm.stopPrank(); - - vm.startPrank(issuerAddress); - moduleRegistry.register("IssuersModuleV2", "IssuersModule description", address(issuersModule)); - moduleRegistry.register("SenderModuleV2", "SenderModule description", address(senderModule)); - - schemaId = schemaRegistry.getIdFromSchemaString( - "(string name, string description, string logoURL, string[] keywords, string CTATitle, string CTALink)" - ); - schemaRegistry.createSchema( - "Issuer", - "Describes an Issuer for the Verax Attestation Registry", - "https://schema.org/Property", - "(string name, string description, string logoURL, string[] keywords, string CTATitle, string CTALink)" - ); - - address[] memory modules = new address[](2); - modules[0] = address(senderModule); - modules[1] = address(issuersModule); - - vm.recordLogs(); - portalRegistry.deployDefaultPortal(modules, "IssuersPortal", "IssuersPortal description", true, "Verax"); - Vm.Log[] memory entries = vm.getRecordedLogs(); - - // Get the address of the Portal that was just deployed and registered - (, , address portalAddress) = abi.decode(entries[0].data, (string, string, address)); - issuersPortal = DefaultPortal(portalAddress); - - address[] memory senders = new address[](1); - senders[0] = address(0); - bool[] memory statuses = new bool[](1); - statuses[0] = true; - - senderModule.setAuthorizedSenders(address(issuersPortal), senders, statuses); - - vm.stopPrank(); - } - - function test_attestV2() public { - string memory name = "Issuer name"; - string memory description = "Issuer name"; - string memory logoURL = "https://example.com/logo"; - string[] memory keywords = new string[](1); - keywords[0] = "Keyword 1"; - string memory CTATitle = "Issuer CTA"; - string memory CTALink = "https://example.com/cta"; - - AttestationPayload memory attestationPayload = AttestationPayload( - schemaId, - 0, - abi.encode(issuerAddress), - abi.encode(name, description, logoURL, keywords, CTATitle, CTALink) - ); - - bytes[] memory validationPayload = new bytes[](2); - validationPayload[0] = abi.encode(address(issuersPortal)); - - vm.prank(address(0), address(0)); - vm.expectEmit(address(attestationRegistry)); - emit AttestationRegistered(0x0000000000000000000000000000000000000000000000000000000000000001); - issuersPortal.attestV2(attestationPayload, validationPayload); - } - - function test_bulkAttestV2() public { - string memory name = "Issuer name"; - string memory description = "Issuer name"; - string memory logoURL = "https://example.com/logo"; - string[] memory keywords = new string[](1); - keywords[0] = "Keyword 1"; - string memory CTATitle = "Issuer CTA"; - string memory CTALink = "https://example.com/cta"; - - AttestationPayload memory attestationPayload = AttestationPayload( - schemaId, - 0, - abi.encode(issuerAddress), - abi.encode(name, description, logoURL, keywords, CTATitle, CTALink) - ); - - AttestationPayload[] memory attestationPayloads = new AttestationPayload[](2); - attestationPayloads[0] = attestationPayload; - attestationPayloads[1] = attestationPayload; - - bytes[] memory validationPayload = new bytes[](2); - validationPayload[0] = abi.encode(address(issuersPortal)); - - bytes[][] memory validationPayloads = new bytes[][](2); - validationPayloads[0] = validationPayload; - validationPayloads[1] = validationPayload; - - vm.startPrank(address(0), address(0)); - vm.expectEmit(address(attestationRegistry)); - emit AttestationRegistered(0x0000000000000000000000000000000000000000000000000000000000000001); - emit AttestationRegistered(0x0000000000000000000000000000000000000000000000000000000000000002); - issuersPortal.bulkAttestV2(attestationPayloads, validationPayloads); - vm.stopPrank(); - } -} diff --git a/contracts/test/mocks/IPortalImplementation.sol b/contracts/test/mocks/IPortalImplementation.sol deleted file mode 100644 index 6c684389..00000000 --- a/contracts/test/mocks/IPortalImplementation.sol +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.21; - -import { IPortal } from "../../src/interfaces/IPortal.sol"; -import { IERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol"; - -contract IPortalImplementation is IPortal { - function test() public {} - - function getModules() external pure override returns (address[] memory) { - return new address[](0); - } - - function getAttester() external view override returns (address) { - return msg.sender; - } - - function supportsInterface(bytes4 interfaceID) public pure override returns (bool) { - return interfaceID == type(IPortal).interfaceId || interfaceID == type(IERC165).interfaceId; - } -} diff --git a/contracts/test/mocks/CorrectModuleMock.sol b/contracts/test/mocks/OldVersionModuleMock.sol similarity index 76% rename from contracts/test/mocks/CorrectModuleMock.sol rename to contracts/test/mocks/OldVersionModuleMock.sol index 56cebe9f..6495624b 100644 --- a/contracts/test/mocks/CorrectModuleMock.sol +++ b/contracts/test/mocks/OldVersionModuleMock.sol @@ -5,11 +5,11 @@ import { AbstractModule } from "../../src/abstracts/AbstractModule.sol"; import { AttestationPayload } from "../../src/types/Structs.sol"; /** - * @title Correct Module + * @title Old Version Module * @author Consensys - * @notice This contract illustrates a valid Module that follows the AbstractModule interface + * @notice This contract illustrates an old version of Module that follows the AbstractModule interface */ -contract CorrectModule is AbstractModule { +contract OldVersionModule is AbstractModule { /// @dev This empty method prevents Foundry from counting this contract in code coverage function test() public {} diff --git a/contracts/test/mocks/OldVersionPortalMock.sol b/contracts/test/mocks/OldVersionPortalMock.sol new file mode 100644 index 00000000..ae101546 --- /dev/null +++ b/contracts/test/mocks/OldVersionPortalMock.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.21; + +import { AbstractPortal } from "../../src/abstracts/AbstractPortal.sol"; + +contract OldVersionPortalMock is AbstractPortal { + constructor(address[] memory modules, address router) AbstractPortal(modules, router) {} + + function test() public {} + + function withdraw(address payable to, uint256 amount) external override {} +} diff --git a/contracts/test/mocks/ValidPortalMock.sol b/contracts/test/mocks/ValidPortalMock.sol index ff866ef1..1ed93b38 100644 --- a/contracts/test/mocks/ValidPortalMock.sol +++ b/contracts/test/mocks/ValidPortalMock.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { AbstractPortal } from "../../src/abstracts/AbstractPortal.sol"; +import { AbstractPortalV2 } from "../../src/abstracts/AbstractPortalV2.sol"; -contract ValidPortalMock is AbstractPortal { - constructor(address[] memory modules, address router) AbstractPortal(modules, router) {} +contract ValidPortalMock is AbstractPortalV2 { + constructor(address[] memory modules, address router) AbstractPortalV2(modules, router) {} function test() public {}