@cofhe/hardhat-plugin 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +168 -194
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +161 -193
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -8
- package/src/consts.ts +0 -5
- package/src/deploy.ts +112 -153
- package/src/index.ts +11 -25
- package/src/logging.ts +7 -13
- package/src/utils.ts +33 -2
package/src/index.ts
CHANGED
|
@@ -6,10 +6,10 @@ import { extendConfig, extendEnvironment, task, types } from 'hardhat/config';
|
|
|
6
6
|
import { TASK_TEST, TASK_NODE } from 'hardhat/builtin-tasks/task-names';
|
|
7
7
|
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
|
|
8
8
|
import {
|
|
9
|
-
MOCKS_ZK_VERIFIER_SIGNER_ADDRESS,
|
|
10
9
|
type CofhesdkClient,
|
|
11
10
|
type CofhesdkConfig,
|
|
12
11
|
type CofhesdkInputConfig,
|
|
12
|
+
MOCKS_ZK_VERIFIER_SIGNER_ADDRESS,
|
|
13
13
|
} from '@cofhe/sdk';
|
|
14
14
|
import { createCofhesdkClient, createCofhesdkConfig } from '@cofhe/sdk/node';
|
|
15
15
|
import { HardhatSignerAdapter } from '@cofhe/sdk/adapters';
|
|
@@ -18,18 +18,11 @@ import { localcofheFundAccount } from './fund.js';
|
|
|
18
18
|
import { TASK_COFHE_MOCKS_DEPLOY, TASK_COFHE_MOCKS_SET_LOG_OPS, TASK_COFHE_USE_FAUCET } from './consts.js';
|
|
19
19
|
import { deployMocks, type DeployMocksArgs } from './deploy.js';
|
|
20
20
|
import { mock_setLoggingEnabled, mock_withLogs } from './logging.js';
|
|
21
|
-
import { mock_expectPlaintext } from './utils.js';
|
|
21
|
+
import { getFixedMockContract, mock_expectPlaintext } from './utils.js';
|
|
22
22
|
import { mock_getPlaintext } from './utils.js';
|
|
23
23
|
import type { Contract } from 'ethers';
|
|
24
|
-
import {
|
|
25
|
-
MockACLArtifact,
|
|
26
|
-
MockQueryDecrypterArtifact,
|
|
27
|
-
MockTaskManagerArtifact,
|
|
28
|
-
MockZkVerifierArtifact,
|
|
29
|
-
TestBedArtifact,
|
|
30
|
-
} from '@cofhe/mock-contracts';
|
|
31
24
|
import { hardhat } from '@cofhe/sdk/chains';
|
|
32
|
-
|
|
25
|
+
import {
|
|
33
26
|
MockACLArtifact,
|
|
34
27
|
MockQueryDecrypterArtifact,
|
|
35
28
|
MockTaskManagerArtifact,
|
|
@@ -186,6 +179,7 @@ task(TASK_COFHE_MOCKS_SET_LOG_OPS, 'Set logging for the Mock CoFHE contracts')
|
|
|
186
179
|
|
|
187
180
|
// MOCK UTILS
|
|
188
181
|
|
|
182
|
+
export * from './consts.js';
|
|
189
183
|
export * from './utils.js';
|
|
190
184
|
export * from './fund.js';
|
|
191
185
|
export * from './logging.js';
|
|
@@ -417,23 +411,15 @@ extendEnvironment((hre) => {
|
|
|
417
411
|
const [signer] = await hre.ethers.getSigners();
|
|
418
412
|
return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
|
|
419
413
|
},
|
|
420
|
-
getMockTaskManager: async () =>
|
|
421
|
-
return await hre.ethers.getContractAt(MockTaskManagerArtifact.abi, MockTaskManagerArtifact.fixedAddress);
|
|
422
|
-
},
|
|
414
|
+
getMockTaskManager: async () => getFixedMockContract(hre, MockTaskManagerArtifact),
|
|
423
415
|
getMockACL: async () => {
|
|
424
|
-
const
|
|
425
|
-
const aclAddress = await
|
|
426
|
-
return
|
|
427
|
-
},
|
|
428
|
-
getMockQueryDecrypter: async () => {
|
|
429
|
-
return await hre.ethers.getContractAt(MockQueryDecrypterArtifact.abi, MockQueryDecrypterArtifact.fixedAddress);
|
|
430
|
-
},
|
|
431
|
-
getMockZkVerifier: async () => {
|
|
432
|
-
return await hre.ethers.getContractAt(MockZkVerifierArtifact.abi, MockZkVerifierArtifact.fixedAddress);
|
|
433
|
-
},
|
|
434
|
-
getTestBed: async () => {
|
|
435
|
-
return await hre.ethers.getContractAt(TestBedArtifact.abi, TestBedArtifact.fixedAddress);
|
|
416
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact);
|
|
417
|
+
const aclAddress = await taskManager.acl();
|
|
418
|
+
return hre.ethers.getContractAt(MockACLArtifact.abi, aclAddress);
|
|
436
419
|
},
|
|
420
|
+
getMockQueryDecrypter: async () => getFixedMockContract(hre, MockQueryDecrypterArtifact),
|
|
421
|
+
getMockZkVerifier: async () => getFixedMockContract(hre, MockZkVerifierArtifact),
|
|
422
|
+
getTestBed: async () => getFixedMockContract(hre, TestBedArtifact),
|
|
437
423
|
},
|
|
438
424
|
};
|
|
439
425
|
});
|
package/src/logging.ts
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { type HardhatRuntimeEnvironment } from 'hardhat/types';
|
|
3
|
-
import {
|
|
3
|
+
import { getFixedMockContract } from './utils';
|
|
4
4
|
import { MockTaskManagerArtifact } from '@cofhe/mock-contracts';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return taskManager;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const getLoggingEnabled = async (hre: HardhatRuntimeEnvironment) => {
|
|
14
|
-
const taskManager = await getDeployedMockTaskManager(hre);
|
|
15
|
-
return await taskManager.logOps();
|
|
6
|
+
const getLoggingEnabled = async (hre: HardhatRuntimeEnvironment): Promise<boolean> => {
|
|
7
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact);
|
|
8
|
+
return taskManager.logOps();
|
|
16
9
|
};
|
|
17
10
|
|
|
18
11
|
const setLoggingEnabled = async (hre: HardhatRuntimeEnvironment, enabled: boolean) => {
|
|
19
|
-
const taskManager = await
|
|
20
|
-
await taskManager.setLogOps(enabled);
|
|
12
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact);
|
|
13
|
+
const tx = await taskManager.setLogOps(enabled);
|
|
14
|
+
await tx.wait();
|
|
21
15
|
};
|
|
22
16
|
|
|
23
17
|
// prettier-ignore
|
package/src/utils.ts
CHANGED
|
@@ -1,7 +1,38 @@
|
|
|
1
|
-
import { TASK_MANAGER_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS } from '
|
|
1
|
+
import { TASK_MANAGER_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS } from '@cofhe/sdk';
|
|
2
2
|
import { expect } from 'chai';
|
|
3
|
-
import { ethers } from 'ethers';
|
|
3
|
+
import { Contract, ethers } from 'ethers';
|
|
4
4
|
import { type HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider';
|
|
5
|
+
import type { MockArtifact } from '@cofhe/mock-contracts';
|
|
6
|
+
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
|
|
7
|
+
|
|
8
|
+
// Deployment utils
|
|
9
|
+
|
|
10
|
+
/// Deploys a mock contract from a pre-built artifact from the mock-contracts package
|
|
11
|
+
/// If the mock contract should be deployed to a fixed address, `hardhat_setCode` op is used to set the code at the fixed address
|
|
12
|
+
/// Otherwise, we deploy the contract using ethers.js to a non-fixed address
|
|
13
|
+
export const deployMockContractFromArtifact = async (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => {
|
|
14
|
+
// Use hardhat_setCode to deploy to fixed address
|
|
15
|
+
if (artifact.isFixed) {
|
|
16
|
+
await hre.network.provider.send('hardhat_setCode', [artifact.fixedAddress, artifact.deployedBytecode]);
|
|
17
|
+
return getFixedMockContract(hre, artifact);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Use ethers.js to deploy to variable address
|
|
21
|
+
const [signer] = await hre.ethers.getSigners();
|
|
22
|
+
const factory = new hre.ethers.ContractFactory(artifact.abi, artifact.bytecode, signer);
|
|
23
|
+
const contract = await factory.deploy(/* constructor args */);
|
|
24
|
+
await contract.waitForDeployment();
|
|
25
|
+
return contract as Contract;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const getFixedMockContract = async (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => {
|
|
29
|
+
if (!artifact.isFixed) {
|
|
30
|
+
throw new Error('Artifact is not fixed');
|
|
31
|
+
}
|
|
32
|
+
return await hre.ethers.getContractAt(artifact.abi, artifact.fixedAddress);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Testing utils
|
|
5
36
|
|
|
6
37
|
const mock_checkIsTestnet = async (fnName: string, provider: HardhatEthersProvider | ethers.JsonRpcProvider) => {
|
|
7
38
|
// Testnet is checked by testing if MockZkVerifier is deployed
|