Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: registry unit tests #657

Merged
merged 7 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions contracts/core/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ contract Registry is IRegistry, Initializable, AccessControlUpgradeable, Errors
/// @notice Checks if the caller is the owner of the profile
/// @dev Internal function used by modifier 'onlyProfileOwner'
/// @param _profileId The ID of the profile
function _checkOnlyProfileOwner(bytes32 _profileId) internal view {
function _checkOnlyProfileOwner(bytes32 _profileId) internal view virtual {
if (!_isOwnerOfProfile(_profileId, msg.sender)) revert UNAUTHORIZED();
}

Expand All @@ -330,7 +330,7 @@ contract Registry is IRegistry, Initializable, AccessControlUpgradeable, Errors
/// @param _profileId The ID of the profile
/// @param _name The name of the profile
/// @return anchor The address of the deployed anchor contract
function _generateAnchor(bytes32 _profileId, string memory _name) internal returns (address anchor) {
function _generateAnchor(bytes32 _profileId, string memory _name) internal virtual returns (address anchor) {
bytes memory encodedData = abi.encode(_profileId, _name);
bytes memory encodedConstructorArgs = abi.encode(_profileId, address(this));

Expand All @@ -356,7 +356,7 @@ contract Registry is IRegistry, Initializable, AccessControlUpgradeable, Errors
/// @param _nonce Nonce provided by the caller to generate 'profileId'
/// @param _owner The owner of the profile
/// @return 'profileId' The ID of the profile
function _generateProfileId(uint256 _nonce, address _owner) internal pure returns (bytes32) {
function _generateProfileId(uint256 _nonce, address _owner) internal pure virtual returns (bytes32) {
return keccak256(abi.encodePacked(_nonce, _owner));
}

Expand All @@ -365,7 +365,7 @@ contract Registry is IRegistry, Initializable, AccessControlUpgradeable, Errors
/// @param _profileId The 'profileId' of the profile
/// @param _owner The address to check
/// @return 'true' if the address is an owner of the profile, otherwise 'false'
function _isOwnerOfProfile(bytes32 _profileId, address _owner) internal view returns (bool) {
function _isOwnerOfProfile(bytes32 _profileId, address _owner) internal view virtual returns (bool) {
return profilesById[_profileId].owner == _owner;
}

Expand All @@ -374,7 +374,7 @@ contract Registry is IRegistry, Initializable, AccessControlUpgradeable, Errors
/// @param _profileId The 'profileId' of the profile
/// @param _member The address to check
/// @return 'true' if the address is a member of the profile, otherwise 'false'
function _isMemberOfProfile(bytes32 _profileId, address _member) internal view returns (bool) {
function _isMemberOfProfile(bytes32 _profileId, address _member) internal view virtual returns (bool) {
return hasRole(_profileId, _member);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"/////// deploy-test ///////": "echo 'deploy test scripts'",
"create-profile": "npx hardhat run scripts/test/createProfile.ts --network",
"create-pool": "npx hardhat run scripts/test/createPool.ts --network",
"smock": "smock-foundry --contracts contracts/core --contracts test/mocks/smock-mocks/"
"smock": "smock-foundry --contracts test/mocks/smock-mocks/"
},
"devDependencies": {
"@defi-wonderland/natspec-smells": "1.1.5",
Expand Down
43 changes: 43 additions & 0 deletions test/mocks/smock-mocks/MockRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import {Registry} from "contracts/core/Registry.sol";

contract MockRegistry is Registry {
function _grantRole(bytes32 role, address account) internal virtual override {
super._grantRole(role, account);
}

function _checkRole(bytes32 role, address account) internal view virtual override {
super._checkRole(role, account);
}

function _revokeRole(bytes32 role, address account) internal virtual override {
super._revokeRole(role, account);
}

function _generateProfileId(uint256 _nonce, address _owner) internal pure virtual override returns (bytes32) {
return super._generateProfileId(_nonce, _owner);
}

function _generateAnchor(bytes32 _profileId, string memory _name)
internal
virtual
override
returns (address anchor)
{
return super._generateAnchor(_profileId, _name);
}

function _checkOnlyProfileOwner(bytes32 _profileId) internal view virtual override {
super._checkOnlyProfileOwner(_profileId);
}

function _isOwnerOfProfile(bytes32 _profileId, address _owner) internal view virtual override returns (bool) {
return super._isOwnerOfProfile(_profileId, _owner);
}

function _isMemberOfProfile(bytes32 _profileId, address _member) internal view virtual override returns (bool) {
return super._isMemberOfProfile(_profileId, _member);
}
}
Loading
Loading