-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest-make-publicly-decryptable.js
More file actions
executable file
·61 lines (48 loc) · 1.85 KB
/
test-make-publicly-decryptable.js
File metadata and controls
executable file
·61 lines (48 loc) · 1.85 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
58
59
60
61
'use strict';
import { ACL } from '../../../lib/internal.js';
import { logCLI, parseCommonOptions } from '../../utils.js';
import { FHETestAddresses } from './fheTest.js';
import { ethers } from 'ethers';
// npx . test make-publicly-decryptable --type euint32 --network devnet
// npx . test make-publicly-decryptable --type euint32 --network testnet
// npx . test make-publicly-decryptable --type euint32 --network mainnet
export async function testFHETestMakePubliclyDecryptableCommand(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];
// Turn 'euint32' into 'Euint32'
const t = 'E' + options.type.substring(1);
const funcName = `makePubliclyDecryptable${t}`;
const getFuncName = `get${t}`;
const contract = new ethers.Contract(
contractAddress,
[
`function ${funcName}() external`,
`function ${getFuncName}() view returns (bytes32)`,
],
signer,
);
const handle = await contract[getFuncName]();
logCLI(`🏈 handle: ${handle}`);
const acl = new ACL({
aclContractAddress: config.fhevmInstanceConfig.aclContractAddress,
provider,
});
const ok = await acl.isAllowedForDecryption([handle]);
if (ok[0] === true) {
logCLI(`🚨 handle is already publicly decryptable.`);
return;
}
/** @type {import('ethers').ContractTransactionResponse} */
const tx = await contract[funcName]();
logCLI(`🚚 tx: ${tx.hash} ...`);
/** @type {import('ethers').ContractTransactionReceipt} */
const txReceipt = await tx.wait();
logCLI(`- tx status: ${txReceipt.status}`);
logCLI(`- tx gas used: ${txReceipt.gasUsed}`);
logCLI(`- tx gas price: ${txReceipt.gasPrice}`);
}