Skip to content

Commit

Permalink
feat: adding default resolverUID
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroknots committed Feb 14, 2024
1 parent fa68503 commit cc8b10a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct SchemaRecord {
}

struct ResolverRecord {
IExternalResolver resolver; // Optional resolver.
IExternalResolver resolver; // resolver.
address resolverOwner; // The address of the account used to register the resolver.
}

Expand Down
2 changes: 1 addition & 1 deletion src/Registry.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.24;

import { SignedAttestation } from "./core/SignedAttestation.sol";
import { IRegistry } from "./IRegistry.sol";
import { SignedAttestation } from "./core/SignedAttestation.sol";
/**
* @author zeroknots
*/
Expand Down
2 changes: 0 additions & 2 deletions src/core/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
internal
returns (ModuleRecord memory moduleRegistration)
{
// ensure that non-zero resolverUID was provided
if (resolverUID == EMPTY_RESOLVER_UID) revert InvalidDeployment();
// ensure moduleAddress is not already registered
if ($moduleAddrToRecords[moduleAddress].resolverUID != EMPTY_RESOLVER_UID) {
revert AlreadyRegistered(moduleAddress);
Expand Down
5 changes: 5 additions & 0 deletions src/core/ResolverManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ abstract contract ResolverManager is IRegistry {

mapping(ResolverUID uid => ResolverRecord resolver) internal $resolvers;

constructor() {
ResolverRecord storage $resolver = $resolvers[ResolverUID.wrap(bytes32(0))];
$resolver.resolverOwner = address(this);
}

/**
* @dev Modifier to require that the caller is the owner of a resolver
*
Expand Down
2 changes: 0 additions & 2 deletions src/lib/ModuleDeploymentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,4 @@ library ModuleDeploymentLib {
)
);
}

error InvalidDeployment();
}
2 changes: 1 addition & 1 deletion src/lib/StubLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ library StubLib {
{
IExternalResolver resolverContract = $resolver.resolver;

if (address(resolverContract) != ZERO_ADDRESS) return;
if (address(resolverContract) == ZERO_ADDRESS) return;

if (resolverContract.resolveModuleRegistration({ sender: msg.sender, moduleAddress: moduleAddress, record: moduleRecord }) == false)
{
Expand Down
13 changes: 12 additions & 1 deletion test/ModuleRegistration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract ModuleRegistrationTest is BaseTest {
function test_WhenRegisteringAModuleOnAnInvalidResolverUID() external prankWithAccount(moduleDev1) {
MockModule newModule = new MockModule();
// It should revert.
ResolverUID invalidUID = ResolverUID.wrap(hex"00");
ResolverUID invalidUID = ResolverUID.wrap(hex"01");
vm.expectRevert(abi.encodeWithSelector(IRegistry.InvalidResolver.selector, address(0)));
registry.registerModule(invalidUID, address(newModule), "");

Expand Down Expand Up @@ -103,4 +103,15 @@ contract ModuleRegistrationTest is BaseTest {
vm.expectRevert();
registry.deployViaFactory(address(registry), "", "", defaultResolverUID);
}

function test_WhenUsingDefaultResolverUID() public prankWithAccount(moduleDev1) {
bytes32 salt = bytes32(abi.encodePacked(address(moduleDev1.addr), bytes12(0)));

bytes memory bytecode = type(MockModule).creationCode;

ResolverUID nullUID = ResolverUID.wrap(bytes32(0));
address moduleAddr = registry.deployModule(salt, nullUID, bytecode, "");
ModuleRecord memory record = registry.findModule(moduleAddr);
assertTrue(record.resolverUID == nullUID);
}
}

0 comments on commit cc8b10a

Please sign in to comment.