From 408e619e82038854cb57de4f9ecdfdbc1b61b84b Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 12 Jun 2024 17:25:19 +0200 Subject: [PATCH] test: conversions for LeaderProof --- ledger/cryptarchia-ledger/src/lib.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/ledger/cryptarchia-ledger/src/lib.rs b/ledger/cryptarchia-ledger/src/lib.rs index 893a00e9..ad058ff6 100644 --- a/ledger/cryptarchia-ledger/src/lib.rs +++ b/ledger/cryptarchia-ledger/src/lib.rs @@ -386,7 +386,7 @@ impl core::fmt::Debug for LedgerState { #[cfg(test)] pub mod tests { - use super::{Coin, EpochState, Ledger, LedgerState}; + use super::{Coin, EpochState, LeaderProof, Ledger, LedgerState, Nullifier}; use crate::{crypto::Blake2b, Commitment, Config, LedgerError}; use blake2::Digest; use cryptarchia_engine::Slot; @@ -741,4 +741,29 @@ pub mod tests { Err(LedgerError::NullifierExists) )); } + + #[test] + fn test_conversions_for_leader_proof() { + + let commitment = Commitment::from([0u8; 32]); + let commitment_bytes: [u8; 32] = commitment.into(); + + let _zero_bytes = [0u8; 32]; + assert!(matches!(commitment_bytes, _zero_bytes)); + + let commitment_ref = commitment.as_ref(); + assert_eq!(commitment_ref, &_zero_bytes); + + let nullifier = Nullifier::from([0u8; 32]); + let _nullifier_bytes: [u8; 32] = nullifier.into(); + assert!(matches!(_nullifier_bytes, _zero_bytes)); + + let slot = Slot::genesis(); + let leader_proof = LeaderProof::dummy(slot); + + assert_eq!(leader_proof.commitment(), &commitment); + assert_eq!(leader_proof.evolved_commitment(), &commitment); + assert_eq!(leader_proof.nullifier(), &nullifier); + + } }