Add test for BlockHeaderHash::from(BlockHeader)
This commit is contained in:
parent
29e1be2442
commit
69164a6943
|
|
@ -184,12 +184,13 @@ impl ZcashDeserialize for Block {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use super::BlockHeaderHash;
|
|
||||||
|
|
||||||
use crate::sha256d_writer::Sha256dWriter;
|
use crate::sha256d_writer::Sha256dWriter;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn blockheaderhash_debug() {
|
fn blockheaderhash_debug() {
|
||||||
let preimage = b"foo bar baz";
|
let preimage = b"foo bar baz";
|
||||||
|
|
@ -203,4 +204,26 @@ mod tests {
|
||||||
"BlockHeaderHash(\"bf46b4b5030752fedac6f884976162bbfb29a9398f104a280b3e34d51b416631\")"
|
"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\")"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,8 +121,6 @@ fn librustzcash_tx_deserialize_and_round_trip() {
|
||||||
let tx = Transaction::zcash_deserialize(&test_vectors::GENERIC_TESTNET_TX[..])
|
let tx = Transaction::zcash_deserialize(&test_vectors::GENERIC_TESTNET_TX[..])
|
||||||
.expect("transaction test vector from librustzcash should deserialize");
|
.expect("transaction test vector from librustzcash should deserialize");
|
||||||
|
|
||||||
println!("{:?}", tx);
|
|
||||||
|
|
||||||
let mut data2 = Vec::new();
|
let mut data2 = Vec::new();
|
||||||
tx.zcash_serialize(&mut data2).expect("tx should serialize");
|
tx.zcash_serialize(&mut data2).expect("tx should serialize");
|
||||||
|
|
||||||
|
|
@ -135,16 +133,12 @@ proptest! {
|
||||||
#[test]
|
#[test]
|
||||||
fn transaction_roundtrip(tx in any::<Transaction>()) {
|
fn transaction_roundtrip(tx in any::<Transaction>()) {
|
||||||
|
|
||||||
println!("{:?}", tx);
|
|
||||||
|
|
||||||
let mut data = Vec::new();
|
let mut data = Vec::new();
|
||||||
|
|
||||||
tx.zcash_serialize(&mut data).expect("tx should serialize");
|
tx.zcash_serialize(&mut data).expect("tx should serialize");
|
||||||
|
|
||||||
let tx2 = Transaction::zcash_deserialize(&data[..]).expect("randomized tx should deserialize");
|
let tx2 = Transaction::zcash_deserialize(&data[..]).expect("randomized tx should deserialize");
|
||||||
|
|
||||||
println!("{:?}", tx2);
|
|
||||||
|
|
||||||
prop_assert_eq![tx, tx2];
|
prop_assert_eq![tx, tx2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue