Comment on page

Testing & Interacting

Now let's talk a little bit about testing for Fhenix FHE contracts. If you don't care about this and you just want to hack, we recommend at least skimming the Remix Section to understand how to use encryption/decryption APIs.

Manual Testing (Remix)

Some developers prefer a more manual approach at first - where you just want to quickly verify that something works, play around with a small function or just verify functionality without writing tests or setting up a full developer environment. To do this, we'll show how you can manually test contracts with FHE-encrypted inputs and outputs without using fhevmjs as a helper library.
Convieniently, LocalFhenix comes with APIs that perform encryption or decryption for you.
The APIs are:
Encrypt a number. If int size is not provided defaults to 32.
http://localhost:5000/decrypt?encrypted=<hex string>
Decrypt a number.
Decryption Public
Get the public key that the service uses to decrypt data.
Network Public Key
Get the public key of the network.
For example, if I wanted to encrypt the number 259 as a uint16, I would use:
curl "http://localhost:5000/encrypt?number=259&int=16"
To decrypt a number, we use a GET request, with the encrypted string (returned from a TFHE.reencrypt function), such as:
curl "http://localhost:5000/decrypt&encrypted=0x0dcc7d99ecbb6fc8b8657321b497b39b2bd6017dd4a159b1d1a801e58149422cb5aa4e2d73994bc15e1dc12604a0da1db0"
Note: At the moment, to perform decryption you must provide the public key of the service for it to be able to decrypt data. That means you need to call the view function of the FHE-enabled contract with the key from the decryption_public endpoint.

Writing Unit Tests

As we mentioned in previous sections, Fhenix uses extensions to the standard EVM to enable FHE functionality. To write unit tests, we use LocalFhenix instead of hardhat network - this is similar to deploying & testing contracts on Ganache. To see an example of how to write unit tests & create CI workflows you can refer to our reference wrapped ERC20 contract repo.