Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Various fixes #65

Merged
merged 11 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .commitlintrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import type { UserConfig } from "@commitlint/types";
const Configuration: UserConfig = {
extends: ["@commitlint/config-conventional"],
rules: {
"type-enum": [2, "always", ["ci", "chore", "docs", "ticket", "feat", "fix", "perf", "refactor", "revert", "style"]],
"type-enum": [
2,
"always",
["ci", "chore", "docs", "ticket", "feat", "fix", "perf", "refactor", "revert", "style", "test"],
],
},
};

Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/testmock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -19,5 +22,6 @@ jobs:
- run: cp .env.example .env
- run: pnpm install
- run: pnpm prettier:check
- name: pnpm CI test:mock
run: pnpm test:mock
- run: pnpm lint:sol
- name: pnpm CI test
run: pnpm test
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
.coverage_artifacts
.coverage_cache
.coverage_contracts
abi
artifacts
build
cache
coverage
dist
fhevmTemp
node_modules
types

Expand Down
1 change: 1 addition & 0 deletions contracts/governance/ICompoundTimelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ interface ICompoundTimelock {
* The grace period indicates how long a transaction can remain queued before it cannot be
* executed again.
*/
/* solhint-disable func-name-mixedcase*/
function GRACE_PERIOD() external view returns (uint256);

/**
Expand Down
16 changes: 3 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,10 @@
"prettier:check": "prettier --check \"**/*.{js,json,md,sol,ts,yml}\"",
"prettier:write": "prettier --write \"**/*.{js,json,md,sol,ts,yml}\"",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain",
"test": "hardhat test",
"test:mock": "HARDHAT_NETWORK=hardhat npx hardhat test --network hardhat",
"coverage:mock": "npx hardhat coverage",
"test": "HARDHAT_NETWORK=hardhat npx hardhat test",
"coverage": "npx hardhat coverage",
"task:getEthereumAddress": "hardhat task:getEthereumAddress",
"task:accounts": "hardhat task:accounts",
"fhevm:start": "./launch-fhevm.sh",
"fhevm:stop": "docker rm -f fhevm",
"fhevm:restart": "fhevm:stop && fhevm:start",
"fhevm:faucet": "npm run fhevm:faucet:alice && sleep 5 && npm run fhevm:faucet:bob && sleep 5 && npm run fhevm:faucet:carol && sleep 5 && npm run fhevm:faucet:dave && sleep 5 && npm run fhevm:faucet:eve",
"fhevm:faucet:alice": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressAlice)",
"fhevm:faucet:bob": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressBob)",
"fhevm:faucet:carol": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressCarol)",
"fhevm:faucet:dave": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressDave)",
"fhevm:faucet:eve": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressEve)"
"task:accounts": "hardhat task:accounts"
},
"dependencies": {
"@openzeppelin/contracts-upgradeable": "5.0.2",
Expand Down
2 changes: 1 addition & 1 deletion test/encryptedERC20/EncryptedERC20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe("EncryptedERC20", function () {
const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
const mintAmount = 100_000;
const transferAmount = 50_000;
let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount);
const tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount);
await tx.wait();

const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address);
Expand Down
2 changes: 1 addition & 1 deletion test/encryptedERC20/EncryptedERC20WithErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ describe("EncryptedERC20WithErrors", function () {
const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
const mintAmount = 100_000;
const transferAmount = 50_000;
let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount);
const tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount);
await tx.wait();

const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address);
Expand Down
5 changes: 2 additions & 3 deletions test/fhevmjsMocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import crypto from "crypto";
import dotenv from "dotenv";
import { Wallet, ethers } from "ethers";
import * as fs from "fs";
import hre from "hardhat";
import { Keccak } from "sha3";
import { isAddress } from "web3-validator";

import { insertSQL } from "./coprocessorUtils";
import { awaitCoprocessor, getClearText } from "./coprocessorUtils";

const hre = require("hardhat");

const parsedEnvACL = dotenv.parse(fs.readFileSync("node_modules/fhevm-core-contracts/addresses/.env.acl"));
const aclAdd = parsedEnvACL.ACL_CONTRACT_ADDRESS;

Expand Down Expand Up @@ -362,7 +361,7 @@ function uint8ArrayToHexString(uint8Array: Uint8Array) {
}

function numberToHex(num: number) {
let hex = num.toString(16);
const hex = num.toString(16);
return hex.length % 2 ? "0" + hex : hex;
}

Expand Down
26 changes: 12 additions & 14 deletions test/governance/Comp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ describe("Comp", function () {
const delegator = this.signers.alice;
const delegatee = this.signers.bob;
const nonce = 0;
let latestBlockNumber = await ethers.provider.getBlockNumber();
const block = await ethers.provider.getBlock(latestBlockNumber);
const block = await ethers.provider.getBlock(await ethers.provider.getBlockNumber());
const expiry = block!.timestamp + 100;
const signature = await delegateBySig(delegator, delegatee.address, this.comp, nonce, expiry);

Expand All @@ -152,8 +151,7 @@ describe("Comp", function () {
const delegator = this.signers.alice;
const delegatee = this.signers.bob;
const nonce = 0;
let latestBlockNumber = await ethers.provider.getBlockNumber();
const block = await ethers.provider.getBlock(latestBlockNumber);
const block = await ethers.provider.getBlock(await ethers.provider.getBlockNumber());
const expiry = block!.timestamp + 100;
const signature = await delegateBySig(delegator, delegatee.address, this.comp, nonce, expiry);

Expand All @@ -171,8 +169,7 @@ describe("Comp", function () {
const delegator = this.signers.alice;
const delegatee = this.signers.bob;
const nonce = 0;
let latestBlockNumber = await ethers.provider.getBlockNumber();
const block = await ethers.provider.getBlock(latestBlockNumber);
const block = await ethers.provider.getBlock(await ethers.provider.getBlockNumber());
const expiry = block!.timestamp + 100;

// Signer is not the delegator
Expand All @@ -187,12 +184,11 @@ describe("Comp", function () {
const delegator = this.signers.alice;
const delegatee = this.signers.bob;
const nonce = 0;
let latestBlockNumber = await ethers.provider.getBlockNumber();
const block = await ethers.provider.getBlock(latestBlockNumber);
const block = await ethers.provider.getBlock(await ethers.provider.getBlockNumber());
const expiry = block!.timestamp + 100;
const signature = await delegateBySig(delegator, delegatee.address, this.comp, nonce, expiry);

ethers.provider.send("evm_increaseTime", ["0xffff"]);
await ethers.provider.send("evm_increaseTime", ["0xffff"]);

await expect(
this.comp.connect(delegatee).delegateBySig(delegator, delegatee, nonce, expiry, signature),
Expand All @@ -207,8 +203,6 @@ describe("Comp", function () {
"BlockNumberEqualOrHigherThanCurrentBlock",
);

const newAllowedContract = "0x9d3e06a2952dc49EDCc73e41C76645797fC53967";

const tx = await this.comp.connect(this.signers.alice).setGovernor(this.signers.bob);
await tx.wait();

Expand Down Expand Up @@ -347,6 +341,8 @@ describe("Comp", function () {

const blockNumbers = [];

const thisBlockNumber = await ethers.provider.getBlockNumber();

while (i < 20) {
let tx = await this.comp.connect(this.signers.alice).delegate(this.signers.alice.address);
await tx.wait();
Expand All @@ -358,21 +354,23 @@ describe("Comp", function () {
i++;
}

waitNBlocks(1);
await waitNBlocks(1);

// There are 40 checkpoints for Alice and 39 checkpoints for Carol
expect(await this.comp.numCheckpoints(this.signers.alice.address)).to.eq(BigInt(40));
expect(await this.comp.numCheckpoints(this.signers.carol.address)).to.eq(BigInt(39));

i = 0;

const startWithAlice = thisBlockNumber % 2 === 1;

while (i < 40) {
if (blockNumbers[i] % 2 === 0) {
expect(
await reencryptPriorVotes(
this.signers,
this.instances,
"carol",
startWithAlice ? "alice" : "carol",
blockNumbers[i],
this.comp,
this.compAddress,
Expand All @@ -383,7 +381,7 @@ describe("Comp", function () {
await reencryptPriorVotes(
this.signers,
this.instances,
"alice",
startWithAlice ? "carol" : "alice",
blockNumbers[i],
this.comp,
this.compAddress,
Expand Down
55 changes: 30 additions & 25 deletions test/governance/GovernorAlphaZama.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ describe("GovernorAlphaZama", function () {
this.compAddress,
);

let tx = await this.governor.connect(this.signers.bob).propose(targets, values, signatures, calldatas, description);
const tx = await this.governor
.connect(this.signers.bob)
.propose(targets, values, signatures, calldatas, description);
await tx.wait();

const proposalId = await this.governor.latestProposalIds(this.signers.bob.address);
Expand Down Expand Up @@ -270,16 +272,16 @@ describe("GovernorAlphaZama", function () {
const proposalId = await this.governor.latestProposalIds(this.signers.bob.address);

// VOTE
let input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
const input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
input.addBool(true);
let encryptedVote = await input.encrypt();
const encryptedVote = await input.encrypt();
tx = await this.governor
.connect(this.signers.bob)
["castVote(uint256,bytes32,bytes)"](proposalId, encryptedVote.handles[0], encryptedVote.inputProof);
await tx.wait();

// Bob reeencrypts his receipt
let [hasVoted, support, votes] = await reencryptVoteReceipt(
const [hasVoted, support, votes] = await reencryptVoteReceipt(
this.signers,
this.instances,
proposalId,
Expand Down Expand Up @@ -419,8 +421,7 @@ describe("GovernorAlphaZama", function () {
});

it("only owner could queue setTimelockPendingAdmin then execute it, and then acceptTimelockAdmin", async function () {
const latestBlockNumber = await ethers.provider.getBlockNumber();
const block = await ethers.provider.getBlock(latestBlockNumber);
const block = await ethers.provider.getBlock(await ethers.provider.getBlockNumber());
const expiry = block!.timestamp + 60 * 60 * 24 * 2 + 60;

const tx = await this.governor.queueSetTimelockPendingAdmin(this.signers.bob, expiry);
Expand Down Expand Up @@ -479,11 +480,11 @@ describe("GovernorAlphaZama", function () {
});

it("all arrays of a proposal should be of same length, non null and less than max operations", async function () {
let targets = [this.signers.bob.address];
let values = ["0"];
let signatures = ["getBalanceOf(address)"];
let calldatas = [ethers.AbiCoder.defaultAbiCoder().encode(["address"], [this.signers.bob.address])];
let description = "description";
const targets = [this.signers.bob.address];
const values = ["0"];
const signatures = ["getBalanceOf(address)"];
const calldatas = [ethers.AbiCoder.defaultAbiCoder().encode(["address"], [this.signers.bob.address])];
const description = "description";

const invalidTargets = [this.signers.bob.address, this.signers.carol.address];
await expect(
Expand Down Expand Up @@ -564,7 +565,9 @@ describe("GovernorAlphaZama", function () {
this.compAddress,
);

let tx = await this.governor.connect(this.signers.bob).propose(targets, values, signatures, calldatas, description);
const tx = await this.governor
.connect(this.signers.bob)
.propose(targets, values, signatures, calldatas, description);
await tx.wait();

// @dev ProposalId starts at 1.
Expand Down Expand Up @@ -592,7 +595,9 @@ describe("GovernorAlphaZama", function () {
this.compAddress,
);

let tx = await this.governor.connect(this.signers.bob).propose(targets, values, signatures, calldatas, description);
const tx = await this.governor
.connect(this.signers.bob)
.propose(targets, values, signatures, calldatas, description);
await tx.wait();

await expect(
Expand Down Expand Up @@ -629,9 +634,9 @@ describe("GovernorAlphaZama", function () {

// VOTE
// Bob casts a vote
let input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
const input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
input.addBool(true);
let encryptedVote = await input.encrypt();
const encryptedVote = await input.encrypt();
tx = await this.governor
.connect(this.signers.bob)
["castVote(uint256,bytes32,bytes)"](proposalId, encryptedVote.handles[0], encryptedVote.inputProof);
Expand Down Expand Up @@ -822,9 +827,9 @@ describe("GovernorAlphaZama", function () {

// VOTE
// Bob votes for
let input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
const input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
input.addBool(true);
let encryptedVote = await input.encrypt();
const encryptedVote = await input.encrypt();
tx = await this.governor
.connect(this.signers.bob)
["castVote(uint256,bytes32,bytes)"](proposalId, encryptedVote.handles[0], encryptedVote.inputProof);
Expand Down Expand Up @@ -885,9 +890,9 @@ describe("GovernorAlphaZama", function () {

// VOTE
// Bob votes for
let input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
const input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
input.addBool(true);
let encryptedVote = await input.encrypt();
const encryptedVote = await input.encrypt();
tx = await this.governor
.connect(this.signers.bob)
["castVote(uint256,bytes32,bytes)"](proposalId, encryptedVote.handles[0], encryptedVote.inputProof);
Expand Down Expand Up @@ -922,9 +927,9 @@ describe("GovernorAlphaZama", function () {
let tx = await this.governor.connect(this.signers.bob).propose(targets, values, signatures, calldatas, description);
const proposalId = await this.governor.latestProposalIds(this.signers.bob.address);

let input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
const input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
input.addBool(true);
let encryptedVote = await input.encrypt();
const encryptedVote = await input.encrypt();

await expect(
this.governor
Expand Down Expand Up @@ -982,9 +987,9 @@ describe("GovernorAlphaZama", function () {

// VOTE
// Bob casts a vote
let input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
const input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
input.addBool(true);
let encryptedVote = await input.encrypt();
const encryptedVote = await input.encrypt();
tx = await this.governor
.connect(this.signers.bob)
["castVote(uint256,bytes32,bytes)"](proposalId, encryptedVote.handles[0], encryptedVote.inputProof);
Expand Down Expand Up @@ -1026,9 +1031,9 @@ describe("GovernorAlphaZama", function () {

// VOTE
// Bob casts a vote
let input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
const input = this.instances.bob.createEncryptedInput(this.governorAddress, this.signers.bob.address);
input.addBool(true);
let encryptedVote = await input.encrypt();
const encryptedVote = await input.encrypt();
tx = await this.governor
.connect(this.signers.bob)
["castVote(uint256,bytes32,bytes)"](proposalId, encryptedVote.handles[0], encryptedVote.inputProof);
Expand Down
Loading