Skip to content

Commit

Permalink
Merge pull request #32 from zama-ai/fix-ci
Browse files Browse the repository at this point in the history
Fix ci
  • Loading branch information
immortal-tofu authored Aug 12, 2024
2 parents bed853b + 78f6614 commit 9ec5005
Show file tree
Hide file tree
Showing 15 changed files with 407 additions and 403 deletions.
21 changes: 0 additions & 21 deletions .eslintignore

This file was deleted.

21 changes: 0 additions & 21 deletions .eslintrc.yml

This file was deleted.

20 changes: 2 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,8 @@ jobs:
- name: "Compile the contracts and generate the TypeChain bindings"
run: "pnpm typechain"

# - name: "Test the contracts and generate the coverage report"
# run: "pnpm coverage"

- name: Login to GitHub Container Registry
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: "CI test"
run: |
pnpm fhevm:start &> fhevm.log &
tail -f fhevm.log | sed '/Starting JSON WebSocket server/ q'
pnpm fhevm:faucet
pnpm test
pnpm fhevm:stop || true
- name: "Test the contracts and generate the coverage report"
run: "pnpm coverage:mock"

- name: "Add test summary"
run: |
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trailingComma: "all"
overrides:
- files: "*.sol"
options:
compiler: "0.8.22"
compiler: "0.8.24"
parser: "solidity-parse"
tabWidth: 4
- files: "*.ts"
Expand Down
7 changes: 6 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"const-name-snakecase": "off",
"no-global-import": "off",
"reason-string": "off",
"state-visibility": "off",
"custom-errors": "off",
"code-complexity": ["error", 8],
"compiler-version": ["error", ">=0.8.4"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 120],
"named-parameters-mapping": "warn",
"named-parameters-mapping": "off",
"no-console": "off",
"not-rely-on-time": "off",
"prettier/prettier": [
Expand Down
23 changes: 14 additions & 9 deletions CustomProvider.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
import { ethers } from "ethers";
import { ProviderWrapper } from "hardhat/plugins";
import type { EIP1193Provider, RequestArguments } from "hardhat/types";

class CustomProvider extends ProviderWrapper {
interface Test {
request: EIP1193Provider["request"];
}

class CustomProvider extends ProviderWrapper implements Test {
public lastBlockSnapshot: number;
public lastCounterRand: number;
public lastBlockSnapshotForDecrypt: number;

constructor(protected readonly _wrappedProvider: any) {
constructor(protected readonly _wrappedProvider: EIP1193Provider) {
super(_wrappedProvider);
this.lastBlockSnapshot = 0; // Initialize the variable
this.lastCounterRand = 0;
this.lastBlockSnapshotForDecrypt = 0;
}

async request(args: { method: string; params?: any[] }) {
async request(args: RequestArguments): ReturnType<EIP1193Provider["request"]> {
if (args.method === "eth_estimateGas") {
const estimatedGasLimit = BigInt(await this._wrappedProvider.request(args));
const estimatedGasLimit = BigInt((await this._wrappedProvider.request(args)) as bigint);
const increasedGasLimit = ethers.toBeHex((estimatedGasLimit * 120n) / 100n); // override estimated gasLimit by 120%, to avoid some edge case with ethermint gas estimation
return increasedGasLimit;
}
if (args.method === "evm_revert") {
const result = await this._wrappedProvider.request(args);
const blockNumberHex = await this._wrappedProvider.request({ method: "eth_blockNumber" });
const blockNumberHex = (await this._wrappedProvider.request({ method: "eth_blockNumber" })) as string;
this.lastBlockSnapshot = parseInt(blockNumberHex);
this.lastBlockSnapshotForDecrypt = parseInt(blockNumberHex);

const callData = {
to: "0x000000000000000000000000000000000000005d",
data: "0x1f20d85c",
};
this.lastCounterRand = await this._wrappedProvider.request({
this.lastCounterRand = (await this._wrappedProvider.request({
method: "eth_call",
params: [callData, "latest"],
});
})) as number;
return result;
}
if (args.method === "get_lastBlockSnapshot") {
Expand All @@ -42,11 +47,11 @@ class CustomProvider extends ProviderWrapper {
return this.lastBlockSnapshotForDecrypt;
}
if (args.method === "set_lastBlockSnapshot") {
this.lastBlockSnapshot = args.params![0];
this.lastBlockSnapshot = Array.isArray(args.params!) && args.params[0];
return this.lastBlockSnapshot;
}
if (args.method === "set_lastBlockSnapshotForDecrypt") {
this.lastBlockSnapshotForDecrypt = args.params![0];
this.lastBlockSnapshotForDecrypt = Array.isArray(args.params!) && args.params[0];
return this.lastBlockSnapshotForDecrypt;
}
const result = this._wrappedProvider.request(args);
Expand Down
21 changes: 14 additions & 7 deletions contracts/TestAsyncDecrypt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ contract TestAsyncDecrypt is GatewayCaller {
function requestFakeBool() public {
uint256[] memory cts = new uint256[](1);
cts[0] = uint256(0x4200000000000000000000000000000000000000000000000000000000000000);
Gateway.requestDecryption(cts, this.callbackBool.selector, 0, block.timestamp + 100, false); // this should revert because previous ebool is not honestly obtained
// this should revert because previous ebool is not honestly obtained
Gateway.requestDecryption(cts, this.callbackBool.selector, 0, block.timestamp + 100, false);
}

function callbackBool(uint256, bool decryptedInput) public onlyGateway returns (bool) {
Expand Down Expand Up @@ -129,7 +130,8 @@ contract TestAsyncDecrypt is GatewayCaller {
function requestFakeUint4() public {
uint256[] memory cts = new uint256[](1);
cts[0] = uint256(0x4200000000000000000000000000000000000000000000000000000000000100);
Gateway.requestDecryption(cts, this.callbackUint4.selector, 0, block.timestamp + 100, false); // this should revert because previous handle is not honestly obtained
// this should revert because previous handle is not honestly obtained
Gateway.requestDecryption(cts, this.callbackUint4.selector, 0, block.timestamp + 100, false);
}

function callbackUint4(uint256, uint8 decryptedInput) public onlyGateway returns (uint8) {
Expand All @@ -146,7 +148,8 @@ contract TestAsyncDecrypt is GatewayCaller {
function requestFakeUint8() public {
uint256[] memory cts = new uint256[](1);
cts[0] = uint256(0x4200000000000000000000000000000000000000000000000000000000000200);
Gateway.requestDecryption(cts, this.callbackUint8.selector, 0, block.timestamp + 100, false); // this should revert because previous handle is not honestly obtained
// this should revert because previous handle is not honestly obtained
Gateway.requestDecryption(cts, this.callbackUint8.selector, 0, block.timestamp + 100, false);
}

function callbackUint8(uint256, uint8 decryptedInput) public onlyGateway returns (uint8) {
Expand All @@ -163,7 +166,8 @@ contract TestAsyncDecrypt is GatewayCaller {
function requestFakeUint16() public {
uint256[] memory cts = new uint256[](1);
cts[0] = uint256(0x4200000000000000000000000000000000000000000000000000000000000300);
Gateway.requestDecryption(cts, this.callbackUint16.selector, 0, block.timestamp + 100, false); // this should revert because previous handle is not honestly obtained
// this should revert because previous handle is not honestly obtained
Gateway.requestDecryption(cts, this.callbackUint16.selector, 0, block.timestamp + 100, false);
}

function callbackUint16(uint256, uint16 decryptedInput) public onlyGateway returns (uint16) {
Expand All @@ -188,7 +192,8 @@ contract TestAsyncDecrypt is GatewayCaller {
function requestFakeUint32() public {
uint256[] memory cts = new uint256[](1);
cts[0] = uint256(0x4200000000000000000000000000000000000000000000000000000000000400);
Gateway.requestDecryption(cts, this.callbackUint32.selector, 0, block.timestamp + 100, false); // this should revert because previous handle is not honestly obtained
// this should revert because previous handle is not honestly obtained
Gateway.requestDecryption(cts, this.callbackUint32.selector, 0, block.timestamp + 100, false);
}

function callbackUint32(uint256 requestID, uint32 decryptedInput) public onlyGateway returns (uint32) {
Expand All @@ -209,7 +214,8 @@ contract TestAsyncDecrypt is GatewayCaller {
function requestFakeUint64() public {
uint256[] memory cts = new uint256[](1);
cts[0] = uint256(0x4200000000000000000000000000000000000000000000000000000000000500);
Gateway.requestDecryption(cts, this.callbackUint64.selector, 0, block.timestamp + 100, false); // this should revert because previous handle is not honestly obtained
// this should revert because previous handle is not honestly obtained
Gateway.requestDecryption(cts, this.callbackUint64.selector, 0, block.timestamp + 100, false);
}

function requestUint64NonTrivial(einput inputHandle, bytes calldata inputProof) public {
Expand Down Expand Up @@ -262,7 +268,8 @@ contract TestAsyncDecrypt is GatewayCaller {
function requestFakeAddress() public {
uint256[] memory cts = new uint256[](1);
cts[0] = uint256(0x4200000000000000000000000000000000000000000000000000000000000700);
Gateway.requestDecryption(cts, this.callbackAddress.selector, 0, block.timestamp + 100, false); // this should revert because previous handle is not honestly obtained
// this should revert because previous handle is not honestly obtained
Gateway.requestDecryption(cts, this.callbackAddress.selector, 0, block.timestamp + 100, false);
}

function callbackAddress(uint256, address decryptedInput) public onlyGateway returns (address) {
Expand Down
17 changes: 17 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import eslint from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";

export default [
{
languageOptions: {
globals: globals.node,
},
linterOptions: {
reportUnusedDisableDirectives: "off",
},
ignores: ["abi/", "artifacts/", "cache/", "res/", "types/*"],
},
eslint.configs.recommended,
...tseslint.configs.recommended,
];
5 changes: 3 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import dotenv from "dotenv";
import * as fs from "fs-extra";
import "hardhat-deploy";
import "hardhat-ignore-warnings";
import type { HardhatUserConfig, extendProvider } from "hardhat/config";
import type { HardhatUserConfig } from "hardhat/config";
import { extendProvider } from "hardhat/config";
import { task } from "hardhat/config";
import type { NetworkUserConfig } from "hardhat/types";
import { resolve } from "path";
Expand All @@ -17,7 +18,7 @@ import "./tasks/taskDeploy";
import "./tasks/taskGatewayRelayer";
import "./tasks/taskTFHE";

extendProvider(async (provider, config, network) => {
extendProvider(async (provider) => {
const newProvider = new CustomProvider(provider);
return newProvider;
});
Expand Down
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"url": "https://github.com/zama-ai"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.6",
Expand All @@ -20,22 +21,24 @@
"@typechain/ethers-v6": "^0.4.0",
"@typechain/hardhat": "^8.0.0",
"@types/chai": "^4.3.4",
"@types/eslint__js": "^8.42.3",
"@types/fs-extra": "^9.0.13",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.0.1",
"chai": "^4.3.7",
"cross-env": "^7.0.3",
"dotenv": "^16.0.3",
"eslint": "^8.28.0",
"eslint": "^9.9.0",
"eslint-config-prettier": "^8.5.0",
"ethers": "^6.8.0",
"fhevm": "^0.5.5",
"fhevm": "^0.5.8",
"fhevmjs": "^0.5.2",
"fs-extra": "^10.1.0",
"globals": "^15.9.0",
"hardhat": "^2.22.8",
"hardhat-deploy": "^0.11.29",
"hardhat-deploy": "^0.12.4",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-ignore-warnings": "^0.2.11",
"hardhat-preprocessor": "^0.1.5",
Expand All @@ -50,7 +53,8 @@
"ts-generator": "^0.1.1",
"ts-node": "^10.9.1",
"typechain": "^8.2.0",
"typescript": "^5.1.6"
"typescript": "^5.5.4",
"typescript-eslint": "^8.0.1"
},
"files": [
"contracts"
Expand All @@ -76,7 +80,7 @@
"deploy:contracts": "hardhat deploy",
"lint": "pnpm lint:sol && pnpm lint:ts && pnpm prettier:check",
"lint:sol": "solhint --max-warnings 25 \"contracts/**/*.sol\"",
"lint:ts": "eslint --ignore-path ./.eslintignore --ext .js,.ts .",
"lint:ts": "eslint .",
"postinstall": "DOTENV_CONFIG_PATH=./.env.example pnpm typechain",
"prettier:check": "prettier --check \"**/*.{js,json,md,sol,ts,yml}\"",
"prettier:write": "prettier --write \"**/*.{js,json,md,sol,ts,yml}\"",
Expand Down
Loading

0 comments on commit 9ec5005

Please sign in to comment.