From 5a65a2a13cecaec9e9986f3a249d75b0835cb0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joseph-Andr=C3=A9=20Turk?= Date: Wed, 6 Mar 2024 13:38:43 +0100 Subject: [PATCH] feat: updated ethermint and added CI fix: typo workflows --- .github/workflows/test.yml | 30 ++++++++++++++++++++++++++++++ .github/workflows/testmock.yml | 25 +++++++++++++++++++++++++ package.json | 6 +++--- pnpm-lock.yaml | 16 ++++++++-------- test/dao/GovernorZama.ts | 10 +++++----- test/instance.ts | 4 +++- test/types.ts | 12 ------------ 7 files changed, 74 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/testmock.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4fc9d25 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Pull request tests + +on: + pull_request: + branches: + - main + +jobs: + build: + runs-on: large_ubuntu_16 + strategy: + matrix: + node-version: [18.x] + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: cp .env.example .env + - run: npm ci + - run: npm run prettier:check + - name: "npm CI test" + run: | + # sometimes not created and is not tailed + touch fhevm.log + npm run fhevm:start &> fhevm.log & + tail -f fhevm.log | sed '/Starting JSON WebSocket server/ q' + npm run test + npm run fhevm:stop || true \ No newline at end of file diff --git a/.github/workflows/testmock.yml b/.github/workflows/testmock.yml new file mode 100644 index 0000000..fb553b4 --- /dev/null +++ b/.github/workflows/testmock.yml @@ -0,0 +1,25 @@ +name: Pull request tests with mocks + +on: + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: cp .env.example .env + - run: npm ci + - name: "npm CI test" + run: | + # sometimes not created and is not tailed + npm run test:mock \ No newline at end of file diff --git a/package.json b/package.json index b6bf8f9..16f4747 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,8 @@ "eslint": "^8.28.0", "eslint-config-prettier": "^8.5.0", "ethers": "^6.8.0", - "fhevm": "0.4.0-0", - "fhevmjs": "^0.4.0-4", + "fhevm": "0.4.0-2", + "fhevmjs": "^0.4.0-6", "fs-extra": "^10.1.0", "hardhat": "^2.19.4", "hardhat-deploy": "^0.11.29", @@ -84,7 +84,7 @@ "task:mint": "hardhat task:mint", "task:deployERC20": "hardhat task:deployERC20", "task:accounts": "hardhat task:accounts", - "fhevm:start": "docker run -i -p 8545:8545 -p 8546:8546 --rm --name fhevm ghcr.io/zama-ai/ethermint-dev-node:v0.3.0-0", + "fhevm:start": "docker run -i -p 8545:8545 -p 8546:8546 --rm --name fhevm ghcr.io/zama-ai/ethermint-dev-node:v0.3.0-5", "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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 16e8ed0..58c8f87 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,11 +74,11 @@ devDependencies: specifier: ^6.8.0 version: 6.10.0 fhevm: - specifier: 0.4.0-0 - version: 0.4.0-0(hardhat@2.19.5) + specifier: 0.4.0-2 + version: 0.4.0-2(hardhat@2.19.5) fhevmjs: - specifier: ^0.4.0-4 - version: 0.4.0-4 + specifier: ^0.4.0-6 + version: 0.4.0-6 fs-extra: specifier: ^10.1.0 version: 10.1.0 @@ -2819,8 +2819,8 @@ packages: reusify: 1.0.4 dev: true - /fhevm@0.4.0-0(hardhat@2.19.5): - resolution: {integrity: sha512-km+ruRXadNpavPiwbapj+P+P6PD3kxMnYUm+u8WbU7WIRDmbKNWOACTeuc/BtGdaBB7tyam9fThHEQlY7Wfh4w==} + /fhevm@0.4.0-2(hardhat@2.19.5): + resolution: {integrity: sha512-yZ+LLjkBHjBtzwB+8JeEt/dfmhbYoTxbBv337gf8F39erZnXQ56UAhmEnsEKF310Dxp3fJ7bTsDT1P891Xv5Dw==} dependencies: '@openzeppelin/contracts': 5.0.1 hardhat-preprocessor: 0.1.5(hardhat@2.19.5) @@ -2828,8 +2828,8 @@ packages: - hardhat dev: true - /fhevmjs@0.4.0-4: - resolution: {integrity: sha512-aCEtp3cNGIc8wuAaxnXaztfP6VLzIHPTFKgCT3izAaWLoo50P6xZ1okbKdeX3vT+lmOYdszwY03ICooKZO68xg==} + /fhevmjs@0.4.0-6: + resolution: {integrity: sha512-1qtfJ9GHdcTq6uKad/Ow7PHsqrMBWoqFidZ8XdFyktkTD708DN/KIzKgpSiY3q4qxI58xig+ds9S3Yx4jGUewg==} hasBin: true dependencies: bigint-buffer: 1.1.5 diff --git a/test/dao/GovernorZama.ts b/test/dao/GovernorZama.ts index c02f7e4..8fa33ff 100644 --- a/test/dao/GovernorZama.ts +++ b/test/dao/GovernorZama.ts @@ -9,7 +9,7 @@ import { deployGovernorZamaFixture, deployTimelockFixture } from "./GovernorZama describe("GovernorZama", function () { before(async function () { - await initSigners(3); + await initSigners(); this.signers = await getSigners(); this.comp = await deployCompFixture(); @@ -88,14 +88,14 @@ describe("GovernorZama", function () { } await waitForBlock(proposals.startBlock + 1n); // Cast some votes - const encryptedSupportBob = this.instances.bob.encrypt8(1); + const encryptedSupportBob = this.instances.bob.encryptBool(true); const txVoteBob = await createTransaction( this.governor.connect(this.signers.bob)["castVote(uint256,bytes)"], proposalId, encryptedSupportBob, ); - const encryptedSupportCarol = this.instances.carol.encrypt8(1); + const encryptedSupportCarol = this.instances.carol.encryptBool(true); const txVoteCarol = await createTransaction( this.governor.connect(this.signers.carol)["castVote(uint256,bytes)"], proposalId, @@ -135,14 +135,14 @@ describe("GovernorZama", function () { await waitForBlock(proposals.startBlock + 1n); // Cast some votes - const encryptedSupportBob = this.instances.bob.encrypt8(0); + const encryptedSupportBob = this.instances.bob.encryptBool(false); const txVoteBob = await createTransaction( this.governor.connect(this.signers.bob)["castVote(uint256,bytes)"], proposalId, encryptedSupportBob, ); - const encryptedSupportCarol = this.instances.carol.encrypt8(0); + const encryptedSupportCarol = this.instances.carol.encryptBool(true); const txVoteCarol = await createTransaction( this.governor.connect(this.signers.carol)["castVote(uint256,bytes)"], proposalId, diff --git a/test/instance.ts b/test/instance.ts index fccac88..4f1a98f 100644 --- a/test/instance.ts +++ b/test/instance.ts @@ -54,6 +54,8 @@ export const createInstance = async (contractAddress: string, account: Signer, e const instance = await fhevmjs.createInstance({ chainId, publicKey }); if (HARDHAT_NETWORK === "hardhat") { + instance.encryptBool = createUintToUint8ArrayFunction(1); + instance.encrypt4 = createUintToUint8ArrayFunction(4); instance.encrypt8 = createUintToUint8ArrayFunction(8); instance.encrypt16 = createUintToUint8ArrayFunction(16); instance.encrypt32 = createUintToUint8ArrayFunction(32); @@ -81,7 +83,7 @@ const generatePublicKey = async (contractAddress: string, signer: Signer, instan function createUintToUint8ArrayFunction(numBits: number) { const numBytes = Math.ceil(numBits / 8); - return function (uint: number | bigint) { + return function (uint: number | bigint | boolean) { const buffer = toBufferBE(BigInt(uint), numBytes); return buffer; }; diff --git a/test/types.ts b/test/types.ts index 30632c3..1e13854 100644 --- a/test/types.ts +++ b/test/types.ts @@ -1,17 +1,5 @@ import type { FhevmInstance } from "fhevmjs"; -import { EncryptedERC20 } from "../types"; -import type { Signers } from "./signers"; - -declare module "mocha" { - export interface Context { - signers: Signers; - contractAddress: string; - instances: FhevmInstances; - erc20: EncryptedERC20; - } -} - export interface FhevmInstances { alice: FhevmInstance; bob: FhevmInstance;