Skip to content

Commit

Permalink
feat: add mock attestation
Browse files Browse the repository at this point in the history
  • Loading branch information
kopy-kat committed Jul 12, 2024
1 parent db97678 commit 0f2ee43
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion src/deployment/RegistryDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
pragma solidity ^0.8.23;

import { IRegistry, IExternalResolver } from "registry/IRegistry.sol";
import { ResolverRecord, ModuleRecord, ResolverUID } from "registry/DataTypes.sol";
import {
ResolverRecord,
ModuleRecord,
ResolverUID,
AttestationRecord,
AttestationRequest,
ModuleType,
SchemaUID,
SchemaRecord
} from "registry/DataTypes.sol";
import { IExternalSchemaValidator } from "registry/external/IExternalSchemaValidator.sol";

address constant REGISTRY_ADDR = 0xe0cde9239d16bEf05e62Bbf7aA93e420f464c826;

Expand All @@ -13,6 +23,12 @@ contract RegistryDeployer {
ResolverUID internal resolverUID =
ResolverUID.wrap(0xdf658e5595d93baa803af242dc6e175b4cbef04de73509b50b944d1b2d167bb6);

SchemaUID internal schemaUID =
SchemaUID.wrap(0xdf658e5595d93baa803af242dc6e175b4cbef04de73509b50b944d1b2d167bb6);

// Mock attester
address internal mockAttester = 0xe0cde9239d16bEf05e62Bbf7aA93e420f464c826;

error InvalidResolver();

// <---- DEPLOYMENT ---->
Expand Down Expand Up @@ -55,6 +71,37 @@ contract RegistryDeployer {
});
}

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

function mockAttestToModule(
address module,
bytes memory attestationData,
ModuleType[] memory moduleTypes
)
public
{
SchemaUID _schemaUID = findSchema();
AttestationRequest memory request = AttestationRequest({
moduleAddress: module,
expirationTime: 0,
data: attestationData,
moduleTypes: moduleTypes
});
registry.attest({
schemaUID: _schemaUID,
request: request,
attester: mockAttester,
signature: hex"414141414141"
});
}

function isModuleAttestedMock(address module) public returns (bool) {
AttestationRecord memory attestation =
registry.findAttestation({ module: module, attester: mockAttester });
return attestation.time > 0 && attestation.expirationTime < block.timestamp
&& attestation.revocationTime == 0;
}

// <---- REGISTRY MANAGEMENT ---->

function findResolver() public view returns (ResolverUID _resolverUID) {
Expand All @@ -69,6 +116,27 @@ contract RegistryDeployer {
_resolverUID = registry.registerResolver(IExternalResolver(resolver));
}

function findSchema() public view returns (SchemaUID _schemaUID) {
_schemaUID = schemaUID;
SchemaRecord memory schema = registry.findSchema(schemaUID);
if (schema.registeredAt == 0) {
revert InvalidResolver();
}
}

function registerSchema(
string memory schema,
address validator
)
public
returns (SchemaUID _schemaUID)
{
_schemaUID = registry.registerSchema({
schema: schema,
validator: IExternalSchemaValidator(validator)
});
}

function findModule(address moduleAddress) public view returns (ModuleRecord memory) {
return registry.findModule(moduleAddress);
}
Expand All @@ -80,4 +148,8 @@ contract RegistryDeployer {
function setResolverUID(ResolverUID _resolverUID) public {
resolverUID = _resolverUID;
}

function setSchemaUID(SchemaUID _schemaUID) public {
schemaUID = _schemaUID;
}
}

0 comments on commit 0f2ee43

Please sign in to comment.