Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
andresaiello committed Oct 9, 2023
1 parent baa2e37 commit 1a61a75
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/zevm-app-contracts/test/zeta-points/InvitationManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { expect, use } from "chai";
import { solidity } from "ethereum-waffle";
use(solidity);
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { ethers } from "hardhat";

import type { InvitationManager } from "../../typechain-types";
import { getInvitationSig } from "./test.helpers";

describe("InvitationManager Contract test", () => {
let invitationManager: InvitationManager, inviter: SignerWithAddress, invitee: SignerWithAddress, addrs: SignerWithAddress[];

beforeEach(async () => {
[inviter, invitee, ...addrs] = await ethers.getSigners();
const InvitationManager = await ethers.getContractFactory("InvitationManager");
//@ts-ignore
invitationManager = await InvitationManager.deploy();
});

describe("True", () => {
it("Should be true", async () => {
expect(true).to.equal(true);
});
});

describe("Invitations test", () => {
it("Should verify an invitation and store it", async () => {
const sig = await getInvitationSig(inviter, invitee.address);
const tx = await invitationManager.connect(invitee).confirmAndAcceptInvitation(inviter.address, sig);
const rec = await tx.wait();

const block = await ethers.provider.getBlock(rec.blockNumber);

const invitation = await invitationManager.acceptedInvitationsTimestamp(inviter.address, invitee.address);
await expect(invitation).to.be.eq(block.timestamp);
});

it("Should revert if invitation is invalid", async () => {
const sig = await getInvitationSig(inviter, addrs[0].address);
const tx = invitationManager.connect(invitee).confirmAndAcceptInvitation(inviter.address, sig);
await expect(tx).to.be.revertedWith("UnrecognizedInvitation");
});
});
});
14 changes: 14 additions & 0 deletions packages/zevm-app-contracts/test/zeta-points/test.helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ts-ignore
import { BigNumber } from "@ethersproject/bignumber";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { ethers, network } from "hardhat";

export const getInvitationSig = async (signer: SignerWithAddress, invitee: string) => {
let payload = ethers.utils.defaultAbiCoder.encode(["address", "address"], [signer.address, invitee]);

let payloadHash = ethers.utils.keccak256(payload);

// This adds the message prefix
let signature = await signer.signMessage(ethers.utils.arrayify(payloadHash));
return ethers.utils.splitSignature(signature);
};

0 comments on commit 1a61a75

Please sign in to comment.