Skip to main content
The plugin deploys mock versions of the CoFHE contracts on every simulated chain. The mocks compute FHE operations onchain and keep each result’s plaintext in storage, so a test can read any encrypted value without the offchain services.

What the mocks deploy

The plugin writes the fixed-address contracts’ bytecode directly with hardhat_setCode. It deploys MockACL and the two ACP contracts as normal transactions, because they need their constructors to run. The SDK detects the mocks by checking for code at the MockZkVerifier address. When it finds them, it skips ZK proof generation and lets the mocks verify inputs.

Call a mock directly

cofhe.mocks exposes four of the mocks as viem { address, abi } descriptors. Spread one into readContract or writeContract:
The ABIs are typed, so viem checks functionName and args at compile time.

Read plaintext values

Because MockTaskManager stores plaintexts, you can assert on encrypted state without an ACP or a decryption request. Both helpers accept the handle as a hex string, which is what viem returns for an euint32 getter, or as a bigint.

getPlaintext(ctHash)

Returns the stored plaintext as a bigint:
getPlaintext returns 0n for a handle that has no stored value, so a typo in the handle reads as zero.

expectPlaintext(ctHash, expectedValue)

Throws when the stored plaintext differs from expectedValue, or when the handle has no stored value:
A mismatch throws an Error whose message names both values:
On a network without the mocks, getPlaintext throws, but expectPlaintext prints a message and returns without asserting anything. A test that relies on expectPlaintext passes silently against a testnet.

Redeploy the mocks

cofhe.mocks.deployMocks(options?) runs the deployment again on the current chain:
These defaults apply to the call itself. deployMocks does not read the cofhe block of your Hardhat config, so a bare call prints the gas warning even when the config turns it off.
A redeploy is not a reset. It deploys a new MockACL and points MockTaskManager at it, but cofhe.mocks.MockACL keeps the old address, and handles created before the redeploy lose their permissions. The next FHE operation on one of those handles reverts with ACLNotAllowed (selector 0x4d13139e). For a clean state, open a new connection with network.create() instead.