mirror of
https://github.com/quadratic-gardens/qfi.git
synced 2026-01-10 06:28:12 -05:00
Merge branch 'dev' into feat/devops
This commit is contained in:
@@ -12,3 +12,12 @@ e.g.:
|
||||
```
|
||||
git commit --no-verify
|
||||
```
|
||||
|
||||
## Protocol Diagrams
|
||||
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
|
||||
BIN
assets/QFI-Proofgen.png
Normal file
BIN
assets/QFI-Proofgen.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 537 KiB |
BIN
assets/QFI-Tally.png
Normal file
BIN
assets/QFI-Tally.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 504 KiB |
BIN
assets/QFI-setup.png
Normal file
BIN
assets/QFI-setup.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 239 KiB |
BIN
assets/QFI-voting.png
Normal file
BIN
assets/QFI-voting.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 370 KiB |
@@ -12,6 +12,10 @@
|
||||
"lerna": "^4.0.0",
|
||||
"lint-staged": "^12.3.7"
|
||||
},
|
||||
"resolutions": {
|
||||
"qaci-cli/circomlib": "https://github.com/weijiekoh/circomlib.git#24ed08eee0bb613b8c0135d66c1013bd9f78d50a",
|
||||
"qaci-crypto/circomlib": "https://github.com/weijiekoh/circomlib.git#24ed08eee0bb613b8c0135d66c1013bd9f78d50a"
|
||||
},
|
||||
"workspaces": {
|
||||
"packages": [
|
||||
"packages/*"
|
||||
|
||||
231
packages/contracts/tests/Unit/BaseRecipientRegistry.ts
Normal file
231
packages/contracts/tests/Unit/BaseRecipientRegistry.ts
Normal file
@@ -0,0 +1,231 @@
|
||||
import { ethers } from "hardhat";
|
||||
import { ContractTransaction, ContractReceipt, Signer, constants } from "ethers";
|
||||
import chai from "chai";
|
||||
import { deployContract, deployMockContract, MockContract, solidity, } from "ethereum-waffle";
|
||||
import { SimpleRecipientRegistry } from "../../typechain";
|
||||
|
||||
chai.use(solidity);
|
||||
const { expect } = chai;
|
||||
|
||||
|
||||
describe("Base Recipient Registry", () => {
|
||||
let deployer : Signer
|
||||
let controller : Signer
|
||||
let controllerAddress : string
|
||||
let simpleRecipientRegistry : SimpleRecipientRegistry
|
||||
|
||||
beforeEach(async () => {
|
||||
[deployer, controller] = await ethers.getSigners();
|
||||
controllerAddress = await controller.getAddress()
|
||||
|
||||
const simpleRecipientRegistryFactory = await ethers.getContractFactory("SimpleRecipientRegistry", deployer)
|
||||
simpleRecipientRegistry = await simpleRecipientRegistryFactory.deploy(controllerAddress)
|
||||
});
|
||||
|
||||
it("verify - initializes properly", async () => {
|
||||
const simpleRecipientRegistryDeployTransaction: ContractTransaction = simpleRecipientRegistry.deployTransaction;
|
||||
const txReceipt = await simpleRecipientRegistryDeployTransaction.wait();
|
||||
expect(txReceipt.status).to.not.equal(0);
|
||||
expect(txReceipt.contractAddress).to.equal(simpleRecipientRegistry.address);
|
||||
})
|
||||
|
||||
it("verify - configured properly", async () => {
|
||||
expect(await simpleRecipientRegistry.owner()).to.be.equal(await deployer.getAddress());
|
||||
expect(await simpleRecipientRegistry.controller()).to.equal(controllerAddress)
|
||||
expect(await simpleRecipientRegistry.maxRecipients()).to.equal(0)
|
||||
})
|
||||
|
||||
describe("setMaxRecipients()", async () => {
|
||||
|
||||
it("only allows max recipients to be increased", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(2)
|
||||
expect(simpleRecipientRegistry.connect(controller).setMaxRecipients(1)).
|
||||
to.be.revertedWith('RecipientRegistry: Max number of recipients can not be decreased')
|
||||
})
|
||||
|
||||
it("only allows controller to update max recipients", async () => {
|
||||
expect(await simpleRecipientRegistry.callStatic.setMaxRecipients(2)).to.equal(false)
|
||||
await simpleRecipientRegistry.setMaxRecipients(2)
|
||||
expect(await simpleRecipientRegistry.maxRecipients()).to.equal(0)
|
||||
})
|
||||
|
||||
it("allows max recipients to be updated", async () => {
|
||||
expect(await simpleRecipientRegistry.connect(controller).callStatic.setMaxRecipients(1)).to.equal(true)
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(1)
|
||||
expect(await simpleRecipientRegistry.maxRecipients()).to.equal(1)
|
||||
|
||||
expect(await simpleRecipientRegistry.connect(controller).callStatic.setMaxRecipients(2)).to.equal(true)
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(2)
|
||||
expect(await simpleRecipientRegistry.maxRecipients()).to.equal(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe("_addRecipient()", async () => {
|
||||
it("reverts if maxRecipients is not grater than 0", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
expect(simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")).
|
||||
to.be.revertedWith('RecipientRegistry: Recipient limit is not set')
|
||||
})
|
||||
it("reverts if recipient registry already registered", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(5)
|
||||
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
expect(simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")).
|
||||
to.be.revertedWith('RecipientRegistry: Recipient already registered')
|
||||
})
|
||||
|
||||
it("reverts if recipient limit reached", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(1)
|
||||
let recipient = ethers.Wallet.createRandom()
|
||||
|
||||
let tx: ContractTransaction = await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
|
||||
const event = receipt.events.filter((e) => e.event === "RecipientAdded")[0]
|
||||
const recipientId = event.args._recipientId
|
||||
await simpleRecipientRegistry.removeRecipient(recipientId)
|
||||
|
||||
recipient = ethers.Wallet.createRandom()
|
||||
await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
|
||||
recipient = ethers.Wallet.createRandom()
|
||||
expect(simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")).
|
||||
to.be.revertedWith('RecipientRegistry: Recipient limit reached')
|
||||
})
|
||||
|
||||
it("succesfully adds a recipient", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(1)
|
||||
let recipient = ethers.Wallet.createRandom()
|
||||
const tx = await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
const txReceipt = await tx.wait()
|
||||
expect(txReceipt.status).to.not.equal(0);
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
describe("getRecipientAddress()", async () => {
|
||||
it("returns 0 address when index is 0, index is greater than number of slots", async () => {
|
||||
expect(await simpleRecipientRegistry.callStatic.getRecipientAddress(0, 100, 110)).to.equal(ethers.constants.AddressZero)
|
||||
//Since slots should be of size 0 initially
|
||||
expect(await simpleRecipientRegistry.callStatic.getRecipientAddress(1, 100, 110)).to.equal(ethers.constants.AddressZero)
|
||||
})
|
||||
|
||||
it("Does not select recipients added after endTime", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(3)
|
||||
let recipient = ethers.Wallet.createRandom()
|
||||
let tx: ContractTransaction = await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RecipientAdded")[0]
|
||||
const recipientIndex = event.args._index
|
||||
const timeStamp = event.args._timestamp.toNumber()
|
||||
|
||||
expect(await simpleRecipientRegistry.callStatic.getRecipientAddress(recipientIndex, 0, timeStamp - 100)).to.equal(ethers.constants.AddressZero)
|
||||
})
|
||||
|
||||
it("Returns recipient added before start time if only once recipient in index", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(2)
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
const tx: ContractTransaction = await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
const receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RecipientAdded")[0]
|
||||
const recipientIndex = event.args._index
|
||||
const timeStamp = event.args._timestamp.toNumber()
|
||||
|
||||
expect(await simpleRecipientRegistry.callStatic.getRecipientAddress(recipientIndex, timeStamp + 100, timeStamp + 200)).to.equal(recipient.address)
|
||||
})
|
||||
|
||||
it("succesfully returns recipient address", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(3)
|
||||
let recipient = ethers.Wallet.createRandom()
|
||||
let tx: ContractTransaction = await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RecipientAdded")[0]
|
||||
const recipientIndex = event.args._index
|
||||
const timeStamp = event.args._timestamp.toNumber()
|
||||
|
||||
expect(await simpleRecipientRegistry.callStatic.getRecipientAddress(recipientIndex, 0, timeStamp + 100)).to.equal(recipient.address)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("getRecipientCount()", async () => {
|
||||
|
||||
it("Returns number of recipients", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(5)
|
||||
let recipient = ethers.Wallet.createRandom()
|
||||
await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
expect(await simpleRecipientRegistry.getRecipientCount()).to.equal(1)
|
||||
|
||||
recipient = ethers.Wallet.createRandom()
|
||||
await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
expect(await simpleRecipientRegistry.getRecipientCount()).to.equal(2)
|
||||
|
||||
})
|
||||
|
||||
it("Tests removal decreases recipient count", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(2)
|
||||
|
||||
let recipient = ethers.Wallet.createRandom()
|
||||
let tx: ContractTransaction = await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
|
||||
expect(await simpleRecipientRegistry.getRecipientCount()).to.equal(1)
|
||||
|
||||
const event = receipt.events.filter((e) => e.event === "RecipientAdded")[0]
|
||||
const recipientId = event.args._recipientId
|
||||
await simpleRecipientRegistry.removeRecipient(recipientId)
|
||||
|
||||
expect(await simpleRecipientRegistry.getRecipientCount()).to.equal(0)
|
||||
|
||||
recipient = ethers.Wallet.createRandom()
|
||||
await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
recipient = ethers.Wallet.createRandom()
|
||||
await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
expect(await simpleRecipientRegistry.getRecipientCount()).to.equal(2)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
describe("_removeRecipient()", async () => {
|
||||
it("Reverts if recipient is not in the registry", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
|
||||
expect(simpleRecipientRegistry.removeRecipient(recipientId)).
|
||||
to.be.revertedWith("RecipientRegistry: Recipient is not in the registry")
|
||||
|
||||
})
|
||||
|
||||
it("Reverts if recipient already removed", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(1)
|
||||
let recipient = ethers.Wallet.createRandom()
|
||||
let tx: ContractTransaction = await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
|
||||
const event = receipt.events.filter((e) => e.event === "RecipientAdded")[0]
|
||||
const recipientId = event.args._recipientId
|
||||
|
||||
await simpleRecipientRegistry.removeRecipient(recipientId)
|
||||
expect(simpleRecipientRegistry.removeRecipient(recipientId)).
|
||||
to.be.revertedWith("RecipientRegistry: Recipient already removed")
|
||||
})
|
||||
|
||||
it("Succesfully removes recipient from registry", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(1)
|
||||
let recipient = ethers.Wallet.createRandom()
|
||||
let tx: ContractTransaction = await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
|
||||
const event = receipt.events.filter((e) => e.event === "RecipientAdded")[0]
|
||||
const recipientId = event.args._recipientId
|
||||
|
||||
await simpleRecipientRegistry.removeRecipient(recipientId)
|
||||
expect(await simpleRecipientRegistry.getRecipientCount()).to.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
302
packages/contracts/tests/Unit/OptimisticRecipientRegistry.ts
Normal file
302
packages/contracts/tests/Unit/OptimisticRecipientRegistry.ts
Normal file
@@ -0,0 +1,302 @@
|
||||
import { ethers } from "hardhat";
|
||||
import { ContractTransaction, ContractReceipt, Signer, constants } from "ethers";
|
||||
import chai from "chai";
|
||||
import { deployContract, deployMockContract, MockContract, solidity, } from "ethereum-waffle";
|
||||
import { OptimisticRecipientRegistry } from "../../typechain";
|
||||
|
||||
chai.use(solidity);
|
||||
const { expect } = chai;
|
||||
|
||||
|
||||
describe("Optimistic Recipient Registry", () => {
|
||||
|
||||
let deployer : Signer
|
||||
let controller : Signer
|
||||
let addr1 : Signer
|
||||
let controllerAddress : string
|
||||
let optimisticRecipientRegistry : OptimisticRecipientRegistry
|
||||
|
||||
beforeEach(async () => {
|
||||
[deployer, controller, addr1] = await ethers.getSigners();
|
||||
controllerAddress = await controller.getAddress()
|
||||
|
||||
const optimisticRecipientRegistryFactory = await ethers.getContractFactory("OptimisticRecipientRegistry", deployer)
|
||||
optimisticRecipientRegistry = await optimisticRecipientRegistryFactory.deploy(0, 60, controllerAddress)
|
||||
});
|
||||
|
||||
it("verify - initializes properly", async () => {
|
||||
const optimisticRecipientRegistryDeployTransaction: ContractTransaction = optimisticRecipientRegistry.deployTransaction;
|
||||
const txReceipt = await optimisticRecipientRegistryDeployTransaction.wait();
|
||||
expect(txReceipt.status).to.not.equal(0);
|
||||
expect(txReceipt.contractAddress).to.equal(optimisticRecipientRegistry.address);
|
||||
})
|
||||
|
||||
it("verify - configured properly", async () => {
|
||||
expect(await optimisticRecipientRegistry.owner()).to.be.equal(await deployer.getAddress());
|
||||
expect(await optimisticRecipientRegistry.controller()).to.equal(controllerAddress)
|
||||
expect(await optimisticRecipientRegistry.baseDeposit()).to.equal(0)
|
||||
expect(await optimisticRecipientRegistry.challengePeriodDuration()).to.equal(60)
|
||||
})
|
||||
|
||||
|
||||
describe("setBaseDeposit()", async () => {
|
||||
it("Only owner can set base deposit", async () => {
|
||||
expect(optimisticRecipientRegistry.connect(addr1).setBaseDeposit(100)).
|
||||
to.be.revertedWith("Ownable: caller is not the owner")
|
||||
})
|
||||
|
||||
it("Succesfully sets base deposit", async () => {
|
||||
await optimisticRecipientRegistry.setBaseDeposit(100)
|
||||
expect(await optimisticRecipientRegistry.baseDeposit()).to.equal(100)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe("setChallengePeriodDuration()", async () => {
|
||||
it("Only owner can set challenge period duration", async () => {
|
||||
expect(optimisticRecipientRegistry.connect(addr1).setChallengePeriodDuration(1)).
|
||||
to.be.revertedWith("Ownable: caller is not the owner")
|
||||
})
|
||||
|
||||
it("Succesfully sets challenge period duration", async () => {
|
||||
await optimisticRecipientRegistry.setChallengePeriodDuration(1)
|
||||
expect(await optimisticRecipientRegistry.challengePeriodDuration()).to.equal(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("addRecipient()", async () => {
|
||||
beforeEach(async () => {
|
||||
await optimisticRecipientRegistry.connect(controller).setMaxRecipients(2)
|
||||
})
|
||||
it("Reverts if recipient address is zero", async () => {
|
||||
expect(optimisticRecipientRegistry.addRecipient(ethers.constants.AddressZero, "metadata info")).
|
||||
to.be.revertedWith("RecipientRegistry: Recipient address is zero")
|
||||
})
|
||||
|
||||
it("Reverts if metadata is empty string", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
expect(optimisticRecipientRegistry.addRecipient(recipient.address, "")).
|
||||
to.be.revertedWith("RecipientRegistry: Metadata info is empty string")
|
||||
})
|
||||
|
||||
it("Reverts if recipient already registered", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
let tx: ContractTransaction = await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RequestSubmitted")[0]
|
||||
const recipientId = event.args._recipientId
|
||||
await optimisticRecipientRegistry.executeRequest(recipientId)
|
||||
|
||||
expect(optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")).
|
||||
to.be.revertedWith("RecipientRegistry: Recipient already registered")
|
||||
})
|
||||
|
||||
it("Reverts if recipient request already submitted", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
expect(optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")).
|
||||
to.be.revertedWith("RecipientRegistry: Request already submitted")
|
||||
})
|
||||
|
||||
it("Reverts if deposit amount is incorrect", async () => {
|
||||
await optimisticRecipientRegistry.setBaseDeposit(10)
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
expect(optimisticRecipientRegistry.addRecipient(
|
||||
recipient.address, "metadata info",
|
||||
{ value: ethers.utils.parseEther("9.0")}
|
||||
)).
|
||||
to.be.revertedWith("RecipientRegistry: Incorrect deposit amount")
|
||||
})
|
||||
|
||||
it("Succesfully adds recipient", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
let tx: ContractTransaction = await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RequestSubmitted")[0]
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
|
||||
expect(event.event).to.equal("RequestSubmitted")
|
||||
expect(event.args._recipientId).to.equal(recipientId)
|
||||
//0 is enum value for Registration
|
||||
expect(event.args._type).to.equal(0)
|
||||
expect(event.args._recipient).to.equal(recipient.address)
|
||||
expect(event.args._metadata).to.equal("metadata info")
|
||||
})
|
||||
})
|
||||
|
||||
describe("removeRecipient()", async () => {
|
||||
beforeEach(async () => {
|
||||
await optimisticRecipientRegistry.connect(controller).setMaxRecipients(1)
|
||||
})
|
||||
it("Reverts if recipient not in registry", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
expect(optimisticRecipientRegistry.removeRecipient(recipientId)).
|
||||
to.be.revertedWith("RecipientRegistry: Recipient is not in the registry")
|
||||
})
|
||||
|
||||
it("Reverts if recipient already removed", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
await optimisticRecipientRegistry.executeRequest(recipientId)
|
||||
|
||||
await optimisticRecipientRegistry.removeRecipient(recipientId)
|
||||
await optimisticRecipientRegistry.executeRequest(recipientId)
|
||||
|
||||
expect(optimisticRecipientRegistry.removeRecipient(recipientId)).
|
||||
to.be.revertedWith("RecipientRegistry: Recipient already removed")
|
||||
})
|
||||
|
||||
it("Reverts if recipient removal request already submitted", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
await optimisticRecipientRegistry.executeRequest(recipientId)
|
||||
|
||||
await optimisticRecipientRegistry.removeRecipient(recipientId)
|
||||
expect(optimisticRecipientRegistry.removeRecipient(recipientId)).
|
||||
to.be.revertedWith("RecipientRegistry: Request already submitted")
|
||||
})
|
||||
|
||||
it("Reverts if incorrect deposit amount", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
await optimisticRecipientRegistry.executeRequest(recipientId)
|
||||
|
||||
await optimisticRecipientRegistry.setBaseDeposit(10)
|
||||
expect(optimisticRecipientRegistry.removeRecipient( recipientId, { value: ethers.utils.parseEther("9.0")})).
|
||||
to.be.revertedWith("RecipientRegistry: Incorrect deposit amount")
|
||||
})
|
||||
|
||||
it("Succesfully removes recipient", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
await optimisticRecipientRegistry.executeRequest(recipientId)
|
||||
|
||||
|
||||
let tx: ContractTransaction = await optimisticRecipientRegistry.removeRecipient(recipientId)
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RequestSubmitted")[0]
|
||||
|
||||
expect(event.event).to.equal("RequestSubmitted")
|
||||
expect(event.args._recipientId).to.equal(recipientId)
|
||||
//1 is enum value for Removal
|
||||
expect(event.args._type).to.equal(1)
|
||||
expect(event.args._recipient).to.equal(ethers.constants.AddressZero)
|
||||
expect(event.args._metadata).to.equal("")
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("challengeRequest()", async () => {
|
||||
|
||||
it("Reverts if request does not exist", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
const beneficiary = ethers.Wallet.createRandom()
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
expect(optimisticRecipientRegistry.challengeRequest(recipientId, beneficiary.address)).
|
||||
to.be.revertedWith("RecipientRegistry: Request does not exist")
|
||||
})
|
||||
|
||||
it("Succesfully challenges request", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
|
||||
const beneficiary = ethers.Wallet.createRandom()
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
|
||||
let tx: ContractTransaction = await optimisticRecipientRegistry.challengeRequest(recipientId, beneficiary.address)
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RequestResolved")[0]
|
||||
expect(event.event).to.equal("RequestResolved")
|
||||
expect(event.args._recipientId).to.equal(recipientId)
|
||||
//0 is enum value for Registration
|
||||
expect(event.args._type).to.equal(0)
|
||||
expect(event.args._recipientIndex).to.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("executeRequest()", async () => {
|
||||
it("Reverts if request does not exist", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
expect(optimisticRecipientRegistry.executeRequest(recipientId)).
|
||||
to.be.revertedWith("RecipientRegistry: Request does not exist")
|
||||
})
|
||||
|
||||
it("Reverts non owner request if challenge period is not over", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
expect(optimisticRecipientRegistry.connect(addr1).executeRequest(recipientId)).
|
||||
to.be.revertedWith('RecipientRegistry: Challenge period is not over')
|
||||
})
|
||||
|
||||
it("Succesfully executes request as non owner is challenge period is over", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
await optimisticRecipientRegistry.connect(controller).setMaxRecipients(2)
|
||||
await ethers.provider.send("evm_increaseTime", [61]);
|
||||
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
|
||||
let tx: ContractTransaction = await optimisticRecipientRegistry.connect(addr1).executeRequest(recipientId)
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RequestResolved")[0]
|
||||
expect(event.args._recipientId).to.equal(recipientId)
|
||||
//0 is enum value for Registration
|
||||
expect(event.args._type).to.equal(0)
|
||||
expect(event.args._recipientIndex).to.equal(1)
|
||||
})
|
||||
|
||||
it("Succesfully executes request as owner before challenge period is over", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
await optimisticRecipientRegistry.connect(controller).setMaxRecipients(2)
|
||||
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
|
||||
let tx: ContractTransaction = await optimisticRecipientRegistry.executeRequest(recipientId)
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RequestResolved")[0]
|
||||
expect(event.args._recipientId).to.equal(recipientId)
|
||||
//0 is enum value for Registration
|
||||
expect(event.args._type).to.equal(0)
|
||||
expect(event.args._recipientIndex).to.equal(1)
|
||||
})
|
||||
|
||||
it("Succesfully executes request as owner after challenge period is over", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await optimisticRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
await optimisticRecipientRegistry.connect(controller).setMaxRecipients(2)
|
||||
await ethers.provider.send("evm_increaseTime", [61]);
|
||||
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
|
||||
let tx: ContractTransaction = await optimisticRecipientRegistry.executeRequest(recipientId)
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RequestResolved")[0]
|
||||
expect(event.args._recipientId).to.equal(recipientId)
|
||||
//0 is enum value for Registration
|
||||
expect(event.args._type).to.equal(0)
|
||||
expect(event.args._recipientIndex).to.equal(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
85
packages/contracts/tests/Unit/SimpleRecipientRegistry.ts
Normal file
85
packages/contracts/tests/Unit/SimpleRecipientRegistry.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { ethers } from "hardhat";
|
||||
import { ContractTransaction, ContractReceipt, Signer, constants } from "ethers";
|
||||
import chai from "chai";
|
||||
import { deployContract, deployMockContract, MockContract, solidity, } from "ethereum-waffle";
|
||||
import { SimpleRecipientRegistry } from "../../typechain";
|
||||
|
||||
chai.use(solidity);
|
||||
const { expect } = chai;
|
||||
|
||||
describe("Simple Recipient Registry", () => {
|
||||
|
||||
let deployer : Signer
|
||||
let controller : Signer
|
||||
let controllerAddress : string
|
||||
let simpleRecipientRegistry : SimpleRecipientRegistry
|
||||
|
||||
beforeEach(async () => {
|
||||
[deployer, controller] = await ethers.getSigners();
|
||||
controllerAddress = await controller.getAddress()
|
||||
|
||||
const simpleRecipientRegistryFactory = await ethers.getContractFactory("SimpleRecipientRegistry", deployer)
|
||||
simpleRecipientRegistry = await simpleRecipientRegistryFactory.deploy(controllerAddress)
|
||||
});
|
||||
|
||||
it("verify - initializes properly", async () => {
|
||||
const simpleRecipientRegistryDeployTransaction: ContractTransaction = simpleRecipientRegistry.deployTransaction;
|
||||
const txReceipt = await simpleRecipientRegistryDeployTransaction.wait();
|
||||
expect(txReceipt.status).to.not.equal(0);
|
||||
expect(txReceipt.contractAddress).to.equal(simpleRecipientRegistry.address);
|
||||
})
|
||||
|
||||
it("verify - configured properly", async () => {
|
||||
expect(await simpleRecipientRegistry.owner()).to.be.equal(await deployer.getAddress());
|
||||
expect(await simpleRecipientRegistry.controller()).to.equal(controllerAddress)
|
||||
expect(await simpleRecipientRegistry.maxRecipients()).to.equal(0)
|
||||
})
|
||||
|
||||
|
||||
describe("addRecipient()", async () => {
|
||||
it("Reverts if recipient address is zero", async () => {
|
||||
expect(simpleRecipientRegistry.addRecipient(ethers.constants.AddressZero, "metadata info")).
|
||||
to.be.revertedWith('RecipientRegistry: Recipient address is zero')
|
||||
})
|
||||
|
||||
it("Reverts if metadata is empty string", async () => {
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
expect(simpleRecipientRegistry.addRecipient(recipient.address, "")).
|
||||
to.be.revertedWith('RecipientRegistry: Metadata info is empty string')
|
||||
})
|
||||
|
||||
it("Succesfully adds recipient", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(1)
|
||||
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
let tx: ContractTransaction = await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events.filter((e) => e.event === "RecipientAdded")[0]
|
||||
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
expect(event.event).to.equal("RecipientAdded")
|
||||
expect(event.args._recipientId).to.equal(recipientId)
|
||||
expect(event.args._recipient).to.equal(recipient.address)
|
||||
expect(event.args._metadata).to.equal("metadata info")
|
||||
expect(event.args._index).to.equal(1)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("removeRecipient()", async () => {
|
||||
it("Succesfully removes recipient", async () => {
|
||||
await simpleRecipientRegistry.connect(controller).setMaxRecipients(1)
|
||||
const recipient = ethers.Wallet.createRandom()
|
||||
await simpleRecipientRegistry.addRecipient(recipient.address, "metadata info")
|
||||
const packed = ethers.utils.solidityPack(["address", "string"], [recipient.address, "metadata info"])
|
||||
const recipientId = ethers.utils.keccak256(packed)
|
||||
|
||||
let tx: ContractTransaction = await simpleRecipientRegistry.removeRecipient(recipientId)
|
||||
let receipt: ContractReceipt = await tx.wait();
|
||||
const event = receipt.events[0]
|
||||
expect(event.event).to.equal("RecipientRemoved")
|
||||
expect(event.args._recipientId).to.equal(recipientId)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user