Files
onchain-id/test/claim-issuers/claim-issuer.test.ts
0407b3bfa4 ONCHAINID v2 (#73)
## [2.0.0]

Version 2.0.0 Audited by Hacken, more details [here](https://tokeny.com/wp-content/uploads/2023/04/Tokeny_ONCHAINID_SC-Audit_Report.pdf)

### Breaking changes

## Deprecation Notice
- ClaimIssuer `revokeClaim` is now deprecated, usage of `revokeClaimBySignature(bytes signature)` is preferred.

### Added
- Add typechain-types (targeting ethers v5).
- Add tests cases for `execute` and `approve` methods.
- Add method `revokeClaimBySignature(bytes signature)` in ClaimIssuer, prefer using this method instead of the now
deprecated `revokeClaim` method.
- Add checks on ClaimIssuer to prevent revoking an already revoked claim.
- Added Factory for ONCHAINIDs

### Updated
- Switch development tooling to hardhat.
- Implemented tests for hardhat (using fixture for faster testing time).
- Prevent calling `approve` method with a non-request execute nonce (added a require on `executionNone`).
- Update NatSpec of `execute` and `approve` methods.

---------

Co-authored-by: Joachim <[email protected]>
2023-04-27 17:27:41 +02:00

89 lines
4.5 KiB
TypeScript

import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
import { expect } from "chai";
import {ethers} from "hardhat";
import {deployIdentityFixture} from "../fixtures";
describe('ClaimIssuer - Reference (with revoke)', () => {
describe('revokeClaim (deprecated)', () => {
describe('when calling as a non MANAGEMENT key', () => {
it('should revert for missing permissions', async () => {
const { claimIssuer, aliceWallet, aliceClaim666 } = await loadFixture(deployIdentityFixture);
await expect(claimIssuer.connect(aliceWallet).revokeClaim(aliceClaim666.id, aliceClaim666.identity)).to.be.revertedWith('Permissions: Sender does not have management key');
});
});
describe("when calling as a MANAGEMENT key", () => {
describe('when claim was already revoked', () => {
it('should revert for conflict', async () => {
const { claimIssuer, claimIssuerWallet, aliceClaim666 } = await loadFixture(deployIdentityFixture);
await claimIssuer.connect(claimIssuerWallet).revokeClaim(aliceClaim666.id, aliceClaim666.identity);
await expect(claimIssuer.connect(claimIssuerWallet).revokeClaim(aliceClaim666.id, aliceClaim666.identity)).to.be.revertedWith('Conflict: Claim already revoked');
});
});
describe('when is not revoked already', () => {
it('should revoke the claim', async () => {
const { claimIssuer, claimIssuerWallet, aliceClaim666 } = await loadFixture(deployIdentityFixture);
expect(await claimIssuer.isClaimValid(aliceClaim666.identity, aliceClaim666.topic, aliceClaim666.signature, aliceClaim666.data)).to.be.true;
const tx = await claimIssuer.connect(claimIssuerWallet).revokeClaim(aliceClaim666.id, aliceClaim666.identity);
await expect(tx).to.emit(claimIssuer, 'ClaimRevoked').withArgs(aliceClaim666.signature);
expect(await claimIssuer.isClaimRevoked(aliceClaim666.signature)).to.be.true;
expect(await claimIssuer.isClaimValid(aliceClaim666.identity, aliceClaim666.topic, aliceClaim666.signature, aliceClaim666.data)).to.be.false;
});
});
});
});
describe('revokeClaimBySignature', () => {
describe('when calling as a non MANAGEMENT key', () => {
it('should revert for missing permissions', async () => {
const { claimIssuer, aliceWallet, aliceClaim666 } = await loadFixture(deployIdentityFixture);
await expect(claimIssuer.connect(aliceWallet).revokeClaimBySignature(aliceClaim666.signature)).to.be.revertedWith('Permissions: Sender does not have management key');
});
});
describe("when calling as a MANAGEMENT key", () => {
describe('when claim was already revoked', () => {
it('should revert for conflict', async () => {
const { claimIssuer, claimIssuerWallet, aliceClaim666 } = await loadFixture(deployIdentityFixture);
await claimIssuer.connect(claimIssuerWallet).revokeClaimBySignature(aliceClaim666.signature);
await expect(claimIssuer.connect(claimIssuerWallet).revokeClaimBySignature(aliceClaim666.signature)).to.be.revertedWith('Conflict: Claim already revoked');
});
});
describe('when is not revoked already', () => {
it('should revoke the claim', async () => {
const { claimIssuer, claimIssuerWallet, aliceClaim666 } = await loadFixture(deployIdentityFixture);
expect(await claimIssuer.isClaimValid(aliceClaim666.identity, aliceClaim666.topic, aliceClaim666.signature, aliceClaim666.data)).to.be.true;
const tx = await claimIssuer.connect(claimIssuerWallet).revokeClaimBySignature(aliceClaim666.signature);
await expect(tx).to.emit(claimIssuer, 'ClaimRevoked').withArgs(aliceClaim666.signature);
expect(await claimIssuer.isClaimRevoked(aliceClaim666.signature)).to.be.true;
expect(await claimIssuer.isClaimValid(aliceClaim666.identity, aliceClaim666.topic, aliceClaim666.signature, aliceClaim666.data)).to.be.false;
});
});
});
});
describe('getRecoveredAddress', () => {
it('should return with a zero address with signature is not of proper length', async () => {
const { claimIssuer, aliceClaim666 } = await loadFixture(deployIdentityFixture);
expect(await claimIssuer.getRecoveredAddress(aliceClaim666.signature + "00", ethers.utils.arrayify(ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(['address', 'uint256', 'bytes'], [aliceClaim666.identity, aliceClaim666.topic, aliceClaim666.data]))))).to.be.equal(ethers.constants.AddressZero);
});
});
});