-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest-random.js
More file actions
executable file
·53 lines (41 loc) · 1.53 KB
/
test-random.js
File metadata and controls
executable file
·53 lines (41 loc) · 1.53 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
'use strict';
import { logCLI, parseCommonOptions } from '../../utils.js';
import { FHETestAddresses } from './fheTest.js';
import { ethers } from 'ethers';
// npx . test random --type euint32 --network testnet
// npx . test random --type euint32 --network devnet
export async function testFHETestRandomCommand(options) {
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);
if (options.type === 'eaddress') {
logCLI(`❌ FHETest does not support random addresses`, options);
process.exit(1);
}
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 = `rand${t}`;
const getFuncName = `get${t}`;
const contract = new ethers.Contract(
contractAddress,
[
`function ${funcName}() external`,
`function ${getFuncName}() view returns (bytes32)`,
],
signer,
);
/** @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}`);
const handle = await contract[getFuncName]();
logCLI(`🏈 new handle: ${handle}`);
}