> ## Documentation Index
> Fetch the complete documentation index at: https://fhenix-docs-broken-sample-fixes.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Mock Contracts

> Interact with mock CoFHE contracts and read plaintext values in tests

The plugin deploys a suite of mock contracts that simulate the full CoFHE coprocessor stack on the Hardhat network. This lets you develop and test FHE contracts without running the offchain FHE engine.

## What the mocks simulate

| Contract | Role |
| - | - |
| `MockTaskManager` | Manages FHE operations; stores plaintext values onchain for testing |
| `MockACL` | Access control for encrypted handles |
| `MockZkVerifier` | Simulates ZK proof verification for encrypted inputs |
| `MockThresholdNetwork` | Handles decryption requests |

The SDK automatically detects when it's running against the mock environment (by checking bytecode at the `MockZkVerifier` fixed address) and adapts its behavior accordingly. ZK proof generation is skipped and verification is handled by the mock contracts.

## Auto-deployment

Mock contracts are deployed automatically before every `npx hardhat test` and `npx hardhat node` run.

To skip auto-deployment:

```bash theme={null}
COFHE_SKIP_MOCKS_DEPLOY=1 npx hardhat test
```

<Note>
  You only need `COFHE_SKIP_MOCKS_DEPLOY=1` if your tests exclusively target an external RPC and don't use the in-process Hardhat network at all.
</Note>

You can also deploy mock contracts manually via the Hardhat task:

```bash theme={null}
npx hardhat task:cofhe-mocks:deploy
```

The task takes no parameters. To control how much it prints, set `mocksDeployVerbosity` in your Hardhat config (`''` for silent, `'v'` for a summary line, `'vv'` for full per-contract logs).

Or programmatically from a test or script:

```typescript theme={null}
import hre from 'hardhat';

await hre.cofhe.mocks.deployMocks();
```

## Accessing mock contracts

`hre.cofhe.mocks` exposes typed accessors for each mock contract:

```typescript theme={null}
import hre from 'hardhat';

const taskManager = await hre.cofhe.mocks.getMockTaskManager();
const acl = await hre.cofhe.mocks.getMockACL();
const thresholdNetwork = await hre.cofhe.mocks.getMockThresholdNetwork();
const zkVerifier = await hre.cofhe.mocks.getMockZkVerifier();
```

## Reading plaintext values

Because `MockTaskManager` stores plaintext values onchain, you can read the underlying plaintext of any encrypted handle directly in tests, no ACP needed.

### `getPlaintext(ctHash)`

Returns the plaintext `bigint` for a given ciphertext hash:

```typescript theme={null}
import hre from 'hardhat';
import { expect } from 'chai';

// Your own contract, deployed from your own artifacts
const counter = await hre.ethers.deployContract('Counter');
await counter.increment();

// A getter on your contract that returns the encrypted handle
const ctHash = await counter.countHash();

const plaintext = await hre.cofhe.mocks.getPlaintext(ctHash);

expect(plaintext).to.equal(1n);
```

### `expectPlaintext(ctHash, expectedValue)`

Assertion shorthand. Wraps `getPlaintext` with a Chai `expect`:

```typescript theme={null}
import hre from 'hardhat';

const counter = await hre.ethers.deployContract('Counter');
await counter.increment();
const ctHash = await counter.countHash();

await hre.cofhe.mocks.expectPlaintext(ctHash, 1n);
```

<Warning>
  `getPlaintext` and `expectPlaintext` only work on the Hardhat network (where `MockTaskManager` stores plaintexts). They will throw on `localcofhe` or any real network.
</Warning>
