-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
baa2e37
commit 1a61a75
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/zevm-app-contracts/test/zeta-points/InvitationManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
packages/zevm-app-contracts/test/zeta-points/test.helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |