Skip to content

Commit

Permalink
fix: fix typo and add test for cast ebool from euint4 and euint8
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Mar 1, 2024
1 parent a798189 commit 9e54915
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
14 changes: 11 additions & 3 deletions examples/tests/TFHEManualTestSuite.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down
32 changes: 26 additions & 6 deletions test/tfheOperations/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit 9e54915

Please sign in to comment.