Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andresaiello committed Aug 23, 2024
1 parent 7905bed commit 85c6268
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { BigNumber, utils } from "ethers";
import { parseEther } from "ethers/lib/utils";
import { ethers } from "hardhat";

import { InstantRewards } from "../../typechain-types";
Expand Down Expand Up @@ -127,6 +128,72 @@ describe("Instant Rewards Contract test", () => {
await expect(tx).to.revertedWith("Pausable: paused");
});

it("Should revert if try to claim twice with same signature", async () => {
const currentBlock = await ethers.provider.getBlock("latest");
const sigExpiration = currentBlock.timestamp + 1000;
const amount = utils.parseEther("1");
const taskId = encodeTaskId("WALLET/TASK/EPOC");
const to = owner.address;

// transfer some funds to the contract
await owner.sendTransaction({
to: instantRewards.address,
value: amount,
});

const claimDataSigned = await getClaimDataSigned(signer, amount, sigExpiration, taskId, to);

instantRewards.claim(claimDataSigned);

const tx = instantRewards.claim(claimDataSigned);
await expect(tx).to.revertedWith("TaskAlreadyClaimed");
});

it("Should revert if try to claim same task with another signature", async () => {
const currentBlock = await ethers.provider.getBlock("latest");
const sigExpiration = currentBlock.timestamp + 1000;
const amount = utils.parseEther("1");
const taskId = encodeTaskId("WALLET/TASK/EPOC");
const to = owner.address;

// transfer some funds to the contract
await owner.sendTransaction({
to: instantRewards.address,
value: amount,
});

{
const claimDataSigned = await getClaimDataSigned(signer, amount, sigExpiration, taskId, to);
instantRewards.claim(claimDataSigned);
}
const claimDataSigned = await getClaimDataSigned(signer, amount.add(parseEther("1")), sigExpiration, taskId, to);
const tx = instantRewards.claim(claimDataSigned);
await expect(tx).to.revertedWith("TaskAlreadyClaimed");
});

it("Should revert if try to claim with an old valid signature if a new one was used", async () => {
const currentBlock = await ethers.provider.getBlock("latest");
const sigExpiration = currentBlock.timestamp + 1000;
const amount = utils.parseEther("2");
const taskId = encodeTaskId("WALLET/TASK/EPOC");
const to = owner.address;

// transfer some funds to the contract
await owner.sendTransaction({
to: instantRewards.address,
value: amount,
});

const claimDataSigned = await getClaimDataSigned(signer, amount, sigExpiration, taskId, to);

const newClaimDataSigned = await getClaimDataSigned(signer, amount, sigExpiration + 1000, taskId, to);

instantRewards.claim(newClaimDataSigned);

const tx = instantRewards.claim(claimDataSigned);
await expect(tx).to.revertedWith("TaskAlreadyClaimed");
});

it("Should revert if not owner try to pause", async () => {
const tx = instantRewards.connect(user).pause();
await expect(tx).to.revertedWith("Ownable: caller is not the owner");
Expand Down

0 comments on commit 85c6268

Please sign in to comment.