Skip to content

Commit

Permalink
fixed tests #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvolear committed Jun 12, 2024
1 parent 064da3b commit c45e740
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
3 changes: 3 additions & 0 deletions test/registration/Registration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ describe("Registration", () => {
expect(await registration.registerCertificate(certificate, icaoMember, proof))
.to.emit(registration, "CertificateRegistered")
.withArgs("0x143607139f5db6f9af9db0c948d40a61c10493ddedb629499095cce3104d4b72");
expect(
await stateKeeper.getCertificateInfo("0x143607139f5db6f9af9db0c948d40a61c10493ddedb629499095cce3104d4b72"),
).to.deep.equal([1915341686n]);
});
});

Expand Down
14 changes: 13 additions & 1 deletion test/state/PoseidonSMT.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { ethers } from "hardhat";
import { HDNodeWallet } from "ethers";
import { HDNodeWallet, ZeroHash } from "ethers";

import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";

Expand Down Expand Up @@ -51,6 +51,18 @@ describe("PoseidonSMT", () => {

afterEach(reverter.revert);

describe("access", () => {
it("should not be called by non-registrations", async () => {
await expect(tree.connect(ADDRESS1).add(ZeroHash, ZeroHash)).to.be.rejectedWith(
"PoseidonSMT: not a state keeper",
);
await expect(tree.connect(ADDRESS1).update(ZeroHash, ZeroHash)).to.be.rejectedWith(
"PoseidonSMT: not a state keeper",
);
await expect(tree.connect(ADDRESS1).remove(ZeroHash)).to.be.rejectedWith("PoseidonSMT: not a state keeper");
});
});

describe("$init flow", () => {
describe("#init", () => {
it("should not initialize twice", async () => {
Expand Down
34 changes: 32 additions & 2 deletions test/state/StateKeeper.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { ethers } from "hardhat";
import { HDNodeWallet } from "ethers";
import { HDNodeWallet, ZeroAddress, ZeroHash } from "ethers";

import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";

Expand Down Expand Up @@ -81,7 +81,20 @@ describe("StateKeeper", () => {

afterEach(reverter.revert);

describe("$TSS flow", async () => {
describe("access", () => {
it("should not be called by non-registrations", async () => {
await expect(stateKeeper.addCertificate(ZeroHash, 0)).to.be.rejectedWith("StateKeeper: not a registration");
await expect(stateKeeper.removeCertificate(ZeroHash)).to.be.rejectedWith("StateKeeper: not a registration");
await expect(stateKeeper.addBond(ZeroHash, ZeroHash, 0)).to.be.rejectedWith("StateKeeper: not a registration");
await expect(stateKeeper.revokeBond(ZeroHash, ZeroHash)).to.be.rejectedWith("StateKeeper: not a registration");
await expect(stateKeeper.reissueBondIdentity(ZeroHash, ZeroHash, 0)).to.be.rejectedWith(
"StateKeeper: not a registration",
);
await expect(stateKeeper.useSignature(ZeroHash)).to.be.rejectedWith("StateKeeper: not a registration");
});
});

describe("$TSS flow", () => {
describe("#changeICAOMasterTreeRoot", () => {
const newIcaoMerkleRoot = "0x3c50ce3aa92bc3dd0351a89970b02630415547ea83c487befbc8b1795ea90c45";
const timestamp = "123456";
Expand Down Expand Up @@ -170,6 +183,8 @@ describe("StateKeeper", () => {

expect(await stateKeeper.isRegistration(ADDRESS1.address)).to.be.true;
expect(await stateKeeper.isRegistration(ADDRESS2.address)).to.be.false;
expect(await stateKeeper.getRegistrationByKey(REG1)).to.equal(ADDRESS1.address);
expect(await stateKeeper.getRegistrationByKey(REG2)).to.equal(ZeroAddress);
});

it("should not be able to add/remove with invalid signer", async () => {
Expand Down Expand Up @@ -216,6 +231,21 @@ describe("StateKeeper", () => {
stateKeeper.updateRegistrationSet(StateKeeperMethodId.AddRegistrations, operation.data, operation.proof),
).to.be.rejectedWith("TSSSigner: invalid signature");
});

it("should revert if invalid operation was signed", async () => {
const hash = merkleTree.getArbitraryDataSignHash(
StateKeeperMethodId.None,
ethers.ZeroAddress,
chainName,
await stateKeeper.getNonce(StateKeeperMethodId.None),
await stateKeeper.getAddress(),
);
const signature = merkleTree.getProof(hash, true, undefined);

await expect(
stateKeeper.updateRegistrationSet(StateKeeperMethodId.None, ethers.ZeroAddress, signature),
).to.be.rejectedWith("StateKeeper: Invalid method");
});
});
});
});

0 comments on commit c45e740

Please sign in to comment.