-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest-user-decrypt.js
More file actions
executable file
·57 lines (48 loc) · 1.72 KB
/
test-user-decrypt.js
File metadata and controls
executable file
·57 lines (48 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
import { logCLI, parseCommonOptions } from '../../utils.js';
import { FHETestAddresses } from './fheTest.js';
import { ethers } from 'ethers';
import { userDecrypt } from '../../userDecrypt.js';
// npx . test user-decrypt --types euint32 --network devnet --version 2
// npx . test user-decrypt --types euint32 --network testnet --version 1
// npx . test user-decrypt --types euint32 --network testnet --version 2
// npx . test user-decrypt --types euint32 --network mainnet --version 2
export async function testFHETestUserDecryptCommand(options) {
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);
if (!FHETestAddresses[config.name]) {
logCLI(`❌ FHETest is not deployed on network ${config.name}`, options);
process.exit(1);
}
const contractAddress = FHETestAddresses[config.name];
logCLI(`🏈 FHETest contract address: ${contractAddress}`);
const abi = [];
const getFuncNames = [];
// Turn 'euint32' into 'Euint32'
for (let i = 0; i < options.types.length; ++i) {
const t = 'E' + options.types[i].substring(1);
const getFuncName = `get${t}`;
getFuncNames.push(getFuncName);
abi.push(`function ${getFuncName}() view returns (bytes32)`);
}
const contract = new ethers.Contract(contractAddress, abi, signer);
const handles = [];
for (let i = 0; i < getFuncNames.length; ++i) {
const handle = await contract[getFuncNames[i]]();
handles.push(handle);
logCLI(`🏈 handle: ${handle}`);
}
await userDecrypt({
handleContractPairs: handles.map((h) => {
return {
handle: h,
contractAddress,
};
}),
contractAddresses: [contractAddress],
signer,
config,
zamaFhevmApiKey,
options,
});
}