Files
onchain-id/test/proxy.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

66 lines
3.5 KiB
TypeScript

import {expect} from "chai";
import {ethers} from "hardhat";
import {loadFixture} from "@nomicfoundation/hardhat-network-helpers";
import {deployIdentityFixture} from "./fixtures";
describe('Proxy', () => {
it('should revert because implementation is Zero address', async () => {
const [deployerWallet, identityOwnerWallet] = await ethers.getSigners();
const IdentityProxy = await ethers.getContractFactory('IdentityProxy');
await expect(IdentityProxy.connect(deployerWallet).deploy(ethers.constants.AddressZero, identityOwnerWallet.address)).to.be.revertedWith('invalid argument - zero address');
});
it('should revert because implementation is not an identity', async () => {
const [deployerWallet, identityOwnerWallet] = await ethers.getSigners();
const claimIssuer = await ethers.deployContract('Test');
const authority = await ethers.deployContract('ImplementationAuthority', [claimIssuer.address]);
const IdentityProxy = await ethers.getContractFactory('IdentityProxy');
await expect(IdentityProxy.connect(deployerWallet).deploy(authority.address, identityOwnerWallet.address)).to.be.revertedWith('Initialization failed.');
});
it('should revert because initial key is Zero address', async () => {
const [deployerWallet] = await ethers.getSigners();
const implementation = await ethers.deployContract('Identity', [deployerWallet.address, true]);
const implementationAuthority = await ethers.deployContract('ImplementationAuthority', [implementation.address]);
const IdentityProxy = await ethers.getContractFactory('IdentityProxy');
await expect(IdentityProxy.connect(deployerWallet).deploy(implementationAuthority.address, ethers.constants.AddressZero)).to.be.revertedWith('invalid argument - zero address');
});
it('should prevent creating an implementation authority with a zero address implementation', async () => {
const [deployerWallet] = await ethers.getSigners();
const ImplementationAuthority = await ethers.getContractFactory('ImplementationAuthority');
await expect(ImplementationAuthority.connect(deployerWallet).deploy(ethers.constants.AddressZero)).to.be.revertedWith('invalid argument - zero address');
});
it('should prevent updating to a Zero address implementation', async () => {
const {implementationAuthority, deployerWallet} = await loadFixture(deployIdentityFixture);
await expect(implementationAuthority.connect(deployerWallet).updateImplementation(ethers.constants.AddressZero)).to.be.revertedWith('invalid argument - zero address');
});
it('should prevent updating when not owner', async () => {
const {implementationAuthority, aliceWallet} = await loadFixture(deployIdentityFixture);
await expect(implementationAuthority.connect(aliceWallet).updateImplementation(ethers.constants.AddressZero)).to.be.revertedWith('Ownable: caller is not the owner');
});
it('should update the implementation address', async () => {
const [deployerWallet] = await ethers.getSigners();
const implementation = await ethers.deployContract('Identity', [deployerWallet.address, true]);
const implementationAuthority = await ethers.deployContract('ImplementationAuthority', [implementation.address]);
const newImplementation = await ethers.deployContract('Identity', [deployerWallet.address, true]);
const tx = await implementationAuthority.connect(deployerWallet).updateImplementation(newImplementation.address);
await expect(tx).to.emit(implementationAuthority, 'UpdatedImplementation').withArgs(newImplementation.address);
});
});