@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/dist/index.mjs
CHANGED
|
@@ -66,10 +66,6 @@ async function localcofheFundWalletIfNeeded(hre, walletAddress) {
|
|
|
66
66
|
var TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
|
|
67
67
|
var TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
|
|
68
68
|
var TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
|
|
69
|
-
var TASK_MANAGER_ADDRESS = "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
|
|
70
|
-
var MOCKS_ZK_VERIFIER_ADDRESS = "0x0000000000000000000000000000000000000100";
|
|
71
|
-
var MOCKS_QUERY_DECRYPTER_ADDRESS = "0x0000000000000000000000000000000000000200";
|
|
72
|
-
var TEST_BED_ADDRESS = "0x0000000000000000000000000000000000000300";
|
|
73
69
|
|
|
74
70
|
// src/deploy.ts
|
|
75
71
|
import "hardhat/types";
|
|
@@ -82,11 +78,122 @@ import {
|
|
|
82
78
|
MockQueryDecrypterArtifact,
|
|
83
79
|
TestBedArtifact
|
|
84
80
|
} from "@cofhe/mock-contracts";
|
|
85
|
-
import { MOCKS_ZK_VERIFIER_SIGNER_ADDRESS } from "@cofhe/sdk";
|
|
81
|
+
import { TASK_MANAGER_ADDRESS as TASK_MANAGER_ADDRESS2, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS } from "@cofhe/sdk";
|
|
82
|
+
|
|
83
|
+
// src/utils.ts
|
|
84
|
+
import { TASK_MANAGER_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS } from "@cofhe/sdk";
|
|
85
|
+
import { expect } from "chai";
|
|
86
|
+
import { ethers } from "ethers";
|
|
87
|
+
import "@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider";
|
|
88
|
+
var deployMockContractFromArtifact = async (hre, artifact) => {
|
|
89
|
+
if (artifact.isFixed) {
|
|
90
|
+
await hre.network.provider.send("hardhat_setCode", [artifact.fixedAddress, artifact.deployedBytecode]);
|
|
91
|
+
return getFixedMockContract(hre, artifact);
|
|
92
|
+
}
|
|
93
|
+
const [signer] = await hre.ethers.getSigners();
|
|
94
|
+
const factory = new hre.ethers.ContractFactory(artifact.abi, artifact.bytecode, signer);
|
|
95
|
+
const contract = await factory.deploy(
|
|
96
|
+
/* constructor args */
|
|
97
|
+
);
|
|
98
|
+
await contract.waitForDeployment();
|
|
99
|
+
return contract;
|
|
100
|
+
};
|
|
101
|
+
var getFixedMockContract = async (hre, artifact) => {
|
|
102
|
+
if (!artifact.isFixed) {
|
|
103
|
+
throw new Error("Artifact is not fixed");
|
|
104
|
+
}
|
|
105
|
+
return await hre.ethers.getContractAt(artifact.abi, artifact.fixedAddress);
|
|
106
|
+
};
|
|
107
|
+
var mock_checkIsTestnet = async (fnName, provider) => {
|
|
108
|
+
const bytecode = await provider.getCode(MOCKS_ZK_VERIFIER_ADDRESS);
|
|
109
|
+
const isTestnet = bytecode.length === 0;
|
|
110
|
+
if (isTestnet) {
|
|
111
|
+
console.log(`${fnName} - skipped on non-testnet chain`);
|
|
112
|
+
}
|
|
113
|
+
return isTestnet;
|
|
114
|
+
};
|
|
115
|
+
var mock_getPlaintext = async (provider, ctHash) => {
|
|
116
|
+
if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
|
|
117
|
+
return;
|
|
118
|
+
const taskManager = new ethers.Contract(
|
|
119
|
+
TASK_MANAGER_ADDRESS,
|
|
120
|
+
["function mockStorage(uint256) view returns (uint256)"],
|
|
121
|
+
provider
|
|
122
|
+
);
|
|
123
|
+
const plaintext = await taskManager.mockStorage(ctHash);
|
|
124
|
+
return plaintext;
|
|
125
|
+
};
|
|
126
|
+
var mock_getPlaintextExists = async (provider, ctHash) => {
|
|
127
|
+
if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
|
|
128
|
+
return;
|
|
129
|
+
const taskManager = new ethers.Contract(
|
|
130
|
+
TASK_MANAGER_ADDRESS,
|
|
131
|
+
["function inMockStorage(uint256) view returns (bool)"],
|
|
132
|
+
provider
|
|
133
|
+
);
|
|
134
|
+
const plaintextExists = await taskManager.inMockStorage(ctHash);
|
|
135
|
+
return plaintextExists;
|
|
136
|
+
};
|
|
137
|
+
var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
|
|
138
|
+
if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
|
|
139
|
+
return;
|
|
140
|
+
const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
|
|
141
|
+
expect(plaintextExists).equal(true, "Plaintext does not exist");
|
|
142
|
+
const plaintext = await mock_getPlaintext(provider, ctHash);
|
|
143
|
+
expect(plaintext).equal(expectedValue, "Plaintext value is incorrect");
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/deploy.ts
|
|
147
|
+
var deployMocks = async (hre, options = {
|
|
148
|
+
deployTestBed: true,
|
|
149
|
+
gasWarning: true,
|
|
150
|
+
silent: false
|
|
151
|
+
}) => {
|
|
152
|
+
const isHardhat = await getIsHardhat(hre);
|
|
153
|
+
if (!isHardhat) {
|
|
154
|
+
logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${hre.network.name}`, 0);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
isSilent = options.silent ?? false;
|
|
158
|
+
logEmpty();
|
|
159
|
+
logSuccess(chalk.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
|
|
160
|
+
logEmpty();
|
|
161
|
+
const taskManager = await deployMockTaskManager(hre);
|
|
162
|
+
logDeployment("MockTaskManager", await taskManager.getAddress());
|
|
163
|
+
const acl = await deployMockACL(hre);
|
|
164
|
+
logDeployment("MockACL", await acl.getAddress());
|
|
165
|
+
await linkTaskManagerAndACL(taskManager, acl);
|
|
166
|
+
logSuccess("ACL address set in TaskManager", 2);
|
|
167
|
+
await fundZkVerifierSigner(hre);
|
|
168
|
+
logSuccess(`ZkVerifier signer (${MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
|
|
169
|
+
const zkVerifierSignerBalance = await getZkVerifierSignerBalance(hre);
|
|
170
|
+
logSuccess(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
|
|
171
|
+
const zkVerifier = await deployMockZkVerifier(hre);
|
|
172
|
+
logDeployment("MockZkVerifier", await zkVerifier.getAddress());
|
|
173
|
+
const queryDecrypter = await deployMockQueryDecrypter(hre, acl);
|
|
174
|
+
logDeployment("MockQueryDecrypter", await queryDecrypter.getAddress());
|
|
175
|
+
if (options.deployTestBed) {
|
|
176
|
+
logSuccess("TestBed deployment enabled", 2);
|
|
177
|
+
const testBed = await deployTestBedContract(hre);
|
|
178
|
+
logDeployment("TestBed", await testBed.getAddress());
|
|
179
|
+
}
|
|
180
|
+
logEmpty();
|
|
181
|
+
logSuccess(chalk.bold("cofhe-hardhat-plugin :: mocks deployed successfully"), 0);
|
|
182
|
+
if (options.gasWarning) {
|
|
183
|
+
logEmpty();
|
|
184
|
+
logWarning(
|
|
185
|
+
"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",
|
|
186
|
+
0
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
logEmpty();
|
|
190
|
+
};
|
|
191
|
+
var getIsHardhat = async (hre) => {
|
|
192
|
+
return hre.network.name === "hardhat";
|
|
193
|
+
};
|
|
86
194
|
var deployMockTaskManager = async (hre) => {
|
|
87
195
|
const [signer] = await hre.ethers.getSigners();
|
|
88
|
-
await
|
|
89
|
-
const taskManager = await hre.ethers.getContractAt(MockTaskManagerArtifact.abi, TASK_MANAGER_ADDRESS);
|
|
196
|
+
const taskManager = await deployMockContractFromArtifact(hre, MockTaskManagerArtifact);
|
|
90
197
|
const initTx = await taskManager.initialize(signer.address);
|
|
91
198
|
await initTx.wait();
|
|
92
199
|
const tmExists = await taskManager.exists();
|
|
@@ -96,146 +203,68 @@ var deployMockTaskManager = async (hre) => {
|
|
|
96
203
|
return taskManager;
|
|
97
204
|
};
|
|
98
205
|
var deployMockACL = async (hre) => {
|
|
99
|
-
const acl = await
|
|
206
|
+
const acl = await deployMockContractFromArtifact(hre, MockACLArtifact);
|
|
100
207
|
const exists = await acl.exists();
|
|
101
208
|
if (!exists) {
|
|
102
|
-
logError("MockACL does not exist", 2);
|
|
103
209
|
throw new Error("MockACL does not exist");
|
|
104
210
|
}
|
|
105
211
|
return acl;
|
|
106
212
|
};
|
|
213
|
+
var fundZkVerifierSigner = async (hre) => {
|
|
214
|
+
const zkVerifierSigner = await hre.ethers.getSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
215
|
+
await hre.network.provider.send("hardhat_setBalance", [
|
|
216
|
+
zkVerifierSigner.address,
|
|
217
|
+
"0x" + hre.ethers.parseEther("10").toString(16)
|
|
218
|
+
]);
|
|
219
|
+
};
|
|
220
|
+
var getZkVerifierSignerBalance = async (hre) => {
|
|
221
|
+
return hre.ethers.provider.getBalance(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
222
|
+
};
|
|
223
|
+
var linkTaskManagerAndACL = async (taskManager, acl) => {
|
|
224
|
+
const aclAddress = await acl.getAddress();
|
|
225
|
+
const linkAclTx = await taskManager.setACLContract(aclAddress);
|
|
226
|
+
await linkAclTx.wait();
|
|
227
|
+
};
|
|
107
228
|
var deployMockZkVerifier = async (hre) => {
|
|
108
|
-
await
|
|
109
|
-
const zkVerifier = await hre.ethers.getContractAt(MockZkVerifierArtifact.abi, MOCKS_ZK_VERIFIER_ADDRESS);
|
|
229
|
+
const zkVerifier = await deployMockContractFromArtifact(hre, MockZkVerifierArtifact);
|
|
110
230
|
const zkVerifierExists = await zkVerifier.exists();
|
|
111
231
|
if (!zkVerifierExists) {
|
|
112
|
-
logError("MockZkVerifier does not exist", 2);
|
|
113
232
|
throw new Error("MockZkVerifier does not exist");
|
|
114
233
|
}
|
|
115
234
|
return zkVerifier;
|
|
116
235
|
};
|
|
117
236
|
var deployMockQueryDecrypter = async (hre, acl) => {
|
|
118
|
-
await
|
|
119
|
-
const
|
|
120
|
-
const initTx = await queryDecrypter.initialize(TASK_MANAGER_ADDRESS, await acl.getAddress());
|
|
237
|
+
const queryDecrypter = await deployMockContractFromArtifact(hre, MockQueryDecrypterArtifact);
|
|
238
|
+
const initTx = await queryDecrypter.initialize(TASK_MANAGER_ADDRESS2, await acl.getAddress());
|
|
121
239
|
await initTx.wait();
|
|
122
240
|
const queryDecrypterExists = await queryDecrypter.exists();
|
|
123
241
|
if (!queryDecrypterExists) {
|
|
124
|
-
logError("MockQueryDecrypter does not exist", 2);
|
|
125
242
|
throw new Error("MockQueryDecrypter does not exist");
|
|
126
243
|
}
|
|
127
244
|
return queryDecrypter;
|
|
128
245
|
};
|
|
129
246
|
var deployTestBedContract = async (hre) => {
|
|
130
|
-
|
|
131
|
-
const testBed = await hre.ethers.getContractAt(TestBedArtifact.abi, TEST_BED_ADDRESS);
|
|
132
|
-
await testBed.waitForDeployment();
|
|
133
|
-
return testBed;
|
|
134
|
-
};
|
|
135
|
-
var fundZkVerifierSigner = async (hre) => {
|
|
136
|
-
const zkVerifierSigner = await hre.ethers.getSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
137
|
-
await hre.network.provider.send("hardhat_setBalance", [
|
|
138
|
-
zkVerifierSigner.address,
|
|
139
|
-
"0x" + hre.ethers.parseEther("10").toString(16)
|
|
140
|
-
]);
|
|
141
|
-
};
|
|
142
|
-
var setTaskManagerACL = async (taskManager, acl) => {
|
|
143
|
-
const setAclTx = await taskManager.setACLContract(await acl.getAddress());
|
|
144
|
-
await setAclTx.wait();
|
|
145
|
-
};
|
|
146
|
-
var deployMocks = async (hre, options = {
|
|
147
|
-
deployTestBed: true,
|
|
148
|
-
gasWarning: true,
|
|
149
|
-
silent: false
|
|
150
|
-
}) => {
|
|
151
|
-
const isHardhat = await checkNetworkAndSkip(hre);
|
|
152
|
-
if (!isHardhat)
|
|
153
|
-
return;
|
|
154
|
-
const logEmptyIfNoisy = () => {
|
|
155
|
-
if (!options.silent) {
|
|
156
|
-
logEmpty();
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const logSuccessIfNoisy = (message, indent = 0) => {
|
|
160
|
-
if (!options.silent) {
|
|
161
|
-
logSuccess(message, indent);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
const logDeploymentIfNoisy = (contractName, address) => {
|
|
165
|
-
if (!options.silent) {
|
|
166
|
-
logDeployment(contractName, address);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
const logWarningIfNoisy = (message, indent = 0) => {
|
|
170
|
-
if (!options.silent) {
|
|
171
|
-
logWarning(message, indent);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
logEmptyIfNoisy();
|
|
175
|
-
logSuccessIfNoisy(chalk.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
|
|
176
|
-
logEmptyIfNoisy();
|
|
177
|
-
const taskManager = await deployMockTaskManager(hre);
|
|
178
|
-
logDeploymentIfNoisy("MockTaskManager", await taskManager.getAddress());
|
|
179
|
-
const acl = await deployMockACL(hre);
|
|
180
|
-
logDeploymentIfNoisy("MockACL", await acl.getAddress());
|
|
181
|
-
await setTaskManagerACL(taskManager, acl);
|
|
182
|
-
logSuccessIfNoisy("ACL address set in TaskManager", 2);
|
|
183
|
-
await fundZkVerifierSigner(hre);
|
|
184
|
-
logSuccessIfNoisy(`ZkVerifier signer (${MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
|
|
185
|
-
const zkVerifierSignerBalance = await hre.ethers.provider.getBalance(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
186
|
-
logSuccessIfNoisy(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
|
|
187
|
-
const zkVerifier = await deployMockZkVerifier(hre);
|
|
188
|
-
logDeploymentIfNoisy("MockZkVerifier", await zkVerifier.getAddress());
|
|
189
|
-
const queryDecrypter = await deployMockQueryDecrypter(hre, acl);
|
|
190
|
-
logDeploymentIfNoisy("MockQueryDecrypter", await queryDecrypter.getAddress());
|
|
191
|
-
if (options.deployTestBed) {
|
|
192
|
-
logSuccessIfNoisy("TestBed deployment enabled", 2);
|
|
193
|
-
const testBed = await deployTestBedContract(hre);
|
|
194
|
-
logDeploymentIfNoisy("TestBed", await testBed.getAddress());
|
|
195
|
-
}
|
|
196
|
-
logEmptyIfNoisy();
|
|
197
|
-
logSuccessIfNoisy(chalk.bold("cofhe-hardhat-plugin :: mocks deployed successfully"), 0);
|
|
198
|
-
if (options.gasWarning) {
|
|
199
|
-
logEmptyIfNoisy();
|
|
200
|
-
logWarningIfNoisy(
|
|
201
|
-
"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",
|
|
202
|
-
0
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
logEmptyIfNoisy();
|
|
206
|
-
};
|
|
207
|
-
var hardhatSetCode = async (hre, address, bytecode) => {
|
|
208
|
-
await hre.network.provider.send("hardhat_setCode", [address, bytecode]);
|
|
209
|
-
};
|
|
210
|
-
var ethersDeployContract = async (hre, abi, bytecode) => {
|
|
211
|
-
const [signer] = await hre.ethers.getSigners();
|
|
212
|
-
const factory = new hre.ethers.ContractFactory(abi, bytecode, signer);
|
|
213
|
-
const contract = await factory.deploy(
|
|
214
|
-
/* constructor args */
|
|
215
|
-
);
|
|
216
|
-
await contract.waitForDeployment();
|
|
217
|
-
return contract;
|
|
218
|
-
};
|
|
219
|
-
var checkNetworkAndSkip = async (hre) => {
|
|
220
|
-
const network = hre.network.name;
|
|
221
|
-
const isHardhat = network === "hardhat";
|
|
222
|
-
if (!isHardhat)
|
|
223
|
-
logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${network}`, 0);
|
|
224
|
-
return isHardhat;
|
|
247
|
+
return deployMockContractFromArtifact(hre, TestBedArtifact);
|
|
225
248
|
};
|
|
249
|
+
var isSilent = false;
|
|
226
250
|
var logEmpty = () => {
|
|
251
|
+
if (isSilent)
|
|
252
|
+
return;
|
|
227
253
|
console.log("");
|
|
228
254
|
};
|
|
229
255
|
var logSuccess = (message, indent = 1) => {
|
|
256
|
+
if (isSilent)
|
|
257
|
+
return;
|
|
230
258
|
console.log(chalk.green(`${" ".repeat(indent)}\u2713 ${message}`));
|
|
231
259
|
};
|
|
232
260
|
var logWarning = (message, indent = 1) => {
|
|
261
|
+
if (isSilent)
|
|
262
|
+
return;
|
|
233
263
|
console.log(chalk.bold(chalk.yellow(`${" ".repeat(indent)}\u26A0 NOTE:`)), message);
|
|
234
264
|
};
|
|
235
|
-
var logError = (message, indent = 1) => {
|
|
236
|
-
console.log(chalk.red(`${" ".repeat(indent)}\u2717 ${message}`));
|
|
237
|
-
};
|
|
238
265
|
var logDeployment = (contractName, address) => {
|
|
266
|
+
if (isSilent)
|
|
267
|
+
return;
|
|
239
268
|
const paddedName = `${contractName} deployed`.padEnd(36);
|
|
240
269
|
logSuccess(`${paddedName} ${chalk.bold(address)}`);
|
|
241
270
|
};
|
|
@@ -244,17 +273,14 @@ var logDeployment = (contractName, address) => {
|
|
|
244
273
|
import chalk2 from "chalk";
|
|
245
274
|
import "hardhat/types";
|
|
246
275
|
import { MockTaskManagerArtifact as MockTaskManagerArtifact2 } from "@cofhe/mock-contracts";
|
|
247
|
-
var getDeployedMockTaskManager = async (hre) => {
|
|
248
|
-
const taskManager = await hre.ethers.getContractAt(MockTaskManagerArtifact2.abi, TASK_MANAGER_ADDRESS);
|
|
249
|
-
return taskManager;
|
|
250
|
-
};
|
|
251
276
|
var getLoggingEnabled = async (hre) => {
|
|
252
|
-
const taskManager = await
|
|
253
|
-
return
|
|
277
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact2);
|
|
278
|
+
return taskManager.logOps();
|
|
254
279
|
};
|
|
255
280
|
var setLoggingEnabled = async (hre, enabled) => {
|
|
256
|
-
const taskManager = await
|
|
257
|
-
await taskManager.setLogOps(enabled);
|
|
281
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact2);
|
|
282
|
+
const tx = await taskManager.setLogOps(enabled);
|
|
283
|
+
await tx.wait();
|
|
258
284
|
};
|
|
259
285
|
var printLogsEnabledMessage = (closureMessage) => {
|
|
260
286
|
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");
|
|
@@ -289,50 +315,8 @@ var mock_withLogs = async (hre, closureName, closure) => {
|
|
|
289
315
|
}
|
|
290
316
|
};
|
|
291
317
|
|
|
292
|
-
// src/utils.ts
|
|
293
|
-
import { expect } from "chai";
|
|
294
|
-
import { ethers } from "ethers";
|
|
295
|
-
import "@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider";
|
|
296
|
-
var mock_checkIsTestnet = async (fnName, provider) => {
|
|
297
|
-
const bytecode = await provider.getCode(MOCKS_ZK_VERIFIER_ADDRESS);
|
|
298
|
-
const isTestnet = bytecode.length === 0;
|
|
299
|
-
if (isTestnet) {
|
|
300
|
-
console.log(`${fnName} - skipped on non-testnet chain`);
|
|
301
|
-
}
|
|
302
|
-
return isTestnet;
|
|
303
|
-
};
|
|
304
|
-
var mock_getPlaintext = async (provider, ctHash) => {
|
|
305
|
-
if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
|
|
306
|
-
return;
|
|
307
|
-
const taskManager = new ethers.Contract(
|
|
308
|
-
TASK_MANAGER_ADDRESS,
|
|
309
|
-
["function mockStorage(uint256) view returns (uint256)"],
|
|
310
|
-
provider
|
|
311
|
-
);
|
|
312
|
-
const plaintext = await taskManager.mockStorage(ctHash);
|
|
313
|
-
return plaintext;
|
|
314
|
-
};
|
|
315
|
-
var mock_getPlaintextExists = async (provider, ctHash) => {
|
|
316
|
-
if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
|
|
317
|
-
return;
|
|
318
|
-
const taskManager = new ethers.Contract(
|
|
319
|
-
TASK_MANAGER_ADDRESS,
|
|
320
|
-
["function inMockStorage(uint256) view returns (bool)"],
|
|
321
|
-
provider
|
|
322
|
-
);
|
|
323
|
-
const plaintextExists = await taskManager.inMockStorage(ctHash);
|
|
324
|
-
return plaintextExists;
|
|
325
|
-
};
|
|
326
|
-
var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
|
|
327
|
-
if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
|
|
328
|
-
return;
|
|
329
|
-
const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
|
|
330
|
-
expect(plaintextExists).equal(true, "Plaintext does not exist");
|
|
331
|
-
const plaintext = await mock_getPlaintext(provider, ctHash);
|
|
332
|
-
expect(plaintext).equal(expectedValue, "Plaintext value is incorrect");
|
|
333
|
-
};
|
|
334
|
-
|
|
335
318
|
// src/index.ts
|
|
319
|
+
import { hardhat } from "@cofhe/sdk/chains";
|
|
336
320
|
import {
|
|
337
321
|
MockACLArtifact as MockACLArtifact2,
|
|
338
322
|
MockQueryDecrypterArtifact as MockQueryDecrypterArtifact2,
|
|
@@ -340,14 +324,6 @@ import {
|
|
|
340
324
|
MockZkVerifierArtifact as MockZkVerifierArtifact2,
|
|
341
325
|
TestBedArtifact as TestBedArtifact2
|
|
342
326
|
} from "@cofhe/mock-contracts";
|
|
343
|
-
import { hardhat } from "@cofhe/sdk/chains";
|
|
344
|
-
import {
|
|
345
|
-
MockACLArtifact as MockACLArtifact3,
|
|
346
|
-
MockQueryDecrypterArtifact as MockQueryDecrypterArtifact3,
|
|
347
|
-
MockTaskManagerArtifact as MockTaskManagerArtifact4,
|
|
348
|
-
MockZkVerifierArtifact as MockZkVerifierArtifact3,
|
|
349
|
-
TestBedArtifact as TestBedArtifact3
|
|
350
|
-
} from "@cofhe/mock-contracts";
|
|
351
327
|
extendConfig((config, userConfig) => {
|
|
352
328
|
if (userConfig.networks && userConfig.networks.localcofhe) {
|
|
353
329
|
return;
|
|
@@ -498,33 +474,25 @@ extendEnvironment((hre) => {
|
|
|
498
474
|
const [signer] = await hre.ethers.getSigners();
|
|
499
475
|
return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
|
|
500
476
|
},
|
|
501
|
-
getMockTaskManager: async () =>
|
|
502
|
-
return await hre.ethers.getContractAt(MockTaskManagerArtifact3.abi, MockTaskManagerArtifact3.fixedAddress);
|
|
503
|
-
},
|
|
477
|
+
getMockTaskManager: async () => getFixedMockContract(hre, MockTaskManagerArtifact3),
|
|
504
478
|
getMockACL: async () => {
|
|
505
|
-
const
|
|
506
|
-
const aclAddress = await
|
|
507
|
-
return
|
|
508
|
-
},
|
|
509
|
-
getMockQueryDecrypter: async () => {
|
|
510
|
-
return await hre.ethers.getContractAt(MockQueryDecrypterArtifact2.abi, MockQueryDecrypterArtifact2.fixedAddress);
|
|
479
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact3);
|
|
480
|
+
const aclAddress = await taskManager.acl();
|
|
481
|
+
return hre.ethers.getContractAt(MockACLArtifact2.abi, aclAddress);
|
|
511
482
|
},
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
getTestBed: async () => {
|
|
516
|
-
return await hre.ethers.getContractAt(TestBedArtifact2.abi, TestBedArtifact2.fixedAddress);
|
|
517
|
-
}
|
|
483
|
+
getMockQueryDecrypter: async () => getFixedMockContract(hre, MockQueryDecrypterArtifact2),
|
|
484
|
+
getMockZkVerifier: async () => getFixedMockContract(hre, MockZkVerifierArtifact2),
|
|
485
|
+
getTestBed: async () => getFixedMockContract(hre, TestBedArtifact2)
|
|
518
486
|
}
|
|
519
487
|
};
|
|
520
488
|
});
|
|
521
489
|
export {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
TestBedArtifact3 as TestBedArtifact,
|
|
490
|
+
TASK_COFHE_MOCKS_DEPLOY,
|
|
491
|
+
TASK_COFHE_MOCKS_SET_LOG_OPS,
|
|
492
|
+
TASK_COFHE_USE_FAUCET,
|
|
493
|
+
deployMockContractFromArtifact,
|
|
527
494
|
deployMocks,
|
|
495
|
+
getFixedMockContract,
|
|
528
496
|
localcofheFundAccount,
|
|
529
497
|
localcofheFundWalletIfNeeded,
|
|
530
498
|
mock_expectPlaintext,
|