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

feat: add module registration helper #143

Merged
merged 2 commits into from
Aug 28, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rhinestone/modulekit",
"version": "0.4.12",
"version": "0.4.13",
"description": "A development kit for building and testing smart account modules.",
"license": "GPL-3.0",
"author": {
Expand Down
26 changes: 22 additions & 4 deletions src/deployment/RegistryDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@
return registry.calcModuleAddress(salt, initCode);
}

// <---- REGISTRATION ---->

function registerModule(
address module,
bytes memory metadata,
bytes memory resolverContext
)
public
{
ResolverUID _resolverUID = findResolver();
registry.registerModule({
resolverUID: _resolverUID,
moduleAddress: module,
metadata: metadata,
resolverContext: resolverContext
});
}

function findModule(address moduleAddress) public view returns (ModuleRecord memory) {
return registry.findModule(moduleAddress);
}

// <---- ATTESTATIONS ---->

function mockAttestToModule(
Expand All @@ -90,7 +112,7 @@
)
public
{
require(isContract(mockAttester), "MockAttester is not deployed on this network");

Check warning on line 115 in src/deployment/RegistryDeployer.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Error message for require is too long: 44 counted / 32 allowed

Check warning on line 115 in src/deployment/RegistryDeployer.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

GC: Use Custom Errors instead of require statements

SchemaUID _schemaUID = findSchema();
AttestationRequest memory request = AttestationRequest({
Expand All @@ -108,7 +130,7 @@
)
);

require(success, "Mock attestation failed");

Check warning on line 133 in src/deployment/RegistryDeployer.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

GC: Use Custom Errors instead of require statements
}

function isModuleAttestedMock(address module) public view returns (bool) {
Expand Down Expand Up @@ -153,10 +175,6 @@
});
}

function findModule(address moduleAddress) public view returns (ModuleRecord memory) {
return registry.findModule(moduleAddress);
}

function setRegistry(address _registry) public {
registry = IRegistry(_registry);
}
Expand All @@ -172,7 +190,7 @@
// <---- OTHER ---->
function isContract(address _addr) internal returns (bool isContract) {
uint32 size;
assembly {

Check warning on line 193 in src/deployment/RegistryDeployer.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Avoid to use inline assembly. It is acceptable only in rare cases
size := extcodesize(_addr)
}
return (size > 0);
Expand Down
17 changes: 17 additions & 0 deletions test/RegistryDeployer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ contract RegistryDeployerTest is RegistryDeployer, BaseTest {
assertEq(moduleRecord.metadata, metadata);
}

function testRegisterModule() public onMainnet {
address module = address(new MockValidator());

ModuleRecord memory moduleRecord = findModule(module);
assertEq(ResolverUID.unwrap(moduleRecord.resolverUID), bytes32(0));
assertEq(moduleRecord.metadata, "");

bytes memory metadata = hex"41414141414141";
bytes memory resolverContext = "";

registerModule({ module: module, metadata: metadata, resolverContext: resolverContext });

moduleRecord = findModule(module);
assertEq(ResolverUID.unwrap(moduleRecord.resolverUID), ResolverUID.unwrap(resolverUID));
assertEq(moduleRecord.metadata, metadata);
}

function testMockAttestModule() public onTestnet {
deployModule();

Expand Down
Loading