-
Notifications
You must be signed in to change notification settings - Fork 18
feature/guild-skill-badge-v2-solidity #186
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
Merged
joelamouche
merged 4 commits into
TheSoftwareDevGuild:main
from
adityagupta0251:feat/guild-skill-badge
Apr 15, 2026
+291
−34
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
the-guild-smart-contracts/src/TheGuildInternalResolver.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| import {SchemaResolver} from "eas-contracts/resolver/SchemaResolver.sol"; | ||
| import {IEAS, Attestation} from "eas-contracts/IEAS.sol"; | ||
| import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol"; | ||
|
|
||
| /// @title TheGuildInternalResolver | ||
| /// @notice EAS schema resolver that restricts attestations to authorized Guild accounts only. | ||
| contract TheGuildInternalResolver is SchemaResolver, Ownable { | ||
| mapping(address => bool) private _authorizedAttesters; | ||
|
|
||
| event AttesterAuthorized(address indexed attester, bool authorized); | ||
|
|
||
| constructor(IEAS eas, address initialOwner) SchemaResolver(eas) Ownable(initialOwner) { | ||
| _authorizedAttesters[initialOwner] = true; | ||
| emit AttesterAuthorized(initialOwner, true); | ||
| } | ||
|
|
||
| /// @notice Authorize or deauthorize an account to create attestations. | ||
| function setAuthorizedAttester(address attester, bool authorized) external onlyOwner { | ||
| _authorizedAttesters[attester] = authorized; | ||
| emit AttesterAuthorized(attester, authorized); | ||
| } | ||
|
|
||
| /// @notice Check if an account is an authorized attester. | ||
| function isAuthorizedAttester(address attester) public view returns (bool) { | ||
| return _authorizedAttesters[attester]; | ||
| } | ||
|
|
||
| /// @inheritdoc SchemaResolver | ||
| function onAttest( | ||
| Attestation calldata attestation, | ||
| uint256 | ||
| ) internal view override returns (bool) { | ||
| return _authorizedAttesters[attestation.attester]; | ||
| } | ||
|
|
||
| /// @inheritdoc SchemaResolver | ||
| function onRevoke( | ||
| Attestation calldata attestation, | ||
| uint256 | ||
| ) internal view override returns (bool) { | ||
| return _authorizedAttesters[attestation.attester]; | ||
| } | ||
| } |
214 changes: 214 additions & 0 deletions
214
the-guild-smart-contracts/test/TheGuildInternalResolver.t.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| import {Test} from "forge-std/Test.sol"; | ||
| import {TheGuildInternalResolver} from "../src/TheGuildInternalResolver.sol"; | ||
|
|
||
|
|
||
| import {EAS} from "eas-contracts/EAS.sol"; | ||
| import {SchemaRegistry} from "eas-contracts/SchemaRegistry.sol"; | ||
| import {IEAS, AttestationRequest, AttestationRequestData, Attestation, RevocationRequestData, RevocationRequest} from "eas-contracts/IEAS.sol"; | ||
|
|
||
| contract TheGuildInternalResolverTest is Test { | ||
| TheGuildInternalResolver private resolver; | ||
| SchemaRegistry private schemaRegistry; | ||
| EAS private eas; | ||
|
|
||
| address private owner = address(this); | ||
| address private authorizedAttester = address(0xA11CE); | ||
| address private unauthorizedAttester = address(0xBEEF); | ||
| address private recipient = address(0xCAFE); | ||
|
|
||
| function setUp() public { | ||
|
|
||
| schemaRegistry = new SchemaRegistry(); | ||
| eas = new EAS(schemaRegistry); | ||
|
|
||
|
|
||
| resolver = new TheGuildInternalResolver( | ||
| IEAS(address(eas)), | ||
| owner | ||
| ); | ||
| } | ||
|
|
||
| function _registerSchema() internal returns (bytes32) { | ||
|
|
||
| string memory schema = "string skillDescription, bytes32[] linkedBadges"; | ||
|
|
||
| bytes32 schemaId = schemaRegistry.register(schema, resolver, true); | ||
| return schemaId; | ||
| } | ||
|
|
||
| function test_AttestationByOwnerSucceeds() public { | ||
| bytes32 schemaId = _registerSchema(); | ||
|
|
||
| bytes32[] memory linkedBadges = new bytes32[](2); | ||
| linkedBadges[0] = bytes32("Solidity"); | ||
| linkedBadges[1] = bytes32("Rust"); | ||
|
|
||
| AttestationRequestData memory data = AttestationRequestData({ | ||
| recipient: recipient, | ||
| expirationTime: 0, | ||
| revocable: true, | ||
| refUID: bytes32(0), | ||
| data: abi.encode("Master of Smart Contracts", linkedBadges), | ||
| value: 0 | ||
| }); | ||
|
|
||
| AttestationRequest memory request = AttestationRequest({ | ||
| schema: schemaId, | ||
| data: data | ||
| }); | ||
|
|
||
|
|
||
| eas.attest(request); | ||
|
|
||
| } | ||
|
|
||
| function test_AttestationByAuthorizedAttesterSucceeds() public { | ||
| bytes32 schemaId = _registerSchema(); | ||
| resolver.setAuthorizedAttester(authorizedAttester, true); | ||
|
|
||
| bytes32[] memory linkedBadges = new bytes32[](1); | ||
| linkedBadges[0] = bytes32("Solidity"); | ||
|
|
||
| AttestationRequestData memory data = AttestationRequestData({ | ||
| recipient: recipient, | ||
| expirationTime: 0, | ||
| revocable: true, | ||
| refUID: bytes32(0), | ||
| data: abi.encode("Solidity Dev", linkedBadges), | ||
| value: 0 | ||
| }); | ||
|
|
||
| AttestationRequest memory request = AttestationRequest({ | ||
| schema: schemaId, | ||
| data: data | ||
| }); | ||
|
|
||
| vm.prank(authorizedAttester); | ||
| eas.attest(request); | ||
|
|
||
| } | ||
|
|
||
| function test_AttestationByUnauthorizedAttesterFails() public { | ||
| bytes32 schemaId = _registerSchema(); | ||
|
|
||
| bytes32[] memory linkedBadges = new bytes32[](1); | ||
| linkedBadges[0] = bytes32("Solidity"); | ||
|
|
||
| AttestationRequestData memory data = AttestationRequestData({ | ||
| recipient: recipient, | ||
| expirationTime: 0, | ||
| revocable: true, | ||
| refUID: bytes32(0), | ||
| data: abi.encode("Solidity Dev", linkedBadges), | ||
| value: 0 | ||
| }); | ||
|
|
||
| AttestationRequest memory request = AttestationRequest({ | ||
| schema: schemaId, | ||
| data: data | ||
| }); | ||
|
|
||
| vm.prank(unauthorizedAttester); | ||
| vm.expectRevert(); | ||
| eas.attest(request); | ||
| } | ||
|
|
||
| function test_RevocationByAuthorizedAttesterSucceeds() public { | ||
| bytes32 schemaId = _registerSchema(); | ||
| resolver.setAuthorizedAttester(authorizedAttester, true); | ||
|
|
||
| bytes32[] memory linkedBadges = new bytes32[](1); | ||
| linkedBadges[0] = bytes32("Solidity"); | ||
|
|
||
| AttestationRequestData memory data = AttestationRequestData({ | ||
| recipient: recipient, | ||
| expirationTime: 0, | ||
| revocable: true, | ||
| refUID: bytes32(0), | ||
| data: abi.encode("Solidity Dev", linkedBadges), | ||
| value: 0 | ||
| }); | ||
|
|
||
| AttestationRequest memory request = AttestationRequest({ | ||
| schema: schemaId, | ||
| data: data | ||
| }); | ||
|
|
||
| vm.prank(authorizedAttester); | ||
| bytes32 uid = eas.attest(request); | ||
|
|
||
| vm.prank(authorizedAttester); | ||
| eas.revoke( | ||
| RevocationRequest({ | ||
| schema: schemaId, | ||
| data: RevocationRequestData({uid: uid, value: 0}) | ||
| }) | ||
| ); | ||
| // success == no revert | ||
| } | ||
|
|
||
| function test_RevocationByUnauthorizedAttesterFails() public { | ||
| bytes32 schemaId = _registerSchema(); | ||
| resolver.setAuthorizedAttester(authorizedAttester, true); | ||
|
|
||
| bytes32[] memory linkedBadges = new bytes32[](1); | ||
| linkedBadges[0] = bytes32("Solidity"); | ||
|
|
||
| AttestationRequestData memory data = AttestationRequestData({ | ||
| recipient: recipient, | ||
| expirationTime: 0, | ||
| revocable: true, | ||
| refUID: bytes32(0), | ||
| data: abi.encode("Solidity Dev", linkedBadges), | ||
| value: 0 | ||
| }); | ||
|
|
||
| AttestationRequest memory request = AttestationRequest({ | ||
| schema: schemaId, | ||
| data: data | ||
| }); | ||
|
|
||
| vm.prank(authorizedAttester); | ||
| bytes32 uid = eas.attest(request); | ||
|
|
||
| vm.prank(unauthorizedAttester); | ||
| vm.expectRevert(); | ||
| eas.revoke( | ||
| RevocationRequest({ | ||
| schema: schemaId, | ||
| data: RevocationRequestData({uid: uid, value: 0}) | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| function test_DeauthorizeAttester() public { | ||
| bytes32 schemaId = _registerSchema(); | ||
| resolver.setAuthorizedAttester(authorizedAttester, true); | ||
| assertTrue(resolver.isAuthorizedAttester(authorizedAttester)); | ||
|
|
||
| resolver.setAuthorizedAttester(authorizedAttester, false); | ||
| assertFalse(resolver.isAuthorizedAttester(authorizedAttester)); | ||
|
|
||
| bytes32[] memory linkedBadges = new bytes32[](1); | ||
| linkedBadges[0] = bytes32("Solidity"); | ||
|
|
||
| AttestationRequest memory request = AttestationRequest({ | ||
| schema: schemaId, | ||
| data: AttestationRequestData({ | ||
| recipient: recipient, | ||
| expirationTime: 0, | ||
| revocable: true, | ||
| refUID: bytes32(0), | ||
| data: abi.encode("Solidity Dev", linkedBadges), | ||
| value: 0 | ||
| }) | ||
| }); | ||
|
|
||
| vm.prank(authorizedAttester); | ||
| vm.expectRevert(); | ||
| eas.attest(request); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.