From 0f2ee434f54ac143b36ceac6d78347a54a0e8b3c Mon Sep 17 00:00:00 2001 From: kopy-kat Date: Fri, 12 Jul 2024 15:46:24 +0200 Subject: [PATCH] feat: add mock attestation --- src/deployment/RegistryDeployer.sol | 74 ++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/src/deployment/RegistryDeployer.sol b/src/deployment/RegistryDeployer.sol index 083b0b38..bb970bf7 100644 --- a/src/deployment/RegistryDeployer.sol +++ b/src/deployment/RegistryDeployer.sol @@ -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; @@ -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 ----> @@ -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) { @@ -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); } @@ -80,4 +148,8 @@ contract RegistryDeployer { function setResolverUID(ResolverUID _resolverUID) public { resolverUID = _resolverUID; } + + function setSchemaUID(SchemaUID _schemaUID) public { + schemaUID = _schemaUID; + } }