fhenix-tests

Write Foundry and Hardhat tests for Fhenix CoFHE confidential smart contracts.

1|Updated Sep 4, 2025
One-click install
npx skills add https://github.com/FuzzysTodd/The-Nexus-Protocol-Token-DAO --skill fhenix-tests-fuzzystodd
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: fhenix-tests
Source: https://github.com/FuzzysTodd/The-Nexus-Protocol-Token-DAO/tree/main/skills/fhenix-tests
Command: npx skills add https://github.com/FuzzysTodd/The-Nexus-Protocol-Token-DAO --skill fhenix-tests-fuzzystodd

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @cofhe/hardhat-plugin, @cofhe/sdk, @fhenixprotocol/cofhe-mock-contracts, and includes references (resource) components.

What problem does it solve? Testing FHE-encrypted contracts is error-prone: mock environments diverge from production gas costs, decrypt flows require correct on-chain/off-chain pairing, and forgotten ACL permissions cause silent failures. This Skill guides you through writing correct tests for confidential CoFHE code. ## Core Features & Use Cases - Dual Framework Support: Choose between Foundry mocks (cofhe-mock-contracts) for fast Solidity unit tests or the Hardhat plugin (@cofhe/hardhat-plugin) for end-to-end SDK flows. - Decrypt Flow Testing: Test the full encrypt → submit → decryptForTx/decryptForView → on-chain verify round-trip with correct permit pairing. - Hard Rules Enforcement: Avoid common pitfalls like unseeded randomness, missing allowThis calls, untested FHE.select branches, and mock-vs-prod gas divergence. - Use Case: You wrote a confidential token contract using FHE.sol and need .t.sol unit tests plus a Hardhat E2E test that encrypts inputs, triggers settlement, and verifies decrypted results on-chain. ## Quick Start Write Foundry and Hardhat tests for my confidential contract that imports FHE.sol, covering encrypted inputs and the decrypt settlement flow.

Frequently Asked Questions about fhenix-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Fhenix confidential smart contracts with Foundry?▼

Install fhenixprotocol/cofhe-mock-contracts via forge install, inherit CoFheTest in your test contract, and call etchFhenixMocks() in setUp to deploy mock TaskManager, ACL, and ZkVerifier contracts at fixed addresses.

Foundry mocks vs Hardhat plugin for CoFHE testing?▼

Use Foundry mocks for fast pure-Solidity unit tests of encrypted state transitions and select/allowThis logic. Use @cofhe/hardhat-plugin for end-to-end tests covering the SDK encrypt→tx→decrypt loop and frontend integration. Both can coexist in one project.

How do I test the decrypt flow with @cofhe/sdk?▼

Encrypt inputs with client.encryptInputs, submit on-chain, trigger the contract's allowPublic reveal, then call client.decryptForTx(ctHash).withoutPermit().execute() and pass the decrypted value and signature back for on-chain verification via FHE.verifyDecryptResult.

Why are my FHE tests flaky or non-deterministic?▼

Flakiness usually comes from unseeded FHE.random calls. Pass a non-zero seed to FHE.random* functions; seed=0 picks a system seed, producing different values each run.

Do mock gas costs match the Fhenix production network?▼

No. Mock environments simulate gas costs that diverge from the threshold network's actual costs. Always validate gas-sensitive code on a testnet before deploying to mainnet.

Why does my encrypted state operation fail after storing a handle?▼

The likely cause is a missing FHE.allowThis call, which grants the contract ACL permission on the ciphertext. Test every stored encrypted value by asserting subsequent operations succeed.