Skip to content

Commit

Permalink
Use new helper function in V4 Sapling spend test
Browse files Browse the repository at this point in the history
Also use the block height for that transaction as specified in the test
vector.
  • Loading branch information
jvff committed Jul 1, 2021
1 parent fedb87a commit 69c655c
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions zebra-consensus/src/transaction/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use zebra_chain::{
block, orchard,
parameters::{Network, NetworkUpgrade},
primitives::{ed25519, x25519, Groth16Proof},
serialization::{ZcashDeserialize, ZcashDeserializeInto},
serialization::ZcashDeserialize,
sprout,
transaction::{
arbitrary::{fake_v5_transactions_for_network, insert_fake_orchard_shielded_data},
arbitrary::{
fake_v5_transactions_for_network, insert_fake_orchard_shielded_data, test_transactions,
},
Hash, HashType, JoinSplitData, LockTime, Transaction,
},
transparent::{self, CoinbaseData},
Expand Down Expand Up @@ -704,30 +706,18 @@ async fn v4_with_sapling_spends() {
let network = Network::Mainnet;
let blocks = zebra_test::vectors::MAINNET_BLOCKS.iter();

let transactions = blocks.flat_map(|(_, block_bytes)| {
let block = block_bytes
.zcash_deserialize_into::<block::Block>()
.expect("block is structurally valid");

block.transactions
});
let network = Network::Mainnet;

let transaction = transactions
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())
.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();

// Mock a block height after Canopy activation
let canopy_activation_height = NetworkUpgrade::Canopy
.activation_height(network)
.expect("Canopy activation height is not set");

let transaction_block_height =
(canopy_activation_height + 10).expect("Canopy activation height is too large");

// Initialize the verifier
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
Expand All @@ -740,7 +730,7 @@ async fn v4_with_sapling_spends() {
.oneshot(Request::Block {
transaction,
known_utxos: Arc::new(HashMap::new()),
height: transaction_block_height,
height,
})
.await;

Expand Down

0 comments on commit 69c655c

Please sign in to comment.