Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 9152892

Browse files
committed
add tests
1 parent 045e286 commit 9152892

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

token/confidential-transfer/proof-tests/tests/proof_test.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ use {
33
encryption::{auth_encryption::AeKey, elgamal::ElGamalKeypair},
44
zk_elgamal_proof_program::proof_data::ZkProofData,
55
},
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+
},
812
};
913

1014
#[test]
@@ -53,3 +57,33 @@ fn test_proof_validity(spendable_balance: u64, transfer_amount: u64) {
5357
)
5458
.unwrap();
5559
}
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

Comments
 (0)