diff --git a/.changeset/hardhat-deploy-mocks-config.md b/.changeset/hardhat-deploy-mocks-config.md new file mode 100644 index 00000000..840b903c --- /dev/null +++ b/.changeset/hardhat-deploy-mocks-config.md @@ -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`. diff --git a/packages/hardhat-3-plugin/src/hooks/hre.ts b/packages/hardhat-3-plugin/src/hooks/hre.ts index f594cef8..afe0a91b 100644 --- a/packages/hardhat-3-plugin/src/hooks/hre.ts +++ b/packages/hardhat-3-plugin/src/hooks/hre.ts @@ -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, @@ -31,7 +32,9 @@ function createCofheConnection( /** Reusable transport factory derived from the walletClient's request method */ transport: ReturnType, 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 = {}) { @@ -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) { @@ -205,7 +216,8 @@ const hreHooks: Partial = { walletClient, connTransport, hre.artifacts, - deployedMockContracts + deployedMockContracts, + hre.config.cofhe ); return conn; }, diff --git a/packages/hardhat-plugin/src/index.ts b/packages/hardhat-plugin/src/index.ts index dc67114c..5598a63a 100644 --- a/packages/hardhat-plugin/src/index.ts +++ b/packages/hardhat-plugin/src/index.ts @@ -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(); diff --git a/test/hardhat-3-plugin-test/test/set-log-ops.test.ts b/test/hardhat-3-plugin-test/test/set-log-ops.test.ts index 546d832b..6d3fcb2f 100644 --- a/test/hardhat-3-plugin-test/test/set-log-ops.test.ts +++ b/test/hardhat-3-plugin-test/test/set-log-ops.test.ts @@ -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'; @@ -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(); + } + }); }); diff --git a/test/hardhat-plugin-test/test/set-log-ops.test.ts b/test/hardhat-plugin-test/test/set-log-ops.test.ts index aaa662df..038c7bd0 100644 --- a/test/hardhat-plugin-test/test/set-log-ops.test.ts +++ b/test/hardhat-plugin-test/test/set-log-ops.test.ts @@ -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; + }); +});