|
1 | | -#![allow(unused)] |
2 | | -use bdk_chain::{tx_graph, BlockId, ChainPosition, ConfirmationBlockTime, TxGraph}; |
3 | | -use bdk_wallet::{CreateParams, KeychainKind, LocalOutput, Update, Wallet}; |
| 1 | +//! `bdk_wallet` test utilities |
| 2 | +
|
| 3 | +use alloc::string::ToString; |
| 4 | +use core::str::FromStr; |
| 5 | + |
| 6 | +use bdk_chain::{tx_graph, BlockId, ConfirmationBlockTime}; |
4 | 7 | use bitcoin::{ |
5 | 8 | hashes::Hash, transaction, Address, Amount, BlockHash, FeeRate, Network, OutPoint, Transaction, |
6 | 9 | TxIn, TxOut, Txid, |
7 | 10 | }; |
8 | | -use std::str::FromStr; |
| 11 | + |
| 12 | +use crate::{KeychainKind, Update, Wallet}; |
9 | 13 |
|
10 | 14 | /// Return a fake wallet that appears to be funded for testing. |
11 | 15 | /// |
@@ -128,69 +132,81 @@ pub fn get_funded_wallet(descriptor: &str) -> (Wallet, bitcoin::Txid) { |
128 | 132 | get_funded_wallet_with_change(descriptor, change) |
129 | 133 | } |
130 | 134 |
|
| 135 | +/// Get funded segwit wallet |
131 | 136 | pub fn get_funded_wallet_wpkh() -> (Wallet, bitcoin::Txid) { |
132 | 137 | get_funded_wallet_with_change(get_test_wpkh(), get_test_wpkh_change()) |
133 | 138 | } |
134 | 139 |
|
| 140 | +/// `wpkh` single key descriptor |
135 | 141 | pub fn get_test_wpkh() -> &'static str { |
136 | 142 | "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)" |
137 | 143 | } |
138 | 144 |
|
| 145 | +/// `wpkh` descriptor and change descriptor |
139 | 146 | pub fn get_test_wpkh_with_change_desc() -> (&'static str, &'static str) { |
140 | 147 | ( |
141 | 148 | "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)", |
142 | 149 | get_test_wpkh_change(), |
143 | 150 | ) |
144 | 151 | } |
145 | 152 |
|
| 153 | +/// `wpkh` change descriptor |
146 | 154 | fn get_test_wpkh_change() -> &'static str { |
147 | 155 | "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/1/0)" |
148 | 156 | } |
149 | 157 |
|
| 158 | +/// `wsh` descriptor with policy `and(pk(A),older(6))` |
150 | 159 | pub fn get_test_single_sig_csv() -> &'static str { |
151 | | - // and(pk(Alice),older(6)) |
152 | 160 | "wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),older(6)))" |
153 | 161 | } |
154 | 162 |
|
| 163 | +/// `wsh` descriptor with policy `or(pk(A),and(pk(B),older(144)))` |
155 | 164 | pub fn get_test_a_or_b_plus_csv() -> &'static str { |
156 | | - // or(pk(Alice),and(pk(Bob),older(144))) |
157 | 165 | "wsh(or_d(pk(cRjo6jqfVNP33HhSS76UhXETZsGTZYx8FMFvR9kpbtCSV1PmdZdu),and_v(v:pk(cMnkdebixpXMPfkcNEjjGin7s94hiehAH4mLbYkZoh9KSiNNmqC8),older(144))))" |
158 | 166 | } |
159 | 167 |
|
| 168 | +/// `wsh` descriptor with policy `and(pk(A),after(100000))` |
160 | 169 | pub fn get_test_single_sig_cltv() -> &'static str { |
161 | | - // and(pk(Alice),after(100000)) |
162 | 170 | "wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100000)))" |
163 | 171 | } |
164 | 172 |
|
| 173 | +/// taproot single key descriptor |
165 | 174 | pub fn get_test_tr_single_sig() -> &'static str { |
166 | 175 | "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG)" |
167 | 176 | } |
168 | 177 |
|
| 178 | +/// taproot descriptor with taptree |
169 | 179 | pub fn get_test_tr_with_taptree() -> &'static str { |
170 | 180 | "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{pk(cPZzKuNmpuUjD1e8jUU4PVzy2b5LngbSip8mBsxf4e7rSFZVb4Uh),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})" |
171 | 181 | } |
172 | 182 |
|
| 183 | +/// taproot descriptor with private key taptree |
173 | 184 | pub fn get_test_tr_with_taptree_both_priv() -> &'static str { |
174 | 185 | "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{pk(cPZzKuNmpuUjD1e8jUU4PVzy2b5LngbSip8mBsxf4e7rSFZVb4Uh),pk(cNaQCDwmmh4dS9LzCgVtyy1e1xjCJ21GUDHe9K98nzb689JvinGV)})" |
175 | 186 | } |
176 | 187 |
|
| 188 | +/// taproot descriptor where one key appears in two script paths |
177 | 189 | pub fn get_test_tr_repeated_key() -> &'static str { |
178 | 190 | "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100)),and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(200))})" |
179 | 191 | } |
180 | 192 |
|
| 193 | +/// taproot xpriv descriptor |
181 | 194 | pub fn get_test_tr_single_sig_xprv() -> &'static str { |
182 | 195 | "tr(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/*)" |
183 | 196 | } |
184 | 197 |
|
| 198 | +/// taproot xpriv and change descriptor |
185 | 199 | pub fn get_test_tr_single_sig_xprv_with_change_desc() -> (&'static str, &'static str) { |
186 | 200 | ("tr(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/0/*)", |
187 | 201 | "tr(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/1/*)") |
188 | 202 | } |
189 | 203 |
|
| 204 | +/// taproot descriptor with taptree |
190 | 205 | pub fn get_test_tr_with_taptree_xprv() -> &'static str { |
191 | 206 | "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG,{pk(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/*),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})" |
192 | 207 | } |
193 | 208 |
|
| 209 | +/// taproot desc with duplicate script paths |
194 | 210 | pub fn get_test_tr_dup_keys() -> &'static str { |
195 | 211 | "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG,{pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})" |
196 | 212 | } |
|
0 commit comments