Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/hardhat-deploy-mocks-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@cofhe/hardhat-3-plugin': patch
'@cofhe/hardhat-plugin': patch
---

`cofhe.mocks.deployMocks()` now uses the `cofhe` config for any option it is not given (`gasWarning`, `mocksDeployVerbosity`, `logMocks`), like the deploy that runs on connect. Previously a re-deploy in Hardhat 3 ignored all three, so it printed the gas warning and deploy summary and left FHE operation logs off, and in Hardhat 2 it ignored `gasWarning`.
18 changes: 15 additions & 3 deletions packages/hardhat-3-plugin/src/hooks/hre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createPublicClient, createWalletClient, custom, type PublicClient, type
import { privateKeyToAccount } from 'viem/accounts';

import type { ArtifactManager } from 'hardhat/types/artifacts';
import type { HardhatConfig } from 'hardhat/types/config';

import {
MockCoFHEAddressBookArtifact,
Expand All @@ -31,7 +32,9 @@ function createCofheConnection(
/** Reusable transport factory derived from the walletClient's request method */
transport: ReturnType<typeof custom>,
artifacts: ArtifactManager,
deployedMockContracts: DeployedMockContracts
deployedMockContracts: DeployedMockContracts,
/** The resolved `cofhe` config, which `mocks.deployMocks` falls back to */
pluginConfig: HardhatConfig['cofhe']
): CofheConnection {
return {
async createConfig(config: Partial<CofheInputConfig> = {}) {
Expand Down Expand Up @@ -85,7 +88,15 @@ function createCofheConnection(

mocks: {
async deployMocks(options?: DeployMocksArgs) {
await deployMocks({ publicClient, walletClient, artifacts }, options);
await deployMocks(
{ publicClient, walletClient, artifacts },
{
gasWarning: pluginConfig.gasWarning,
mocksDeployVerbosity: pluginConfig.mocksDeployVerbosity,
logMocks: pluginConfig.logMocks,
...options,
}
);
},

async withLogs(closureName: string, closure: () => Promise<void>) {
Expand Down Expand Up @@ -205,7 +216,8 @@ const hreHooks: Partial<HardhatRuntimeEnvironmentHooks> = {
walletClient,
connTransport,
hre.artifacts,
deployedMockContracts
deployedMockContracts,
hre.config.cofhe
);
return conn;
},
Expand Down
6 changes: 5 additions & 1 deletion packages/hardhat-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,11 @@ extendEnvironment((hre) => {
return mock_setLoggingEnabled(hre, false);
},
deployMocks: async (options: DeployMocksArgs = {}) => {
return deployMocks(hre, { mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity, ...options });
return deployMocks(hre, {
gasWarning: hre.config.cofhe.gasWarning,
mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity,
...options,
});
},
getPlaintext: async (ctHash: bigint | string) => {
const [signer] = await hre.ethers.getSigners();
Expand Down
49 changes: 48 additions & 1 deletion test/hardhat-3-plugin-test/test/set-log-ops.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, beforeEach } from 'node:test';
import { describe, it, beforeEach, mock } from 'node:test';
import assert from 'node:assert/strict';
import { network } from 'hardhat';
import { createHardhatRuntimeEnvironment } from 'hardhat/hre';
Expand Down Expand Up @@ -81,4 +81,51 @@ describe('cofhe.logMocks config', () => {
});
assert.equal(logOps, true);
});

it('logMocks: true turns logging back on when cofhe.mocks.deployMocks() re-deploys', async () => {
const hre = await createHardhatRuntimeEnvironment(
{
solidity: { version: '0.8.28' },
plugins: [cofhePlugin, hardhatViem],
cofhe: { logMocks: true, mocksDeployVerbosity: '' },
},
{},
process.cwd()
);
const { viem, cofhe } = await hre.network.connect();
const publicClient = await viem.getPublicClient();

await cofhe.mocks.disableLogs();
await cofhe.mocks.deployMocks();

const logOps = await publicClient.readContract({
address: MOCKS_TASK_MANAGER_ADDRESS,
abi: [{ name: 'logOps', type: 'function', inputs: [], outputs: [{ type: 'bool' }], stateMutability: 'view' }],
functionName: 'logOps',
});
assert.equal(logOps, true);
});
});

describe('cofhe.mocks.deployMocks() output', () => {
it('follows gasWarning and mocksDeployVerbosity from the config', async () => {
const hre = await createHardhatRuntimeEnvironment(
{
solidity: { version: '0.8.28' },
plugins: [cofhePlugin, hardhatViem],
cofhe: { gasWarning: false, mocksDeployVerbosity: '' },
},
{},
process.cwd()
);
const { cofhe } = await hre.network.connect();

const consoleLog = mock.method(console, 'log', () => {});
try {
await cofhe.mocks.deployMocks();
assert.equal(consoleLog.mock.callCount(), 0);
} finally {
consoleLog.mock.restore();
}
});
});
18 changes: 18 additions & 0 deletions test/hardhat-plugin-test/test/set-log-ops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,21 @@ describe('cofhe.logMocks config', () => {
}
});
});

describe('cofhe.mocks.deployMocks() output', () => {
it('prints the gas warning when gasWarning is true in the config', async () => {
const snapshot = await hre.network.provider.send('evm_snapshot');
hre.config.cofhe.gasWarning = true;
const logged: string[] = [];
const originalLog = console.log;
console.log = (...args: unknown[]) => logged.push(args.join(' '));
try {
await hre.cofhe.mocks.deployMocks({ mocksDeployVerbosity: 'v' });
} finally {
console.log = originalLog;
hre.config.cofhe.gasWarning = false;
await hre.network.provider.send('evm_revert', [snapshot]);
}
expect(logged.some((line) => line.includes("'cofhe.gasWarning: false'"))).to.be.true;
});
});