Skip to content

Commit 9044a4e

Browse files
committed
update test code
1 parent 61664c2 commit 9044a4e

6 files changed

Lines changed: 110 additions & 91 deletions

File tree

crates/chain/tests/common/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod tx_template;
2+
use bitcoin::transaction::Version;
23
#[allow(unused_imports)]
34
pub use tx_template::*;
45

@@ -70,7 +71,7 @@ macro_rules! changeset {
7071
#[allow(unused)]
7172
pub fn new_tx(lt: u32) -> bitcoin::Transaction {
7273
bitcoin::Transaction {
73-
version: 0x00,
74+
version: Version(0x00),
7475
lock_time: bitcoin::absolute::LockTime::from_consensus(lt),
7576
input: vec![],
7677
output: vec![],

crates/chain/tests/common/tx_template.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::collections::HashMap;
33

44
use bdk_chain::{tx_graph::TxGraph, BlockId, SpkTxOutIndex};
55
use bitcoin::{
6-
locktime::absolute::LockTime, secp256k1::Secp256k1, OutPoint, ScriptBuf, Sequence, Transaction,
7-
TxIn, TxOut, Txid, Witness,
6+
locktime::absolute::LockTime, secp256k1::Secp256k1, transaction::Version, Amount, OutPoint,
7+
ScriptBuf, Sequence, Transaction, TxIn, TxOut, Txid, Witness,
88
};
99
use miniscript::Descriptor;
1010

@@ -68,7 +68,7 @@ pub fn init_graph<'a>(
6868

6969
for (bogus_txin_vout, tx_tmp) in tx_templates.into_iter().enumerate() {
7070
let tx = Transaction {
71-
version: 0,
71+
version: Version(0),
7272
lock_time: LockTime::ZERO,
7373
input: tx_tmp
7474
.inputs
@@ -111,11 +111,11 @@ pub fn init_graph<'a>(
111111
.iter()
112112
.map(|output| match &output.spk_index {
113113
None => TxOut {
114-
value: output.value,
114+
value: Amount::from_int_btc(output.value),
115115
script_pubkey: ScriptBuf::new(),
116116
},
117117
Some(index) => TxOut {
118-
value: output.value,
118+
value: Amount::from_int_btc(output.value),
119119
script_pubkey: spk_index.spk_at_index(index).unwrap().to_owned(),
120120
},
121121
})

crates/chain/tests/test_indexed_tx_graph.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use bdk_chain::{
99
local_chain::LocalChain,
1010
tx_graph, BlockId, ChainPosition, ConfirmationHeightAnchor,
1111
};
12-
use bitcoin::{secp256k1::Secp256k1, OutPoint, Script, ScriptBuf, Transaction, TxIn, TxOut};
12+
use bitcoin::{
13+
secp256k1::Secp256k1, Amount, OutPoint, Script, ScriptBuf, Transaction, TxIn, TxOut,
14+
};
1315
use miniscript::Descriptor;
1416

1517
/// Ensure [`IndexedTxGraph::insert_relevant_txs`] can successfully index transactions NOT presented
@@ -35,11 +37,11 @@ fn insert_relevant_txs() {
3537
let tx_a = Transaction {
3638
output: vec![
3739
TxOut {
38-
value: 10_000,
40+
value: Amount::from_int_btc(10_000),
3941
script_pubkey: spk_0,
4042
},
4143
TxOut {
42-
value: 20_000,
44+
value: Amount::from_int_btc(20_000),
4345
script_pubkey: spk_1,
4446
},
4547
],
@@ -155,7 +157,7 @@ fn test_list_owned_txouts() {
155157
..Default::default()
156158
}],
157159
output: vec![TxOut {
158-
value: 70000,
160+
value: Amount::from_int_btc(70000),
159161
script_pubkey: trusted_spks[0].to_owned(),
160162
}],
161163
..common::new_tx(0)
@@ -164,7 +166,7 @@ fn test_list_owned_txouts() {
164166
// tx2 is an incoming transaction received at untrusted keychain at block 1.
165167
let tx2 = Transaction {
166168
output: vec![TxOut {
167-
value: 30000,
169+
value: Amount::from_int_btc(30000),
168170
script_pubkey: untrusted_spks[0].to_owned(),
169171
}],
170172
..common::new_tx(0)
@@ -177,7 +179,7 @@ fn test_list_owned_txouts() {
177179
..Default::default()
178180
}],
179181
output: vec![TxOut {
180-
value: 10000,
182+
value: Amount::from_int_btc(10000),
181183
script_pubkey: trusted_spks[1].to_owned(),
182184
}],
183185
..common::new_tx(0)
@@ -186,7 +188,7 @@ fn test_list_owned_txouts() {
186188
// tx4 is an external transaction receiving at untrusted keychain, unconfirmed.
187189
let tx4 = Transaction {
188190
output: vec![TxOut {
189-
value: 20000,
191+
value: Amount::from_int_btc(20000),
190192
script_pubkey: untrusted_spks[1].to_owned(),
191193
}],
192194
..common::new_tx(0)
@@ -195,7 +197,7 @@ fn test_list_owned_txouts() {
195197
// tx5 is spending tx3 and receiving change at trusted keychain, unconfirmed.
196198
let tx5 = Transaction {
197199
output: vec![TxOut {
198-
value: 15000,
200+
value: Amount::from_int_btc(15000),
199201
script_pubkey: trusted_spks[2].to_owned(),
200202
}],
201203
..common::new_tx(0)

crates/chain/tests/test_keychain_txout_index.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use bdk_chain::{
99
Append,
1010
};
1111

12-
use bitcoin::{secp256k1::Secp256k1, OutPoint, ScriptBuf, Transaction, TxOut};
12+
use bitcoin::{secp256k1::Secp256k1, Amount, OutPoint, ScriptBuf, Transaction, TxOut};
1313
use miniscript::{Descriptor, DescriptorPublicKey};
1414

1515
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
@@ -176,14 +176,14 @@ fn test_lookahead() {
176176
.at_derivation_index(external_index)
177177
.unwrap()
178178
.script_pubkey(),
179-
value: 10_000,
179+
value: Amount::from_int_btc(10_000),
180180
},
181181
TxOut {
182182
script_pubkey: internal_desc
183183
.at_derivation_index(internal_index)
184184
.unwrap()
185185
.script_pubkey(),
186-
value: 10_000,
186+
value: Amount::from_int_btc(10_000),
187187
},
188188
],
189189
..common::new_tx(external_index)
@@ -238,7 +238,7 @@ fn test_scan_with_lookahead() {
238238
let op = OutPoint::new(h!("fake tx"), spk_i);
239239
let txout = TxOut {
240240
script_pubkey: spk.clone(),
241-
value: 0,
241+
value: Amount::from_int_btc(0),
242242
};
243243

244244
let changeset = txout_index.index_txout(op, &txout);
@@ -264,7 +264,7 @@ fn test_scan_with_lookahead() {
264264
let op = OutPoint::new(h!("fake tx"), 41);
265265
let txout = TxOut {
266266
script_pubkey: spk_41,
267-
value: 0,
267+
value: Amount::from_int_btc(0),
268268
};
269269
let changeset = txout_index.index_txout(op, &txout);
270270
assert!(changeset.is_empty());

crates/chain/tests/test_spk_txout_index.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use bdk_chain::{indexed_tx_graph::Indexer, SpkTxOutIndex};
2-
use bitcoin::{absolute, OutPoint, ScriptBuf, Transaction, TxIn, TxOut};
2+
use bitcoin::{
3+
absolute, transaction::Version, Amount, OutPoint, ScriptBuf, Transaction, TxIn, TxOut,
4+
};
35

46
#[test]
57
fn spk_txout_sent_and_received() {
@@ -11,11 +13,11 @@ fn spk_txout_sent_and_received() {
1113
index.insert_spk(1, spk2.clone());
1214

1315
let tx1 = Transaction {
14-
version: 0x02,
16+
version: bitcoin::transaction::Version(0x02),
1517
lock_time: absolute::LockTime::ZERO,
1618
input: vec![],
1719
output: vec![TxOut {
18-
value: 42_000,
20+
value: Amount::from_int_btc(42_000),
1921
script_pubkey: spk1.clone(),
2022
}],
2123
};
@@ -30,7 +32,7 @@ fn spk_txout_sent_and_received() {
3032
);
3133

3234
let tx2 = Transaction {
33-
version: 0x1,
35+
version: Version(0x1),
3436
lock_time: absolute::LockTime::ZERO,
3537
input: vec![TxIn {
3638
previous_output: OutPoint {
@@ -41,12 +43,12 @@ fn spk_txout_sent_and_received() {
4143
}],
4244
output: vec![
4345
TxOut {
44-
value: 20_000,
46+
value: Amount::from_int_btc(20_000),
4547
script_pubkey: spk2,
4648
},
4749
TxOut {
4850
script_pubkey: spk1,
49-
value: 30_000,
51+
value: Amount::from_int_btc(30_000),
5052
},
5153
],
5254
};
@@ -73,11 +75,11 @@ fn mark_used() {
7375
assert!(spk_index.is_used(&1));
7476

7577
let tx1 = Transaction {
76-
version: 0x02,
78+
version: Version(0x02),
7779
lock_time: absolute::LockTime::ZERO,
7880
input: vec![],
7981
output: vec![TxOut {
80-
value: 42_000,
82+
value: Amount::from_int_btc(42_000),
8183
script_pubkey: spk1,
8284
}],
8385
};

0 commit comments

Comments
 (0)