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

Ld/add local copro setup for e2e #71

Open
wants to merge 4 commits into
base: mano/cleanup
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions e2e/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export MNEMONIC="adapt mosquito move limb mobile illegal tree voyage juice mosquito burger raise father hope layer"

export TFHE_EXECUTOR_CONTRACT_ADDRESS=0x596E6682c72946AF006B27C131793F2b62527A4b
export ACL_CONTRACT_ADDRESS=0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2
export PAYMENT_CONTRACT_ADDRESS=0x6d5A11aC509C707c00bc3A0a113ACcC26c532547
export KMS_VERIFIER_CONTRACT_ADDRESS=0x208De73316E44722e16f6dDFF40881A3e4F86104
export GATEWAY_CONTRACT_ADDRESS=0x096b4679d45fB675d4e2c1E4565009Cec99A12B1

export GATEWAY_URL="http://localhost:7077"
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ abi/
coverage.json
pnpm-lock.yaml
yarn.lock
contracts/E2EFHEVMConfig.sol
47 changes: 47 additions & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/make -f

# Variables for paths and commands
ENV_FILE=.env
CONFIG_FILE=contracts/E2EFHEVMConfig.sol
HARDHAT_CONFIG=hardhat.config.ts
NPM_CMD=npm run task:accounts

.PHONY: all print-accounts prepare-test-local-coprocessor prepare-test-sepolia clean

# Default target
all: print-accounts

# Prints accounts with a reminder to ensure they are funded
print-accounts:
@echo "Checking accounts. Ensure the first account has sufficient funds."
@$(NPM_CMD)

# Prepares the environment for local coprocessor testing
prepare-test-local-coprocessor:
@echo "Preparing environment for local coprocessor testing..."
@cp -v .env.local $(ENV_FILE)
@cp -v contracts/E2EFHEVMConfigLocal.sol $(CONFIG_FILE)
@$(MAKE) set-local-network
$(MAKE) print-accounts

# Prepares the environment for Sepolia network testing
prepare-test-sepolia:
@echo "Preparing environment for Sepolia network testing..."
@cp -v .env.example $(ENV_FILE)
@cp -v contracts/E2EFHEVMConfigSepolia.sol $(CONFIG_FILE)
$(MAKE) print-accounts

# Sets the default network to "localCoprocessor" in hardhat.config.ts
set-local-network:
@echo "Setting default network to 'localCoprocessor' in $(HARDHAT_CONFIG)..."
@if [ "$(shell uname)" = "Darwin" ]; then \
sed -i '' 's/defaultNetwork: ".*"/defaultNetwork: "localCoprocessor"/' $(HARDHAT_CONFIG); \
else \
sed -i 's/defaultNetwork: ".*"/defaultNetwork: "localCoprocessor"/' $(HARDHAT_CONFIG); \
fi

# Cleans up generated or temporary files
clean:
@echo "Cleaning up temporary files..."
@rm -fv $(ENV_FILE)
@rm -fv $(CONFIG_FILE)
62 changes: 51 additions & 11 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,69 @@
# e2e tests
# End-to-End (E2E) Tests

## Install
This repository contains end-to-end (E2E) tests to ensure that all components work together as intended.

## Installation

Before you begin, ensure that you have [Node.js](https://nodejs.org/) and [npm](https://www.npmjs.com/) installed on your machine.

```bash
npm install
```

## Configuration

1. Copy `.env.example` to `.env` and edit addresses with the correct one.
2. Edit your `.env` file with correct values.
3. Edit `contracts/E2EFHEVMConfig.sol` and set correct addresses of your fhEVM.
4. Edit `hardhat.config.ts` to set the `defaultNetwork`. By default, it is set to Sepolia, but you can use a different one
or add your own L1 address.
5. Fund the primary wallet derived from your mnemomic. If you don't know what is the public address, run
`npm run task:accounts`
### Default Configuration: Sepolia

The default configuration is set up for the Sepolia network. To prepare the environment for testing on Sepolia, run the following command:

```bash
make prepare-test-sepolia
```

This will:

1. Copy `.env.example` to `.env`.
2. Update the `contracts/E2EFHEVMConfig.sol` file with the Sepolia-specific configuration.
3. Print the list of accounts and remind you to ensure the first account is funded.
4. Info: In hardhat.config.ts Seploia is already set as default network

### Local Testing Configuration

## Run
To prepare the environment for testing with a local coprocessor setup, use the following command:

```bash
make prepare-test-local-coprocessor
```

This will:

1. Copy `.env.local` to `.env`.
2. Update the `contracts/E2EFHEVMConfig.sol` file with the local configuration.
3. Print the list of accounts and remind you to ensure the first account is funded.
4. Update hardhat.config.ts to make localCorpocessor as default network

## Running the Tests

To run the entire test suite:

```bash
npm run test
```

or if you want to run only one test
If you want to focus on a specific test:

```bash
npm run test test/encryptedERC20/EncryptedERC20.ts
```

## Cleaning Up

To clean up temporary files and reset the environment, run:

```bash
make clean
```

---

**Note:** Always double-check your `.env` file and address configurations before running tests to avoid unexpected errors.
40 changes: 40 additions & 0 deletions e2e/contracts/E2EFHEVMConfigLocal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import {FHEVMConfig, TFHE} from "fhevm/lib/TFHE.sol";
import { Gateway } from "fhevm/gateway/GatewayCaller.sol";

address constant gatewayAddress = 0x096b4679d45fB675d4e2c1E4565009Cec99A12B1;

/**
* @title ZamaFHEVMConfig.
* @notice This library returns the TFHE config for different networks
* with the contract addresses for
* (1) ACL, (2) TFHEExecutor, (3) FHEPayment, (4) KMSVerifier,
* which are deployed & maintained by Zama.
*/
library DefaultFHEVMConfig {
function getConfig() internal pure returns (FHEVMConfig.FHEVMConfigStruct memory) {
return
FHEVMConfig.FHEVMConfigStruct({
ACLAddress: 0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2,
TFHEExecutorAddress: 0x596E6682c72946AF006B27C131793F2b62527A4b,
FHEPaymentAddress: 0x6d5A11aC509C707c00bc3A0a113ACcC26c532547,
KMSVerifierAddress: 0x208De73316E44722e16f6dDFF40881A3e4F86104
});
}
}

/**
* @title MockZamaFHEVMConfig.
* @dev This contract can be inherited by a contract wishing to use these contracts on the mock
* environment provided by Zama.
* Other providers may offer similar contracts deployed at different addresses.
* If you wish to use them, you should rely on the instructions from these providers.
*/
contract E2EFHEVMConfig {
constructor() {
TFHE.setFHEVM(DefaultFHEVMConfig.getConfig());
Gateway.setGateway(gatewayAddress);
}
}
5 changes: 5 additions & 0 deletions e2e/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if (!mnemonic) {

const chainIds = {
zama: 9000,
localCoprocessor: 12345,
local: 9000,
ethereum: 1,
sepolia: 11155111,
Expand All @@ -34,6 +35,9 @@ function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {
case "local":
jsonRpcUrl = "http://localhost:8545";
break;
case 'localCoprocessor':
jsonRpcUrl = 'http://localhost:8745';
break;
case "zama":
jsonRpcUrl = "https://devnet.zama.ai";
break;
Expand Down Expand Up @@ -85,6 +89,7 @@ const config: HardhatUserConfig = {
},
zama: getChainConfig("zama"),
local: getChainConfig("local"),
localCoprocessor: getChainConfig('localCoprocessor'),
sepolia: getChainConfig("sepolia"),
ethereum: getChainConfig("ethereum"),
},
Expand Down