From 5cbfd1455c7795b376450f3da92f47da7996b14d Mon Sep 17 00:00:00 2001 From: kopy-kat Date: Thu, 15 Aug 2024 15:40:36 +0200 Subject: [PATCH 1/3] feat: add mock combination component --- test/mocks/MockCombination.sol | 89 ++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/mocks/MockCombination.sol diff --git a/test/mocks/MockCombination.sol b/test/mocks/MockCombination.sol new file mode 100644 index 0000000..b700bd6 --- /dev/null +++ b/test/mocks/MockCombination.sol @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.0; + +import "src/external/IExternalResolver.sol"; +import "src/external/IExternalSchemaValidator.sol"; +import { IRegistry, SchemaUID, AttestationRequest } from "src/IRegistry.sol"; + +contract MockCombination is IExternalResolver, IExternalSchemaValidator { + bool immutable returnVal; + + bool public onAttestCalled; + bool public onRevokeCalled; + bool public onModuleCalled; + + constructor(bool ret) { + returnVal = ret; + } + + /*////////////////////////////////////////////////////////////////////////// + RESOLVER + //////////////////////////////////////////////////////////////////////////*/ + + function reset() public { + onAttestCalled = false; + onRevokeCalled = false; + onModuleCalled = false; + } + + function supportsInterface(bytes4 interfaceId) public pure override returns (bool) { + if (interfaceId == type(IExternalResolver).interfaceId || interfaceId == type(IExternalSchemaValidator).interfaceId) return true; + } + + function resolveAttestation(AttestationRecord calldata attestation) external payable override returns (bool) { + onAttestCalled = true; + return returnVal; + } + + function resolveAttestation(AttestationRecord[] calldata attestation) external payable override returns (bool) { + onAttestCalled = true; + return returnVal; + } + + function resolveRevocation(AttestationRecord calldata attestation) external payable override returns (bool) { + revert(); + onRevokeCalled = true; + return returnVal; + } + + function resolveRevocation(AttestationRecord[] calldata attestation) external payable override returns (bool) { + revert(); + onRevokeCalled = true; + return returnVal; + } + + function resolveModuleRegistration( + address sender, + address moduleRecord, + ModuleRecord calldata record, + bytes calldata resolverContext + ) + external + payable + override + returns (bool) + { + onModuleCalled = true; + return returnVal; + } + + /*////////////////////////////////////////////////////////////////////////// + SCHEMA VALIDATOR + //////////////////////////////////////////////////////////////////////////*/ + + function validateSchema(AttestationRecord calldata attestation) external view override returns (bool) { + return returnVal; + } + + function validateSchema(AttestationRecord[] calldata attestations) external view override returns (bool) { + return returnVal; + } + + /*////////////////////////////////////////////////////////////////////////// + MOCK ATTESTER + //////////////////////////////////////////////////////////////////////////*/ + + function attest(IRegistry registry, SchemaUID schemaUID, AttestationRequest calldata request) external payable returns (bool) { + registry.attest(schemaUID, request); + } +} From 70bdf96b3fd5b5ea154cdb2902ac3f71cfba85e7 Mon Sep 17 00:00:00 2001 From: kopy-kat Date: Fri, 16 Aug 2024 14:11:11 +0200 Subject: [PATCH 2/3] feat: add events --- test/mocks/MockCombination.sol | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/mocks/MockCombination.sol b/test/mocks/MockCombination.sol index b700bd6..6e55130 100644 --- a/test/mocks/MockCombination.sol +++ b/test/mocks/MockCombination.sol @@ -8,6 +8,10 @@ import { IRegistry, SchemaUID, AttestationRequest } from "src/IRegistry.sol"; contract MockCombination is IExternalResolver, IExternalSchemaValidator { bool immutable returnVal; + event AttestationCalled(); + event RevokeCalled(); + event ModuleCalled(); + bool public onAttestCalled; bool public onRevokeCalled; bool public onModuleCalled; @@ -32,23 +36,25 @@ contract MockCombination is IExternalResolver, IExternalSchemaValidator { function resolveAttestation(AttestationRecord calldata attestation) external payable override returns (bool) { onAttestCalled = true; + emit AttestationCalled(); return returnVal; } function resolveAttestation(AttestationRecord[] calldata attestation) external payable override returns (bool) { onAttestCalled = true; + emit AttestationCalled(); return returnVal; } function resolveRevocation(AttestationRecord calldata attestation) external payable override returns (bool) { - revert(); onRevokeCalled = true; + emit RevokeCalled(); return returnVal; } function resolveRevocation(AttestationRecord[] calldata attestation) external payable override returns (bool) { - revert(); onRevokeCalled = true; + emit RevokeCalled(); return returnVal; } @@ -64,6 +70,7 @@ contract MockCombination is IExternalResolver, IExternalSchemaValidator { returns (bool) { onModuleCalled = true; + emit ModuleCalled(); return returnVal; } From 7a38769989411e4d0ef23f19c06b93595c65d1e8 Mon Sep 17 00:00:00 2001 From: kopy-kat Date: Fri, 23 Aug 2024 11:10:56 +0200 Subject: [PATCH 3/3] feat: remove storage from mock combination --- test/mocks/MockCombination.sol | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/test/mocks/MockCombination.sol b/test/mocks/MockCombination.sol index 6e55130..1132d3d 100644 --- a/test/mocks/MockCombination.sol +++ b/test/mocks/MockCombination.sol @@ -12,10 +12,6 @@ contract MockCombination is IExternalResolver, IExternalSchemaValidator { event RevokeCalled(); event ModuleCalled(); - bool public onAttestCalled; - bool public onRevokeCalled; - bool public onModuleCalled; - constructor(bool ret) { returnVal = ret; } @@ -24,36 +20,26 @@ contract MockCombination is IExternalResolver, IExternalSchemaValidator { RESOLVER //////////////////////////////////////////////////////////////////////////*/ - function reset() public { - onAttestCalled = false; - onRevokeCalled = false; - onModuleCalled = false; - } - function supportsInterface(bytes4 interfaceId) public pure override returns (bool) { if (interfaceId == type(IExternalResolver).interfaceId || interfaceId == type(IExternalSchemaValidator).interfaceId) return true; } function resolveAttestation(AttestationRecord calldata attestation) external payable override returns (bool) { - onAttestCalled = true; emit AttestationCalled(); return returnVal; } function resolveAttestation(AttestationRecord[] calldata attestation) external payable override returns (bool) { - onAttestCalled = true; emit AttestationCalled(); return returnVal; } function resolveRevocation(AttestationRecord calldata attestation) external payable override returns (bool) { - onRevokeCalled = true; emit RevokeCalled(); return returnVal; } function resolveRevocation(AttestationRecord[] calldata attestation) external payable override returns (bool) { - onRevokeCalled = true; emit RevokeCalled(); return returnVal; } @@ -69,7 +55,6 @@ contract MockCombination is IExternalResolver, IExternalSchemaValidator { override returns (bool) { - onModuleCalled = true; emit ModuleCalled(); return returnVal; }