|
| 1 | +#![cfg(feature = "rusqlite")] |
| 2 | +use bdk_chain::{keychain_txout, local_chain, tx_graph, ConfirmationBlockTime}; |
| 3 | +use bdk_testenv::persist_test_utils::{ |
| 4 | + persist_anchors, persist_first_seen, persist_indexer_changeset, persist_last_evicted, |
| 5 | + persist_last_revealed, persist_last_seen, persist_local_chain_changeset, persist_spk_cache, |
| 6 | + persist_txgraph_changeset, persist_txouts, persist_txs, |
| 7 | +}; |
| 8 | + |
| 9 | +#[test] |
| 10 | +fn txgraph_is_persisted() { |
| 11 | + persist_txgraph_changeset::<rusqlite::Connection, _, _, _>( |
| 12 | + "wallet.sqlite", |
| 13 | + |path| Ok(bdk_chain::rusqlite::Connection::open(path)?), |
| 14 | + |db| { |
| 15 | + let db_tx = db.transaction()?; |
| 16 | + tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?; |
| 17 | + let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?; |
| 18 | + db_tx.commit()?; |
| 19 | + Ok(changeset) |
| 20 | + }, |
| 21 | + |db, changeset| { |
| 22 | + let db_tx = db.transaction()?; |
| 23 | + changeset.persist_to_sqlite(&db_tx)?; |
| 24 | + Ok(db_tx.commit()?) |
| 25 | + }, |
| 26 | + ); |
| 27 | +} |
| 28 | + |
| 29 | +#[test] |
| 30 | +fn indexer_is_persisted() { |
| 31 | + persist_indexer_changeset::<rusqlite::Connection, _, _, _>( |
| 32 | + "wallet.sqlite", |
| 33 | + |path| Ok(rusqlite::Connection::open(path)?), |
| 34 | + |db| { |
| 35 | + let db_tx = db.transaction()?; |
| 36 | + keychain_txout::ChangeSet::init_sqlite_tables(&db_tx)?; |
| 37 | + let changeset = keychain_txout::ChangeSet::from_sqlite(&db_tx)?; |
| 38 | + db_tx.commit()?; |
| 39 | + Ok(changeset) |
| 40 | + }, |
| 41 | + |db, changeset| { |
| 42 | + let db_tx = db.transaction()?; |
| 43 | + changeset.persist_to_sqlite(&db_tx)?; |
| 44 | + Ok(db_tx.commit()?) |
| 45 | + }, |
| 46 | + ); |
| 47 | +} |
| 48 | + |
| 49 | +#[test] |
| 50 | +fn local_chain_is_persisted() { |
| 51 | + persist_local_chain_changeset::<rusqlite::Connection, _, _, _>( |
| 52 | + "wallet.sqlite", |
| 53 | + |path| Ok(rusqlite::Connection::open(path)?), |
| 54 | + |db| { |
| 55 | + let db_tx = db.transaction()?; |
| 56 | + local_chain::ChangeSet::init_sqlite_tables(&db_tx)?; |
| 57 | + let changeset = local_chain::ChangeSet::from_sqlite(&db_tx)?; |
| 58 | + db_tx.commit()?; |
| 59 | + Ok(changeset) |
| 60 | + }, |
| 61 | + |db, changeset| { |
| 62 | + let db_tx = db.transaction()?; |
| 63 | + changeset.persist_to_sqlite(&db_tx)?; |
| 64 | + Ok(db_tx.commit()?) |
| 65 | + }, |
| 66 | + ); |
| 67 | +} |
| 68 | + |
| 69 | +#[test] |
| 70 | +fn txouts_are_persisted() { |
| 71 | + persist_txouts::<rusqlite::Connection, _, _, _>( |
| 72 | + "wallet.sqlite", |
| 73 | + |path| Ok(bdk_chain::rusqlite::Connection::open(path)?), |
| 74 | + |db| { |
| 75 | + let db_tx = db.transaction()?; |
| 76 | + tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?; |
| 77 | + let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?; |
| 78 | + db_tx.commit()?; |
| 79 | + Ok(changeset) |
| 80 | + }, |
| 81 | + |db, changeset| { |
| 82 | + let db_tx = db.transaction()?; |
| 83 | + changeset.persist_to_sqlite(&db_tx)?; |
| 84 | + Ok(db_tx.commit()?) |
| 85 | + }, |
| 86 | + ); |
| 87 | +} |
| 88 | + |
| 89 | +#[test] |
| 90 | +fn txs_are_persisted() { |
| 91 | + persist_txs::<rusqlite::Connection, _, _, _>( |
| 92 | + "wallet.sqlite", |
| 93 | + |path| Ok(bdk_chain::rusqlite::Connection::open(path)?), |
| 94 | + |db| { |
| 95 | + let db_tx = db.transaction()?; |
| 96 | + tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?; |
| 97 | + let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?; |
| 98 | + db_tx.commit()?; |
| 99 | + Ok(changeset) |
| 100 | + }, |
| 101 | + |db, changeset| { |
| 102 | + let db_tx = db.transaction()?; |
| 103 | + changeset.persist_to_sqlite(&db_tx)?; |
| 104 | + Ok(db_tx.commit()?) |
| 105 | + }, |
| 106 | + ); |
| 107 | +} |
| 108 | + |
| 109 | +#[test] |
| 110 | +fn anchors_are_persisted() { |
| 111 | + persist_anchors::<rusqlite::Connection, _, _, _>( |
| 112 | + "wallet.sqlite", |
| 113 | + |path| Ok(bdk_chain::rusqlite::Connection::open(path)?), |
| 114 | + |db| { |
| 115 | + let db_tx = db.transaction()?; |
| 116 | + tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?; |
| 117 | + let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?; |
| 118 | + db_tx.commit()?; |
| 119 | + Ok(changeset) |
| 120 | + }, |
| 121 | + |db, changeset| { |
| 122 | + let db_tx = db.transaction()?; |
| 123 | + changeset.persist_to_sqlite(&db_tx)?; |
| 124 | + Ok(db_tx.commit()?) |
| 125 | + }, |
| 126 | + ); |
| 127 | +} |
| 128 | + |
| 129 | +#[test] |
| 130 | +fn last_seen_is_persisted() { |
| 131 | + persist_last_seen::<rusqlite::Connection, _, _, _>( |
| 132 | + "wallet.sqlite", |
| 133 | + |path| Ok(bdk_chain::rusqlite::Connection::open(path)?), |
| 134 | + |db| { |
| 135 | + let db_tx = db.transaction()?; |
| 136 | + tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?; |
| 137 | + let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?; |
| 138 | + db_tx.commit()?; |
| 139 | + Ok(changeset) |
| 140 | + }, |
| 141 | + |db, changeset| { |
| 142 | + let db_tx = db.transaction()?; |
| 143 | + changeset.persist_to_sqlite(&db_tx)?; |
| 144 | + Ok(db_tx.commit()?) |
| 145 | + }, |
| 146 | + ); |
| 147 | +} |
| 148 | + |
| 149 | +#[test] |
| 150 | +fn last_evicted_is_persisted() { |
| 151 | + persist_last_evicted::<rusqlite::Connection, _, _, _>( |
| 152 | + "wallet.sqlite", |
| 153 | + |path| Ok(bdk_chain::rusqlite::Connection::open(path)?), |
| 154 | + |db| { |
| 155 | + let db_tx = db.transaction()?; |
| 156 | + tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?; |
| 157 | + let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?; |
| 158 | + db_tx.commit()?; |
| 159 | + Ok(changeset) |
| 160 | + }, |
| 161 | + |db, changeset| { |
| 162 | + let db_tx = db.transaction()?; |
| 163 | + changeset.persist_to_sqlite(&db_tx)?; |
| 164 | + Ok(db_tx.commit()?) |
| 165 | + }, |
| 166 | + ); |
| 167 | +} |
| 168 | + |
| 169 | +#[test] |
| 170 | +fn first_seen_is_persisted() { |
| 171 | + persist_first_seen::<rusqlite::Connection, _, _, _>( |
| 172 | + "wallet.sqlite", |
| 173 | + |path| Ok(bdk_chain::rusqlite::Connection::open(path)?), |
| 174 | + |db| { |
| 175 | + let db_tx = db.transaction()?; |
| 176 | + tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?; |
| 177 | + let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?; |
| 178 | + db_tx.commit()?; |
| 179 | + Ok(changeset) |
| 180 | + }, |
| 181 | + |db, changeset| { |
| 182 | + let db_tx = db.transaction()?; |
| 183 | + changeset.persist_to_sqlite(&db_tx)?; |
| 184 | + Ok(db_tx.commit()?) |
| 185 | + }, |
| 186 | + ); |
| 187 | +} |
| 188 | + |
| 189 | +#[test] |
| 190 | +fn last_revealed_is_persisted() { |
| 191 | + persist_last_revealed::<rusqlite::Connection, _, _, _>( |
| 192 | + "wallet.sqlite", |
| 193 | + |path| Ok(rusqlite::Connection::open(path)?), |
| 194 | + |db| { |
| 195 | + let db_tx = db.transaction()?; |
| 196 | + keychain_txout::ChangeSet::init_sqlite_tables(&db_tx)?; |
| 197 | + let changeset = keychain_txout::ChangeSet::from_sqlite(&db_tx)?; |
| 198 | + db_tx.commit()?; |
| 199 | + Ok(changeset) |
| 200 | + }, |
| 201 | + |db, changeset| { |
| 202 | + let db_tx = db.transaction()?; |
| 203 | + changeset.persist_to_sqlite(&db_tx)?; |
| 204 | + Ok(db_tx.commit()?) |
| 205 | + }, |
| 206 | + ); |
| 207 | +} |
| 208 | + |
| 209 | +#[test] |
| 210 | +fn spk_cache_is_persisted() { |
| 211 | + persist_spk_cache::<rusqlite::Connection, _, _, _>( |
| 212 | + "wallet.sqlite", |
| 213 | + |path| Ok(rusqlite::Connection::open(path)?), |
| 214 | + |db| { |
| 215 | + let db_tx = db.transaction()?; |
| 216 | + keychain_txout::ChangeSet::init_sqlite_tables(&db_tx)?; |
| 217 | + let changeset = keychain_txout::ChangeSet::from_sqlite(&db_tx)?; |
| 218 | + db_tx.commit()?; |
| 219 | + Ok(changeset) |
| 220 | + }, |
| 221 | + |db, changeset| { |
| 222 | + let db_tx = db.transaction()?; |
| 223 | + changeset.persist_to_sqlite(&db_tx)?; |
| 224 | + Ok(db_tx.commit()?) |
| 225 | + }, |
| 226 | + ); |
| 227 | +} |
0 commit comments