Skip to main content
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 off-chain FHE engine.

What the mocks simulate

ContractRole
MockTaskManagerManages FHE operations; stores plaintext values on-chain for testing
MockACLAccess control for encrypted handles
MockZkVerifierSimulates ZK proof verification for encrypted inputs
MockThresholdNetworkHandles decryption requests
TestBedHelper contract for testing — exposes trivial value setters and a numberHash getter
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:
COFHE_SKIP_MOCKS_DEPLOY=1 npx hardhat test
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.
You can also deploy mock contracts manually via the Hardhat task:
npx hardhat task:cofhe-mocks:deploy
npx hardhat task:cofhe-mocks:deploy --deployTestBed false  # skip TestBed
npx hardhat task:cofhe-mocks:deploy --silent true          # suppress output
Or programmatically from a test or script:
import hre from 'hardhat';

await hre.cofhe.mocks.deployMocks();

Accessing mock contracts

hre.cofhe.mocks exposes typed accessors for each mock contract:
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();
const testBed = await hre.cofhe.mocks.getTestBed();

Reading plaintext values

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

getPlaintext(ctHash)

Returns the plaintext bigint for a given ciphertext hash:
import hre from 'hardhat';
import { expect } from 'chai';

const testBed = await hre.cofhe.mocks.getTestBed();
await testBed.setNumberTrivial(7);
const ctHash = await testBed.numberHash();

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

expect(plaintext).to.equal(7n);

expectPlaintext(ctHash, expectedValue)

Assertion shorthand — wraps getPlaintext with a Chai expect:
import hre from 'hardhat';

const testBed = await hre.cofhe.mocks.getTestBed();
await testBed.setNumberTrivial(7);
const ctHash = await testBed.numberHash();

await hre.cofhe.mocks.expectPlaintext(ctHash, 7n);
getPlaintext and expectPlaintext only work on the Hardhat network (where MockTaskManager stores plaintexts). They will throw on localcofhe or any real network.