Files
zeekayandHanzo Dev a8c164c427 Depend on the packages that exist
A rebrand renamed third-party names it did not own. @luxfhe-fhe/relayer-sdk and
@luxfhe-fhe/oracle-solidity were never published, and @fhevm/solidity ships
config/ZamaConfig.sol, not LuxConfig.sol, so nothing installed and no contract
compiled. The overrides now say what the lockfile already resolved
(@zama-fhe/relayer-sdk ^0.3.0-8, @zama-fhe/oracle-solidity ^0.2.0), and the
relayer bundle loads from cdn.zama.org, the host that serves it.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-23 01:53:25 -07:00

90 lines
3.6 KiB
TypeScript

import { UserDecryptMultipleValues, UserDecryptMultipleValues__factory } from "../../../types";
import type { Signers } from "../../types";
import { HardhatFhevmRuntimeEnvironment } from "@fhevm/hardhat-plugin";
import { utils as fhevm_utils } from "@fhevm/mock-utils";
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
import { DecryptedResults } from "@zama-fhe/relayer-sdk";
import { expect } from "chai";
import { ethers } from "hardhat";
import * as hre from "hardhat";
async function deployFixture() {
// Contracts are deployed using the first signer/account by default
const factory = (await ethers.getContractFactory("UserDecryptMultipleValues")) as UserDecryptMultipleValues__factory;
const userDecryptMultipleValues = (await factory.deploy()) as UserDecryptMultipleValues;
const userDecryptMultipleValues_address = await userDecryptMultipleValues.getAddress();
return { userDecryptMultipleValues, userDecryptMultipleValues_address };
}
/**
* This trivial example demonstrates the FHE user decryption mechanism
* and highlights a common pitfall developers may encounter.
*/
describe("UserDecryptMultipleValues", function () {
let contract: UserDecryptMultipleValues;
let contractAddress: string;
let signers: Signers;
before(async function () {
// Check whether the tests are running against an FHEVM mock environment
if (!hre.fhevm.isMock) {
throw new Error(`This hardhat test suite cannot run on Sepolia Testnet`);
}
const ethSigners: HardhatEthersSigner[] = await ethers.getSigners();
signers = { owner: ethSigners[0], alice: ethSigners[1] };
});
beforeEach(async function () {
// Deploy a new contract each time we run a new test
const deployment = await deployFixture();
contractAddress = deployment.userDecryptMultipleValues_address;
contract = deployment.userDecryptMultipleValues;
});
// ✅ Test should succeed
it("user decryption should succeed", async function () {
const tx = await contract.connect(signers.alice).initialize(true, 123456, 78901234567);
await tx.wait();
const encryptedBool = await contract.encryptedBool();
const encryptedUint32 = await contract.encryptedUint32();
const encryptedUint64 = await contract.encryptedUint64();
// The FHEVM Hardhat plugin provides a set of convenient helper functions
// that make it easy to perform FHEVM operations within your Hardhat environment.
const fhevm: HardhatFhevmRuntimeEnvironment = hre.fhevm;
const aliceKeypair = fhevm.generateKeypair();
const startTimestamp = fhevm_utils.timestampNow();
const durationDays = 365;
const aliceEip712 = fhevm.createEIP712(aliceKeypair.publicKey, [contractAddress], startTimestamp, durationDays);
const aliceSignature = await signers.alice.signTypedData(
aliceEip712.domain,
{ UserDecryptRequestVerification: aliceEip712.types.UserDecryptRequestVerification },
aliceEip712.message,
);
const decrytepResults: DecryptedResults = await fhevm.userDecrypt(
[
{ handle: encryptedBool, contractAddress: contractAddress },
{ handle: encryptedUint32, contractAddress: contractAddress },
{ handle: encryptedUint64, contractAddress: contractAddress },
],
aliceKeypair.privateKey,
aliceKeypair.publicKey,
aliceSignature,
[contractAddress],
signers.alice.address,
startTimestamp,
durationDays,
);
expect(decrytepResults[encryptedBool]).to.equal(true);
expect(decrytepResults[encryptedUint32]).to.equal(123456 + 1);
expect(decrytepResults[encryptedUint64]).to.equal(78901234567 + 1);
});
});