-
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
5715168
commit ae9aad8
Showing
4 changed files
with
113 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
94 changes: 94 additions & 0 deletions
94
packages/zevm-app-contracts/test/instant-rewards/instant-rewards-v2.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,94 @@ | ||
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 { InstantRewardsFactory, InstantRewardsV2 } from "../../typechain-types"; | ||
import { ClaimData, getSignature } from "./test.helpers"; | ||
|
||
const HARDHAT_CHAIN_ID = 1337; | ||
|
||
describe("Instant Rewards Contract test", () => { | ||
let instantRewardsFactory: InstantRewardsFactory, | ||
deployer: SignerWithAddress, | ||
owner: SignerWithAddress, | ||
signer: SignerWithAddress, | ||
user: SignerWithAddress, | ||
addrs: SignerWithAddress[]; | ||
|
||
const encodeTaskId = (taskId: string) => utils.keccak256(utils.defaultAbiCoder.encode(["string"], [taskId])); | ||
|
||
const getClaimDataSigned = async ( | ||
chainId: number, | ||
verifyingContract: string, | ||
signer: SignerWithAddress, | ||
amount: BigNumber, | ||
sigExpiration: number, | ||
taskId: string, | ||
to: string | ||
) => { | ||
const claimData: ClaimData = { | ||
amount, | ||
sigExpiration, | ||
taskId, | ||
to, | ||
}; | ||
|
||
const signature = await getSignature(chainId, verifyingContract, signer, claimData); | ||
return { | ||
...claimData, | ||
signature, | ||
}; | ||
}; | ||
|
||
beforeEach(async () => { | ||
[deployer, owner, signer, user, ...addrs] = await ethers.getSigners(); | ||
const instantRewardsFactoryF = await ethers.getContractFactory("InstantRewardsFactory"); | ||
instantRewardsFactory = (await instantRewardsFactoryF.deploy(owner.address)) as InstantRewardsFactory; | ||
await instantRewardsFactory.deployed(); | ||
await instantRewardsFactory.connect(owner).acceptOwnership(); | ||
}); | ||
|
||
it("Should deploy an IR instance", async () => { | ||
const currentBlock = await ethers.provider.getBlock("latest"); | ||
const start = currentBlock.timestamp + 1000; | ||
const end = start + 1000; | ||
const name = "Instant Rewards"; | ||
const tx = instantRewardsFactory.connect(owner).createInstantRewards(signer.address, start, end, name); | ||
await expect(tx).to.emit(instantRewardsFactory, "InstantRewardsCreated"); | ||
|
||
const events = await instantRewardsFactory.queryFilter("InstantRewardsCreated"); | ||
const address = events[0].args?.instantRewards; | ||
expect(address).to.be.not.undefined; | ||
|
||
const instantRewards = (await ethers.getContractAt("InstantRewardsV2", address)) as InstantRewardsV2; | ||
expect(await instantRewards.signerAddress()).to.be.eq(signer.address); | ||
expect(await instantRewards.start()).to.be.eq(start); | ||
expect(await instantRewards.end()).to.be.eq(end); | ||
expect(await instantRewards.name()).to.be.eq(name); | ||
|
||
await instantRewards.connect(owner).acceptOwnership(); | ||
expect(await instantRewards.owner()).to.be.eq(owner.address); | ||
}); | ||
|
||
it("Should revert if not owner try to deploy", async () => { | ||
const currentBlock = await ethers.provider.getBlock("latest"); | ||
const start = currentBlock.timestamp + 1000; | ||
const end = start + 1000; | ||
const name = "Instant Rewards"; | ||
const tx = instantRewardsFactory.createInstantRewards(signer.address, start, end, name); | ||
await expect(tx).to.revertedWith("AccessDenied"); | ||
}); | ||
|
||
it("Should deploy an IR instance with any wallet if it's open", async () => { | ||
await instantRewardsFactory.connect(owner).setAllowPublicCreation(true); | ||
|
||
const currentBlock = await ethers.provider.getBlock("latest"); | ||
const start = currentBlock.timestamp + 1000; | ||
const end = start + 1000; | ||
const name = "Instant Rewards"; | ||
const tx = instantRewardsFactory.createInstantRewards(signer.address, start, end, name); | ||
await expect(tx).to.emit(instantRewardsFactory, "InstantRewardsCreated"); | ||
}); | ||
}); |