@cofhe/hardhat-plugin 0.1.0
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/README.md +142 -0
- package/dist/index.d.mts +192 -0
- package/dist/index.d.ts +192 -0
- package/dist/index.js +565 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +526 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +56 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
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,
|
|
38
|
+
deployMocks: () => deployMocks,
|
|
39
|
+
expectResultError: () => expectResultError,
|
|
40
|
+
expectResultPartialValue: () => expectResultPartialValue,
|
|
41
|
+
expectResultSuccess: () => expectResultSuccess,
|
|
42
|
+
expectResultValue: () => expectResultValue,
|
|
43
|
+
localcofheFundAccount: () => localcofheFundAccount,
|
|
44
|
+
localcofheFundWalletIfNeeded: () => localcofheFundWalletIfNeeded,
|
|
45
|
+
mock_expectPlaintext: () => mock_expectPlaintext,
|
|
46
|
+
mock_getPlaintext: () => mock_getPlaintext,
|
|
47
|
+
mock_getPlaintextExists: () => mock_getPlaintextExists,
|
|
48
|
+
mock_setLoggingEnabled: () => mock_setLoggingEnabled,
|
|
49
|
+
mock_withLogs: () => mock_withLogs
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(src_exports);
|
|
52
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
53
|
+
var import_viem = require("viem");
|
|
54
|
+
var import_config = require("hardhat/config");
|
|
55
|
+
var import_task_names = require("hardhat/builtin-tasks/task-names");
|
|
56
|
+
var import_signers = require("@nomicfoundation/hardhat-ethers/signers");
|
|
57
|
+
var import_sdk2 = require("@cofhe/sdk");
|
|
58
|
+
var import_node = require("@cofhe/sdk/node");
|
|
59
|
+
var import_adapters = require("@cofhe/sdk/adapters");
|
|
60
|
+
|
|
61
|
+
// src/fund.ts
|
|
62
|
+
var import_types = require("hardhat/types");
|
|
63
|
+
var import_hardhat_ethers = require("@nomicfoundation/hardhat-ethers");
|
|
64
|
+
async function localcofheFundAccount(hre, toAddress, amount = "10") {
|
|
65
|
+
const privateKey = process.env.FUNDER_PRIVATE_KEY ?? "0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659";
|
|
66
|
+
if (!privateKey) {
|
|
67
|
+
console.error("Error: FUNDER_PRIVATE_KEY environment variable not set");
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const wallet = new hre.ethers.Wallet(privateKey, hre.ethers.provider);
|
|
72
|
+
const balance = await hre.ethers.provider.getBalance(wallet.address);
|
|
73
|
+
console.log(`Funder wallet address: ${wallet.address}`);
|
|
74
|
+
console.log(`Funder wallet balance: ${hre.ethers.formatEther(balance)} ETH`);
|
|
75
|
+
const amountToSend = hre.ethers.parseEther(amount);
|
|
76
|
+
if (balance < amountToSend) {
|
|
77
|
+
console.error(
|
|
78
|
+
`Error: Funder wallet doesn't have enough funds. Current balance: ${hre.ethers.formatEther(balance)} ETH`
|
|
79
|
+
);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
console.log(`Sending ${amount} ETH to ${toAddress}...`);
|
|
83
|
+
const tx = await wallet.sendTransaction({
|
|
84
|
+
to: toAddress,
|
|
85
|
+
value: amountToSend
|
|
86
|
+
});
|
|
87
|
+
console.log(`Transaction sent! Hash: ${tx.hash}`);
|
|
88
|
+
console.log("Waiting for confirmation...");
|
|
89
|
+
const receipt = await tx.wait();
|
|
90
|
+
console.log(`Transaction confirmed in block ${receipt?.blockNumber}`);
|
|
91
|
+
console.log(`Successfully sent ${amount} ETH to ${toAddress}`);
|
|
92
|
+
return receipt;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error("Error sending funds:", error);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function localcofheFundWalletIfNeeded(hre, walletAddress) {
|
|
99
|
+
const walletBalance = await hre.ethers.provider.getBalance(walletAddress);
|
|
100
|
+
console.log(`Wallet balance: ${hre.ethers.formatEther(walletBalance)} ETH`);
|
|
101
|
+
if (walletBalance < hre.ethers.parseEther("1")) {
|
|
102
|
+
console.log(`Wallet balance is less than 1 ETH. Funding ${walletAddress}...`);
|
|
103
|
+
const receipt = await localcofheFundAccount(hre, walletAddress);
|
|
104
|
+
if (receipt) {
|
|
105
|
+
const newBalance = await hre.ethers.provider.getBalance(walletAddress);
|
|
106
|
+
console.log(`Wallet new balance: ${hre.ethers.formatEther(newBalance)} ETH`);
|
|
107
|
+
} else {
|
|
108
|
+
console.error(`Failed to fund ${walletAddress}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/consts.ts
|
|
114
|
+
var TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
|
|
115
|
+
var TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
|
|
116
|
+
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
|
+
|
|
124
|
+
// src/deploy.ts
|
|
125
|
+
var import_types2 = require("hardhat/types");
|
|
126
|
+
var import_chalk = __toESM(require("chalk"));
|
|
127
|
+
var import_ethers = require("ethers");
|
|
128
|
+
var import_mock_contracts = require("@cofhe/mock-contracts");
|
|
129
|
+
var deployMockTaskManager = async (hre) => {
|
|
130
|
+
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);
|
|
133
|
+
const initTx = await taskManager.initialize(signer.address);
|
|
134
|
+
await initTx.wait();
|
|
135
|
+
const tmExists = await taskManager.exists();
|
|
136
|
+
if (!tmExists) {
|
|
137
|
+
throw new Error("MockTaskManager does not exist");
|
|
138
|
+
}
|
|
139
|
+
return taskManager;
|
|
140
|
+
};
|
|
141
|
+
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);
|
|
144
|
+
const exists = await acl.exists();
|
|
145
|
+
if (!exists) {
|
|
146
|
+
logError("MockACL does not exist", 2);
|
|
147
|
+
throw new Error("MockACL does not exist");
|
|
148
|
+
}
|
|
149
|
+
return acl;
|
|
150
|
+
};
|
|
151
|
+
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);
|
|
154
|
+
const zkVerifierExists = await zkVerifier.exists();
|
|
155
|
+
if (!zkVerifierExists) {
|
|
156
|
+
logError("MockZkVerifier does not exist", 2);
|
|
157
|
+
throw new Error("MockZkVerifier does not exist");
|
|
158
|
+
}
|
|
159
|
+
return zkVerifier;
|
|
160
|
+
};
|
|
161
|
+
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());
|
|
165
|
+
await initTx.wait();
|
|
166
|
+
const queryDecrypterExists = await queryDecrypter.exists();
|
|
167
|
+
if (!queryDecrypterExists) {
|
|
168
|
+
logError("MockQueryDecrypter does not exist", 2);
|
|
169
|
+
throw new Error("MockQueryDecrypter does not exist");
|
|
170
|
+
}
|
|
171
|
+
return queryDecrypter;
|
|
172
|
+
};
|
|
173
|
+
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;
|
|
262
|
+
};
|
|
263
|
+
var logEmpty = () => {
|
|
264
|
+
console.log("");
|
|
265
|
+
};
|
|
266
|
+
var logSuccess = (message, indent = 1) => {
|
|
267
|
+
console.log(import_chalk.default.green(`${" ".repeat(indent)}\u2713 ${message}`));
|
|
268
|
+
};
|
|
269
|
+
var logWarning = (message, indent = 1) => {
|
|
270
|
+
console.log(import_chalk.default.bold(import_chalk.default.yellow(`${" ".repeat(indent)}\u26A0 NOTE:`)), message);
|
|
271
|
+
};
|
|
272
|
+
var logError = (message, indent = 1) => {
|
|
273
|
+
console.log(import_chalk.default.red(`${" ".repeat(indent)}\u2717 ${message}`));
|
|
274
|
+
};
|
|
275
|
+
var logDeployment = (contractName, address) => {
|
|
276
|
+
const paddedName = `${contractName} deployed`.padEnd(36);
|
|
277
|
+
logSuccess(`${paddedName} ${import_chalk.default.bold(address)}`);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// src/logging.ts
|
|
281
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
282
|
+
var import_types3 = require("hardhat/types");
|
|
283
|
+
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
|
+
var getLoggingEnabled = async (hre) => {
|
|
289
|
+
const taskManager = await getDeployedMockTaskManager(hre);
|
|
290
|
+
return await taskManager.logOps();
|
|
291
|
+
};
|
|
292
|
+
var setLoggingEnabled = async (hre, enabled) => {
|
|
293
|
+
const taskManager = await getDeployedMockTaskManager(hre);
|
|
294
|
+
await taskManager.setLogOps(enabled);
|
|
295
|
+
};
|
|
296
|
+
var printLogsEnabledMessage = (closureMessage) => {
|
|
297
|
+
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");
|
|
298
|
+
console.log(`\u2502 [COFHE-MOCKS] \u2502 ${closureMessage}`);
|
|
299
|
+
console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\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");
|
|
300
|
+
};
|
|
301
|
+
var printLogsBlockEnd = () => {
|
|
302
|
+
console.log("\u2514\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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
303
|
+
};
|
|
304
|
+
var mock_setLoggingEnabled = async (hre, enabled, closureName) => {
|
|
305
|
+
try {
|
|
306
|
+
const initiallyEnabled = await getLoggingEnabled(hre);
|
|
307
|
+
await setLoggingEnabled(hre, enabled);
|
|
308
|
+
if (enabled) {
|
|
309
|
+
printLogsEnabledMessage(`${closureName ? `"${import_chalk2.default.bold(closureName)}" logs:` : "Logs:"}`);
|
|
310
|
+
}
|
|
311
|
+
if (!enabled && initiallyEnabled) {
|
|
312
|
+
printLogsBlockEnd();
|
|
313
|
+
}
|
|
314
|
+
} catch (error) {
|
|
315
|
+
console.log(import_chalk2.default.red("mock_setLoggingEnabled error"), error);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
var mock_withLogs = async (hre, closureName, closure) => {
|
|
319
|
+
const initiallyEnabled = await getLoggingEnabled(hre);
|
|
320
|
+
await setLoggingEnabled(hre, true);
|
|
321
|
+
printLogsEnabledMessage(`"${import_chalk2.default.bold(closureName)}" logs:`);
|
|
322
|
+
await closure();
|
|
323
|
+
printLogsBlockEnd();
|
|
324
|
+
if (!initiallyEnabled) {
|
|
325
|
+
await setLoggingEnabled(hre, false);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
|
|
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
|
+
// src/index.ts
|
|
395
|
+
var import_mock_contracts3 = require("@cofhe/mock-contracts");
|
|
396
|
+
(0, import_config.extendConfig)((config, userConfig) => {
|
|
397
|
+
if (userConfig.networks && userConfig.networks.localcofhe) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
config.networks.localcofhe = {
|
|
401
|
+
gas: "auto",
|
|
402
|
+
gasMultiplier: 1.2,
|
|
403
|
+
gasPrice: "auto",
|
|
404
|
+
timeout: 1e4,
|
|
405
|
+
httpHeaders: {},
|
|
406
|
+
url: "http://127.0.0.1:42069",
|
|
407
|
+
accounts: [
|
|
408
|
+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
|
|
409
|
+
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
|
|
410
|
+
"0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a",
|
|
411
|
+
"0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6"
|
|
412
|
+
]
|
|
413
|
+
};
|
|
414
|
+
if (!userConfig.networks?.["eth-sepolia"]) {
|
|
415
|
+
config.networks["eth-sepolia"] = {
|
|
416
|
+
url: process.env.SEPOLIA_RPC_URL ?? "https://ethereum-sepolia.publicnode.com",
|
|
417
|
+
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
|
|
418
|
+
chainId: 11155111,
|
|
419
|
+
gas: "auto",
|
|
420
|
+
gasMultiplier: 1.2,
|
|
421
|
+
gasPrice: "auto",
|
|
422
|
+
timeout: 6e4,
|
|
423
|
+
httpHeaders: {}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
if (!userConfig.networks?.["arb-sepolia"]) {
|
|
427
|
+
config.networks["arb-sepolia"] = {
|
|
428
|
+
url: process.env.ARBITRUM_SEPOLIA_RPC_URL ?? "https://sepolia-rollup.arbitrum.io/rpc",
|
|
429
|
+
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
|
|
430
|
+
chainId: 421614,
|
|
431
|
+
gas: "auto",
|
|
432
|
+
gasMultiplier: 1.2,
|
|
433
|
+
gasPrice: "auto",
|
|
434
|
+
timeout: 6e4,
|
|
435
|
+
httpHeaders: {}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
config.cofhesdk = {
|
|
439
|
+
logMocks: userConfig.cofhesdk?.logMocks ?? true,
|
|
440
|
+
gasWarning: userConfig.cofhesdk?.gasWarning ?? true
|
|
441
|
+
};
|
|
442
|
+
});
|
|
443
|
+
(0, import_config.task)(TASK_COFHE_USE_FAUCET, "Fund an account from the funder").addOptionalParam("address", "Address to fund", void 0, import_config.types.string).setAction(async ({ address }, hre) => {
|
|
444
|
+
const { network } = hre;
|
|
445
|
+
const { name: networkName } = network;
|
|
446
|
+
if (networkName !== "localcofhe") {
|
|
447
|
+
console.info(import_chalk3.default.yellow(`Programmatic faucet only supported for localcofhe`));
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (!address) {
|
|
451
|
+
console.info(import_chalk3.default.red(`Failed to get address to fund`));
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
console.info(import_chalk3.default.green(`Getting funds from faucet for ${address}`));
|
|
455
|
+
try {
|
|
456
|
+
await localcofheFundAccount(hre, address);
|
|
457
|
+
} catch (e) {
|
|
458
|
+
console.info(import_chalk3.default.red(`failed to get funds from localcofhe for ${address}: ${e}`));
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
(0, import_config.task)(TASK_COFHE_MOCKS_DEPLOY, "Deploys the mock contracts on the Hardhat network").addOptionalParam("deployTestBed", "Whether to deploy the test bed", true, import_config.types.boolean).addOptionalParam("silent", "Whether to suppress output", false, import_config.types.boolean).setAction(async ({ deployTestBed, silent }, hre) => {
|
|
462
|
+
await deployMocks(hre, {
|
|
463
|
+
deployTestBed: deployTestBed ?? true,
|
|
464
|
+
gasWarning: hre.config.cofhesdk.gasWarning ?? true,
|
|
465
|
+
silent: silent ?? false
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
(0, import_config.task)(import_task_names.TASK_TEST, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
|
|
469
|
+
await deployMocks(hre, {
|
|
470
|
+
deployTestBed: true,
|
|
471
|
+
gasWarning: hre.config.cofhesdk.gasWarning ?? true
|
|
472
|
+
});
|
|
473
|
+
return runSuper();
|
|
474
|
+
});
|
|
475
|
+
(0, import_config.task)(import_task_names.TASK_NODE, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
|
|
476
|
+
await deployMocks(hre, {
|
|
477
|
+
deployTestBed: true,
|
|
478
|
+
gasWarning: hre.config.cofhesdk.gasWarning ?? true
|
|
479
|
+
});
|
|
480
|
+
return runSuper();
|
|
481
|
+
});
|
|
482
|
+
(0, import_config.task)(TASK_COFHE_MOCKS_SET_LOG_OPS, "Set logging for the Mock CoFHE contracts").addParam("enable", "Whether to enable logging", false, import_config.types.boolean).setAction(async ({ enable }, hre) => {
|
|
483
|
+
await mock_setLoggingEnabled(hre, enable);
|
|
484
|
+
});
|
|
485
|
+
(0, import_config.extendEnvironment)((hre) => {
|
|
486
|
+
hre.cofhesdk = {
|
|
487
|
+
createCofhesdkConfig: async (config) => {
|
|
488
|
+
const zkvHhSigner = await hre.ethers.getImpersonatedSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
489
|
+
const { walletClient: zkvWalletClient } = await (0, import_adapters.HardhatSignerAdapter)(zkvHhSigner);
|
|
490
|
+
const configWithZkvWalletClient = {
|
|
491
|
+
...config,
|
|
492
|
+
_internal: {
|
|
493
|
+
...config._internal,
|
|
494
|
+
zkvWalletClient
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
return (0, import_node.createCofhesdkConfig)(configWithZkvWalletClient);
|
|
498
|
+
},
|
|
499
|
+
createCofhesdkClient: (config) => {
|
|
500
|
+
return (0, import_node.createCofhesdkClient)(config);
|
|
501
|
+
},
|
|
502
|
+
hardhatSignerAdapter: async (signer) => {
|
|
503
|
+
return (0, import_adapters.HardhatSignerAdapter)(signer);
|
|
504
|
+
},
|
|
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);
|
|
512
|
+
},
|
|
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);
|
|
520
|
+
},
|
|
521
|
+
mocks: {
|
|
522
|
+
withLogs: async (closureName, closure) => {
|
|
523
|
+
return mock_withLogs(hre, closureName, closure);
|
|
524
|
+
},
|
|
525
|
+
enableLogs: async (closureName) => {
|
|
526
|
+
return mock_setLoggingEnabled(hre, true, closureName);
|
|
527
|
+
},
|
|
528
|
+
disableLogs: async () => {
|
|
529
|
+
return mock_setLoggingEnabled(hre, false);
|
|
530
|
+
},
|
|
531
|
+
deployMocks: async (options) => {
|
|
532
|
+
return deployMocks(hre, options);
|
|
533
|
+
},
|
|
534
|
+
getPlaintext: async (ctHash) => {
|
|
535
|
+
const [signer] = await hre.ethers.getSigners();
|
|
536
|
+
return mock_getPlaintext(signer.provider, ctHash);
|
|
537
|
+
},
|
|
538
|
+
expectPlaintext: async (ctHash, expectedValue) => {
|
|
539
|
+
const [signer] = await hre.ethers.getSigners();
|
|
540
|
+
return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
});
|
|
545
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
546
|
+
0 && (module.exports = {
|
|
547
|
+
MockACLArtifact,
|
|
548
|
+
MockQueryDecrypterArtifact,
|
|
549
|
+
MockTaskManagerArtifact,
|
|
550
|
+
MockZkVerifierArtifact,
|
|
551
|
+
TestBedArtifact,
|
|
552
|
+
deployMocks,
|
|
553
|
+
expectResultError,
|
|
554
|
+
expectResultPartialValue,
|
|
555
|
+
expectResultSuccess,
|
|
556
|
+
expectResultValue,
|
|
557
|
+
localcofheFundAccount,
|
|
558
|
+
localcofheFundWalletIfNeeded,
|
|
559
|
+
mock_expectPlaintext,
|
|
560
|
+
mock_getPlaintext,
|
|
561
|
+
mock_getPlaintextExists,
|
|
562
|
+
mock_setLoggingEnabled,
|
|
563
|
+
mock_withLogs
|
|
564
|
+
});
|
|
565
|
+
//# sourceMappingURL=index.js.map
|