From 406e8f4769a04be81354c32c9c856451bf784741 Mon Sep 17 00:00:00 2001 From: zeroknots Date: Wed, 21 Feb 2024 13:43:29 +0700 Subject: [PATCH] fix: more coverage fic: more coverage --- test/Attestation.t.sol | 57 +++++++++++++++++++++++++++++++++++++ test/SchemaValidation.t.sol | 11 ++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/test/Attestation.t.sol b/test/Attestation.t.sol index 5d6beb12..981825f9 100644 --- a/test/Attestation.t.sol +++ b/test/Attestation.t.sol @@ -45,6 +45,63 @@ contract AttestationTest is BaseTest { assertEq(record.attester, attester1.addr); } + function test_WhenUsingValidMulti() public prankWithAccount(attester1) { + // It should recover. + uint32[] memory types = new uint32[](1); + + AttestationRequest[] memory requests = new AttestationRequest[](2); + requests[0] = mockAttestation(address(module1), uint48(block.timestamp + 100), "", types); + requests[1] = mockAttestation(address(module2), uint48(block.timestamp + 100), "", types); + + registry.attest(defaultSchemaUID, requests); + + AttestationRecord memory record = registry.findAttestation(address(module1), attester1.addr); + + assertEq(record.time, block.timestamp); + assertEq(record.expirationTime, requests[0].expirationTime); + assertEq(record.moduleAddr, requests[0].moduleAddr); + assertEq(record.attester, attester1.addr); + } + + function test_WhenUsingValidMulti__Revocation() public { + test_WhenUsingValidMulti(); + + RevocationRequest[] memory requests = new RevocationRequest[](2); + requests[0] = mockRevocation(address(module1)); + requests[1] = mockRevocation(address(module2)); + vm.prank(attester1.addr); + registry.revoke(requests); + } + + function test_findAttestation() public { + // It should recover. + uint32[] memory types = new uint32[](1); + + AttestationRequest[] memory requests = new AttestationRequest[](2); + requests[0] = mockAttestation(address(module1), uint48(block.timestamp + 100), "", types); + requests[1] = mockAttestation(address(module2), uint48(block.timestamp + 100), "", types); + + vm.prank(attester1.addr); + registry.attest(defaultSchemaUID, requests); + vm.prank(attester2.addr); + registry.attest(defaultSchemaUID, requests); + + address[] memory attesters = new address[](2); + attesters[0] = attester1.addr; + attesters[1] = attester2.addr; + AttestationRecord[] memory record = registry.findAttestations(address(module1), attesters); + + assertEq(record[0].time, block.timestamp); + assertEq(record[0].expirationTime, requests[0].expirationTime); + assertEq(record[0].moduleAddr, requests[0].moduleAddr); + assertEq(record[0].attester, attester1.addr); + + assertEq(record[1].time, block.timestamp); + assertEq(record[1].expirationTime, requests[0].expirationTime); + assertEq(record[1].moduleAddr, requests[0].moduleAddr); + assertEq(record[1].attester, attester2.addr); + } + function test_WhenReAttestingToARevokedAttestation() public prankWithAccount(attester1) { address module = address(new MockModule()); registry.registerModule(defaultResolverUID, module, ""); diff --git a/test/SchemaValidation.t.sol b/test/SchemaValidation.t.sol index 39a829b7..ce96eff6 100644 --- a/test/SchemaValidation.t.sol +++ b/test/SchemaValidation.t.sol @@ -12,16 +12,25 @@ contract SchemaValidationTest is BaseTest { string memory schema = "schema"; SchemaUID uid = registry.registerSchema(schema, IExternalSchemaValidator(address(0))); SchemaUID uid1 = registry.registerSchema(schema, IExternalSchemaValidator(address(schemaValidatorFalse))); + vm.expectRevert(); + uid1 = registry.registerSchema(schema, IExternalSchemaValidator(address(schemaValidatorFalse))); assertTrue(uid != uid1); + } function test_WhenSchemaNew() external whenRegisteringNewSchema { // It should register schema. string memory schema = "schema"; - SchemaUID uid = registry.registerSchema(schema, IExternalSchemaValidator(address(0))); + SchemaUID uid = registry.registerSchema(schema, IExternalSchemaValidator(address(schemaValidatorFalse))); assertTrue(uid != SchemaUID.wrap(bytes32(0))); + + + SchemaRecord memory record = registry.findSchema(uid); + assertEq(record.registeredAt, block.timestamp); + assertEq(keccak256(abi.encodePacked(record.schema)), keccak256(abi.encodePacked(schema))); + assertTrue(record.validator == IExternalSchemaValidator(address(schemaValidatorFalse))); } }