Skip to main content
The privora-sdk-testing crate provides a complete environment for testing FHE programs using LiteSVM.

Installation

[dev-dependencies]
privora-sdk-testing = { git = "https://github.com/privora-xyz/privora" }

Quick Start

use privora_sdk_testing::prelude::*;

#[test]
fn test_fhe_program() {
    // Create test environment
    let mut env = FheTestEnv::new();

    // Deploy program
    env.deploy_program(PROGRAM_ID, include_bytes!("../program.so"));

    // Create funded keypair
    let payer = env.create_funded_keypair();

    // Encrypt and submit test data
    let price_hash = env.encrypt_and_submit_u8(100);

    // Sync data store before transaction
    env.sync_data_store_to_syscalls();

    // Build and send transaction...

    // Sync data store after transaction
    env.sync_data_store_from_syscalls();

    // Verify results
    env.assert_encrypted_eq_u8(&result_hash, 100);
}

FheTestEnv

The main test environment providing:
  • LiteSVM instance: Modified Solana VM with FHE syscalls
  • TFHE keys: Client and server keys for encryption/decryption
  • Data store: Content-addressable store for ciphertexts
  • Helper methods: Encryption, decryption, and assertion utilities

Key Features

Encryption Helpers

let hash = env.encrypt_and_submit_u8(100);
let hash = env.encrypt_and_submit_u32(10000);
let hash = env.encrypt_and_submit_u64(1000000);

Decryption Helpers

let value: u8 = env.fetch_and_decrypt_u8(&hash);
let value: u32 = env.fetch_and_decrypt_u32(&hash);
let value: u64 = env.fetch_and_decrypt_u64(&hash);

Assertions

env.assert_encrypted_eq_u8(&hash, expected_value);
env.assert_encrypted_true(&bool_hash);
env.assert_encrypted_false(&bool_hash);

Data Store Sync

// Before transaction: make submitted data available to program
env.sync_data_store_to_syscalls();

// Send transaction...

// After transaction: retrieve results from program
env.sync_data_store_from_syscalls();

Test Flow

Next Steps