Utility contracts for locally testing LuxFHE with FHE primitives in foundry.
npm install @luxfhe/foundry-mocks> [!CAUTION]
> DEPRECATED
>
> Use fhe-mock-contracts instead.
---------
[npm]: https://www.npmjs.com/package/@luxfheprotocol/fhe-foundry-mocks
[npm-badge]: https://img.shields.io/npm/v/@luxfheprotocol/fhe-foundry-mocks.svg
[license]: https://opensource.org/licenses/MIT
[license-badge]: https://img.shields.io/badge/License-MIT-blue.svg
Utility contracts for locally testing FHE locally in foundry.
Need help getting started? Check out the luxfhe documentation!
These contracts are still under heavy constructions and will be changing frequently. Consider binding your contracts to a specific version, and keep an eye on the changelog
v0.1.3 - Rename assertStoredValue to assertHashValue
```
forge install luxfheprotocol/fhe-foundry-mocks
add the following remapping:
``
@luxfheprotocol/fhe-foundry-mocks/=lib/fhe-foundry-mocks/src/
Import CoFheTest from @luxfhe-protocol/fhe-foundry-mocks/CoFheTest.sol and include it in your test file:
`solidity
import {Test} from "forge-std/Test.sol";
import { CoFheTest } from "@luxfheprotocol/fhe-foundry-mocks/CoFheTest.sol";
contract ExampleFHECounterTest is Test {
CoFheTest CFT;
...
function setUp() public {
CFT = new CoFheTest(false);
...
}
`
Creating a new CoFheTest contract initializes a mock CoFHE TaskManager which stores encrypted values locally as cleartext. This mock TM contract is etched to the address found in FHE.sol, and will handle all FHE.___ calls. The boolean param is log which sets whether the mocked ops should be logged to the console.
> [!NOTE]
> Outside of a test environment FHE.sealoutput and FHE.decrypt will resolve asynchronously. See IAsyncFHEReceiver. Due to the nature of foundry tests, these async callbacks are called synchronously.
Additionally, you now have access to CFT which has the following functions (the following examples and more can be found in ExampleFHECounter.t.sol)
Used to create inEBool / InEuintXX / inAddress to be used as function inputs.
`solidity`
// Set number to 5
InEuint32 memory inNumber = CFT.createInEuint32(5);
counter.setNumber(inNumber);
- Param 1: An encrypted value (ebool / euint8 ... euint256 / eaddress) or the hash of a value (InEuint32.hash / ebool.unwrap(eBoolVal))
- Param 2: The expected encrypted value
This will revert if the encrypted hash isn't stored, or if the expected value doesn't match.
`solidity``
function test_setNumber() public {
InEuint32 memory inNumber = CFT.createInEuint32(10);
counter.setNumber(inNumber);
CFT.assertStoredValue(counter.eNumber(), 10);
}
This project is licensed under MIT.