Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bitcoind_rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bdk_core = { path = "../core", version = "0.6.1", default-features = false }

[dev-dependencies]
bdk_bitcoind_rpc = { path = "." }
bdk_testenv = { path = "../testenv" }
bdk_testenv = { path = "../testenv", features = ["download"]}
bdk_chain = { path = "../chain" }

[features]
Expand Down
2 changes: 1 addition & 1 deletion crates/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rusqlite = { version = "0.31.0", features = ["bundled"], optional = true }
[dev-dependencies]
rand = "0.8"
proptest = "1.2.0"
bdk_testenv = { path = "../testenv" }
bdk_testenv = { path = "../testenv", features = ["download"]}
criterion = { version = "0.2" }

[features]
Expand Down
227 changes: 227 additions & 0 deletions crates/chain/tests/test_rusqlite_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
#![cfg(feature = "rusqlite")]
use bdk_chain::{keychain_txout, local_chain, tx_graph, ConfirmationBlockTime};
use bdk_testenv::persist_test_utils::{
persist_anchors, persist_first_seen, persist_indexer_changeset, persist_last_evicted,
persist_last_revealed, persist_last_seen, persist_local_chain_changeset, persist_spk_cache,
persist_txgraph_changeset, persist_txouts, persist_txs,
};

#[test]
fn txgraph_is_persisted() {
persist_txgraph_changeset::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?;
let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}

#[test]
fn indexer_is_persisted() {
persist_indexer_changeset::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
keychain_txout::ChangeSet::init_sqlite_tables(&db_tx)?;
let changeset = keychain_txout::ChangeSet::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}

#[test]
fn local_chain_is_persisted() {
persist_local_chain_changeset::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
local_chain::ChangeSet::init_sqlite_tables(&db_tx)?;
let changeset = local_chain::ChangeSet::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}

#[test]
fn txouts_are_persisted() {
persist_txouts::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?;
let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}

#[test]
fn txs_are_persisted() {
persist_txs::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?;
let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}

#[test]
fn anchors_are_persisted() {
persist_anchors::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?;
let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}

#[test]
fn last_seen_is_persisted() {
persist_last_seen::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?;
let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}

#[test]
fn last_evicted_is_persisted() {
persist_last_evicted::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?;
let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}

#[test]
fn first_seen_is_persisted() {
persist_first_seen::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?;
let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}

#[test]
fn last_revealed_is_persisted() {
persist_last_revealed::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
keychain_txout::ChangeSet::init_sqlite_tables(&db_tx)?;
let changeset = keychain_txout::ChangeSet::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}

#[test]
fn spk_cache_is_persisted() {
persist_spk_cache::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(rusqlite::Connection::open(path)?),
|db| {
let db_tx = db.transaction()?;
keychain_txout::ChangeSet::init_sqlite_tables(&db_tx)?;
let changeset = keychain_txout::ChangeSet::from_sqlite(&db_tx)?;
db_tx.commit()?;
Ok(changeset)
},
|db, changeset| {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
Ok(db_tx.commit()?)
},
);
}
2 changes: 1 addition & 1 deletion crates/electrum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bdk_core = { path = "../core", version = "0.6.1" }
electrum-client = { version = "0.24.0", features = [ "proxy" ], default-features = false }

[dev-dependencies]
bdk_testenv = { path = "../testenv" }
bdk_testenv = { path = "../testenv", features = ["download"]}
bdk_chain = { path = "../chain" }
criterion = { version = "0.2" }

Expand Down
2 changes: 1 addition & 1 deletion crates/esplora/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ futures = { version = "0.3.26", optional = true }
[dev-dependencies]
esplora-client = { version = "0.12.0" }
bdk_chain = { path = "../chain" }
bdk_testenv = { path = "../testenv" }
bdk_testenv = { path = "../testenv", features = ["download"]}
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }

[features]
Expand Down
2 changes: 2 additions & 0 deletions crates/file_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ serde = { version = "1", features = ["derive"] }

[dev-dependencies]
tempfile = "3"
bdk_testenv = {path = "../testenv"}
bdk_chain = { path = "../chain", version = "0.23.1", default-features = false, features = ["serde"]}
117 changes: 117 additions & 0 deletions crates/file_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ mod test {
const TEST_MAGIC_BYTES: [u8; TEST_MAGIC_BYTES_LEN] =
[98, 100, 107, 102, 115, 49, 49, 49, 49, 49, 49, 49];

use bdk_chain::{keychain_txout, local_chain, tx_graph, ConfirmationBlockTime};
use bdk_testenv::persist_test_utils::{
persist_anchors, persist_first_seen, persist_indexer_changeset, persist_last_evicted,
persist_last_revealed, persist_last_seen, persist_local_chain_changeset, persist_spk_cache,
persist_txgraph_changeset, persist_txouts, persist_txs,
};

type TestChangeSet = BTreeSet<String>;

/// Check behavior of [`Store::create`] and [`Store::load`].
Expand Down Expand Up @@ -599,4 +606,114 @@ mod test {
// current position matches EOF
assert_eq!(current_pointer, expected_pointer);
}

#[test]
fn txgraph_is_persisted() {
persist_txgraph_changeset::<Store<tx_graph::ChangeSet<ConfirmationBlockTime>>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}

#[test]
fn indexer_is_persisted() {
persist_indexer_changeset::<Store<keychain_txout::ChangeSet>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}

#[test]
fn local_chain_is_persisted() {
persist_local_chain_changeset::<Store<local_chain::ChangeSet>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}

#[test]
fn txouts_are_persisted() {
persist_txouts::<Store<tx_graph::ChangeSet<ConfirmationBlockTime>>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}

#[test]
fn txs_are_persisted() {
persist_txs::<Store<tx_graph::ChangeSet<ConfirmationBlockTime>>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}

#[test]
fn anchors_are_persisted() {
persist_anchors::<Store<tx_graph::ChangeSet<ConfirmationBlockTime>>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}

#[test]
fn last_seen_is_persisted() {
persist_last_seen::<Store<tx_graph::ChangeSet<ConfirmationBlockTime>>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}

#[test]
fn last_evicted_is_persisted() {
persist_last_evicted::<Store<tx_graph::ChangeSet<ConfirmationBlockTime>>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}

#[test]
fn first_seen_is_persisted() {
persist_first_seen::<Store<tx_graph::ChangeSet<ConfirmationBlockTime>>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}

#[test]
fn last_revealed_is_persisted() {
persist_last_revealed::<Store<keychain_txout::ChangeSet>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}

#[test]
fn spk_cache_is_persisted() {
persist_spk_cache::<Store<keychain_txout::ChangeSet>, _, _, _>(
"wallet.db",
|path| Ok(Store::create(&TEST_MAGIC_BYTES, path)?),
|db| Ok(db.dump().map(Option::unwrap_or_default)?),
|db, changeset| Ok(db.append(changeset)?),
);
}
}
Loading
Loading