> ## Documentation Index
> Fetch the complete documentation index at: https://fhenix-ci-version-drift-check.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Foundry Plugin Reference

> Complete API reference for @cofhe/foundry-plugin

<Info>
  This page summarizes the public surface of `@cofhe/foundry-plugin`. For task-oriented walkthroughs, see [Getting Started](/client-sdk/foundry-plugin/getting-started) and [Testing](/client-sdk/foundry-plugin/testing).
</Info>

## `CofheTest`

Abstract test base. Inherit it instead of `forge-std/Test` (it inherits `Test` for you).

```solidity theme={null}
import { CofheTest } from "@cofhe/foundry-plugin/contracts/CofheTest.sol";
```

### Setup

| Function              | Description                                                                                                                                                                                                                                                                       |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `deployMocks()`       | Deploy `MockTaskManager`, `MockACL`, `MockZkVerifier`, `MockZkVerifierSigner`, `MockThresholdNetwork`, `MockThresholdNetworkSigner`. Wires them via `setACLContract` / `setVerifierSigner` / `setDecryptResultSigner`. Funds the ZK signer with 10 ether. Call once in `setUp()`. |
| `createCofheClient()` | Returns a fresh `CofheClient`. Follow with `client.connect(pkey)`.                                                                                                                                                                                                                |

### Plaintext reads

| Function                                                                                                   | Description                                                             |
| ---------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| `getPlaintext(bytes32 handle)`                                                                             | Returns the raw `bytes32` plaintext from `MockTaskManager.mockStorage`. |
| `getPlaintext(ebool)` / `(euint8)` / `(euint16)` / `(euint32)` / `(euint64)` / `(euint128)` / `(eaddress)` | Typed overloads returning `bool` / `uint8`–`uint128` / `address`.       |
| `expectPlaintext(handle, value)`                                                                           | Assertion variant. Typed overloads for the same set.                    |
| `expectPlaintext(handle, value, "msg")`                                                                    | With assertion message.                                                 |

Reverts if the handle isn't in mock storage.

### Logging

| Function        | Description                               |
| --------------- | ----------------------------------------- |
| `enableLogs()`  | Calls `mockTaskManager.setLogOps(true)`.  |
| `disableLogs()` | Calls `mockTaskManager.setLogOps(false)`. |

### Public state

| Field                        | Type                         |
| ---------------------------- | ---------------------------- |
| `mockTaskManager`            | `MockTaskManager`            |
| `mockAcl`                    | `MockACL`                    |
| `mockZkVerifier`             | `MockZkVerifier`             |
| `mockZkVerifierSigner`       | `MockZkVerifierSigner`       |
| `mockThresholdNetwork`       | `MockThresholdNetwork`       |
| `mockThresholdNetworkSigner` | `MockThresholdNetworkSigner` |

## `CofheClient`

Per-user shim. One client per scenario address.

```solidity theme={null}
import { CofheClient } from "@cofhe/foundry-plugin/contracts/CofheClient.sol";
```

### Connection

| Function                | Description                                                                                          |
| ----------------------- | ---------------------------------------------------------------------------------------------------- |
| `connect(uint256 pkey)` | Set the connected account to `vm.addr(pkey)`. Required before any `createExternal*` or `ACP_*` call. |
| `account()`             | Returns the connected `address`.                                                                     |

### Encrypt inputs

| Function                                   | Returns                     |
| ------------------------------------------ | --------------------------- |
| `createExternalEbool(bool, address)`       | `(externalEbool, bytes)`    |
| `createExternalEuint8(uint8, address)`     | `(externalEuint8, bytes)`   |
| `createExternalEuint16(uint16, address)`   | `(externalEuint16, bytes)`  |
| `createExternalEuint32(uint32, address)`   | `(externalEuint32, bytes)`  |
| `createExternalEuint64(uint64, address)`   | `(externalEuint64, bytes)`  |
| `createExternalEuint128(uint128, address)` | `(externalEuint128, bytes)` |
| `createExternalEaddress(address, address)` | `(externalEaddress, bytes)` |

All produce signed `EncryptedInput` shapes signed for `account()`.

### Decrypt

| Function                                        | Returns                     | Notes                                                                                                                                         |
| ----------------------------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `decryptForTx_withoutACP(bytes32 ctHash)`       | `(bytes32, uint256, bytes)` | `(ctHash, plaintext, signature)`. Signature consumable by `FHE.publishDecryptResult`. Requires `FHE.allowPublic(handle)` to have been called. |
| `decryptForTx_withACP(bytes32 ctHash, ACP acp)` | `(bytes32, uint256, bytes)` | ACL-gated `decryptForTx`.                                                                                                                     |
| `decryptForView(bytes32 ctHash, ACP acp)`       | `uint256`                   | Offchain seal/unseal. **Reverts on deny**, to assert deny use `mockThresholdNetwork.querySealOutput(...)`.                                    |

### Permits

| Function                                   | Description                                                                |
| ------------------------------------------ | -------------------------------------------------------------------------- |
| `ACP_createSelf()`                         | Self-ACP for the connected account; sealing key auto-derived.              |
| `ACP_createShared(address recipient)`      | Issuer-side shared ACP.                                                    |
| `ACP_exportShared(ACP acp)`                | Strip sensitive fields to `SharedACPExport`.                               |
| `ACP_importShared(SharedACPExport export)` | Recipient-side completion. Reverts unless `export.recipient == account()`. |
| `createSealingKey(bytes32 seed)`           | Custom sealing key (rarely needed).                                        |

## Mock storage layout

`MockTaskManager.mockStorage` is the onchain plaintext storage that backs `getPlaintext` / `expectPlaintext`. It only exists in the mock environment. `getPlaintext` reverts on real CoFHE networks.

## `foundry.toml` requirements

```toml theme={null}
[profile.default]
solc_version = "0.8.25"     # cofhe-contracts target
auto_detect_remappings = false
code_size_limit = 100000    # mocks exceed 24 KB
libs = ["node_modules"]
```

<Note>
  `evm_version = "cancun"` is no longer required as of `@cofhe/mock-contracts@0.7.1`. `MockACL` was migrated off transient storage to block-number-based storage. Set it only if your own contracts need cancun-specific opcodes.
</Note>

## `remappings.txt` (canonical shape)

```text theme={null}
forge-std/=node_modules/forge-std/src/
hardhat/=node_modules/forge-std/src/
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
@fhenixprotocol/cofhe-contracts/=node_modules/@fhenixprotocol/cofhe-contracts/
@cofhe/mock-contracts/=node_modules/@cofhe/mock-contracts/
@cofhe/foundry-plugin/=node_modules/@cofhe/foundry-plugin/
```

* `@cofhe/mock-contracts/` points at the **package root**, not `…/contracts/`. The plugin's imports include the `contracts/` segment themselves.
* `hardhat/=node_modules/forge-std/src/` is required so that `MockCoFHE.sol`'s `import "hardhat/console.sol"` resolves to forge-std's compatible console.

## Version pinning

`@cofhe/foundry-plugin` and `@cofhe/mock-contracts` pin `@fhenixprotocol/cofhe-contracts` *exactly*, keep all three CoFHE packages aligned. Known-good tuple as of the latest release:

| Package                           | Version |
| --------------------------------- | ------- |
| `@cofhe/foundry-plugin`           | `0.7.1` |
| `@cofhe/mock-contracts`           | `0.7.1` |
| `@fhenixprotocol/cofhe-contracts` | `0.2.0` |

See the [Compatibility](/get-started/introduction/compatibility) page for the canonical table.
