From 6d35583a4b7eff04c094a82a16be83a7e97727a1 Mon Sep 17 00:00:00 2001 From: Daira-Emma Hopwood Date: Sun, 16 Jun 2024 19:27:40 +0100 Subject: [PATCH] Add `OutPoint::fake()` helper. Signed-off-by: Daira-Emma Hopwood --- zcash_client_sqlite/src/testing/pool.rs | 2 +- zcash_client_sqlite/src/wallet.rs | 5 ++--- .../src/wallet/init/migrations/add_transaction_views.rs | 2 +- .../src/transaction/components/transparent.rs | 9 +++++++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/zcash_client_sqlite/src/testing/pool.rs b/zcash_client_sqlite/src/testing/pool.rs index 0ad9072e2..d3c43ac44 100644 --- a/zcash_client_sqlite/src/testing/pool.rs +++ b/zcash_client_sqlite/src/testing/pool.rs @@ -1206,7 +1206,7 @@ pub(crate) fn shield_transparent() { st.scan_cached_blocks(h, 1); let utxo = WalletTransparentOutput::from_parts( - OutPoint::new([1u8; 32], 1), + OutPoint::fake(), TxOut { value: NonNegativeAmount::const_from_u64(10000), script_pubkey: taddr.script(), diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index e8ed54159..dff1fd76c 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -2919,7 +2919,7 @@ mod tests { // Create a fake transparent output. let value = NonNegativeAmount::const_from_u64(100000); - let outpoint = OutPoint::new([1u8; 32], 1); + let outpoint = OutPoint::fake(); let txout = TxOut { value, script_pubkey: taddr.script(), @@ -3098,7 +3098,6 @@ mod tests { // Create a fake transparent output. let value = NonNegativeAmount::from_u64(100000).unwrap(); - let outpoint = OutPoint::new([1u8; 32], 1); let txout = TxOut { value, script_pubkey: taddr.script(), @@ -3106,7 +3105,7 @@ mod tests { // Pretend the output was received in the chain tip. let height = st.wallet().chain_height().unwrap().unwrap(); - let utxo = WalletTransparentOutput::from_parts(outpoint, txout, height).unwrap(); + let utxo = WalletTransparentOutput::from_parts(OutPoint::fake(), txout, height).unwrap(); st.wallet_mut() .put_received_transparent_utxo(&utxo) .unwrap(); diff --git a/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs b/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs index a84f99a05..b73c7af89 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs @@ -420,7 +420,7 @@ mod tests { BlockHeight::from(3), Some(transparent::Bundle { vin: vec![TxIn { - prevout: OutPoint::new([1u8; 32], 1), + prevout: OutPoint::fake(), script_sig: Script(vec![]), sequence: 0, }], diff --git a/zcash_primitives/src/transaction/components/transparent.rs b/zcash_primitives/src/transaction/components/transparent.rs index b7049fb3e..30ea80500 100644 --- a/zcash_primitives/src/transaction/components/transparent.rs +++ b/zcash_primitives/src/transaction/components/transparent.rs @@ -100,6 +100,15 @@ impl OutPoint { OutPoint { hash, n } } + /// Constructs a fake `OutPoint` for use in tests. + #[cfg(any(test, feature = "test-dependencies"))] + pub const fn fake() -> Self { + OutPoint { + hash: [1u8; 32], + n: 1, + } + } + pub fn read(mut reader: R) -> io::Result { let mut hash = [0u8; 32]; reader.read_exact(&mut hash)?;