-
Notifications
You must be signed in to change notification settings - Fork 450
Expand file tree
/
Copy pathtest_rusqlite_impl.rs
More file actions
165 lines (150 loc) · 5.23 KB
/
test_rusqlite_impl.rs
File metadata and controls
165 lines (150 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#![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,
};
fn tx_graph_changeset_init(
db: &mut rusqlite::Connection,
) -> rusqlite::Result<tx_graph::ChangeSet<ConfirmationBlockTime>> {
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)
}
fn tx_graph_changeset_persist(
db: &mut rusqlite::Connection,
changeset: &tx_graph::ChangeSet<ConfirmationBlockTime>,
) -> rusqlite::Result<()> {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
db_tx.commit()
}
fn keychain_txout_changeset_init(
db: &mut rusqlite::Connection,
) -> rusqlite::Result<keychain_txout::ChangeSet> {
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)
}
fn keychain_txout_changeset_persist(
db: &mut rusqlite::Connection,
changeset: &keychain_txout::ChangeSet,
) -> rusqlite::Result<()> {
let db_tx = db.transaction()?;
changeset.persist_to_sqlite(&db_tx)?;
db_tx.commit()
}
#[test]
fn txgraph_is_persisted() {
persist_txgraph_changeset::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| Ok(tx_graph_changeset_init(db)?),
|db, changeset| Ok(tx_graph_changeset_persist(db, changeset)?),
);
}
#[test]
fn indexer_is_persisted() {
persist_indexer_changeset::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(rusqlite::Connection::open(path)?),
|db| Ok(keychain_txout_changeset_init(db)?),
|db, changeset| Ok(keychain_txout_changeset_persist(db, changeset)?),
);
}
#[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| Ok(tx_graph_changeset_init(db)?),
|db, changeset| Ok(tx_graph_changeset_persist(db, changeset)?),
);
}
#[test]
fn txs_are_persisted() {
persist_txs::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| Ok(tx_graph_changeset_init(db)?),
|db, changeset| Ok(tx_graph_changeset_persist(db, changeset)?),
);
}
#[test]
fn anchors_are_persisted() {
persist_anchors::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| Ok(tx_graph_changeset_init(db)?),
|db, changeset| Ok(tx_graph_changeset_persist(db, changeset)?),
);
}
#[test]
fn last_seen_is_persisted() {
persist_last_seen::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| Ok(tx_graph_changeset_init(db)?),
|db, changeset| Ok(tx_graph_changeset_persist(db, changeset)?),
);
}
#[test]
fn last_evicted_is_persisted() {
persist_last_evicted::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| Ok(tx_graph_changeset_init(db)?),
|db, changeset| Ok(tx_graph_changeset_persist(db, changeset)?),
);
}
#[test]
fn first_seen_is_persisted() {
persist_first_seen::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
|db| Ok(tx_graph_changeset_init(db)?),
|db, changeset| Ok(tx_graph_changeset_persist(db, changeset)?),
);
}
#[test]
fn last_revealed_is_persisted() {
persist_last_revealed::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(rusqlite::Connection::open(path)?),
|db| Ok(keychain_txout_changeset_init(db)?),
|db, changeset| Ok(keychain_txout_changeset_persist(db, changeset)?),
);
}
#[test]
fn spk_cache_is_persisted() {
persist_spk_cache::<rusqlite::Connection, _, _, _>(
"wallet.sqlite",
|path| Ok(rusqlite::Connection::open(path)?),
|db| Ok(keychain_txout_changeset_init(db)?),
|db, changeset| Ok(keychain_txout_changeset_persist(db, changeset)?),
);
}