Skip to content

Commit

Permalink
Remove unneeded test for fake V5 txs
Browse files Browse the repository at this point in the history
We don't need this test anymore since we have real V5 txs now.
  • Loading branch information
upbqdn committed Dec 17, 2024
1 parent e1e0162 commit 7228929
Showing 1 changed file with 0 additions and 124 deletions.
124 changes: 0 additions & 124 deletions zebra-chain/src/transaction/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,130 +326,6 @@ fn empty_v5_librustzcash_round_trip() {
);
}

/// Do a round-trip test on fake v5 transactions created from v4 transactions
/// in the block test vectors.
///
/// Covers Sapling only, Transparent only, and Sapling/Transparent v5
/// transactions.
#[test]
fn fake_v5_round_trip() {
let _init_guard = zebra_test::init();
for network in Network::iter() {
fake_v5_round_trip_for_network(network);
}
}

fn fake_v5_round_trip_for_network(network: Network) {
let block_iter = network.block_iter();

let overwinter_activation_height = NetworkUpgrade::Overwinter
.activation_height(&network)
.expect("a valid height")
.0;

// skip blocks that are before overwinter as they will not have a valid consensus branch id
let blocks_after_overwinter =
block_iter.skip_while(|(height, _)| **height < overwinter_activation_height);

for (height, original_bytes) in blocks_after_overwinter {
let original_block = original_bytes
.zcash_deserialize_into::<Block>()
.expect("block is structurally valid");

// skip this block if it only contains v5 transactions,
// the block round-trip test covers it already
if original_block
.transactions
.iter()
.all(|trans| matches!(trans.as_ref(), &Transaction::V5 { .. }))
{
continue;
}

let mut fake_block = original_block.clone();
fake_block.transactions = fake_block
.transactions
.iter()
.map(AsRef::as_ref)
.map(|t| arbitrary::transaction_to_fake_v5(t, &network, Height(*height)))
.map(Into::into)
.collect();

// test each transaction
for (original_tx, fake_tx) in original_block
.transactions
.iter()
.zip(fake_block.transactions.iter())
{
assert_ne!(
&original_tx, &fake_tx,
"v1-v4 transactions must change when converted to fake v5"
);

let fake_bytes = fake_tx
.zcash_serialize_to_vec()
.expect("vec serialization is infallible");

assert_ne!(
&original_bytes[..],
fake_bytes,
"v1-v4 transaction data must change when converted to fake v5"
);

let fake_tx2 = fake_bytes
.zcash_deserialize_into::<Transaction>()
.expect("tx is structurally valid");

assert_eq!(fake_tx.as_ref(), &fake_tx2);

let fake_bytes2 = fake_tx2
.zcash_serialize_to_vec()
.expect("vec serialization is infallible");

assert_eq!(
fake_bytes, fake_bytes2,
"data must be equal if structs are equal"
);
}

// test full blocks
assert_ne!(
&original_block, &fake_block,
"v1-v4 transactions must change when converted to fake v5"
);

let fake_bytes = fake_block
.zcash_serialize_to_vec()
.expect("vec serialization is infallible");

assert_ne!(
&original_bytes[..],
fake_bytes,
"v1-v4 transaction data must change when converted to fake v5"
);

// skip fake blocks which exceed the block size limit
if fake_bytes.len() > MAX_BLOCK_BYTES.try_into().unwrap() {
continue;
}

let fake_block2 = fake_bytes
.zcash_deserialize_into::<Block>()
.expect("block is structurally valid");

assert_eq!(fake_block, fake_block2);

let fake_bytes2 = fake_block2
.zcash_serialize_to_vec()
.expect("vec serialization is infallible");

assert_eq!(
fake_bytes, fake_bytes2,
"data must be equal if structs are equal"
);
}
}

#[test]
fn invalid_orchard_nullifier() {
let _init_guard = zebra_test::init();
Expand Down

0 comments on commit 7228929

Please sign in to comment.