mirror of
https://github.com/zama-ai/fhevm-solidity.git
synced 2026-04-17 03:00:47 -04:00
222 lines
8.0 KiB
TypeScript
222 lines
8.0 KiB
TypeScript
import { expect } from 'chai';
|
|
import { ethers } from 'hardhat';
|
|
|
|
import type { TFHETestSuite1 } from '../../types/contracts/tests/TFHETestSuite1';
|
|
import type { TFHETestSuite2 } from '../../types/contracts/tests/TFHETestSuite2';
|
|
import type { TFHETestSuite3 } from '../../types/contracts/tests/TFHETestSuite3';
|
|
import type { TFHETestSuite4 } from '../../types/contracts/tests/TFHETestSuite4';
|
|
import type { TFHETestSuite5 } from '../../types/contracts/tests/TFHETestSuite5';
|
|
import type { TFHETestSuite6 } from '../../types/contracts/tests/TFHETestSuite6';
|
|
import type { TFHETestSuite7 } from '../../types/contracts/tests/TFHETestSuite7';
|
|
import type { TFHETestSuite8 } from '../../types/contracts/tests/TFHETestSuite8';
|
|
import type { TFHETestSuite9 } from '../../types/contracts/tests/TFHETestSuite9';
|
|
import type { TFHETestSuite10 } from '../../types/contracts/tests/TFHETestSuite10';
|
|
import type { TFHETestSuite11 } from '../../types/contracts/tests/TFHETestSuite11';
|
|
import {
|
|
createInstances,
|
|
decrypt4,
|
|
decrypt8,
|
|
decrypt16,
|
|
decrypt32,
|
|
decrypt64,
|
|
decrypt128,
|
|
decrypt256,
|
|
decryptBool,
|
|
} from '../instance';
|
|
import { getSigners, initSigners } from '../signers';
|
|
|
|
async function deployTfheTestFixture1(): Promise<TFHETestSuite1> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite1');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
async function deployTfheTestFixture2(): Promise<TFHETestSuite2> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite2');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
async function deployTfheTestFixture3(): Promise<TFHETestSuite3> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite3');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
async function deployTfheTestFixture4(): Promise<TFHETestSuite4> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite4');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
async function deployTfheTestFixture5(): Promise<TFHETestSuite5> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite5');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
async function deployTfheTestFixture6(): Promise<TFHETestSuite6> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite6');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
async function deployTfheTestFixture7(): Promise<TFHETestSuite7> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite7');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
async function deployTfheTestFixture8(): Promise<TFHETestSuite8> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite8');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
async function deployTfheTestFixture9(): Promise<TFHETestSuite9> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite9');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
async function deployTfheTestFixture10(): Promise<TFHETestSuite10> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite10');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
async function deployTfheTestFixture11(): Promise<TFHETestSuite11> {
|
|
const signers = await getSigners();
|
|
const admin = signers.alice;
|
|
|
|
const contractFactory = await ethers.getContractFactory('TFHETestSuite11');
|
|
const contract = await contractFactory.connect(admin).deploy();
|
|
await contract.waitForDeployment();
|
|
|
|
return contract;
|
|
}
|
|
|
|
describe('TFHE operations 13', function () {
|
|
before(async function () {
|
|
await initSigners(1);
|
|
this.signers = await getSigners();
|
|
|
|
const contract1 = await deployTfheTestFixture1();
|
|
this.contract1Address = await contract1.getAddress();
|
|
this.contract1 = contract1;
|
|
|
|
const contract2 = await deployTfheTestFixture2();
|
|
this.contract2Address = await contract2.getAddress();
|
|
this.contract2 = contract2;
|
|
|
|
const contract3 = await deployTfheTestFixture3();
|
|
this.contract3Address = await contract3.getAddress();
|
|
this.contract3 = contract3;
|
|
|
|
const contract4 = await deployTfheTestFixture4();
|
|
this.contract4Address = await contract4.getAddress();
|
|
this.contract4 = contract4;
|
|
|
|
const contract5 = await deployTfheTestFixture5();
|
|
this.contract5Address = await contract5.getAddress();
|
|
this.contract5 = contract5;
|
|
|
|
const contract6 = await deployTfheTestFixture6();
|
|
this.contract6Address = await contract6.getAddress();
|
|
this.contract6 = contract6;
|
|
|
|
const contract7 = await deployTfheTestFixture7();
|
|
this.contract7Address = await contract7.getAddress();
|
|
this.contract7 = contract7;
|
|
|
|
const contract8 = await deployTfheTestFixture8();
|
|
this.contract8Address = await contract8.getAddress();
|
|
this.contract8 = contract8;
|
|
|
|
const contract9 = await deployTfheTestFixture9();
|
|
this.contract9Address = await contract9.getAddress();
|
|
this.contract9 = contract9;
|
|
|
|
const contract10 = await deployTfheTestFixture10();
|
|
this.contract10Address = await contract10.getAddress();
|
|
this.contract10 = contract10;
|
|
|
|
const contract11 = await deployTfheTestFixture11();
|
|
this.contract11Address = await contract11.getAddress();
|
|
this.contract11 = contract11;
|
|
|
|
const instances = await createInstances(this.signers);
|
|
this.instances = instances;
|
|
});
|
|
|
|
it('test operator "neg" overload (euint256) => euint256 test 1 (115792089237316195423570985008687907853269984665640564039457578680357072424439)', async function () {
|
|
const input = this.instances.alice.createEncryptedInput(this.contract11Address, this.signers.alice.address);
|
|
input.add256(115792089237316195423570985008687907853269984665640564039457578680357072424439n);
|
|
const encryptedAmount = await input.encrypt();
|
|
const tx = await this.contract11.neg_euint256(encryptedAmount.handles[0], encryptedAmount.inputProof);
|
|
await tx.wait();
|
|
const res = await decrypt256(await this.contract11.res256());
|
|
expect(res).to.equal(5327556057215497n);
|
|
});
|
|
|
|
it('test operator "not" overload (euint256) => euint256 test 1 (115792089237316195423570985008687907853269984665640564039457581938347870429377)', async function () {
|
|
const input = this.instances.alice.createEncryptedInput(this.contract11Address, this.signers.alice.address);
|
|
input.add256(115792089237316195423570985008687907853269984665640564039457581938347870429377n);
|
|
const encryptedAmount = await input.encrypt();
|
|
const tx = await this.contract11.not_euint256(encryptedAmount.handles[0], encryptedAmount.inputProof);
|
|
await tx.wait();
|
|
const res = await decrypt256(await this.contract11.res256());
|
|
expect(res).to.equal(2069565259210558n);
|
|
});
|
|
});
|