Skip to main content
CofheTest is the abstract test base shipped by @cofhe/foundry-plugin. It already inherits forge-std/Test, so inherit CofheTest directly — inheriting both is a redeclaration error.

deployMocks()

Call once in setUp(). Deploys the full CoFHE mock stack and wires the contracts together: After deployMocks() runs, the following public state vars are available on CofheTest:
Reach into them when you need behavior expectPlaintext doesn’t cover (e.g. permission-denied assertions — see Testing).

createCofheClient()

Returns a fresh CofheClient. You typically follow it with connect(pkey):
One client per scenario address. Connecting with a deterministic plaintext private key keeps test output debuggable.

Reading plaintext values

Because MockTaskManager stores plaintext values on-chain, you can read the underlying plaintext of any encrypted handle directly — no permit needed.

getPlaintext(handle)

Returns the on-chain plaintext from MockTaskManager.mockStorage. Typed overloads exist for every encrypted Solidity type:
Reverts if the handle isn’t in mock storage.

expectPlaintext(handle, value) and (handle, value, "msg")

Assertion variant — typed overloads for the same type set. Faster than decryptForView (no SDK round-trip, no permit needed). Use it whenever you only care about the value, not the SDK code path.
Prefer expectPlaintext over decryptForView for state assertions. Reserve the SDK path for tests where the SDK behavior itself is under test.

Logging

The mocks log every FHE operation to the console when log mode is on. Toggle it locally with: Logging is verbose — enable it only around the operation you’re investigating.
Each operation prints in a formatted block:

Common pitfalls

Solidity LSPs (Wake, Cursor, etc.) often resolve imports from the monorepo root rather than the package’s node_modules. The plugin’s remappings are package-local, so the LSP may flag valid imports. forge is authoritative — if forge build and forge test succeed, the test is correct.
That import path is the old API from @cofhe/mock-contracts@0.4.x. Migrate to:
See the migration mapping for the full rename table.
The remappings are relative to the foundry package’s root. Running forge test from a parent monorepo directory won’t resolve them — forge resolves from the working directory.

Next steps

  • CofheClient — per-user encrypt / decrypt / permit shim.
  • Testing — canonical test-writing patterns and migration mapping.