use anyhow::Context;
use assert_matches::assert_matches;
use miden_tx_batch::{BatchExecutor, BatchVerifier, BatchVerifierError, LocalBatchProver};
use super::proposed_batch::setup_chain;
use super::test_batch_kernel::two_tx_batch;
#[test]
fn batch_verifier_accepts_freshly_proven_batch() -> anyhow::Result<()> {
let mut setup = setup_chain();
let batch = two_tx_batch(&mut setup)?;
let executed = BatchExecutor::new().execute(batch).context("batch execution failed")?;
let proven = LocalBatchProver::new().prove(executed).context("batch proving failed")?;
let security_level = proven.proof_security_level();
BatchVerifier::new(security_level)
.verify(&proven)
.context("verifying the proven batch should succeed")?;
let err = BatchVerifier::new(security_level + 1).verify(&proven).unwrap_err();
assert_matches!(err, BatchVerifierError::InsufficientProofSecurityLevel { .. });
Ok(())
}
#[test]
fn batch_verifier_rejects_dummy_proof() -> anyhow::Result<()> {
let mut setup = setup_chain();
let batch = two_tx_batch(&mut setup)?;
let proven = LocalBatchProver::new().prove_dummy(batch)?;
let err = BatchVerifier::new(0).verify(&proven).unwrap_err();
assert_matches!(err, BatchVerifierError::BatchVerificationFailed(_));
Ok(())
}