test: change circuit encryption/decryption test

This commit is contained in:
agureev 2026-06-22 23:06:21 +04:00
parent 78e5b1d1ae
commit a5cb2e484b

View File

@ -204,7 +204,6 @@ mod tests {
&output.encrypted_private_post_states[idx].ciphertext, &output.encrypted_private_post_states[idx].ciphertext,
ssk, ssk,
&output.new_commitments[idx], &output.new_commitments[idx],
u32::try_from(idx).expect("idx fits in u32"),
) )
.unwrap(); .unwrap();
kind kind
@ -296,7 +295,6 @@ mod tests {
&output.encrypted_private_post_states[0].ciphertext, &output.encrypted_private_post_states[0].ciphertext,
&shared_secret, &shared_secret,
&output.new_commitments[0], &output.new_commitments[0],
0,
) )
.unwrap(); .unwrap();
assert_eq!(recipient_post, expected_recipient_post); assert_eq!(recipient_post, expected_recipient_post);
@ -328,7 +326,7 @@ mod tests {
let mut commitment_set = CommitmentSet::with_capacity(2); let mut commitment_set = CommitmentSet::with_capacity(2);
commitment_set.extend(std::slice::from_ref(&commitment_sender)); commitment_set.extend(std::slice::from_ref(&commitment_sender));
let expected_new_nullifiers = vec![ let mut expected_new_nullifiers = vec![
( (
Nullifier::for_account_update(&commitment_sender, &sender_keys.nsk), Nullifier::for_account_update(&commitment_sender, &sender_keys.nsk),
commitment_set.digest(), commitment_set.digest(),
@ -353,7 +351,7 @@ mod tests {
nonce: Nonce::private_account_nonce_init(&recipient_account_id), nonce: Nonce::private_account_nonce_init(&recipient_account_id),
..Default::default() ..Default::default()
}; };
let expected_new_commitments = vec![ let mut expected_new_commitments = vec![
Commitment::new(&sender_account_id, &expected_private_account_1), Commitment::new(&sender_account_id, &expected_private_account_1),
Commitment::new(&recipient_account_id, &expected_private_account_2), Commitment::new(&recipient_account_id, &expected_private_account_2),
]; ];
@ -402,27 +400,34 @@ mod tests {
assert!(proof.is_valid_for(&output)); assert!(proof.is_valid_for(&output));
assert!(output.public_pre_states.is_empty()); assert!(output.public_pre_states.is_empty());
assert!(output.public_post_states.is_empty()); assert!(output.public_post_states.is_empty());
let mut expected_ciphertexts = vec![
EncryptionScheme::encrypt(
&expected_private_account_1,
&PrivateAccountKind::Regular(0),
&shared_secret_1,
&expected_new_commitments[0],
),
EncryptionScheme::encrypt(
&expected_private_account_2,
&PrivateAccountKind::Regular(0),
&shared_secret_2,
&expected_new_commitments[1],
),
];
expected_new_commitments.sort_unstable_by_key(Commitment::to_byte_array);
expected_new_nullifiers.sort_unstable_by_key(|entry| entry.0.to_byte_array());
expected_ciphertexts.sort_unstable_by(|a, b| a.as_bytes().cmp(b.as_bytes()));
assert_eq!(output.new_commitments, expected_new_commitments); assert_eq!(output.new_commitments, expected_new_commitments);
assert_eq!(output.new_nullifiers, expected_new_nullifiers); assert_eq!(output.new_nullifiers, expected_new_nullifiers);
assert_eq!(output.encrypted_private_post_states.len(), 2); assert_eq!(
output
let (_identifier, sender_post) = EncryptionScheme::decrypt( .encrypted_private_post_states
&output.encrypted_private_post_states[0].ciphertext, .iter()
&shared_secret_1, .map(|e| e.ciphertext.clone())
&expected_new_commitments[0], .collect::<Vec<_>>(),
0, expected_ciphertexts,
) );
.unwrap();
assert_eq!(sender_post, expected_private_account_1);
let (_identifier, recipient_post) = EncryptionScheme::decrypt(
&output.encrypted_private_post_states[1].ciphertext,
&shared_secret_2,
&expected_new_commitments[1],
1,
)
.unwrap();
assert_eq!(recipient_post, expected_private_account_2);
} }
#[test] #[test]