use alloc::sync::Arc;
use std::collections::BTreeMap;
use anyhow::Context;
use miden_protocol::Word;
use miden_protocol::batch::ProposedBatch;
use miden_protocol::block::BlockNumber;
use miden_tx_batch::{BatchExecutor, LocalBatchProver};
use super::proposed_batch::{TestSetup, mock_note, mock_output_note, setup_chain};
use super::proven_tx_builder::MockProvenTxBuilder;
pub(super) fn two_tx_batch(setup: &mut TestSetup) -> anyhow::Result<ProposedBatch> {
let block1 = setup.chain.block_header(1);
let block2 = setup.chain.prove_next_block()?;
let tx1 = MockProvenTxBuilder::with_account(
setup.account1.id(),
Word::empty(),
setup.account1.to_commitment(),
)
.reference_block(&block1)
.authenticated_notes(vec![setup.note1.clone()])
.output_notes(vec![mock_output_note(80)])
.expiration_block_num(BlockNumber::from(1234u32))
.build()?;
let tx2_input = mock_note(81);
let tx2 = MockProvenTxBuilder::with_account(
setup.account2.id(),
Word::empty(),
setup.account2.to_commitment(),
)
.reference_block(&block1)
.unauthenticated_notes(vec![tx2_input])
.output_notes(vec![mock_output_note(82), mock_output_note(83)])
.expiration_block_num(BlockNumber::from(800u32))
.build()?;
Ok(ProposedBatch::new_unverified(
[tx1, tx2].into_iter().map(Arc::new).collect(),
block2.header().clone(),
setup.chain.latest_partial_blockchain(),
BTreeMap::default(),
)?)
}
#[test]
fn batch_kernel_skeleton_emits_empty_outputs() -> 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 output = executed.batch_outputs();
assert_eq!(output.input_notes_commitment(), Word::empty());
assert_eq!(output.batch_note_tree_root(), Word::empty());
assert_eq!(output.batch_expiration_block_num(), BlockNumber::from(0u32));
Ok(())
}
#[test]
fn batch_executor_then_prover_produces_proven_batch() -> anyhow::Result<()> {
let mut setup = setup_chain();
let batch = two_tx_batch(&mut setup)?;
let expected_id = batch.id();
let executed = BatchExecutor::new().execute(batch).context("batch execution failed")?;
let proven = LocalBatchProver::new().prove(executed).context("batch proving failed")?;
assert_eq!(proven.id(), expected_id);
Ok(())
}