@cofhe/hardhat-plugin 0.1.1 → 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/dist/index.js CHANGED
@@ -30,16 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- MockACLArtifact: () => import_mock_contracts3.MockACLArtifact,
34
- MockQueryDecrypterArtifact: () => import_mock_contracts3.MockQueryDecrypterArtifact,
35
- MockTaskManagerArtifact: () => import_mock_contracts3.MockTaskManagerArtifact,
36
- MockZkVerifierArtifact: () => import_mock_contracts3.MockZkVerifierArtifact,
37
- TestBedArtifact: () => import_mock_contracts3.TestBedArtifact,
33
+ TASK_COFHE_MOCKS_DEPLOY: () => TASK_COFHE_MOCKS_DEPLOY,
34
+ TASK_COFHE_MOCKS_SET_LOG_OPS: () => TASK_COFHE_MOCKS_SET_LOG_OPS,
35
+ TASK_COFHE_USE_FAUCET: () => TASK_COFHE_USE_FAUCET,
36
+ deployMockContractFromArtifact: () => deployMockContractFromArtifact,
38
37
  deployMocks: () => deployMocks,
39
- expectResultError: () => expectResultError,
40
- expectResultPartialValue: () => expectResultPartialValue,
41
- expectResultSuccess: () => expectResultSuccess,
42
- expectResultValue: () => expectResultValue,
38
+ getFixedMockContract: () => getFixedMockContract,
43
39
  localcofheFundAccount: () => localcofheFundAccount,
44
40
  localcofheFundWalletIfNeeded: () => localcofheFundWalletIfNeeded,
45
41
  mock_expectPlaintext: () => mock_expectPlaintext,
@@ -54,7 +50,7 @@ var import_viem = require("viem");
54
50
  var import_config = require("hardhat/config");
55
51
  var import_task_names = require("hardhat/builtin-tasks/task-names");
56
52
  var import_signers = require("@nomicfoundation/hardhat-ethers/signers");
57
- var import_sdk2 = require("@cofhe/sdk");
53
+ var import_sdk3 = require("@cofhe/sdk");
58
54
  var import_node = require("@cofhe/sdk/node");
59
55
  var import_adapters = require("@cofhe/sdk/adapters");
60
56
 
@@ -114,22 +110,128 @@ async function localcofheFundWalletIfNeeded(hre, walletAddress) {
114
110
  var TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
115
111
  var TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
116
112
  var TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
117
- var TASK_MANAGER_ADDRESS = "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
118
- var MOCKS_ACL_ADDRESS = "0x0000000000000000000000000000000000000400";
119
- var MOCKS_ZK_VERIFIER_ADDRESS = "0x0000000000000000000000000000000000000100";
120
- var MOCKS_QUERY_DECRYPTER_ADDRESS = "0x0000000000000000000000000000000000000200";
121
- var TEST_BED_ADDRESS = "0x0000000000000000000000000000000000000300";
122
- var MOCKS_ZK_VERIFIER_SIGNER_ADDRESS = "0x6E12D8C87503D4287c294f2Fdef96ACd9DFf6bd2";
123
113
 
124
114
  // src/deploy.ts
125
115
  var import_types2 = require("hardhat/types");
126
116
  var import_chalk = __toESM(require("chalk"));
127
- var import_ethers = require("ethers");
117
+ var import_ethers2 = require("ethers");
128
118
  var import_mock_contracts = require("@cofhe/mock-contracts");
119
+ var import_sdk2 = require("@cofhe/sdk");
120
+
121
+ // src/utils.ts
122
+ var import_sdk = require("@cofhe/sdk");
123
+ var import_chai = require("chai");
124
+ var import_ethers = require("ethers");
125
+ var import_hardhat_ethers_provider = require("@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider");
126
+ var deployMockContractFromArtifact = async (hre, artifact) => {
127
+ if (artifact.isFixed) {
128
+ await hre.network.provider.send("hardhat_setCode", [artifact.fixedAddress, artifact.deployedBytecode]);
129
+ return getFixedMockContract(hre, artifact);
130
+ }
131
+ const [signer] = await hre.ethers.getSigners();
132
+ const factory = new hre.ethers.ContractFactory(artifact.abi, artifact.bytecode, signer);
133
+ const contract = await factory.deploy(
134
+ /* constructor args */
135
+ );
136
+ await contract.waitForDeployment();
137
+ return contract;
138
+ };
139
+ var getFixedMockContract = async (hre, artifact) => {
140
+ if (!artifact.isFixed) {
141
+ throw new Error("Artifact is not fixed");
142
+ }
143
+ return await hre.ethers.getContractAt(artifact.abi, artifact.fixedAddress);
144
+ };
145
+ var mock_checkIsTestnet = async (fnName, provider) => {
146
+ const bytecode = await provider.getCode(import_sdk.MOCKS_ZK_VERIFIER_ADDRESS);
147
+ const isTestnet = bytecode.length === 0;
148
+ if (isTestnet) {
149
+ console.log(`${fnName} - skipped on non-testnet chain`);
150
+ }
151
+ return isTestnet;
152
+ };
153
+ var mock_getPlaintext = async (provider, ctHash) => {
154
+ if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
155
+ return;
156
+ const taskManager = new import_ethers.ethers.Contract(
157
+ import_sdk.TASK_MANAGER_ADDRESS,
158
+ ["function mockStorage(uint256) view returns (uint256)"],
159
+ provider
160
+ );
161
+ const plaintext = await taskManager.mockStorage(ctHash);
162
+ return plaintext;
163
+ };
164
+ var mock_getPlaintextExists = async (provider, ctHash) => {
165
+ if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
166
+ return;
167
+ const taskManager = new import_ethers.ethers.Contract(
168
+ import_sdk.TASK_MANAGER_ADDRESS,
169
+ ["function inMockStorage(uint256) view returns (bool)"],
170
+ provider
171
+ );
172
+ const plaintextExists = await taskManager.inMockStorage(ctHash);
173
+ return plaintextExists;
174
+ };
175
+ var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
176
+ if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
177
+ return;
178
+ const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
179
+ (0, import_chai.expect)(plaintextExists).equal(true, "Plaintext does not exist");
180
+ const plaintext = await mock_getPlaintext(provider, ctHash);
181
+ (0, import_chai.expect)(plaintext).equal(expectedValue, "Plaintext value is incorrect");
182
+ };
183
+
184
+ // src/deploy.ts
185
+ var deployMocks = async (hre, options = {
186
+ deployTestBed: true,
187
+ gasWarning: true,
188
+ silent: false
189
+ }) => {
190
+ const isHardhat = await getIsHardhat(hre);
191
+ if (!isHardhat) {
192
+ logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${hre.network.name}`, 0);
193
+ return;
194
+ }
195
+ isSilent = options.silent ?? false;
196
+ logEmpty();
197
+ logSuccess(import_chalk.default.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
198
+ logEmpty();
199
+ const taskManager = await deployMockTaskManager(hre);
200
+ logDeployment("MockTaskManager", await taskManager.getAddress());
201
+ const acl = await deployMockACL(hre);
202
+ logDeployment("MockACL", await acl.getAddress());
203
+ await linkTaskManagerAndACL(taskManager, acl);
204
+ logSuccess("ACL address set in TaskManager", 2);
205
+ await fundZkVerifierSigner(hre);
206
+ logSuccess(`ZkVerifier signer (${import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
207
+ const zkVerifierSignerBalance = await getZkVerifierSignerBalance(hre);
208
+ logSuccess(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
209
+ const zkVerifier = await deployMockZkVerifier(hre);
210
+ logDeployment("MockZkVerifier", await zkVerifier.getAddress());
211
+ const queryDecrypter = await deployMockQueryDecrypter(hre, acl);
212
+ logDeployment("MockQueryDecrypter", await queryDecrypter.getAddress());
213
+ if (options.deployTestBed) {
214
+ logSuccess("TestBed deployment enabled", 2);
215
+ const testBed = await deployTestBedContract(hre);
216
+ logDeployment("TestBed", await testBed.getAddress());
217
+ }
218
+ logEmpty();
219
+ logSuccess(import_chalk.default.bold("cofhe-hardhat-plugin :: mocks deployed successfully"), 0);
220
+ if (options.gasWarning) {
221
+ logEmpty();
222
+ logWarning(
223
+ "When using mocks, FHE operations (eg FHE.add / FHE.mul) report a higher gas price due to additional on-chain mocking logic. Deploy your contracts on a testnet chain to check the true gas costs.\n(Disable this warning by setting '@cofhe/sdk.gasWarning' to false in your hardhat config",
224
+ 0
225
+ );
226
+ }
227
+ logEmpty();
228
+ };
229
+ var getIsHardhat = async (hre) => {
230
+ return hre.network.name === "hardhat";
231
+ };
129
232
  var deployMockTaskManager = async (hre) => {
130
233
  const [signer] = await hre.ethers.getSigners();
131
- await hardhatSetCode(hre, TASK_MANAGER_ADDRESS, import_mock_contracts.MockTaskManagerArtifact.deployedBytecode);
132
- const taskManager = await hre.ethers.getContractAt(import_mock_contracts.MockTaskManagerArtifact.abi, TASK_MANAGER_ADDRESS);
234
+ const taskManager = await deployMockContractFromArtifact(hre, import_mock_contracts.MockTaskManagerArtifact);
133
235
  const initTx = await taskManager.initialize(signer.address);
134
236
  await initTx.wait();
135
237
  const tmExists = await taskManager.exists();
@@ -139,140 +241,68 @@ var deployMockTaskManager = async (hre) => {
139
241
  return taskManager;
140
242
  };
141
243
  var deployMockACL = async (hre) => {
142
- await hardhatSetCode(hre, MOCKS_ACL_ADDRESS, import_mock_contracts.MockACLArtifact.deployedBytecode);
143
- const acl = await hre.ethers.getContractAt(import_mock_contracts.MockACLArtifact.abi, MOCKS_ACL_ADDRESS);
244
+ const acl = await deployMockContractFromArtifact(hre, import_mock_contracts.MockACLArtifact);
144
245
  const exists = await acl.exists();
145
246
  if (!exists) {
146
- logError("MockACL does not exist", 2);
147
247
  throw new Error("MockACL does not exist");
148
248
  }
149
249
  return acl;
150
250
  };
251
+ var fundZkVerifierSigner = async (hre) => {
252
+ const zkVerifierSigner = await hre.ethers.getSigner(import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
253
+ await hre.network.provider.send("hardhat_setBalance", [
254
+ zkVerifierSigner.address,
255
+ "0x" + hre.ethers.parseEther("10").toString(16)
256
+ ]);
257
+ };
258
+ var getZkVerifierSignerBalance = async (hre) => {
259
+ return hre.ethers.provider.getBalance(import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
260
+ };
261
+ var linkTaskManagerAndACL = async (taskManager, acl) => {
262
+ const aclAddress = await acl.getAddress();
263
+ const linkAclTx = await taskManager.setACLContract(aclAddress);
264
+ await linkAclTx.wait();
265
+ };
151
266
  var deployMockZkVerifier = async (hre) => {
152
- await hardhatSetCode(hre, MOCKS_ZK_VERIFIER_ADDRESS, import_mock_contracts.MockZkVerifierArtifact.deployedBytecode);
153
- const zkVerifier = await hre.ethers.getContractAt(import_mock_contracts.MockZkVerifierArtifact.abi, MOCKS_ZK_VERIFIER_ADDRESS);
267
+ const zkVerifier = await deployMockContractFromArtifact(hre, import_mock_contracts.MockZkVerifierArtifact);
154
268
  const zkVerifierExists = await zkVerifier.exists();
155
269
  if (!zkVerifierExists) {
156
- logError("MockZkVerifier does not exist", 2);
157
270
  throw new Error("MockZkVerifier does not exist");
158
271
  }
159
272
  return zkVerifier;
160
273
  };
161
274
  var deployMockQueryDecrypter = async (hre, acl) => {
162
- await hardhatSetCode(hre, MOCKS_QUERY_DECRYPTER_ADDRESS, import_mock_contracts.MockQueryDecrypterArtifact.deployedBytecode);
163
- const queryDecrypter = await hre.ethers.getContractAt(import_mock_contracts.MockQueryDecrypterArtifact.abi, MOCKS_QUERY_DECRYPTER_ADDRESS);
164
- const initTx = await queryDecrypter.initialize(TASK_MANAGER_ADDRESS, await acl.getAddress());
275
+ const queryDecrypter = await deployMockContractFromArtifact(hre, import_mock_contracts.MockQueryDecrypterArtifact);
276
+ const initTx = await queryDecrypter.initialize(import_sdk2.TASK_MANAGER_ADDRESS, await acl.getAddress());
165
277
  await initTx.wait();
166
278
  const queryDecrypterExists = await queryDecrypter.exists();
167
279
  if (!queryDecrypterExists) {
168
- logError("MockQueryDecrypter does not exist", 2);
169
280
  throw new Error("MockQueryDecrypter does not exist");
170
281
  }
171
282
  return queryDecrypter;
172
283
  };
173
284
  var deployTestBedContract = async (hre) => {
174
- await hardhatSetCode(hre, TEST_BED_ADDRESS, import_mock_contracts.TestBedArtifact.deployedBytecode);
175
- const testBed = await hre.ethers.getContractAt(import_mock_contracts.TestBedArtifact.abi, TEST_BED_ADDRESS);
176
- await testBed.waitForDeployment();
177
- return testBed;
178
- };
179
- var fundZkVerifierSigner = async (hre) => {
180
- const zkVerifierSigner = await hre.ethers.getSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
181
- await hre.network.provider.send("hardhat_setBalance", [
182
- zkVerifierSigner.address,
183
- "0x" + hre.ethers.parseEther("10").toString(16)
184
- ]);
185
- };
186
- var setTaskManagerACL = async (taskManager, acl) => {
187
- const setAclTx = await taskManager.setACLContract(await acl.getAddress());
188
- await setAclTx.wait();
189
- };
190
- var deployMocks = async (hre, options = {
191
- deployTestBed: true,
192
- gasWarning: true,
193
- silent: false
194
- }) => {
195
- const isHardhat = await checkNetworkAndSkip(hre);
196
- if (!isHardhat)
197
- return;
198
- const logEmptyIfNoisy = () => {
199
- if (!options.silent) {
200
- logEmpty();
201
- }
202
- };
203
- const logSuccessIfNoisy = (message, indent = 0) => {
204
- if (!options.silent) {
205
- logSuccess(message, indent);
206
- }
207
- };
208
- const logDeploymentIfNoisy = (contractName, address) => {
209
- if (!options.silent) {
210
- logDeployment(contractName, address);
211
- }
212
- };
213
- const logWarningIfNoisy = (message, indent = 0) => {
214
- if (!options.silent) {
215
- logWarning(message, indent);
216
- }
217
- };
218
- logEmptyIfNoisy();
219
- logSuccessIfNoisy(import_chalk.default.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
220
- logEmptyIfNoisy();
221
- logEmptyIfNoisy();
222
- logSuccessIfNoisy("Mock contracts compiled", 1);
223
- const taskManager = await deployMockTaskManager(hre);
224
- logDeploymentIfNoisy("MockTaskManager", await taskManager.getAddress());
225
- const acl = await deployMockACL(hre);
226
- logDeploymentIfNoisy("MockACL", await acl.getAddress());
227
- await setTaskManagerACL(taskManager, acl);
228
- logSuccessIfNoisy("ACL address set in TaskManager", 2);
229
- await fundZkVerifierSigner(hre);
230
- logSuccessIfNoisy(`ZkVerifier signer (${MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
231
- const zkVerifierSignerBalance = await hre.ethers.provider.getBalance(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
232
- logSuccessIfNoisy(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
233
- const zkVerifier = await deployMockZkVerifier(hre);
234
- logDeploymentIfNoisy("MockZkVerifier", await zkVerifier.getAddress());
235
- const queryDecrypter = await deployMockQueryDecrypter(hre, acl);
236
- logDeploymentIfNoisy("MockQueryDecrypter", await queryDecrypter.getAddress());
237
- if (options.deployTestBed) {
238
- logSuccessIfNoisy("TestBed deployment enabled", 2);
239
- const testBed = await deployTestBedContract(hre);
240
- logDeploymentIfNoisy("TestBed", await testBed.getAddress());
241
- }
242
- logEmptyIfNoisy();
243
- logSuccessIfNoisy(import_chalk.default.bold("cofhe-hardhat-plugin :: mocks deployed successfully"), 0);
244
- if (options.gasWarning) {
245
- logEmptyIfNoisy();
246
- logWarningIfNoisy(
247
- "When using mocks, FHE operations (eg FHE.add / FHE.mul) report a higher gas price due to additional on-chain mocking logic. Deploy your contracts on a testnet chain to check the true gas costs.\n(Disable this warning by setting '@cofhe/sdk.gasWarning' to false in your hardhat config",
248
- 0
249
- );
250
- }
251
- logEmptyIfNoisy();
252
- };
253
- var hardhatSetCode = async (hre, address, bytecode) => {
254
- await hre.network.provider.send("hardhat_setCode", [address, bytecode]);
255
- };
256
- var checkNetworkAndSkip = async (hre) => {
257
- const network = hre.network.name;
258
- const isHardhat = network === "hardhat";
259
- if (!isHardhat)
260
- logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${network}`, 0);
261
- return isHardhat;
285
+ return deployMockContractFromArtifact(hre, import_mock_contracts.TestBedArtifact);
262
286
  };
287
+ var isSilent = false;
263
288
  var logEmpty = () => {
289
+ if (isSilent)
290
+ return;
264
291
  console.log("");
265
292
  };
266
293
  var logSuccess = (message, indent = 1) => {
294
+ if (isSilent)
295
+ return;
267
296
  console.log(import_chalk.default.green(`${" ".repeat(indent)}\u2713 ${message}`));
268
297
  };
269
298
  var logWarning = (message, indent = 1) => {
299
+ if (isSilent)
300
+ return;
270
301
  console.log(import_chalk.default.bold(import_chalk.default.yellow(`${" ".repeat(indent)}\u26A0 NOTE:`)), message);
271
302
  };
272
- var logError = (message, indent = 1) => {
273
- console.log(import_chalk.default.red(`${" ".repeat(indent)}\u2717 ${message}`));
274
- };
275
303
  var logDeployment = (contractName, address) => {
304
+ if (isSilent)
305
+ return;
276
306
  const paddedName = `${contractName} deployed`.padEnd(36);
277
307
  logSuccess(`${paddedName} ${import_chalk.default.bold(address)}`);
278
308
  };
@@ -281,17 +311,14 @@ var logDeployment = (contractName, address) => {
281
311
  var import_chalk2 = __toESM(require("chalk"));
282
312
  var import_types3 = require("hardhat/types");
283
313
  var import_mock_contracts2 = require("@cofhe/mock-contracts");
284
- var getDeployedMockTaskManager = async (hre) => {
285
- const taskManager = await hre.ethers.getContractAt(import_mock_contracts2.MockTaskManagerArtifact.abi, TASK_MANAGER_ADDRESS);
286
- return taskManager;
287
- };
288
314
  var getLoggingEnabled = async (hre) => {
289
- const taskManager = await getDeployedMockTaskManager(hre);
290
- return await taskManager.logOps();
315
+ const taskManager = await getFixedMockContract(hre, import_mock_contracts2.MockTaskManagerArtifact);
316
+ return taskManager.logOps();
291
317
  };
292
318
  var setLoggingEnabled = async (hre, enabled) => {
293
- const taskManager = await getDeployedMockTaskManager(hre);
294
- await taskManager.setLogOps(enabled);
319
+ const taskManager = await getFixedMockContract(hre, import_mock_contracts2.MockTaskManagerArtifact);
320
+ const tx = await taskManager.setLogOps(enabled);
321
+ await tx.wait();
295
322
  };
296
323
  var printLogsEnabledMessage = (closureMessage) => {
297
324
  console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
@@ -326,72 +353,8 @@ var mock_withLogs = async (hre, closureName, closure) => {
326
353
  }
327
354
  };
328
355
 
329
- // src/utils.ts
330
- var import_chai = require("chai");
331
- var import_ethers2 = require("ethers");
332
- var import_hardhat_ethers_provider = require("@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider");
333
- var mock_checkIsTestnet = async (fnName, provider) => {
334
- const bytecode = await provider.getCode(MOCKS_ZK_VERIFIER_ADDRESS);
335
- const isTestnet = bytecode.length === 0;
336
- if (isTestnet) {
337
- console.log(`${fnName} - skipped on non-testnet chain`);
338
- }
339
- return isTestnet;
340
- };
341
- var mock_getPlaintext = async (provider, ctHash) => {
342
- if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
343
- return;
344
- const taskManager = new import_ethers2.ethers.Contract(
345
- TASK_MANAGER_ADDRESS,
346
- ["function mockStorage(uint256) view returns (uint256)"],
347
- provider
348
- );
349
- const plaintext = await taskManager.mockStorage(ctHash);
350
- return plaintext;
351
- };
352
- var mock_getPlaintextExists = async (provider, ctHash) => {
353
- if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
354
- return;
355
- const taskManager = new import_ethers2.ethers.Contract(
356
- TASK_MANAGER_ADDRESS,
357
- ["function inMockStorage(uint256) view returns (bool)"],
358
- provider
359
- );
360
- const plaintextExists = await taskManager.inMockStorage(ctHash);
361
- return plaintextExists;
362
- };
363
- var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
364
- if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
365
- return;
366
- const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
367
- (0, import_chai.expect)(plaintextExists).equal(true, "Plaintext does not exist");
368
- const plaintext = await mock_getPlaintext(provider, ctHash);
369
- (0, import_chai.expect)(plaintext).equal(expectedValue, "Plaintext value is incorrect");
370
- };
371
-
372
- // src/expectResultUtils.ts
373
- var import_sdk = require("@cofhe/sdk");
374
- var import_chai2 = require("chai");
375
- var expectResultError = (result, errorPartial) => {
376
- (0, import_chai2.expect)(result.success).to.eq(false, "Result should be an error");
377
- (0, import_chai2.expect)(result.error).to.include(errorPartial, `Error should contain error partial: ${errorPartial}`);
378
- };
379
- var expectResultSuccess = (result) => {
380
- (0, import_chai2.expect)(result.success).to.eq(true, "Result should be a success");
381
- return result.data;
382
- };
383
- var expectResultValue = (result, value) => {
384
- (0, import_chai2.expect)(result.success).to.eq(true, "Result should be a success");
385
- (0, import_chai2.expect)(result.data).to.eq(value, `Result should have the expected value ${value}`);
386
- return result.data;
387
- };
388
- var expectResultPartialValue = (result, partial) => {
389
- (0, import_chai2.expect)(result.success).to.eq(true, "Result should be a success");
390
- (0, import_chai2.expect)(result.data).to.include(partial, `Result should have the expected partial ${partial}`);
391
- return result.data;
392
- };
393
-
394
356
  // src/index.ts
357
+ var import_chains = require("@cofhe/sdk/chains");
395
358
  var import_mock_contracts3 = require("@cofhe/mock-contracts");
396
359
  (0, import_config.extendConfig)((config, userConfig) => {
397
360
  if (userConfig.networks && userConfig.networks.localcofhe) {
@@ -485,9 +448,10 @@ var import_mock_contracts3 = require("@cofhe/mock-contracts");
485
448
  (0, import_config.extendEnvironment)((hre) => {
486
449
  hre.cofhesdk = {
487
450
  createCofhesdkConfig: async (config) => {
488
- const zkvHhSigner = await hre.ethers.getImpersonatedSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
451
+ const zkvHhSigner = await hre.ethers.getImpersonatedSigner(import_sdk3.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
489
452
  const { walletClient: zkvWalletClient } = await (0, import_adapters.HardhatSignerAdapter)(zkvHhSigner);
490
453
  const configWithZkvWalletClient = {
454
+ environment: "hardhat",
491
455
  ...config,
492
456
  _internal: {
493
457
  ...config._internal,
@@ -502,21 +466,24 @@ var import_mock_contracts3 = require("@cofhe/mock-contracts");
502
466
  hardhatSignerAdapter: async (signer) => {
503
467
  return (0, import_adapters.HardhatSignerAdapter)(signer);
504
468
  },
505
- expectResultSuccess: async (result) => {
506
- const awaitedResult = await result;
507
- return expectResultSuccess(awaitedResult);
508
- },
509
- expectResultError: async (result, errorPartial) => {
510
- const awaitedResult = await result;
511
- return expectResultError(awaitedResult, errorPartial);
469
+ connectWithHardhatSigner: async (client, signer) => {
470
+ const { publicClient, walletClient } = await (0, import_adapters.HardhatSignerAdapter)(signer);
471
+ return client.connect(publicClient, walletClient);
512
472
  },
513
- expectResultValue: async (result, value) => {
514
- const awaitedResult = await result;
515
- return expectResultValue(awaitedResult, value);
516
- },
517
- expectResultPartialValue: async (result, partial) => {
518
- const awaitedResult = await result;
519
- return expectResultPartialValue(awaitedResult, partial);
473
+ createBatteriesIncludedCofhesdkClient: async (signer) => {
474
+ if (!signer) {
475
+ [signer] = await hre.ethers.getSigners();
476
+ }
477
+ const config = await hre.cofhesdk.createCofhesdkConfig({
478
+ environment: "hardhat",
479
+ supportedChains: [import_chains.hardhat]
480
+ });
481
+ const client = hre.cofhesdk.createCofhesdkClient(config);
482
+ await hre.cofhesdk.connectWithHardhatSigner(client, signer);
483
+ await client.permits.createSelf({
484
+ issuer: signer.address
485
+ });
486
+ return client;
520
487
  },
521
488
  mocks: {
522
489
  withLogs: async (closureName, closure) => {
@@ -538,22 +505,27 @@ var import_mock_contracts3 = require("@cofhe/mock-contracts");
538
505
  expectPlaintext: async (ctHash, expectedValue) => {
539
506
  const [signer] = await hre.ethers.getSigners();
540
507
  return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
541
- }
508
+ },
509
+ getMockTaskManager: async () => getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact),
510
+ getMockACL: async () => {
511
+ const taskManager = await getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact);
512
+ const aclAddress = await taskManager.acl();
513
+ return hre.ethers.getContractAt(import_mock_contracts3.MockACLArtifact.abi, aclAddress);
514
+ },
515
+ getMockQueryDecrypter: async () => getFixedMockContract(hre, import_mock_contracts3.MockQueryDecrypterArtifact),
516
+ getMockZkVerifier: async () => getFixedMockContract(hre, import_mock_contracts3.MockZkVerifierArtifact),
517
+ getTestBed: async () => getFixedMockContract(hre, import_mock_contracts3.TestBedArtifact)
542
518
  }
543
519
  };
544
520
  });
545
521
  // Annotate the CommonJS export names for ESM import in node:
546
522
  0 && (module.exports = {
547
- MockACLArtifact,
548
- MockQueryDecrypterArtifact,
549
- MockTaskManagerArtifact,
550
- MockZkVerifierArtifact,
551
- TestBedArtifact,
523
+ TASK_COFHE_MOCKS_DEPLOY,
524
+ TASK_COFHE_MOCKS_SET_LOG_OPS,
525
+ TASK_COFHE_USE_FAUCET,
526
+ deployMockContractFromArtifact,
552
527
  deployMocks,
553
- expectResultError,
554
- expectResultPartialValue,
555
- expectResultSuccess,
556
- expectResultValue,
528
+ getFixedMockContract,
557
529
  localcofheFundAccount,
558
530
  localcofheFundWalletIfNeeded,
559
531
  mock_expectPlaintext,