Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
samkim-crypto committed Apr 22, 2024
1 parent a50cc4c commit f629d59
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions zk-token-sdk/src/instruction/transfer/without_fee_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,53 @@ impl TransferProofContext {
})
}
}

#[cfg(test)]
mod test {
use {
super::*,
crate::{encryption::auth_encryption::AeKey, instruction::ZkProofData},
};

#[test]
fn test_transfer_with_split_proof_correctness() {
let source_keypair = ElGamalKeypair::new_rand();

let destination_keypair = ElGamalKeypair::new_rand();
let destination_pubkey = destination_keypair.pubkey();

let auditor_keypair = ElGamalKeypair::new_rand();
let auditor_pubkey = auditor_keypair.pubkey();

let aes_key = AeKey::new_rand();
let remaining_balance = 100;
let remaining_balance_elgamal_ciphertext =
source_keypair.pubkey().encrypt(remaining_balance);
let remaining_balance_decryptable_ciphertext = aes_key.encrypt(remaining_balance);

let transfer_amount = 10;

let (equality_proof_data, validity_proof_data, range_proof_data) =
transfer_split_proof_data(
&remaining_balance_elgamal_ciphertext,
&remaining_balance_decryptable_ciphertext,
transfer_amount,
&source_keypair,
&aes_key,
destination_pubkey,
&Some(auditor_pubkey),
)
.unwrap();

equality_proof_data.verify_proof().unwrap();
validity_proof_data.verify_proof().unwrap();
range_proof_data.verify_proof().unwrap();

TransferProofContext::new_from_split_proofs(
equality_proof_data.context_data(),
validity_proof_data.context_data(),
range_proof_data.context_data(),
)
.unwrap();
}
}

0 comments on commit f629d59

Please sign in to comment.