Skip to content

Commit

Permalink
Merge pull request #6 from blockful-io/fix#isAttesterHostFunction
Browse files Browse the repository at this point in the history
Fix#is attester host function
  • Loading branch information
RafaDSan authored Nov 14, 2024
2 parents 37bc13e + 9476fff commit ac8c6f2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/resolver/Resolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { IResolver } from "../interfaces/IResolver.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { AccessDenied, InvalidEAS, InvalidLength, uncheckedInc, EMPTY_UID, NO_EXPIRATION_TIME, Session, slice } from "../Common.sol";


error AlreadyHasResponse();
error InsufficientValue();
error InvalidAttestationTitle();
Expand Down Expand Up @@ -245,9 +244,15 @@ contract Resolver is IResolver, AccessControl {
/// @dev Checks if the attester is the host of the session
function isAttesterHost(address attester, string memory title) internal view returns (bool) {
bytes memory titleBytes = bytes(title);
string memory sessionTitle = string(slice(titleBytes, 5, titleBytes.length - 5));
bytes32 sessionId = keccak256(abi.encodePacked(attester, sessionTitle));

bytes32 sessionId;
if (keccak256(abi.encodePacked(slice(titleBytes, 0, 5))) == keccak256("Host_")) {
string memory sessionTitle = string(slice(titleBytes, 5, titleBytes.length-5));
sessionId = keccak256(abi.encodePacked(attester, sessionTitle));
}
else if (keccak256(abi.encodePacked(slice(titleBytes, 0, 9))) == keccak256("Attendee_")) {
string memory sessionTitle = string(slice(titleBytes, 9, titleBytes.length - 9));
sessionId = keccak256(abi.encodePacked(attester, sessionTitle));
}
return _session[sessionId].host == attester;
}

Expand Down
36 changes: 36 additions & 0 deletions test/Resolver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,42 @@ contract ResolverTest is Test {
vm.stopPrank();
}


function test_attendee_attestation_allowed() public {
bytes32[] memory uids = test_access_control_add_schemas();
address host = roleReceiver;
address atendee = address(0x5678);

string memory sessionTitle = "TestSession";
grantRole(VILLAGER_ROLE, roleReceiver);
grantRole(VILLAGER_ROLE, atendee);

// Create a session
vm.startPrank(host);
resolver.createSession(10, sessionTitle);

// Prepare attestation data
string memory attendeeTitle = string(abi.encodePacked("Attendee_", sessionTitle));
bytes memory attestationData = abi.encode(attendeeTitle, "Test comment");

// Create attestation request
AttestationRequest memory request = AttestationRequest({
schema: uids[2],
data: AttestationRequestData({
recipient: address(0x5678),
expirationTime: 0,
revocable: false,
refUID: bytes32(0),
data: attestationData,
value: 0
})
});

bytes32 attestationUID = eas.attest(request);
vm.stopPrank();
assertTrue(eas.isAttestationValid(attestationUID), "Attestation should be valid");
}

function test_create_session_as_villager() public {
address villager = roleReceiver;
string memory sessionTitle = "Test Session";
Expand Down

0 comments on commit ac8c6f2

Please sign in to comment.