-
Notifications
You must be signed in to change notification settings - Fork 406
Add functions to test persistence #2012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
110CodingP
wants to merge
6
commits into
bitcoindevkit:master
Choose a base branch
from
110CodingP:add_persist_test_utils
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb141b6
feat: add utilities for testing persistence
110CodingP 509f148
test: use test utils to test file_store and sqlite
110CodingP 6e5c9f4
docs: document persist_test_utils module
110CodingP 10c42dc
fix: correct Cargo.toml and refactor test utils
110CodingP fd9429c
build(testenv): make "miniscript" feature default
110CodingP c4b6873
build(testenv): modify default feature
110CodingP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()?) | ||
}, | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the correct thing to do is something like this by making the dependency explicit.
But a simpler hack is to just have
default = ["bdk_chain/default"]
(which seems to be missing and should probably be done anyway). In that case the cfg attribute would be changed to#[cfg(feature = "default"]
. Sorry to cause more bikeshedding on the matter. I'll be in favor of whatever is clear and easy to understand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with the second approach since the first seemed a bit complicated 😅 (like the test utils are gated by miniscript feature which might not be enabled even though all we need is bdk_chain/default).