Skip to content

Commit

Permalink
refactor: Set functions for FHEVM/Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificYield committed Nov 7, 2024
1 parent d06396e commit 75e5aba
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const istanbulReporter = ["html", "lcov"];
export const providerOptions = {
mnemonic: process.env.MNEMONIC,
};
export const skipFiles = ["mocks", "test", "fhevmTemp"];
export const skipFiles = ["test", "fhevmTemp"];
export const mocha = {
fgrep: "[skip-on-coverage]",
invert: true,
Expand Down
5 changes: 1 addition & 4 deletions contracts/governance/GovernorAlphaZama.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ICompoundTimelock } from "./ICompoundTimelock.sol";
* - Proposal: A new proposal is made to introduce a change.
* - Voting: Users can vote on the proposal, either in favor or against it.
* - Quorum: A minimum number of votes (quorum) must be reached for the proposal to pass.
* - Execution: Once a proposal passes, it is executed and takes effect on the taregt protocol.
* - Execution: Once a proposal passes, it is executed and takes effect on the protocol.
*/
contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
/// @notice Returned if proposal contains too many changes.
Expand Down Expand Up @@ -245,9 +245,6 @@ contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
* For instance, 3 days would have a votingPeriod = 21,600 blocks if 12s per block.
*/
constructor(address owner_, address timelock_, address comp_, uint256 votingPeriod_) Ownable(owner_) {
TFHE.setFHEVM(FHEVMConfig.defaultConfig());
Gateway.setGateway(Gateway.defaultGatewayAddress());

TIMELOCK = ICompoundTimelock(timelock_);
COMP = IComp(comp_);
VOTING_PERIOD = votingPeriod_;
Expand Down
10 changes: 10 additions & 0 deletions contracts/test/DefaultFHEVMConfig.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import "fhevm/lib/TFHE.sol";

contract DefaultFHEVMConfig {
constructor() {
TFHE.setFHEVM(FHEVMConfig.defaultConfig());
}
}
10 changes: 10 additions & 0 deletions contracts/test/DefaultGatewayConfig.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import "fhevm/gateway/GatewayCaller.sol";

contract DefaultGatewayConfig {
constructor() {
Gateway.setGateway(Gateway.defaultGatewayAddress());
}
}
11 changes: 11 additions & 0 deletions contracts/test/governance/TestComp.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import { Comp } from "../../governance/Comp.sol";
import { DefaultFHEVMConfig } from "../DefaultFHEVMConfig.sol";

contract TestComp is DefaultFHEVMConfig, Comp {
constructor(address owner_) Comp(owner_) {
//
}
}
17 changes: 17 additions & 0 deletions contracts/test/governance/TestGovernorAlphaZama.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import { GovernorAlphaZama } from "../../governance/GovernorAlphaZama.sol";
import { DefaultFHEVMConfig } from "../DefaultFHEVMConfig.sol";
import { DefaultGatewayConfig } from "../DefaultGatewayConfig.sol";

contract TestGovernorAlphaZama is DefaultFHEVMConfig, DefaultGatewayConfig, GovernorAlphaZama {
constructor(
address owner_,
address timelock_,
address comp_,
uint256 votingPeriod_
) GovernorAlphaZama(owner_, timelock_, comp_, votingPeriod_) {
//
}
}
15 changes: 15 additions & 0 deletions contracts/test/token/ERC20/TestEncryptedERC20Mintable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import { EncryptedERC20Mintable } from "../../../token/ERC20/extensions/EncryptedERC20Mintable.sol";
import { DefaultFHEVMConfig } from "../../DefaultFHEVMConfig.sol";

contract TestEncryptedERC20Mintable is DefaultFHEVMConfig, EncryptedERC20Mintable {
constructor(
string memory name_,
string memory symbol_,
address owner_
) EncryptedERC20Mintable(name_, symbol_, owner_) {
//
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import { EncryptedERC20WithErrorsMintable } from "../../../token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol";
import { DefaultFHEVMConfig } from "../../DefaultFHEVMConfig.sol";

contract TestEncryptedERC20WithErrorsMintable is DefaultFHEVMConfig, EncryptedERC20WithErrorsMintable {
constructor(
string memory name_,
string memory symbol_,
address owner_
) EncryptedERC20WithErrorsMintable(name_, symbol_, owner_) {
//
}
}
1 change: 0 additions & 1 deletion contracts/token/ERC20/EncryptedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ abstract contract EncryptedERC20 is IEncryptedERC20 {
* @param symbol_ Symbol.
*/
constructor(string memory name_, string memory symbol_) {
TFHE.setFHEVM(FHEVMConfig.defaultConfig());
_name = name_;
_symbol = symbol_;
}
Expand Down
6 changes: 3 additions & 3 deletions test/encryptedERC20/EncryptedERC20.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from "hardhat";

import type { EncryptedERC20Mintable, IEncryptedERC20 } from "../../types";
import type { IEncryptedERC20, TestEncryptedERC20Mintable } from "../../types";
import { reencryptEuint64 } from "../reencrypt";
import { Signers } from "../signers";
import { FhevmInstances } from "../types";
Expand All @@ -10,8 +10,8 @@ export async function deployEncryptedERC20Fixture(
name: string,
symbol: string,
owner: string,
): Promise<EncryptedERC20Mintable> {
const contractFactory = await ethers.getContractFactory("EncryptedERC20Mintable");
): Promise<TestEncryptedERC20Mintable> {
const contractFactory = await ethers.getContractFactory("TestEncryptedERC20Mintable");
const contract = await contractFactory
.connect(signers[owner as keyof Signers])
.deploy(name, symbol, signers[owner as keyof Signers].address);
Expand Down
8 changes: 4 additions & 4 deletions test/encryptedERC20/EncryptedERC20WithErrors.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from "hardhat";

import type { EncryptedERC20WithErrorsMintable } from "../../types";
import type { TestEncryptedERC20WithErrorsMintable } from "../../types";
import { reencryptEuint8 } from "../reencrypt";
import { Signers } from "../signers";
import { FhevmInstances } from "../types";
Expand All @@ -10,8 +10,8 @@ export async function deployEncryptedERC20WithErrorsFixture(
name: string,
symbol: string,
owner: string,
): Promise<EncryptedERC20WithErrorsMintable> {
const contractFactory = await ethers.getContractFactory("EncryptedERC20WithErrorsMintable");
): Promise<TestEncryptedERC20WithErrorsMintable> {
const contractFactory = await ethers.getContractFactory("TestEncryptedERC20WithErrorsMintable");
const contract = await contractFactory
.connect(signers[owner as keyof Signers])
.deploy(name, symbol, signers[owner as keyof Signers].address);
Expand All @@ -24,7 +24,7 @@ export async function checkErrorCode(
instances: FhevmInstances,
account: string,
transferId: bigint,
token: EncryptedERC20WithErrorsMintable,
token: TestEncryptedERC20WithErrorsMintable,
tokenAddress: string,
): Promise<string> {
const errorCodeHandle = await token.getErrorCodeForTransferId(transferId);
Expand Down
12 changes: 6 additions & 6 deletions test/governance/Comp.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ethers } from "hardhat";

import type { Comp } from "../../types";
import type { TestComp } from "../../types";
import { reencryptEuint64 } from "../reencrypt";
import { Signers } from "../signers";
import { FhevmInstances } from "../types";

export async function deployCompFixture(signers: Signers): Promise<Comp> {
const contractFactory = await ethers.getContractFactory("Comp");
export async function deployCompFixture(signers: Signers): Promise<TestComp> {
const contractFactory = await ethers.getContractFactory("TestComp");
const contract = await contractFactory.connect(signers.alice).deploy(signers.alice.address);
await contract.waitForDeployment();
return contract;
Expand All @@ -18,7 +18,7 @@ export async function transferTokensAndDelegate(
transferAmount: bigint,
account: string,
delegate: string,
comp: Comp,
comp: TestComp,
compAddress: string,
): Promise<void> {
const input = instances.alice.createEncryptedInput(compAddress, signers.alice.address);
Expand All @@ -42,7 +42,7 @@ export async function reencryptCurrentVotes(
signers: Signers,
instances: FhevmInstances,
account: string,
comp: Comp,
comp: TestComp,
compAddress: string,
): Promise<bigint> {
const voteHandle = await comp.getCurrentVotes(signers[account as keyof Signers].address);
Expand All @@ -55,7 +55,7 @@ export async function reencryptPriorVotes(
instances: FhevmInstances,
account: string,
blockNumber: number,
comp: Comp,
comp: TestComp,
compAddress: string,
): Promise<bigint> {
const voteHandle = await comp.getPriorVotes(signers[account as keyof Signers].address, blockNumber);
Expand Down
8 changes: 4 additions & 4 deletions test/governance/GovernorAlphaZama.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from "hardhat";

import type { CompoundTimelock, GovernorAlphaZama } from "../../types";
import type { CompoundTimelock, TestGovernorAlphaZama } from "../../types";
import { reencryptEbool, reencryptEuint64 } from "../reencrypt";
import { Signers, getSigners } from "../signers";
import { FhevmInstances } from "../types";
Expand All @@ -17,11 +17,11 @@ export async function deployGovernorAlphaZamaFixture(
signers: Signers,
compAddress: string,
timelockAddress: string,
): Promise<GovernorAlphaZama> {
): Promise<TestGovernorAlphaZama> {
// @dev We use 5 only for testing purpose.
// DO NOT use this value in production.
const votingPeriod = 5;
const governorFactory = await ethers.getContractFactory("GovernorAlphaZama");
const governorFactory = await ethers.getContractFactory("TestGovernorAlphaZama");
const governor = await governorFactory
.connect(signers.alice)
.deploy(signers.alice.address, timelockAddress, compAddress, votingPeriod);
Expand All @@ -34,7 +34,7 @@ export async function reencryptVoteReceipt(
instances: FhevmInstances,
proposalId: bigint,
account: string,
governor: GovernorAlphaZama,
governor: TestGovernorAlphaZama,
governorAddress: string,
): Promise<[boolean, boolean, bigint]> {
const [hasVoted, supportHandle, voteHandle] = await governor.getReceipt(
Expand Down

0 comments on commit 75e5aba

Please sign in to comment.