Write FHEVM tests in Foundry
Inherit from FhevmTest
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import {FhevmTest} from "forge-fhevm/FhevmTest.sol";
import {FHE} from "@fhevm/solidity/lib/FHE.sol";
import "encrypted-types/EncryptedTypes.sol";
contract MyTest is FhevmTest {
MyContract myContract;
function setUp() public override {
super.setUp(); // deploy FHEVM host contracts
myContract = new MyContract();
}
}Encrypt inputs
1
2
3
Supported encrypt helpers
Function
Value type
Returned handle
Decrypt results
decrypt(handle) — low-level lookup
publicDecrypt(handles) — KMS-signed public decryption
userDecrypt(handle, user, contract, signature) — user-facing flow
Error
Cause
Full counter test example
Run the tests
Where to go next
Last updated