/fhenix-toolkit:fhenix-testsfrom fhenix-toolkit
Helps write and extend tests for confidential CoFHE (Fhenix) smart contracts and dApps. Covers Foundry mocks for unit-level Solidity testing and Hardhat plugin for end-to-end encrypt-tx-decrypt flows, including encrypted input fixtures and SDK decrypt flows.
Ships in fhenix-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You activate when the user is writing tests that exercise Fhenix-encrypted code: Foundry .t.sol files importing FHE.sol, Hardhat .test.ts files using @cofhe/sdk or the Hardhat plugin's mock environment, or any file under tests/contracts/.
| Choice | Use when |
|---|---|
Foundry mocks (cofhe-mock-contracts) | Pure-Solidity testing; fast iteration; no Node.js dependency; testing branchless logic, select/allowThis paths, encrypted state transitions. |
Hardhat plugin (@cofhe/hardhat-plugin) | End-to-end with the SDK; tests the encrypt→tx→decrypt loop; tests frontend integration; covers the on-chain + off-chain split. |
You can use both in one project — Foundry for unit-level Solidity logic, Hardhat for E2E flows.
Decision tree: references/decision-trees.md.
Mock gas ≠ prod gas. Mock environments simulate gas costs that don't match the threshold network's actual costs. Always validate gas-sensitive code on a testnet before mainnet.
execute() is the one async terminator — don't poll. The legacy on-chain FHE.decrypt(ct) + getDecryptResultSafe(ct) poll loop is gone. All decrypt paths terminate on await client.decryptFor*(...).execute(); in MOCK mode it resolves immediately, in TESTNET mode it takes seconds. Tests must await properly and use realistic timeouts.
Seed FHE.random* for determinism. Pass a non-zero seed to make tests reproducible. Seed=0 picks a system seed → flaky tests.
Test the ACL path. For every encrypted op stored in state, assert that subsequent operations succeed (proving allowThis was called correctly). Forgotten allowThis is a silent class of bug.
Test both arms of FHE.select. Even when the encrypted condition picks one arm at runtime, both must be valid expressions. Force both branches in tests by varying inputs.
Verify on-chain + off-chain pairing. E2E tests must exercise the decrypt-flow pairing matrix (allowPublic ↔ withoutPermit, etc.). A test that uses one without the other is testing a non-existent code path.
Full rule list: references/hard-rules.md.
Install the mocks (note: the old cofhe-foundry-mocks repo is archived; the live one is cofhe-mock-contracts):
forge install fhenixprotocol/cofhe-mock-contracts
In foundry.toml, point remappings at the library. Tests inherit CoFheTest and call etchFhenixMocks() to deploy the mocks at fixed addresses:
import { Test } from "forge-std/Test.sol";
import { CoFheTest } from "@fhenixprotocol/cofhe-mock-contracts/CoFheTest.sol";
contract MyTest is Test, CoFheTest {
function setUp() public {
etchFhenixMocks(); // installs mock TaskManager / ACL / ZkVerifier
// ... deploy your contracts
}
}
Details: concepts/foundry-mocks-setup.md.
Install the plugin:
npm install --save-dev @cofhe/hardhat-plugin
In hardhat.config.ts:
import "@cofhe/hardhat-plugin";
Inside a test fixture, deploy the mocks then construct an SDK client bound to a signer:
await hre.run("task:cofhe-mocks:deploy");
const client = await hre.cofhe.createClientWithBatteries(signer);
Tests then use the SDK normally; the plugin handles MOCK-vs-TESTNET keying.
Details: concepts/hardhat-plugin-setup.md.
E2E tests must exercise the on-chain allow* plus the SDK decrypt plus on-chain verify, in that order:
// Encrypt input, submit
const [encInput] = await client.encryptInputs([Encryptable.uint64(42n)]).execute();
await contract.submit(encInput);
// Trigger reveal (contract calls FHE.allowPublic inside)
await contract.requestSettlement();
const ctHash = await contract.publicHandle();
// Client decrypts via SDK
const { decryptedValue, signature } = await client
.decryptForTx(ctHash).withoutPermit().execute();
// Settle by calling back with the proven plaintext
await contract.finalizeWith(decryptedValue, signature);
// Contract verifies via FHE.verifyDecryptResult(decryptedValue, signature)
Pattern: concepts/testing-decrypt-flows.md.
foundry-mocks-setup.md — installing and using cofhe-mock-contracts.hardhat-plugin-setup.md — installing and using @cofhe/hardhat-plugin, MOCK vs TESTNET mode.testing-encrypted-input.md — building InEuintXX test fixtures off-chain.testing-decrypt-flows.md — testing SDK decryptForView / decryptForTx round-trips and on-chain verify.testing-multi-permit.md — multiple permits / sharing permits / cross-user flows.mock-vs-prod-divergence.md — what mocks differ on (gas, latency, randomness).For exact mock APIs, Hardhat plugin tasks, or current setup snippets, see references/lookup-recipes.md — prefer live source over recall.
references/concepts/foundry-mocks-setup.md (opens in a new tab)references/concepts/hardhat-plugin-setup.md (opens in a new tab)references/concepts/mock-vs-prod-divergence.md (opens in a new tab)references/concepts/testing-decrypt-flows.md (opens in a new tab)references/concepts/testing-encrypted-input.md (opens in a new tab)references/concepts/testing-multi-permit.md (opens in a new tab)references/decision-trees.md (opens in a new tab)references/hard-rules.md (opens in a new tab)references/lookup-recipes.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
fhenix, cofhe, confidential-contracts, foundry, hardhat, encrypted-testing
npx claudepluginhub fhenixprotocol/fhenix-toolkit --plugin fhenix-toolkit4 skills in this plugin
/fhenix-contractsUse when working on Solidity files importing @fhenixprotocol/cofhe-contracts/FHE.sol or fhenix-confidential-contracts, or using euint*/ebool/eaddress types. Teaches confidential contract patterns — branchless updates with FHE.select, the four ACL verbs, the two decryption flows, and the confidential-token standards picker. Activates on Fhenix CoFHE contract work./fhenix-reviewUse when auditing or reviewing confidential code for Fhenix CoFHE — both on-chain (FHE.sol) and off-chain (@cofhe/sdk). Catches ACL bugs, decrypt-flow mismatches, plaintext leaks, confidentiality-vs-anonymity confusion, and the 30+ recurring gotchas in this catalog. Activates only in review/audit contexts — PR diffs, `gh pr view` output, or prompts like "audit this", "review this", "is this safe", "security check", "look over my FHE code"./fhenix-sdkUse when working with @cofhe/sdk in TypeScript — encrypting inputs, managing permits, choosing decrypt modes (decryptForView vs decryptForTx), or wiring CoFHE into a Next.js / wagmi / viem dApp. Activates on imports of @cofhe/sdk or its subpaths, on hooks named useCofhe* or usePermit*, and on prompts like "encrypt this input" or "set up cofhe in Next.js."Other plugins' skills for the same job