From ff64a7f388703f97d4738673ec78799c39397c80 Mon Sep 17 00:00:00 2001 From: mejango Date: Mon, 19 Aug 2024 19:46:43 -0300 Subject: [PATCH] fmt --- src/JBProjectHandles.sol | 89 +++++---------- src/interfaces/IJBProjectHandles.sol | 24 ++-- test/JBProjectHandles.t.sol | 165 +++++++-------------------- 3 files changed, 80 insertions(+), 198 deletions(-) diff --git a/src/JBProjectHandles.sol b/src/JBProjectHandles.sol index b887621..4200bb6 100644 --- a/src/JBProjectHandles.sol +++ b/src/JBProjectHandles.sol @@ -32,8 +32,7 @@ contract JBProjectHandles is IJBProjectHandles, ERC2771Context { /// @notice The ENS registry contract address. /// @dev Same on Ethereum mainnet and most of its testnets. - ENS public constant override ENS_REGISTRY = - ENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e); + ENS public constant override ENS_REGISTRY = ENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e); //*********************************************************************// // --------------------- private stored properties ------------------- // @@ -44,8 +43,8 @@ contract JBProjectHandles is IJBProjectHandles, ERC2771Context { /// @custom:param chainId The chain ID of the network the project is on. /// @custom:param projectId The ID of the project to get the ENS parts of. /// @custom:param setter The address that set the requested `ensParts`. This should be the project's current owner. - mapping(uint256 chainId => mapping(uint256 projectId => mapping(address setter => string[] ensParts))) - private _ensNamePartsOf; + mapping(uint256 chainId => mapping(uint256 projectId => mapping(address setter => string[] ensParts))) private + _ensNamePartsOf; //*********************************************************************// // ------------------------- external views -------------------------- // @@ -60,7 +59,12 @@ contract JBProjectHandles is IJBProjectHandles, ERC2771Context { uint256 chainId, uint256 projectId, address setter - ) external view override returns (string[] memory) { + ) + external + view + override + returns (string[] memory) + { return _ensNamePartsOf[chainId][projectId][setter]; } @@ -74,11 +78,14 @@ contract JBProjectHandles is IJBProjectHandles, ERC2771Context { uint256 chainId, uint256 projectId, address setter - ) external view override returns (string memory) { + ) + external + view + override + returns (string memory) + { // Get a reference to the project's ENS name parts. - string[] memory ensNameParts = _ensNamePartsOf[chainId][projectId][ - setter - ]; + string[] memory ensNameParts = _ensNamePartsOf[chainId][projectId][setter]; // Return an empty string if not found. if (ensNameParts.length == 0) return ""; @@ -93,23 +100,12 @@ contract JBProjectHandles is IJBProjectHandles, ERC2771Context { if (textResolver == address(0)) return ""; // Find the `projectId` that the text record of the ENS name is mapped to. - string memory textRecord = ITextResolver(textResolver).text( - hashedName, - TEXT_KEY - ); + string memory textRecord = ITextResolver(textResolver).text(hashedName, TEXT_KEY); // Return empty string if text record from ENS name doesn't match `projectId` and `chainId`. if ( - keccak256(bytes(textRecord)) != - keccak256( - bytes( - string.concat( - Strings.toString(chainId), - ":", - Strings.toString(projectId) - ) - ) - ) + keccak256(bytes(textRecord)) + != keccak256(bytes(string.concat(Strings.toString(chainId), ":", Strings.toString(projectId)))) ) return ""; // Format the handle from the name parts. @@ -121,22 +117,14 @@ contract JBProjectHandles is IJBProjectHandles, ERC2771Context { //*********************************************************************// /// @dev ERC-2771 specifies the context as being a single address (20 bytes). - function _contextSuffixLength() - internal - view - virtual - override - returns (uint256) - { + function _contextSuffixLength() internal view virtual override returns (uint256) { return super._contextSuffixLength(); } /// @notice Formats ENS name parts into a handle. /// @param ensNameParts The ENS name parts to format into a handle. /// @return handle The formatted ENS handle. - function _formatHandle( - string[] memory ensNameParts - ) internal pure returns (string memory handle) { + function _formatHandle(string[] memory ensNameParts) internal pure returns (string memory handle) { // Get a reference to the number of parts are in the ENS name. uint256 partsLength = ensNameParts.length; @@ -144,9 +132,7 @@ contract JBProjectHandles is IJBProjectHandles, ERC2771Context { for (uint256 i = 1; i <= partsLength; i++) { // Compute the handle. // slither-disable-next-line encode-packed-collision - handle = string( - abi.encodePacked(handle, ensNameParts[partsLength - i]) - ); + handle = string(abi.encodePacked(handle, ensNameParts[partsLength - i])); // Add a dot if this part isn't the last. if (i < partsLength) handle = string(abi.encodePacked(handle, ".")); @@ -157,25 +143,16 @@ contract JBProjectHandles is IJBProjectHandles, ERC2771Context { /// @dev See https://eips.ethereum.org/EIPS/eip-137. /// @param ensNameParts The parts of an ENS name to hash. /// @return namehash The namehash for an ENS name parts. - function _namehash( - string[] memory ensNameParts - ) internal pure returns (bytes32 namehash) { + function _namehash(string[] memory ensNameParts) internal pure returns (bytes32 namehash) { // Hash the trailing "eth" suffix. - namehash = keccak256( - abi.encodePacked(namehash, keccak256(abi.encodePacked("eth"))) - ); + namehash = keccak256(abi.encodePacked(namehash, keccak256(abi.encodePacked("eth")))); // Get a reference to the number of parts are in the ENS name. uint256 nameLength = ensNameParts.length; // Hash each part. for (uint256 i; i < nameLength; i++) { - namehash = keccak256( - abi.encodePacked( - namehash, - keccak256(abi.encodePacked(ensNameParts[i])) - ) - ); + namehash = keccak256(abi.encodePacked(namehash, keccak256(abi.encodePacked(ensNameParts[i])))); } } @@ -208,11 +185,7 @@ contract JBProjectHandles is IJBProjectHandles, ERC2771Context { /// @param chainId The chain ID of the network the project is on. /// @param projectId The ID of the project to set an ENS handle for. /// @param parts The parts of the ENS domain to use as the project handle, excluding the trailing .eth. - function setEnsNamePartsFor( - uint256 chainId, - uint256 projectId, - string[] memory parts - ) external override { + function setEnsNamePartsFor(uint256 chainId, uint256 projectId, string[] memory parts) external override { // Get a reference to the number of parts are in the ENS name. uint256 partsLength = parts.length; @@ -221,18 +194,14 @@ contract JBProjectHandles is IJBProjectHandles, ERC2771Context { // Make sure no provided parts are empty. for (uint256 i; i < partsLength; i++) { - if (bytes(parts[i]).length == 0) + if (bytes(parts[i]).length == 0) { revert JBProjectHandles_EmptyNamePart(); + } } // Store the parts. _ensNamePartsOf[chainId][projectId][_msgSender()] = parts; - emit SetEnsNameParts({ - projectId: projectId, - handle: _formatHandle(parts), - parts: parts, - caller: _msgSender() - }); + emit SetEnsNameParts({projectId: projectId, handle: _formatHandle(parts), parts: parts, caller: _msgSender()}); } } diff --git a/src/interfaces/IJBProjectHandles.sol b/src/interfaces/IJBProjectHandles.sol index 8e75d92..170a592 100644 --- a/src/interfaces/IJBProjectHandles.sol +++ b/src/interfaces/IJBProjectHandles.sol @@ -6,12 +6,7 @@ import {ENS} from "@ensdomains/ens-contracts/contracts/registry/ENS.sol"; import {ITextResolver} from "@ensdomains/ens-contracts/contracts/resolvers/profiles/ITextResolver.sol"; interface IJBProjectHandles { - event SetEnsNameParts( - uint256 indexed projectId, - string indexed handle, - string[] parts, - address caller - ); + event SetEnsNameParts(uint256 indexed projectId, string indexed handle, string[] parts, address caller); function TEXT_KEY() external view returns (string memory); function ENS_REGISTRY() external view returns (ENS); @@ -20,17 +15,12 @@ interface IJBProjectHandles { uint256 chainId, uint256 projectId, address projectOwner - ) external view returns (string[] memory); + ) + external + view + returns (string[] memory); - function handleOf( - uint256 chainId, - uint256 projectId, - address projectOwner - ) external view returns (string memory); + function handleOf(uint256 chainId, uint256 projectId, address projectOwner) external view returns (string memory); - function setEnsNamePartsFor( - uint256 chainId, - uint256 projectId, - string[] memory parts - ) external; + function setEnsNamePartsFor(uint256 chainId, uint256 projectId, string[] memory parts) external; } diff --git a/test/JBProjectHandles.t.sol b/test/JBProjectHandles.t.sol index 5f0943a..5610c46 100644 --- a/test/JBProjectHandles.t.sol +++ b/test/JBProjectHandles.t.sol @@ -13,18 +13,11 @@ import "../src/JBProjectHandles.sol"; import {JBPermissionIds} from "@bananapus/permission-ids/src/JBPermissionIds.sol"; ENS constant ensRegistry = ENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e); -IJBProjectHandles constant oldHandle = IJBProjectHandles( - 0x41126eC99F8A989fEB503ac7bB4c5e5D40E06FA4 -); +IJBProjectHandles constant oldHandle = IJBProjectHandles(0x41126eC99F8A989fEB503ac7bB4c5e5D40E06FA4); contract ContractTest is Test { // For testing the event emitted - event SetEnsNameParts( - uint256 indexed projectId, - string indexed ensName, - string[] parts, - address caller - ); + event SetEnsNameParts(uint256 indexed projectId, string indexed ensName, string[] parts, address caller); address projectOwner = address(6_942_069); @@ -48,9 +41,7 @@ contract ContractTest is Test { // ------------------------ SetEnsNamePartsFor(..) ------------------- // //*********************************************************************// - function testSetEnsNamePartsFor_passIfCallerIsProjectOwnerAndOnlyName( - string calldata name - ) public { + function testSetEnsNamePartsFor_passIfCallerIsProjectOwnerAndOnlyName(string calldata name) public { vm.assume(bytes(name).length != 0); uint256 projectId = jbProjects.createFor(projectOwner); @@ -67,22 +58,17 @@ contract ContractTest is Test { projectHandle.setEnsNamePartsFor(chainId, projectId, nameParts); // Control: correct ENS name? - assertEq( - projectHandle.ensNamePartsOf(chainId, projectId, projectOwner), - nameParts - ); + assertEq(projectHandle.ensNamePartsOf(chainId, projectId, projectOwner), nameParts); } function testSetEnsNameWithSubdomainFor_passIfMultipleSubdomainLevels( string memory name, string memory subdomain, string memory subsubdomain - ) public { - vm.assume( - bytes(name).length > 0 && - bytes(subdomain).length > 0 && - bytes(subsubdomain).length > 0 - ); + ) + public + { + vm.assume(bytes(name).length > 0 && bytes(subdomain).length > 0 && bytes(subsubdomain).length > 0); uint256 projectId = jbProjects.createFor(projectOwner); uint256 chainId = 1; @@ -93,9 +79,7 @@ contract ContractTest is Test { nameParts[1] = subdomain; nameParts[2] = name; - string memory fullName = string( - abi.encodePacked(name, ".", subdomain, ".", subsubdomain) - ); + string memory fullName = string(abi.encodePacked(name, ".", subdomain, ".", subsubdomain)); // Test event vm.expectEmit(true, true, true, true); @@ -105,22 +89,17 @@ contract ContractTest is Test { projectHandle.setEnsNamePartsFor(chainId, projectId, nameParts); // Control: ENS has correct name and domain - assertEq( - projectHandle.ensNamePartsOf(chainId, projectId, projectOwner), - nameParts - ); + assertEq(projectHandle.ensNamePartsOf(chainId, projectId, projectOwner), nameParts); } function testSetEnsNameWithSubdomainFor_RevertIfEmptyElementInNameParts( string memory name, string memory subdomain, string memory subsubdomain - ) public { - vm.assume( - bytes(name).length == 0 || - bytes(subdomain).length == 0 || - bytes(subsubdomain).length == 0 - ); + ) + public + { + vm.assume(bytes(name).length == 0 || bytes(subdomain).length == 0 || bytes(subsubdomain).length == 0); uint256 projectId = jbProjects.createFor(projectOwner); uint256 chainId = 1; @@ -132,16 +111,11 @@ contract ContractTest is Test { nameParts[2] = name; vm.prank(projectOwner); - vm.expectRevert( - JBProjectHandles.JBProjectHandles_EmptyNamePart.selector - ); + vm.expectRevert(JBProjectHandles.JBProjectHandles_EmptyNamePart.selector); projectHandle.setEnsNamePartsFor(chainId, projectId, nameParts); // Control: ENS has correct name and domain - assertEq( - projectHandle.ensNamePartsOf(chainId, projectId, projectOwner), - new string[](0) - ); + assertEq(projectHandle.ensNamePartsOf(chainId, projectId, projectOwner), new string[](0)); } function testSetEnsNameWithSubdomainFor_RevertIfEmptyNameParts() public { @@ -156,27 +130,18 @@ contract ContractTest is Test { projectHandle.setEnsNamePartsFor(chainId, projectId, nameParts); // Control: ENS has correct name and domain - assertEq( - projectHandle.ensNamePartsOf(chainId, projectId, projectOwner), - new string[](0) - ); + assertEq(projectHandle.ensNamePartsOf(chainId, projectId, projectOwner), new string[](0)); } //*********************************************************************// // ---------------------------- handleOf(..) ------------------------- // //*********************************************************************// - function testHandleOf_returnsEmptyStringIfNoHandleSet( - uint256 chainId, - uint256 projectId - ) public { + function testHandleOf_returnsEmptyStringIfNoHandleSet(uint256 chainId, uint256 projectId) public { // No handle set on the previous JBProjectHandle version neither vm.mockCall( address(oldHandle), - abi.encodeCall( - IJBProjectHandles.ensNamePartsOf, - (chainId, projectId, projectOwner) - ), + abi.encodeCall(IJBProjectHandles.ensNamePartsOf, (chainId, projectId, projectOwner)), abi.encode(new string[](0)) ); @@ -187,12 +152,10 @@ contract ContractTest is Test { string calldata name, string calldata subdomain, string calldata subsubdomain - ) public { - vm.assume( - bytes(name).length > 0 && - bytes(subdomain).length > 0 && - bytes(subsubdomain).length > 0 - ); + ) + public + { + vm.assume(bytes(name).length > 0 && bytes(subdomain).length > 0 && bytes(subsubdomain).length > 0); uint256 projectId = jbProjects.createFor(projectOwner); uint256 chainId = 1; @@ -222,27 +185,14 @@ contract ContractTest is Test { vm.mockCall( address(ensTextResolver), - abi.encodeWithSelector( - ITextResolver.text.selector, - _namehash(nameParts), - KEY - ), - abi.encode( - string.concat( - Strings.toString(chainId), - ":", - Strings.toString(projectId) - ) - ) + abi.encodeWithSelector(ITextResolver.text.selector, _namehash(nameParts), KEY), + abi.encode(string.concat(Strings.toString(chainId), ":", Strings.toString(projectId))) ); // Mock the registration on the previous version vm.mockCall( address(oldHandle), - abi.encodeCall( - IJBProjectHandles.ensNamePartsOf, - (chainId, projectId, projectOwner) - ), + abi.encodeCall(IJBProjectHandles.ensNamePartsOf, (chainId, projectId, projectOwner)), abi.encode(oldNamePart) ); @@ -260,16 +210,15 @@ contract ContractTest is Test { string calldata name, string calldata subdomain, string calldata subsubdomain - ) public { + ) + public + { vm.assume(projectId != reverseId); // No handle set on the previous JBProjectHandle version vm.mockCall( address(oldHandle), - abi.encodeCall( - IJBProjectHandles.ensNamePartsOf, - (chainId, projectId, projectOwner) - ), + abi.encodeCall(IJBProjectHandles.ensNamePartsOf, (chainId, projectId, projectOwner)), abi.encode(new string[](0)) ); @@ -295,16 +244,15 @@ contract ContractTest is Test { string calldata name, string calldata subdomain, string calldata subsubdomain - ) public { + ) + public + { vm.assume(projectId != reverseId); // No handle set on the previous JBProjectHandle version vm.mockCall( address(oldHandle), - abi.encodeCall( - IJBProjectHandles.ensNamePartsOf, - (chainId, projectId, projectOwner) - ), + abi.encodeCall(IJBProjectHandles.ensNamePartsOf, (chainId, projectId, projectOwner)), abi.encode(new string[](0)) ); @@ -324,11 +272,7 @@ contract ContractTest is Test { vm.mockCall( address(ensTextResolver), - abi.encodeWithSelector( - ITextResolver.text.selector, - _namehash(nameParts), - KEY - ), + abi.encodeWithSelector(ITextResolver.text.selector, _namehash(nameParts), KEY), abi.encode(Strings.toString(reverseId)) ); @@ -339,12 +283,10 @@ contract ContractTest is Test { string calldata name, string calldata subdomain, string calldata subsubdomain - ) public { - vm.assume( - bytes(name).length > 0 && - bytes(subdomain).length > 0 && - bytes(subsubdomain).length > 0 - ); + ) + public + { + vm.assume(bytes(name).length > 0 && bytes(subdomain).length > 0 && bytes(subsubdomain).length > 0); uint256 projectId = jbProjects.createFor(projectOwner); uint256 chainId = 1; @@ -368,18 +310,8 @@ contract ContractTest is Test { vm.mockCall( address(ensTextResolver), - abi.encodeWithSelector( - ITextResolver.text.selector, - _namehash(nameParts), - KEY - ), - abi.encode( - string.concat( - Strings.toString(chainId), - ":", - Strings.toString(projectId) - ) - ) + abi.encodeWithSelector(ITextResolver.text.selector, _namehash(nameParts), KEY), + abi.encode(string.concat(Strings.toString(chainId), ":", Strings.toString(projectId))) ); assertEq( @@ -400,24 +332,15 @@ contract ContractTest is Test { } } - function _namehash( - string[] memory ensName - ) internal pure returns (bytes32 namehash) { - namehash = keccak256( - abi.encodePacked(namehash, keccak256(abi.encodePacked("eth"))) - ); + function _namehash(string[] memory ensName) internal pure returns (bytes32 namehash) { + namehash = keccak256(abi.encodePacked(namehash, keccak256(abi.encodePacked("eth")))); // Get a reference to the number of parts are in the ENS name. uint256 nameLength = ensName.length; // Hash each part. for (uint256 i = 0; i < nameLength; i++) { - namehash = keccak256( - abi.encodePacked( - namehash, - keccak256(abi.encodePacked(ensName[i])) - ) - ); + namehash = keccak256(abi.encodePacked(namehash, keccak256(abi.encodePacked(ensName[i])))); } } }