From 9e54915e4401d86eaeffa027c99fa87ba7ce5030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20=27birdy=27=20Danjou?= Date: Fri, 1 Mar 2024 13:50:20 +0100 Subject: [PATCH] fix: fix typo and add test for cast ebool from euint4 and euint8 --- examples/tests/TFHEManualTestSuite.sol | 14 ++++++++--- test/tfheOperations/manual.ts | 32 +++++++++++++++++++++----- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/examples/tests/TFHEManualTestSuite.sol b/examples/tests/TFHEManualTestSuite.sol index 628a6cc6..c39b1fbb 100644 --- a/examples/tests/TFHEManualTestSuite.sol +++ b/examples/tests/TFHEManualTestSuite.sol @@ -15,15 +15,23 @@ contract TFHEManualTestSuite { return TFHE.decrypt(TFHE.cmux(controlProc, ifTrueProc, ifFalseProc)); } - function test_eboolo_euint16_cast(bool input) public view returns (uint16) { + function test_ebool_euint4_cast(bool input) public view returns (uint16) { + return TFHE.decrypt(TFHE.asEuint4(TFHE.asEbool(input))); + } + + function test_ebool_euint8_cast(bool input) public view returns (uint16) { + return TFHE.decrypt(TFHE.asEuint8(TFHE.asEbool(input))); + } + + function test_ebool_euint16_cast(bool input) public view returns (uint16) { return TFHE.decrypt(TFHE.asEuint16(TFHE.asEbool(input))); } - function test_eboolo_euint32_cast(bool input) public view returns (uint32) { + function test_ebool_euint32_cast(bool input) public view returns (uint32) { return TFHE.decrypt(TFHE.asEuint32(TFHE.asEbool(input))); } - function test_eboolo_euint64_cast(bool input) public view returns (uint64) { + function test_ebool_euint64_cast(bool input) public view returns (uint64) { return TFHE.decrypt(TFHE.asEuint64(TFHE.asEbool(input))); } diff --git a/test/tfheOperations/manual.ts b/test/tfheOperations/manual.ts index 08a8b9ae..a3bc25e8 100644 --- a/test/tfheOperations/manual.ts +++ b/test/tfheOperations/manual.ts @@ -48,33 +48,53 @@ describe('TFHE manual operations', function () { expect(res).to.equal(3); }); + it('ebool to euint4 casting works with true', async function () { + const res = await this.contract.test_ebool_euint4_cast(true); + expect(res).to.equal(1); + }); + + it('ebool to euint4 casting works with false', async function () { + const res = await this.contract.test_ebool_euint4_cast(false); + expect(res).to.equal(0); + }); + + it('ebool to euint8 casting works with true', async function () { + const res = await this.contract.test_ebool_euint8_cast(true); + expect(res).to.equal(1); + }); + + it('ebool to euint8 casting works with false', async function () { + const res = await this.contract.test_ebool_euint8_cast(false); + expect(res).to.equal(0); + }); + it('ebool to euint16 casting works with true', async function () { - const res = await this.contract.test_eboolo_euint16_cast(true); + const res = await this.contract.test_ebool_euint16_cast(true); expect(res).to.equal(1); }); it('ebool to euint16 casting works with false', async function () { - const res = await this.contract.test_eboolo_euint16_cast(false); + const res = await this.contract.test_ebool_euint16_cast(false); expect(res).to.equal(0); }); it('ebool to euint32 casting works with true', async function () { - const res = await this.contract.test_eboolo_euint32_cast(true); + const res = await this.contract.test_ebool_euint32_cast(true); expect(res).to.equal(1); }); it('ebool to euint32 casting works with false', async function () { - const res = await this.contract.test_eboolo_euint32_cast(false); + const res = await this.contract.test_ebool_euint32_cast(false); expect(res).to.equal(0); }); it('ebool to euint64 casting works with true', async function () { - const res = await this.contract.test_eboolo_euint64_cast(true); + const res = await this.contract.test_ebool_euint64_cast(true); expect(res).to.equal(1); }); it('ebool to euint32 casting works with false', async function () { - const res = await this.contract.test_eboolo_euint64_cast(false); + const res = await this.contract.test_ebool_euint64_cast(false); expect(res).to.equal(0); });