docs/solidity-guides/hardhat/run_test.md
In this section, you'll find everything you need to test your FHEVM smart contracts in your Hardhat project.
The FHEVM Hardhat plugin provides three FHEVM runtime modes tailored for different stages of contract development and testing. Each mode offers a trade-off between speed, encryption, and persistence.
The Hardhat (In-Memory) default network: π§ͺ Uses mock encryption. Ideal for regular tests, CI test coverage, and fast feedback during early contract development. No real encryption is used.
The Hardhat Node (Local Server) network: π§ͺ Uses mock encryption. Ideal when you need persistent state - for example, when testing frontend interactions, simulating user flows, or validating deployments in a realistic local environment. Still uses mock encryption.
The Sepolia Testnet network: π Uses real encryption. Use this mode once your contract logic is stable and validated locally. This is the only mode that runs on the full FHEVM stack with real encrypted values. It simulates real-world production conditions but is slower and requires Sepolia ETH.
{% hint style="success" %} Zama Testnet is not a blockchain itself. It is a protocol that enables you to run confidential smart contracts on existing blockchains (such as Ethereum, Base, and others) with the support of encrypted types. See the FHE on blockchain guide to learn more about the protocol architecture.
Currently, Zama Protocol is available on the Sepolia Testnet. Support for additional chains will be added in the future. See the roadmapβ {% endhint %}
| Mode | Encryption | Persistent | Chain | Speed | Usage |
|---|---|---|---|---|---|
| Hardhat (default) | π§ͺ Mock | β No | In-Memory | β‘β‘ Very Fast | Fast local testing and coverage |
| Hardhat Node | π§ͺ Mock | β Yes | Server | β‘ Fast | Frontend integration and local persistent testing |
| Sepolia Testnet | π Real Encryption | β Yes | Server | π’ Slow | Full-stack validation with real encrypted data |
To demonstrate the three available testing modes, we'll use the fhevm-hardhat-template, which comes with the FHEVM Hardhat Plugin pre-installed, a basic FHECounter smart contract, and ready-to-use tasks for interacting with a deployed instance of this contract.
To run your tests in-memory using FHEVM mock values, simply run the following:
npx hardhat test --network hardhat
You can also run your tests against a local Hardhat node, allowing you to deploy contract instances and interact with them in a persistent environment.
{% stepper %} {% step %}
npx hardhat node
{% endstep %} {% step %}
From the root project directory:
npx hardhat test --network localhost
{% endstep %} {% step %}
FHECounter smart contract on Hardhat NodeFrom the root project directory:
npx hardhat deploy --network localhost
Check the deployed contract FHEVM configuration:
npx hardhat fhevm check-fhevm-compatibility --network localhost --address <deployed contract address>
{% endstep %} {% step %}
FHECounter smart contractFrom the root project directory:
npx hardhat --network localhost task:decrypt-count
npx hardhat --network localhost task:increment --value 1
npx hardhat --network localhost task:decrypt-count
{% endstep %} {% endstepper %}
To test your FHEVM smart contract using real encrypted values, you can run your tests on the Sepolia Testnet.
{% stepper %} {% step %}
From the root project directory:
npx hardhat clean
npx hardhat compile --network sepolia
{% endstep %} {% step %}
FHECounter smart contract on Sepolianpx hardhat deploy --network sepolia
{% endstep %} {% step %}
FHECounter contract FHEVM configurationFrom the root project directory:
npx hardhat fhevm check-fhevm-compatibility --network sepolia --address <deployed contract address>
If an internal exception is raised, it likely means the contract was not properly compiled for the Sepolia network.
{% endstep %} {% step %}
FHECounter contractFrom the root project directory:
npx hardhat --network sepolia task:decrypt-count
npx hardhat --network sepolia task:increment --value 1
npx hardhat --network sepolia task:decrypt-count
{% endstep %} {% endstepper %}