Skip to content

Commit 8ea257a

Browse files
committed
feat: use persistence test utils in txgraph tests
1 parent 6d8d827 commit 8ea257a

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ wallet = ["bdk_wallet"]
2121

2222
[dev-dependencies]
2323
anyhow = "1.0.98"
24-
bdk_testenv = { version = "0.13.0" }
24+
bdk_testenv = { git = "https://github.com/110CodingP/bdk", branch = "add_persist_test_utils"}
2525
tempfile = "3.20.0"
2626
bdk_wallet = {git = "https://github.com/110CodingP/bdk_wallet", branch = "add_persist_test_utils", features = ["test-utils"]}
2727
bdk_chain = {version = "0.23.0", features = ["serde"]}

src/lib.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ mod test {
890890
miniscript::descriptor::Descriptor,
891891
};
892892

893+
use bdk_testenv::persist_test_utils::persist_txgraph_changeset;
893894
use std::sync::Arc;
894895
use std::{collections::BTreeMap, path::Path};
895896
use tempfile::NamedTempFile;
@@ -2164,4 +2165,50 @@ mod test {
21642165
Ok(Store::new(Arc::new(db), "wallet".to_string())?)
21652166
});
21662167
}
2168+
2169+
#[test]
2170+
fn txgraph_is_persisted() {
2171+
// const DB_MAGIC: &[u8] = &[0x21, 0x24, 0x48];
2172+
// persist_txgraph_changeset::<bdk_wallet::file_store::Store<tx_graph::ChangeSet<ConfirmationBlockTime>>, _, _, _>(
2173+
// "store.db",
2174+
// |path| Ok(bdk_wallet::file_store::Store::create(DB_MAGIC, path)?),
2175+
// |db| Ok(db.dump().map(Option::unwrap_or_default)?),
2176+
// |db, changeset| Ok(db.append(changeset)?),
2177+
// );
2178+
2179+
// persist_txgraph_changeset::<bdk_chain::rusqlite::Connection, _, _, _>(
2180+
// "store.sqlite",
2181+
// |path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
2182+
// |db| {
2183+
// let db_tx = db.transaction()?;
2184+
// tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?;
2185+
// let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
2186+
// db_tx.commit()?;
2187+
// Ok(changeset)
2188+
// },
2189+
// |db, changeset| {
2190+
// let db_tx = db.transaction()?;
2191+
// changeset.persist_to_sqlite(&db_tx)?;
2192+
// Ok(db_tx.commit()?)
2193+
// },
2194+
// );
2195+
2196+
persist_txgraph_changeset(
2197+
"wallet.redb",
2198+
|path| {
2199+
let db = redb::Database::create(path)?;
2200+
Ok(Store::new(Arc::new(db), "wallet".to_string())?)
2201+
},
2202+
|db| {
2203+
db.create_tables::<ConfirmationBlockTime>()?;
2204+
let mut changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::default();
2205+
db.read_tx_graph(&mut changeset)?;
2206+
Ok(changeset)
2207+
},
2208+
|db, changeset| {
2209+
db.persist_tx_graph(changeset)?;
2210+
Ok(())
2211+
},
2212+
);
2213+
}
21672214
}

0 commit comments

Comments
 (0)