Skip to content

Commit

Permalink
feat: same addresses as Sepolia in mocked, tests work on Sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
jatZama committed Dec 5, 2024
1 parent 98a05bf commit a8fc716
Show file tree
Hide file tree
Showing 17 changed files with 256 additions and 909 deletions.
5 changes: 0 additions & 5 deletions CustomProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ class CustomProvider extends ProviderWrapper implements Test {
}

async request(args: RequestArguments): ReturnType<EIP1193Provider["request"]> {
if (args.method === "eth_estimateGas") {
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" })) as string;
Expand Down
44 changes: 2 additions & 42 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ import type { HardhatUserConfig, extendProvider } from "hardhat/config";
import { task } from "hardhat/config";
import type { NetworkUserConfig } from "hardhat/types";
import { resolve } from "path";
import * as path from "path";

import CustomProvider from "./CustomProvider";
// Adjust the import path as needed
import "./tasks/accounts";
import "./tasks/getEthereumAddress";
import "./tasks/mint";
import "./tasks/taskDeploy";
import "./tasks/taskGatewayRelayer";
import "./tasks/taskTFHE";
import { setCodeMocked } from "./test/mockedSetup";

extendProvider(async (provider, config, network) => {
const newProvider = new CustomProvider(provider);
Expand Down Expand Up @@ -92,43 +88,7 @@ function replaceImportStatement(filePath: string, oldImport: string, newImport:
task("test", async (taskArgs, hre, runSuper) => {
// Run modified test task
if (hre.network.name === "hardhat") {
// in fhevm mode all this block is done when launching the node via `pnmp fhevm:start`
const privKeyGatewayDeployer = process.env.PRIVATE_KEY_GATEWAY_DEPLOYER;
const privKeyFhevmDeployer = process.env.PRIVATE_KEY_FHEVM_DEPLOYER;
await hre.run("task:computeGatewayAddress", { privateKey: privKeyGatewayDeployer });
await hre.run("task:computeACLAddress", { privateKey: privKeyFhevmDeployer });
await hre.run("task:computeTFHEExecutorAddress", { privateKey: privKeyFhevmDeployer });
await hre.run("task:computeKMSVerifierAddress", { privateKey: privKeyFhevmDeployer });
await hre.run("task:computeInputVerifierAddress", { privateKey: privKeyFhevmDeployer, useAddress: false });
await hre.run("task:computeFHEPaymentAddress", { privateKey: privKeyFhevmDeployer });
await hre.run("compile:specific", { contract: "contracts/" });
const sourceDir = path.resolve(__dirname, "node_modules/fhevm-core-contracts/");
const destinationDir = path.resolve(__dirname, "fhevmTemp/");
fs.copySync(sourceDir, destinationDir, { dereference: true });

const sourceDir2 = path.resolve("./node_modules/fhevm/gateway/GatewayContract.sol");
const destinationFilePath = path.join(destinationDir, "GatewayContract.sol");
fs.copySync(sourceDir2, destinationFilePath, { dereference: true });
const oldImport = `import "../lib/TFHE.sol";`;
const newImport = `import "fhevm/lib/TFHE.sol";`;
replaceImportStatement(destinationFilePath, oldImport, newImport);
const sourceDir3 = path.resolve("./node_modules/fhevm/gateway/IKMSVerifier.sol");
const destinationFilePath3 = path.join(destinationDir, "IKMSVerifier.sol");
fs.copySync(sourceDir3, destinationFilePath3, { dereference: true });

await hre.run("compile:specific", { contract: "fhevmTemp/" });
await hre.run("task:faucetToPrivate", { privateKey: privKeyFhevmDeployer });
await hre.run("task:deployACL", { privateKey: privKeyFhevmDeployer });
await hre.run("task:deployTFHEExecutor", { privateKey: privKeyFhevmDeployer });
await hre.run("task:deployKMSVerifier", { privateKey: privKeyFhevmDeployer });
await hre.run("task:deployInputVerifier", { privateKey: privKeyFhevmDeployer });
await hre.run("task:deployFHEPayment", { privateKey: privKeyFhevmDeployer });
await hre.run("task:addSigners", {
numSigners: process.env.NUM_KMS_SIGNERS!,
privateKey: privKeyFhevmDeployer,
useAddress: false,
});
await hre.run("task:launchFhevm", { skipGetCoin: false, useAddress: false });
await setCodeMocked(hre);
}
await runSuper();
});
Expand Down
34 changes: 0 additions & 34 deletions tasks/getEthereumAddress.ts

This file was deleted.

156 changes: 0 additions & 156 deletions tasks/taskDeploy.ts

This file was deleted.

Loading

0 comments on commit a8fc716

Please sign in to comment.