From 72935a0f6e0abed3d16b83681328c04538e9593a Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Wed, 12 Jan 2022 14:22:45 +1100 Subject: [PATCH 1/4] Move test_data/* tests/data In preparation for adding integration tests in the standard Rust `tests/` directroy; move the contents of `test_data` to `tests/data`. --- bitcoin/Cargo.toml | 2 +- bitcoin/src/bip158.rs | 2 +- bitcoin/src/blockdata/block.rs | 10 +++++----- bitcoin/src/network/message.rs | 2 +- bitcoin/src/sighash.rs | 4 ++-- bitcoin/src/util/hash.rs | 2 +- bitcoin/src/util/psbt/mod.rs | 10 +++++----- bitcoin/src/util/taproot.rs | 2 +- bitcoin/{test_data => tests/data}/bip341_tests.json | 0 bitcoin/{test_data => tests/data}/blockfilters.json | 0 .../{test_data => tests/data}/legacy_sighash.json | 0 ...0c835b2adcaedc20fdf6ee440009c249452c726dafae.raw | Bin bitcoin/{test_data => tests/data}/psbt1.hex | 0 bitcoin/{test_data => tests/data}/psbt2.hex | 0 bitcoin/{test_data => tests/data}/psbt_combined.hex | 0 ...60b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw | Bin 16 files changed, 17 insertions(+), 17 deletions(-) rename bitcoin/{test_data => tests/data}/bip341_tests.json (100%) rename bitcoin/{test_data => tests/data}/blockfilters.json (100%) rename bitcoin/{test_data => tests/data}/legacy_sighash.json (100%) rename bitcoin/{test_data => tests/data}/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw (100%) rename bitcoin/{test_data => tests/data}/psbt1.hex (100%) rename bitcoin/{test_data => tests/data}/psbt2.hex (100%) rename bitcoin/{test_data => tests/data}/psbt_combined.hex (100%) rename bitcoin/{test_data => tests/data}/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw (100%) diff --git a/bitcoin/Cargo.toml b/bitcoin/Cargo.toml index 3ebe7dad..adbfe092 100644 --- a/bitcoin/Cargo.toml +++ b/bitcoin/Cargo.toml @@ -9,7 +9,7 @@ documentation = "https://docs.rs/bitcoin/" description = "General purpose library for using and interoperating with Bitcoin and other cryptocurrencies." keywords = [ "crypto", "bitcoin" ] readme = "README.md" -exclude = ["test_data/"] +exclude = ["tests/"] edition = "2018" # Please don't forget to add relevant features to docs.rs below diff --git a/bitcoin/src/bip158.rs b/bitcoin/src/bip158.rs index 7692d5a2..9e7bacff 100644 --- a/bitcoin/src/bip158.rs +++ b/bitcoin/src/bip158.rs @@ -564,7 +564,7 @@ mod test { #[test] fn test_blockfilters() { // test vectors from: https://github.com/jimpo/bitcoin/blob/c7efb652f3543b001b4dd22186a354605b14f47e/src/test/data/blockfilters.json - let data = include_str!("../test_data/blockfilters.json"); + let data = include_str!("../tests/data/blockfilters.json"); let testdata = serde_json::from_str::(data).unwrap().as_array().unwrap().clone(); for t in testdata.iter().skip(1) { diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs index 1fa7bc1b..9ab112a8 100644 --- a/bitcoin/src/blockdata/block.rs +++ b/bitcoin/src/blockdata/block.rs @@ -460,7 +460,7 @@ mod tests { // Check testnet block 000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b #[test] fn segwit_block_test() { - let segwit_block = include_bytes!("../../test_data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw").to_vec(); + let segwit_block = include_bytes!("../../tests/data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw").to_vec(); let decode: Result = deserialize(&segwit_block); @@ -564,7 +564,7 @@ mod benches { #[bench] pub fn bench_stream_reader(bh: &mut Bencher) { - let big_block = include_bytes!("../../test_data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw"); + let big_block = include_bytes!("../../tests/data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw"); assert_eq!(big_block.len(), 1_381_836); let big_block = black_box(big_block); @@ -577,7 +577,7 @@ mod benches { #[bench] pub fn bench_block_serialize(bh: &mut Bencher) { - let raw_block = include_bytes!("../../test_data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw"); + let raw_block = include_bytes!("../../tests/data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw"); let block: Block = deserialize(&raw_block[..]).unwrap(); @@ -592,7 +592,7 @@ mod benches { #[bench] pub fn bench_block_serialize_logic(bh: &mut Bencher) { - let raw_block = include_bytes!("../../test_data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw"); + let raw_block = include_bytes!("../../tests/data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw"); let block: Block = deserialize(&raw_block[..]).unwrap(); @@ -604,7 +604,7 @@ mod benches { #[bench] pub fn bench_block_deserialize(bh: &mut Bencher) { - let raw_block = include_bytes!("../../test_data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw"); + let raw_block = include_bytes!("../../tests/data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw"); bh.iter(|| { let block: Block = deserialize(&raw_block[..]).unwrap(); diff --git a/bitcoin/src/network/message.rs b/bitcoin/src/network/message.rs index 5e1b0ee1..6de93622 100644 --- a/bitcoin/src/network/message.rs +++ b/bitcoin/src/network/message.rs @@ -497,7 +497,7 @@ mod test { // TODO: Impl Rand traits here to easily generate random values. let version_msg: VersionMessage = deserialize(&Vec::from_hex("721101000100000000000000e6e0845300000000010000000000000000000000000000000000ffff0000000000000100000000000000fd87d87eeb4364f22cf54dca59412db7208d47d920cffce83ee8102f5361746f7368693a302e392e39392f2c9f040001").unwrap()).unwrap(); let tx: Transaction = deserialize(&Vec::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap()).unwrap(); - let block: Block = deserialize(&include_bytes!("../../test_data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw")[..]).unwrap(); + let block: Block = deserialize(&include_bytes!("../../tests/data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw")[..]).unwrap(); let header: BlockHeader = deserialize(&Vec::from_hex("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b").unwrap()).unwrap(); let script: Script = deserialize(&Vec::from_hex("1976a91431a420903c05a0a7de2de40c9f02ebedbacdc17288ac").unwrap()).unwrap(); let merkle_block: MerkleBlock = deserialize(&Vec::from_hex("0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b4b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f196367291b4d4c86041b8fa45d630100000001b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f19630101").unwrap()).unwrap(); diff --git a/bitcoin/src/sighash.rs b/bitcoin/src/sighash.rs index 3b3fe380..582e2811 100644 --- a/bitcoin/src/sighash.rs +++ b/bitcoin/src/sighash.rs @@ -1127,7 +1127,7 @@ mod tests { // These test vectors were stolen from libbtc, which is Copyright 2014 Jonas Schnelli MIT // They were transformed by replacing {...} with run_test_sighash(...), then the ones containing // OP_CODESEPARATOR in their pubkeys were removed - let data = include_str!("../test_data/legacy_sighash.json"); + let data = include_str!("../tests/data/legacy_sighash.json"); let testdata = serde_json::from_str::(data).unwrap().as_array().unwrap().clone(); for t in testdata.iter().skip(1) { @@ -1479,7 +1479,7 @@ mod tests { } fn bip_341_read_json() -> serde_json::Value { - let json_str = include_str!("../test_data/bip341_tests.json"); + let json_str = include_str!("../tests/data/bip341_tests.json"); serde_json::from_str(json_str).expect("JSON was not well-formatted") } diff --git a/bitcoin/src/util/hash.rs b/bitcoin/src/util/hash.rs index 3f492e4d..79f75c77 100644 --- a/bitcoin/src/util/hash.rs +++ b/bitcoin/src/util/hash.rs @@ -108,7 +108,7 @@ mod tests { #[test] fn both_merkle_root_functions_return_the_same_result() { // testnet block 000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b - let segwit_block = include_bytes!("../../test_data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw"); + let segwit_block = include_bytes!("../../tests/data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw"); let block: Block = deserialize(&segwit_block[..]).expect("Failed to deserialize block"); assert!(block.check_merkle_root()); // Sanity check. diff --git a/bitcoin/src/util/psbt/mod.rs b/bitcoin/src/util/psbt/mod.rs index b103968f..304e641d 100644 --- a/bitcoin/src/util/psbt/mod.rs +++ b/bitcoin/src/util/psbt/mod.rs @@ -1664,9 +1664,9 @@ mod tests { // PSBTs taken from BIP 174 test vectors. #[test] fn combine_psbts() { - let mut psbt1 = hex_psbt!(include_str!("../../../test_data/psbt1.hex")).unwrap(); - let psbt2 = hex_psbt!(include_str!("../../../test_data/psbt2.hex")).unwrap(); - let psbt_combined = hex_psbt!(include_str!("../../../test_data/psbt2.hex")).unwrap(); + let mut psbt1 = hex_psbt!(include_str!("../../../tests/data/psbt1.hex")).unwrap(); + let psbt2 = hex_psbt!(include_str!("../../../tests/data/psbt2.hex")).unwrap(); + let psbt_combined = hex_psbt!(include_str!("../../../tests/data/psbt2.hex")).unwrap(); psbt1.combine(psbt2).expect("psbt combine to succeed"); assert_eq!(psbt1, psbt_combined); @@ -1674,8 +1674,8 @@ mod tests { #[test] fn combine_psbts_commutative() { - let mut psbt1 = hex_psbt!(include_str!("../../../test_data/psbt1.hex")).unwrap(); - let mut psbt2 = hex_psbt!(include_str!("../../../test_data/psbt2.hex")).unwrap(); + let mut psbt1 = hex_psbt!(include_str!("../../../tests/data/psbt1.hex")).unwrap(); + let mut psbt2 = hex_psbt!(include_str!("../../../tests/data/psbt2.hex")).unwrap(); let psbt1_clone = psbt1.clone(); let psbt2_clone = psbt2.clone(); diff --git a/bitcoin/src/util/taproot.rs b/bitcoin/src/util/taproot.rs index c41f9883..096c71e9 100644 --- a/bitcoin/src/util/taproot.rs +++ b/bitcoin/src/util/taproot.rs @@ -1438,7 +1438,7 @@ mod test { } fn bip_341_read_json() -> serde_json::Value { - let json_str = include_str!("../../test_data/bip341_tests.json"); + let json_str = include_str!("../../tests/data/bip341_tests.json"); serde_json::from_str(json_str).expect("JSON was not well-formatted") } } diff --git a/bitcoin/test_data/bip341_tests.json b/bitcoin/tests/data/bip341_tests.json similarity index 100% rename from bitcoin/test_data/bip341_tests.json rename to bitcoin/tests/data/bip341_tests.json diff --git a/bitcoin/test_data/blockfilters.json b/bitcoin/tests/data/blockfilters.json similarity index 100% rename from bitcoin/test_data/blockfilters.json rename to bitcoin/tests/data/blockfilters.json diff --git a/bitcoin/test_data/legacy_sighash.json b/bitcoin/tests/data/legacy_sighash.json similarity index 100% rename from bitcoin/test_data/legacy_sighash.json rename to bitcoin/tests/data/legacy_sighash.json diff --git a/bitcoin/test_data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw b/bitcoin/tests/data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw similarity index 100% rename from bitcoin/test_data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw rename to bitcoin/tests/data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw diff --git a/bitcoin/test_data/psbt1.hex b/bitcoin/tests/data/psbt1.hex similarity index 100% rename from bitcoin/test_data/psbt1.hex rename to bitcoin/tests/data/psbt1.hex diff --git a/bitcoin/test_data/psbt2.hex b/bitcoin/tests/data/psbt2.hex similarity index 100% rename from bitcoin/test_data/psbt2.hex rename to bitcoin/tests/data/psbt2.hex diff --git a/bitcoin/test_data/psbt_combined.hex b/bitcoin/tests/data/psbt_combined.hex similarity index 100% rename from bitcoin/test_data/psbt_combined.hex rename to bitcoin/tests/data/psbt_combined.hex diff --git a/bitcoin/test_data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw b/bitcoin/tests/data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw similarity index 100% rename from bitcoin/test_data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw rename to bitcoin/tests/data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw From 6b6ef528a42df1d5868be1e1d7db5d5321cb43dc Mon Sep 17 00:00:00 2001 From: DanGould Date: Thu, 30 Jun 2022 13:01:50 +0800 Subject: [PATCH 2/4] Add OP_0 alias for OP_PUSHBYTES_0 --- bitcoin/src/blockdata/opcodes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bitcoin/src/blockdata/opcodes.rs b/bitcoin/src/blockdata/opcodes.rs index 7b37d663..c5605aec 100644 --- a/bitcoin/src/blockdata/opcodes.rs +++ b/bitcoin/src/blockdata/opcodes.rs @@ -755,6 +755,8 @@ impl serde::Serialize for All { } } +/// Push an empty array onto the stack. +pub static OP_0: All = OP_PUSHBYTES_0; /// Empty stack is also FALSE. pub static OP_FALSE: All = OP_PUSHBYTES_0; /// Number 1 is also TRUE. From 16bf6f68dd95d5cd21e756d937417dfe9fc6e96d Mon Sep 17 00:00:00 2001 From: DanGould Date: Sun, 28 Aug 2022 14:36:52 -0400 Subject: [PATCH 3/4] Test PSBT integration Implement Test Vectors from BIP 174 Co-authored-by: Tobin Harding Co-authored-by: Armin Sabouri --- bitcoin/tests/data/README.md | 4 + bitcoin/tests/data/combine_psbt_hex | 1 + bitcoin/tests/data/create_psbt_hex | 1 + bitcoin/tests/data/extract_tx_hex | 1 + bitcoin/tests/data/finalize_psbt_hex | 1 + bitcoin/tests/data/lex_combine_psbt_hex | 1 + bitcoin/tests/data/lex_psbt_1_hex | 1 + bitcoin/tests/data/lex_psbt_2_hex | 1 + bitcoin/tests/data/previous_tx_0_hex | 1 + bitcoin/tests/data/previous_tx_1_hex | 1 + bitcoin/tests/data/sign_1_psbt_hex | 1 + bitcoin/tests/data/sign_2_psbt_hex | 1 + bitcoin/tests/data/update_1_psbt_hex | 1 + bitcoin/tests/data/update_2_psbt_hex | 1 + bitcoin/tests/psbt.rs | 466 ++++++++++++++++++++++++ 15 files changed, 483 insertions(+) create mode 100644 bitcoin/tests/data/README.md create mode 100644 bitcoin/tests/data/combine_psbt_hex create mode 100644 bitcoin/tests/data/create_psbt_hex create mode 100644 bitcoin/tests/data/extract_tx_hex create mode 100644 bitcoin/tests/data/finalize_psbt_hex create mode 100644 bitcoin/tests/data/lex_combine_psbt_hex create mode 100644 bitcoin/tests/data/lex_psbt_1_hex create mode 100644 bitcoin/tests/data/lex_psbt_2_hex create mode 100644 bitcoin/tests/data/previous_tx_0_hex create mode 100644 bitcoin/tests/data/previous_tx_1_hex create mode 100644 bitcoin/tests/data/sign_1_psbt_hex create mode 100644 bitcoin/tests/data/sign_2_psbt_hex create mode 100644 bitcoin/tests/data/update_1_psbt_hex create mode 100644 bitcoin/tests/data/update_2_psbt_hex create mode 100644 bitcoin/tests/psbt.rs diff --git a/bitcoin/tests/data/README.md b/bitcoin/tests/data/README.md new file mode 100644 index 00000000..70ed7a4e --- /dev/null +++ b/bitcoin/tests/data/README.md @@ -0,0 +1,4 @@ +Test vector data +================ + +This file contains data (hex strings) taken from BIP test vectors. diff --git a/bitcoin/tests/data/combine_psbt_hex b/bitcoin/tests/data/combine_psbt_hex new file mode 100644 index 00000000..47f38701 --- /dev/null +++ b/bitcoin/tests/data/combine_psbt_hex @@ -0,0 +1 @@ +70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000002202029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01220202dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d7483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01010304010000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e887220203089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f012202023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e73473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d2010103040100000001042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000 \ No newline at end of file diff --git a/bitcoin/tests/data/create_psbt_hex b/bitcoin/tests/data/create_psbt_hex new file mode 100644 index 00000000..b5ef8d5e --- /dev/null +++ b/bitcoin/tests/data/create_psbt_hex @@ -0,0 +1 @@ +70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000000000000000000 \ No newline at end of file diff --git a/bitcoin/tests/data/extract_tx_hex b/bitcoin/tests/data/extract_tx_hex new file mode 100644 index 00000000..41c22961 --- /dev/null +++ b/bitcoin/tests/data/extract_tx_hex @@ -0,0 +1 @@ +0200000000010258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7500000000da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752aeffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d01000000232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00000000 \ No newline at end of file diff --git a/bitcoin/tests/data/finalize_psbt_hex b/bitcoin/tests/data/finalize_psbt_hex new file mode 100644 index 00000000..2866b82b --- /dev/null +++ b/bitcoin/tests/data/finalize_psbt_hex @@ -0,0 +1 @@ +70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000107da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae0001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8870107232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b20289030108da0400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000 \ No newline at end of file diff --git a/bitcoin/tests/data/lex_combine_psbt_hex b/bitcoin/tests/data/lex_combine_psbt_hex new file mode 100644 index 00000000..9ee710b6 --- /dev/null +++ b/bitcoin/tests/data/lex_combine_psbt_hex @@ -0,0 +1 @@ +70736274ff01003f0200000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000ffffffff010000000000000000036a0100000000000af00102030405060708090f0102030405060708090a0b0c0d0e0f0af00102030405060708100f0102030405060708090a0b0c0d0e0f000af00102030405060708090f0102030405060708090a0b0c0d0e0f0af00102030405060708100f0102030405060708090a0b0c0d0e0f000af00102030405060708090f0102030405060708090a0b0c0d0e0f0af00102030405060708100f0102030405060708090a0b0c0d0e0f00 \ No newline at end of file diff --git a/bitcoin/tests/data/lex_psbt_1_hex b/bitcoin/tests/data/lex_psbt_1_hex new file mode 100644 index 00000000..a125c529 --- /dev/null +++ b/bitcoin/tests/data/lex_psbt_1_hex @@ -0,0 +1 @@ +70736274ff01003f0200000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000ffffffff010000000000000000036a0100000000000af00102030405060708090f0102030405060708090a0b0c0d0e0f000af00102030405060708090f0102030405060708090a0b0c0d0e0f000af00102030405060708090f0102030405060708090a0b0c0d0e0f00 \ No newline at end of file diff --git a/bitcoin/tests/data/lex_psbt_2_hex b/bitcoin/tests/data/lex_psbt_2_hex new file mode 100644 index 00000000..766c7eee --- /dev/null +++ b/bitcoin/tests/data/lex_psbt_2_hex @@ -0,0 +1 @@ +70736274ff01003f0200000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000ffffffff010000000000000000036a0100000000000af00102030405060708100f0102030405060708090a0b0c0d0e0f000af00102030405060708100f0102030405060708090a0b0c0d0e0f000af00102030405060708100f0102030405060708090a0b0c0d0e0f00 \ No newline at end of file diff --git a/bitcoin/tests/data/previous_tx_0_hex b/bitcoin/tests/data/previous_tx_0_hex new file mode 100644 index 00000000..ce208945 --- /dev/null +++ b/bitcoin/tests/data/previous_tx_0_hex @@ -0,0 +1 @@ +0200000000010158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88702483045022100a22edcc6e5bc511af4cc4ae0de0fcd75c7e04d8c1c3a8aa9d820ed4b967384ec02200642963597b9b1bc22c75e9f3e117284a962188bf5e8a74c895089046a20ad770121035509a48eb623e10aace8bfd0212fdb8a8e5af3c94b0b133b95e114cab89e4f7965000000 \ No newline at end of file diff --git a/bitcoin/tests/data/previous_tx_1_hex b/bitcoin/tests/data/previous_tx_1_hex new file mode 100644 index 00000000..9297523e --- /dev/null +++ b/bitcoin/tests/data/previous_tx_1_hex @@ -0,0 +1 @@ +0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000 \ No newline at end of file diff --git a/bitcoin/tests/data/sign_1_psbt_hex b/bitcoin/tests/data/sign_1_psbt_hex new file mode 100644 index 00000000..3bcb9179 --- /dev/null +++ b/bitcoin/tests/data/sign_1_psbt_hex @@ -0,0 +1 @@ +70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000002202029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01010304010000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e887220203089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f010103040100000001042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000 \ No newline at end of file diff --git a/bitcoin/tests/data/sign_2_psbt_hex b/bitcoin/tests/data/sign_2_psbt_hex new file mode 100644 index 00000000..70231338 --- /dev/null +++ b/bitcoin/tests/data/sign_2_psbt_hex @@ -0,0 +1 @@ +70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000220202dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d7483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01010304010000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8872202023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e73473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d2010103040100000001042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000 \ No newline at end of file diff --git a/bitcoin/tests/data/update_1_psbt_hex b/bitcoin/tests/data/update_1_psbt_hex new file mode 100644 index 00000000..705d70d0 --- /dev/null +++ b/bitcoin/tests/data/update_1_psbt_hex @@ -0,0 +1 @@ +70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88701042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000 \ No newline at end of file diff --git a/bitcoin/tests/data/update_2_psbt_hex b/bitcoin/tests/data/update_2_psbt_hex new file mode 100644 index 00000000..31fbd54f --- /dev/null +++ b/bitcoin/tests/data/update_2_psbt_hex @@ -0,0 +1 @@ +70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000010304010000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8870103040100000001042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000 \ No newline at end of file diff --git a/bitcoin/tests/psbt.rs b/bitcoin/tests/psbt.rs new file mode 100644 index 00000000..9844cd00 --- /dev/null +++ b/bitcoin/tests/psbt.rs @@ -0,0 +1,466 @@ +//! Tests PSBT integration vectors from BIP 174 +//! defined at + +use std::collections::BTreeMap; +use std::str::FromStr; + +use bitcoin::bip32::{ExtendedPrivKey, ExtendedPubKey, Fingerprint, IntoDerivationPath, KeySource}; +use bitcoin::blockdata::opcodes::OP_0; +use bitcoin::blockdata::script; +use bitcoin::consensus::encode::{deserialize, serialize_hex}; +use bitcoin::hashes::hex::FromHex; +use bitcoin::psbt::{Psbt, PsbtSighashType}; +use bitcoin::secp256k1::{self, Secp256k1}; +use bitcoin::{ + absolute, Amount, Denomination, Network, OutPoint, PrivateKey, PublicKey, Script, Sequence, + Transaction, TxIn, TxOut, Txid, Witness, +}; + +const NETWORK: Network = Network::Testnet; + +macro_rules! hex_script { + ($s:expr) => { +