Add test for BlockHeaderHash::from(BlockHeader)

This commit is contained in:
Deirdre Connolly 2020-01-31 21:02:43 -05:00 committed by Deirdre Connolly
parent 29e1be2442
commit 69164a6943
2 changed files with 25 additions and 8 deletions

View File

@ -184,12 +184,13 @@ impl ZcashDeserialize for Block {
#[cfg(test)]
mod tests {
use chrono::NaiveDateTime;
use std::io::Write;
use super::BlockHeaderHash;
use crate::sha256d_writer::Sha256dWriter;
use super::*;
#[test]
fn blockheaderhash_debug() {
let preimage = b"foo bar baz";
@ -203,4 +204,26 @@ mod tests {
"BlockHeaderHash(\"bf46b4b5030752fedac6f884976162bbfb29a9398f104a280b3e34d51b416631\")"
);
}
#[test]
fn blockheaderhash_from_blockheader() {
let some_bytes = [0; 32];
let blockheader = BlockHeader {
previous_block_hash: BlockHeaderHash(some_bytes),
merkle_root_hash: MerkleTreeRootHash(some_bytes),
final_sapling_root_hash: SaplingNoteTreeRootHash(some_bytes),
time: DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(61, 0), Utc),
bits: 0,
nonce: some_bytes,
solution: vec![0; 1344],
};
let hash = BlockHeaderHash::from(blockheader);
assert_eq!(
format!("{:?}", hash),
"BlockHeaderHash(\"35be4a0f97803879ed642d4e10a146c3fba8727a1dca8079e3f107221be1e7e4\")"
);
}
}

View File

@ -121,8 +121,6 @@ fn librustzcash_tx_deserialize_and_round_trip() {
let tx = Transaction::zcash_deserialize(&test_vectors::GENERIC_TESTNET_TX[..])
.expect("transaction test vector from librustzcash should deserialize");
println!("{:?}", tx);
let mut data2 = Vec::new();
tx.zcash_serialize(&mut data2).expect("tx should serialize");
@ -135,16 +133,12 @@ proptest! {
#[test]
fn transaction_roundtrip(tx in any::<Transaction>()) {
println!("{:?}", tx);
let mut data = Vec::new();
tx.zcash_serialize(&mut data).expect("tx should serialize");
let tx2 = Transaction::zcash_deserialize(&data[..]).expect("randomized tx should deserialize");
println!("{:?}", tx2);
prop_assert_eq![tx, tx2];
}
}