Skip to content

Commit

Permalink
clean: add NatSpec
Browse files Browse the repository at this point in the history
feature/add_sample
  • Loading branch information
kaiadachi committed Nov 29, 2024
1 parent 8cdbd73 commit c306428
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
- name: Install dependencies
run: bun i

- name: Create remappings
run: forge remappings > remappings.txt

- name: Run Forge build
run: |
forge --version
Expand Down
40 changes: 39 additions & 1 deletion test/SignProtocolExample.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ import { Attestation } from "@ethsign/sign-protocol-evm/src/models/Attestation.s
* @dev Demonstrates basic schema registration and attestation creation
*/
contract SignProtocolExample is Test {
// ============ Storage ============
ISP public sp;
WhitelistHook public whitelistHook;
uint64 public schemaId;

address public constant EXAMPLE_ATTESTER = 0x55D22d83752a9bE59B8959f97FCf3b2CAbca5094;

/**
* @notice Set up the test environment
* @dev Deploys SP, initializes WhitelistHook, and registers schema
*/
function setUp() external {
sp = new SP();
SP(address(sp)).initialize(1, 1);
Expand All @@ -32,6 +37,10 @@ contract SignProtocolExample is Test {
schemaId = sp.register(schema, "");
}

/**
* @notice Test the basic attestation flow
* @dev Creates and verifies a simple attestation
*/
function test_attestationFlow() external {
bytes memory data = encodeData("exampleId", "exampleField", block.timestamp);

Expand All @@ -43,6 +52,10 @@ contract SignProtocolExample is Test {
_verifyAttestation(attestationId);
}

/**
* @notice Creates a schema definition
* @return Schema memory The created schema
*/
function _createSchema() internal view returns (Schema memory) {
return Schema({
registrant: address(this),
Expand All @@ -55,6 +68,11 @@ contract SignProtocolExample is Test {
});
}

/**
* @notice Creates an attestation with the given data
* @param data The encoded attestation data
* @return Attestation memory The created attestation
*/
function _createAttestation(bytes memory data) internal view returns (Attestation memory) {
return Attestation({
schemaId: schemaId,
Expand All @@ -70,7 +88,11 @@ contract SignProtocolExample is Test {
});
}

function _verifyAttestation(uint64 attestationId) internal {
/**
* @notice Verifies an attestation's data
* @param attestationId The ID of the attestation to verify
*/
function _verifyAttestation(uint64 attestationId) internal view {
Attestation memory storedAttestation = sp.getAttestation(attestationId);
(string memory id, string memory field, uint256 timestamp) = decodeData(storedAttestation.data);

Expand All @@ -79,15 +101,31 @@ contract SignProtocolExample is Test {
assertEq(timestamp, block.timestamp);
}

/**
* @notice Returns the schema data definition
* @return string memory The schema data in JSON format
*/
function _getSchemaData() internal pure returns (string memory) {
return "{\"name\":\"ExampleSchema\",\"data\":[{\"name\":\"id\",\"type\":\"string\"},"
"{\"name\":\"field\",\"type\":\"string\"},{\"name\":\"timestamp\",\"type\":\"uint256\"}]}";
}

/**
* @notice Encodes the attestation data
* @param id The ID field
* @param field The example field
* @param timestamp The timestamp
* @return bytes memory The encoded data
*/
function encodeData(string memory id, string memory field, uint256 timestamp) public pure returns (bytes memory) {
return abi.encode(id, field, timestamp);
}

/**
* @notice Decodes the attestation data
* @param data The encoded data
* @return tuple containing decoded id, field, and timestamp
*/
function decodeData(bytes memory data) public pure returns (string memory, string memory, uint256) {
return abi.decode(data, (string, string, uint256));
}
Expand Down

0 comments on commit c306428

Please sign in to comment.