From 85c626877113cdfe6c8d9f9b9432509f495992e3 Mon Sep 17 00:00:00 2001 From: Andres Aiello Date: Fri, 23 Aug 2024 12:22:54 -0300 Subject: [PATCH] add tests --- .../test/instant-rewards/instant-rewards.ts | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/packages/zevm-app-contracts/test/instant-rewards/instant-rewards.ts b/packages/zevm-app-contracts/test/instant-rewards/instant-rewards.ts index 5636949..27ff901 100644 --- a/packages/zevm-app-contracts/test/instant-rewards/instant-rewards.ts +++ b/packages/zevm-app-contracts/test/instant-rewards/instant-rewards.ts @@ -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"; @@ -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");