Merge bitcoindevkit/bdk#726: [bug-fix] Set the db sync height
08668ac462Set the db sync height (rajarshimaitra) Pull request description: <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### Description Fixes #719 Previously we weren't setting the db sync height in populate_test_db macro even when current height is provided.. This creates a bug that get_funded_wallet will return 0 balance. This PR fixes the populate_test_db macro and updates tests which were previously dependent on the unsynced wallet behavior. ### Notes to the reviewers <!-- In this section you can include notes directed to the reviewers, like explaining why some parts of the PR were done in a specific way --> ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### Bugfixes: * [x] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: afilini: ACK08668ac462Tree-SHA512: 1dcc968e4b3551e916b450c5ff2fab6636083f104cc982eb3f7602c624382434e0170d9f0c0a356e6c9c5f834eebe5cb1365b37ef73d7b4ef15d652a364dc2ab
This commit is contained in:
@@ -1926,6 +1926,12 @@ pub(crate) mod test {
|
||||
// OP_PUSH.
|
||||
const P2WPKH_FAKE_WITNESS_SIZE: usize = 106;
|
||||
|
||||
#[test]
|
||||
fn test_get_funded_wallet_balance() {
|
||||
let (wallet, _, _) = get_funded_wallet(get_test_wpkh());
|
||||
assert_eq!(wallet.get_balance().unwrap().confirmed, 50000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cache_addresses_fixed() {
|
||||
let db = MemoryDatabase::new();
|
||||
@@ -2173,7 +2179,22 @@ pub(crate) mod test {
|
||||
|
||||
#[test]
|
||||
fn test_create_tx_default_locktime() {
|
||||
let (wallet, _, _) = get_funded_wallet(get_test_wpkh());
|
||||
let descriptors = testutils!(@descriptors (get_test_wpkh()));
|
||||
let wallet = Wallet::new(
|
||||
&descriptors.0,
|
||||
None,
|
||||
Network::Regtest,
|
||||
AnyDatabase::Memory(MemoryDatabase::new()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let tx_meta = testutils! {
|
||||
@tx ( (@external descriptors, 0) => 50_000 )
|
||||
};
|
||||
|
||||
// Add the transaction to our db, but do not sync the db.
|
||||
crate::populate_test_db!(wallet.database.borrow_mut(), tx_meta, None);
|
||||
|
||||
let addr = wallet.get_address(New).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
@@ -2364,7 +2385,23 @@ pub(crate) mod test {
|
||||
|
||||
#[test]
|
||||
fn test_create_tx_default_sequence() {
|
||||
let (wallet, _, _) = get_funded_wallet(get_test_wpkh());
|
||||
let descriptors = testutils!(@descriptors (get_test_wpkh()));
|
||||
let wallet = Wallet::new(
|
||||
&descriptors.0,
|
||||
None,
|
||||
Network::Regtest,
|
||||
AnyDatabase::Memory(MemoryDatabase::new()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let tx_meta = testutils! {
|
||||
@tx ( (@external descriptors, 0) => 50_000 )
|
||||
};
|
||||
|
||||
// Add the transaction to our db, but do not sync the db. Unsynced db
|
||||
// should trigger the default sequence value for a new transaction as 0xFFFFFFFF
|
||||
crate::populate_test_db!(wallet.database.borrow_mut(), tx_meta, None);
|
||||
|
||||
let addr = wallet.get_address(New).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
@@ -2862,7 +2899,22 @@ pub(crate) mod test {
|
||||
|
||||
#[test]
|
||||
fn test_create_tx_policy_path_no_csv() {
|
||||
let (wallet, _, _) = get_funded_wallet(get_test_a_or_b_plus_csv());
|
||||
let descriptors = testutils!(@descriptors (get_test_wpkh()));
|
||||
let wallet = Wallet::new(
|
||||
&descriptors.0,
|
||||
None,
|
||||
Network::Regtest,
|
||||
AnyDatabase::Memory(MemoryDatabase::new()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let tx_meta = testutils! {
|
||||
@tx ( (@external descriptors, 0) => 50_000 )
|
||||
};
|
||||
|
||||
// Add the transaction to our db, but do not sync the db. Unsynced db
|
||||
// should trigger the default sequence value for a new transaction as 0xFFFFFFFF
|
||||
crate::populate_test_db!(wallet.database.borrow_mut(), tx_meta, None);
|
||||
|
||||
let external_policy = wallet.policies(KeychainKind::External).unwrap().unwrap();
|
||||
let root_id = external_policy.id;
|
||||
|
||||
Reference in New Issue
Block a user