mirror of https://github.com/vacp2p/zerokit.git
test(rln): Add passing semaphore test
This commit is contained in:
parent
ddb3efc4a5
commit
f2f3c820ff
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue