import { describe } from "mocha"; import hre from "hardhat"; import { BigNumber } from "ethers"; import { expect } from "chai"; import { CommitmentMapperTester } from "../packages/commitment-mapper-tester-js/src/commitmentMapperTester"; import { OWNERSHIP_SIGNATURE_MESSAGE } from "../packages/commitment-mapper-tester-js/src/constants"; describe("Sismo mocked comintment mapper", () => { let comintmentMapper: CommitmentMapperTester; let account: string; let messageSigned: string; let secret: any; let signer: any; before(async () => { comintmentMapper = await CommitmentMapperTester.generate(); const signers = await hre.ethers.getSigners(); signer = signers[0]; account = await signer.getAddress(); messageSigned = await signer.signMessage(OWNERSHIP_SIGNATURE_MESSAGE); secret = BigNumber.from(1); }) it("Should generete the commitment proof", async () => { messageSigned = await signer.signMessage(OWNERSHIP_SIGNATURE_MESSAGE); const commitmentReceipt = await comintmentMapper.commit(account, messageSigned, secret); expect(BigNumber.from(commitmentReceipt[0]).toHexString()).to.equal("0x1de710b30b7ec9da702ea25cc3d0b4854061a5fa7d19662e83da3b9be9e58436"); expect(BigNumber.from(commitmentReceipt[1]).toHexString()).to.equal("0x18273b6c3d0da8a80c79a92535b8819fec3284343e9d455c67e577e7fca58c72"); expect(BigNumber.from(commitmentReceipt[2]).toHexString()).to.equal("0x030aa6586eee4fc15061e4cc92476bd5673e56f2dce537900df5c4da3682196c"); }); it("Should throw when trying to commit a second time with another secret", async () => { try { await comintmentMapper.commit(account, messageSigned, BigNumber.from(2)); } catch (e: any) { expect(e.message).to.have.string("Ethereum address already commited with another secret"); } }); it('Should throw when trying to generate a Merkle tree without hash function.', async () => { try { const incorrectSignedMessage = await signer.signMessage("This is an incorect signature"); await comintmentMapper.commit(account, incorrectSignedMessage, BigNumber.from(1)); } catch (e: any) { expect(e.message).to.have.string("Invalid signature"); } }); })