chain: add transaction hash test.

This commit is contained in:
Henry de Valence 2020-09-04 13:37:43 -07:00 committed by Deirdre Connolly
parent ca4a5ce30c
commit 2a50298b2e
2 changed files with 15 additions and 4 deletions

View File

@ -9,10 +9,7 @@ use crate::serialization::{sha256d, SerializationError, ZcashSerialize};
use super::Transaction;
/// A hash of a `Transaction`
///
/// TODO: I'm pretty sure this is also a SHA256d hash but I haven't
/// confirmed it yet.
/// A transaction hash.
#[derive(Copy, Clone, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[cfg_attr(test, derive(Arbitrary))]
pub struct Hash(pub [u8; 32]);

View File

@ -13,6 +13,20 @@ fn librustzcash_tx_deserialize_and_round_trip() {
assert_eq!(&zebra_test::vectors::GENERIC_TESTNET_TX[..], &data2[..]);
}
#[test]
fn librustzcash_tx_hash() {
let tx = Transaction::zcash_deserialize(&zebra_test::vectors::GENERIC_TESTNET_TX[..])
.expect("transaction test vector from librustzcash should deserialize");
// TxID taken from comment in zebra_test::vectors
let hash = tx.hash();
let expected = "3956b54c11736f4ac5e2c474029cba8f5b83dca2e38f355337e20ce37fbdf064"
.parse::<Hash>()
.expect("hash should parse correctly");
assert_eq!(hash, expected);
}
#[test]
fn zip143_deserialize_and_round_trip() {
let tx1 = Transaction::zcash_deserialize(&zebra_test::vectors::ZIP143_1[..])