test(rln): Add passing semaphore test

This commit is contained in:
Oskar Thoren 2022-03-18 19:17:50 +08:00
parent ddb3efc4a5
commit f2f3c820ff
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
1 changed files with 33 additions and 0 deletions

View File

@ -46,6 +46,39 @@ mod test {
println!("Merkle proof: {:#?}", merkle_proof);
}
#[test]
fn test_semaphore() {
const LEAF: Hash = Hash::from_bytes_be(hex!(
"0000000000000000000000000000000000000000000000000000000000000000"
));
// generate identity
let id = Identity::new(b"hello");
// generate merkle tree
let mut tree = PoseidonTree::new(21, LEAF);
tree.set(0, id.commitment().into());
let merkle_proof = tree.proof(0).expect("proof should exist");
let root = tree.root().into();
// change signal and external_nullifier here
let signal = b"xxx";
let external_nullifier = b"appId";
let external_nullifier_hash = semaphore::protocol::hash_external_nullifier(external_nullifier);
let nullifier_hash = semaphore::protocol::generate_nullifier_hash(&id, external_nullifier_hash);
let proof = semaphore::protocol::generate_proof(&id, &merkle_proof, external_nullifier, signal).unwrap();
let success =
semaphore::protocol::verify_proof(root, nullifier_hash, signal, external_nullifier, &proof).unwrap();
assert!(success);
}
#[ignore]
#[test]
fn test_end_to_end() {