diff --git a/Cargo.lock b/Cargo.lock index f2d9910..95493e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,6 +81,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" +[[package]] +name = "bitcoin-test-data" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c188654f9dce3bc6ce1bfa9c49777ad514bcad37e421b5f53e9d0ee10603f34" + [[package]] name = "bitcoin_hashes" version = "0.12.0" @@ -348,6 +354,7 @@ version = "0.10.0" dependencies = [ "anyhow", "bitcoin", + "bitcoin-test-data", "bitcoin_slices", "bitcoincore-rpc", "configure_me", diff --git a/Cargo.toml b/Cargo.toml index 031178e..ccb74b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,5 +51,6 @@ features = ["zstd", "snappy"] configure_me_codegen = { version = "0.4.4", default-features = false } [dev-dependencies] +bitcoin-test-data = "0.2.0" hex_lit = "0.1.1" tempfile = "3.5" diff --git a/src/status.rs b/src/status.rs index 8d4a8fe..c6429ae 100644 --- a/src/status.rs +++ b/src/status.rs @@ -572,8 +572,13 @@ fn filter_block_txs_inputs( #[cfg(test)] mod tests { + use std::str::FromStr; + + use crate::types::ScriptHash; + use super::HistoryEntry; - use bitcoin::Amount; + use bitcoin::{Address, Amount}; + use bitcoin_test_data::blocks::mainnet_702861; use serde_json::json; #[test] @@ -598,4 +603,25 @@ mod tests { json!({"tx_hash": "5b75086dafeede555fc8f9a810d8b10df57c46f9f176ccc3dd8d2fa20edd685b", "height": 0, "fee": 123}) ); } + + #[test] + fn test_find_outputs() { + let block = mainnet_702861().to_vec(); + + let addr = Address::from_str("1A9MXXG26vZVySrNNytQK1N8bX42ZuJ6Ax") + .unwrap() + .assume_checked(); + let scripthash = ScriptHash::new(&addr.script_pubkey()); + + let result = super::filter_block_txs_outputs(block, scripthash) + .next() + .unwrap(); + assert_eq!( + result.txid.to_string(), + "7bcdcb44422da5a99daad47d6ba1c3d6f2e48f961a75e42c4fa75029d4b0ef49" + ); + assert_eq!(result.pos, 8); + assert_eq!(result.result[0].index, 0); + assert_eq!(result.result[0].value.to_sat(), 709503); + } }