Skip to content

Commit

Permalink
Test V4 tx. with Sapling outputs but no spends
Browse files Browse the repository at this point in the history
Find a transaction V4 vector that has Sapling outputs but no spends, and
check that the verifier accepts it.
  • Loading branch information
jvff committed Jul 1, 2021
1 parent 69c655c commit 0f0d40f
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions zebra-consensus/src/transaction/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,16 +704,53 @@ 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)
.rev()
.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();
Expand Down

0 comments on commit 0f0d40f

Please sign in to comment.