Skip to content

Commit 2c011f1

Browse files
committed
refactor(persist_test_utils): Reuse ChangeSet construction helpers
1 parent a482ffb commit 2c011f1

1 file changed

Lines changed: 4 additions & 130 deletions

File tree

src/persist_test_utils.rs

Lines changed: 4 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -99,88 +99,10 @@ where
9999
}
100100

101101
// create changeset
102-
let descriptor: Descriptor<DescriptorPublicKey> = DESCRIPTORS[0].parse().unwrap();
103-
let change_descriptor: Descriptor<DescriptorPublicKey> = DESCRIPTORS[1].parse().unwrap();
104-
105-
let local_chain_changeset = local_chain::ChangeSet {
106-
blocks: [
107-
(910234, Some(hash!("B"))),
108-
(910233, Some(hash!("T"))),
109-
(910235, Some(hash!("C"))),
110-
]
111-
.into(),
112-
};
113-
114-
let tx1 = Arc::new(create_one_inp_one_out_tx(
115-
hash!("We_are_all_Satoshi"),
116-
30_000,
117-
));
118-
let tx2 = Arc::new(create_one_inp_one_out_tx(tx1.compute_txid(), 20_000));
119-
120-
let conf_anchor: ConfirmationBlockTime = ConfirmationBlockTime {
121-
block_id: block_id!(910234, "B"),
122-
confirmation_time: 1755317160,
123-
};
124-
125-
let outpoint = OutPoint::new(hash!("Rust"), 0);
126-
127-
let tx_graph_changeset = tx_graph::ChangeSet::<ConfirmationBlockTime> {
128-
txs: [tx1.clone()].into(),
129-
txouts: [
130-
(
131-
outpoint,
132-
TxOut {
133-
value: Amount::from_sat(1300),
134-
script_pubkey: spk_at_index(&descriptor, 4),
135-
},
136-
),
137-
(
138-
OutPoint::new(hash!("REDB"), 0),
139-
TxOut {
140-
value: Amount::from_sat(1400),
141-
script_pubkey: spk_at_index(&descriptor, 10),
142-
},
143-
),
144-
]
145-
.into(),
146-
anchors: [(conf_anchor, tx1.compute_txid())].into(),
147-
last_seen: [(tx1.compute_txid(), 1755317760)].into(),
148-
first_seen: [(tx1.compute_txid(), 1755317750)].into(),
149-
last_evicted: [(tx1.compute_txid(), 1755317760)].into(),
150-
};
151-
152-
let keychain_txout_changeset = keychain_txout::ChangeSet {
153-
last_revealed: [
154-
(descriptor.descriptor_id(), 12),
155-
(change_descriptor.descriptor_id(), 10),
156-
]
157-
.into(),
158-
spk_cache: [
159-
(
160-
descriptor.descriptor_id(),
161-
SpkIterator::new_with_range(&descriptor, 0..=37).collect(),
162-
),
163-
(
164-
change_descriptor.descriptor_id(),
165-
SpkIterator::new_with_range(&change_descriptor, 0..=35).collect(),
166-
),
167-
]
168-
.into(),
169-
};
170-
171-
let locked_outpoints_changeset = locked_outpoints::ChangeSet {
172-
outpoints: [(outpoint, true)].into(),
173-
};
102+
let tx1 = create_one_inp_one_out_tx(hash!("We_are_all_Satoshi"), 30_000);
103+
let tx2 = create_one_inp_one_out_tx(tx1.compute_txid(), 20_000);
174104

175-
let mut changeset = ChangeSet {
176-
descriptor: Some(descriptor.clone()),
177-
change_descriptor: Some(change_descriptor.clone()),
178-
network: Some(Network::Testnet),
179-
local_chain: local_chain_changeset,
180-
tx_graph: tx_graph_changeset,
181-
indexer: keychain_txout_changeset,
182-
locked_outpoints: locked_outpoints_changeset,
183-
};
105+
let mut changeset = get_changeset(tx1);
184106

185107
// persist and load
186108
WalletPersister::persist(&mut store, &changeset).map_err(E::persister)?;
@@ -195,55 +117,7 @@ where
195117
}
196118

197119
// create another changeset
198-
let local_chain_changeset = local_chain::ChangeSet {
199-
blocks: [(910236, Some(hash!("BDK")))].into(),
200-
};
201-
202-
let conf_anchor: ConfirmationBlockTime = ConfirmationBlockTime {
203-
block_id: block_id!(910236, "BDK"),
204-
confirmation_time: 1755317760,
205-
};
206-
207-
let outpoint = OutPoint::new(hash!("Bitcoin_fixes_things"), 1);
208-
209-
let tx_graph_changeset = tx_graph::ChangeSet::<ConfirmationBlockTime> {
210-
txs: [tx2.clone()].into(),
211-
txouts: [(
212-
outpoint,
213-
TxOut {
214-
value: Amount::from_sat(10000),
215-
script_pubkey: spk_at_index(&descriptor, 21),
216-
},
217-
)]
218-
.into(),
219-
anchors: [(conf_anchor, tx2.compute_txid())].into(),
220-
last_seen: [(tx2.compute_txid(), 1755317700)].into(),
221-
first_seen: [(tx2.compute_txid(), 1755317700)].into(),
222-
last_evicted: [(tx2.compute_txid(), 1755317760)].into(),
223-
};
224-
225-
let keychain_txout_changeset = keychain_txout::ChangeSet {
226-
last_revealed: [(descriptor.descriptor_id(), 14)].into(),
227-
spk_cache: [(
228-
descriptor.descriptor_id(),
229-
SpkIterator::new_with_range(&descriptor, 37..=39).collect(),
230-
)]
231-
.into(),
232-
};
233-
234-
let locked_outpoints_changeset = locked_outpoints::ChangeSet {
235-
outpoints: [(outpoint, true)].into(),
236-
};
237-
238-
let changeset_new = ChangeSet {
239-
descriptor: None,
240-
change_descriptor: None,
241-
network: None,
242-
local_chain: local_chain_changeset,
243-
tx_graph: tx_graph_changeset,
244-
indexer: keychain_txout_changeset,
245-
locked_outpoints: locked_outpoints_changeset,
246-
};
120+
let changeset_new = get_changeset_two(tx2);
247121

248122
// persist, load and check if same as merged
249123
WalletPersister::persist(&mut store, &changeset_new).map_err(E::persister)?;

0 commit comments

Comments
 (0)