diff --git a/zebra-consensus/src/transaction/tests.rs b/zebra-consensus/src/transaction/tests.rs index 9e0b4c7ecc1..54d2f0d77c4 100644 --- a/zebra-consensus/src/transaction/tests.rs +++ b/zebra-consensus/src/transaction/tests.rs @@ -704,8 +704,42 @@ async fn v4_with_sapling_spends() { zebra_test::init(); zebra_test::RUNTIME.block_on(async { let network = Network::Mainnet; - let blocks = zebra_test::vectors::MAINNET_BLOCKS.iter(); + let (height, transaction) = test_transactions(network) + .rev() + .filter(|(_, transaction)| { + !transaction.is_coinbase() && transaction.inputs().is_empty() + }) + .find(|(_, transaction)| transaction.sapling_spends_per_anchor().next().is_some()) + .expect("No transaction found with Sapling spends"); + + let expected_hash = transaction.hash(); + + // Initialize the verifier + let state_service = + service_fn(|_| async { unreachable!("State service should not be called") }); + let script_verifier = script::Verifier::new(state_service); + let verifier = Verifier::new(network, script_verifier); + + // Test the transaction verifier + let result = verifier + .clone() + .oneshot(Request::Block { + transaction, + known_utxos: Arc::new(HashMap::new()), + height, + }) + .await; + + assert_eq!(result, Ok(expected_hash)); + }); +} + +/// Test if a V4 transaction with Sapling outputs but no spends is accepted by the verifier. +#[tokio::test] +async fn v4_with_sapling_outputs_and_no_spends() { + zebra_test::init(); + zebra_test::RUNTIME.block_on(async { let network = Network::Mainnet; let (height, transaction) = test_transactions(network) @@ -713,7 +747,10 @@ async fn v4_with_sapling_spends() { .filter(|(_, transaction)| { !transaction.is_coinbase() && transaction.inputs().is_empty() }) - .find(|(_, transaction)| transaction.sapling_spends_per_anchor().next().is_some()) + .find(|(_, transaction)| { + transaction.sapling_spends_per_anchor().next().is_none() + && transaction.sapling_outputs().next().is_some() + }) .expect("No transaction found with Sapling spends"); let expected_hash = transaction.hash();