Skip to content

Commit

Permalink
test: revert paths
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificYield committed Dec 19, 2024
1 parent dd34f8b commit 655dc24
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/tests/TFHERevertTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import "../../lib/TFHE.sol";
import "../FHEVMConfig.sol";

contract TFHERevertTest {
constructor() {
TFHE.setFHEVM(FHEVMConfig.defaultConfig());
}

function padToBytes64(bytes memory input) public pure {
TFHE.padToBytes64(input);
}

function padToBytes128(bytes memory input) public pure {
TFHE.padToBytes128(input);
}

function padToBytes256(bytes memory input) public pure {
TFHE.padToBytes256(input);
}
}
45 changes: 45 additions & 0 deletions test/tfheOperations/tfheRevertPaths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect } from 'chai';
import { randomBytes } from 'crypto';
import { ethers } from 'hardhat';

import { getSigners, initSigners } from '../signers';

describe('TFHE revert paths', function () {
before(async function () {
await initSigners(1);
this.signers = await getSigners();

const contractFactory = await ethers.getContractFactory('TFHERevertTest');
const contract = await contractFactory.connect(this.signers.alice).deploy();
await contract.waitForDeployment();

this.contract = contract;
});

it('padToBytes64 reverts if input > 64 bytes', async function () {
const numberBytes = 65;
const input = randomBytes(numberBytes);

await expect(this.contract.padToBytes64(input))
.to.be.revertedWithCustomError(this.contract, 'InputLengthAbove64Bytes')
.withArgs(numberBytes);
});

it('padToBytes128 reverts if input > 128 bytes', async function () {
const numberBytes = 129;
const input = randomBytes(numberBytes);

await expect(this.contract.padToBytes128(input))
.to.be.revertedWithCustomError(this.contract, 'InputLengthAbove128Bytes')
.withArgs(numberBytes);
});

it('padToBytes256 reverts if input > 256 bytes', async function () {
const numberBytes = 257;
const input = randomBytes(numberBytes);

await expect(this.contract.padToBytes256(input))
.to.be.revertedWithCustomError(this.contract, 'InputLengthAbove256Bytes')
.withArgs(numberBytes);
});
});

0 comments on commit 655dc24

Please sign in to comment.