|
3 | 3 | encryption::{auth_encryption::AeKey, elgamal::ElGamalKeypair},
|
4 | 4 | zk_elgamal_proof_program::proof_data::ZkProofData,
|
5 | 5 | },
|
6 |
| - spl_token_confidential_transfer_proof_extraction::transfer::TransferProofContext, |
7 |
| - spl_token_confidential_transfer_proof_generation::transfer::transfer_split_proof_data, |
| 6 | + spl_token_confidential_transfer_proof_extraction::{ |
| 7 | + transfer::TransferProofContext, withdraw::WithdrawProofContext, |
| 8 | + }, |
| 9 | + spl_token_confidential_transfer_proof_generation::{ |
| 10 | + transfer::transfer_split_proof_data, withdraw::withdraw_proof_data, |
| 11 | + }, |
8 | 12 | };
|
9 | 13 |
|
10 | 14 | #[test]
|
@@ -53,3 +57,33 @@ fn test_proof_validity(spendable_balance: u64, transfer_amount: u64) {
|
53 | 57 | )
|
54 | 58 | .unwrap();
|
55 | 59 | }
|
| 60 | + |
| 61 | +#[test] |
| 62 | +fn test_withdraw_proof_correctness() { |
| 63 | + test_withdraw_validity(0, 0); |
| 64 | + test_withdraw_validity(77, 55); |
| 65 | + test_withdraw_validity(281474976710655, 281474976710655); |
| 66 | +} |
| 67 | + |
| 68 | +fn test_withdraw_validity(spendable_balance: u64, withdraw_amount: u64) { |
| 69 | + let keypair = ElGamalKeypair::new_rand(); |
| 70 | + |
| 71 | + let spendable_ciphertext = keypair.pubkey().encrypt(spendable_balance); |
| 72 | + |
| 73 | + let (equality_proof_data, range_proof_data) = withdraw_proof_data( |
| 74 | + &spendable_ciphertext, |
| 75 | + spendable_balance, |
| 76 | + withdraw_amount, |
| 77 | + &keypair, |
| 78 | + ) |
| 79 | + .unwrap(); |
| 80 | + |
| 81 | + equality_proof_data.verify_proof().unwrap(); |
| 82 | + range_proof_data.verify_proof().unwrap(); |
| 83 | + |
| 84 | + WithdrawProofContext::verify_and_extract( |
| 85 | + equality_proof_data.context_data(), |
| 86 | + range_proof_data.context_data(), |
| 87 | + ) |
| 88 | + .unwrap(); |
| 89 | +} |
0 commit comments