Skip to content

Commit 8fb2938

Browse files
committed
Depend on the new bitcoind-json-rpc group of crates
There is an effort to improve the state of affairs in regards to integration testing extensively against multiple versions of Bitcoin Core. As part of this do: - Depend on the new `rust-bitcoind-json-rpc` crates - Run the integration tests against most versions of Core since 0.17.1 (Note the latest supported version is currently 26.0) This patch effects integration testing only and should hopefully help with our upgrade process because I will personally make sure the new crates are ready and tested during the rust-bitcoin RC cycle.
1 parent 72e5e37 commit 8fb2938

File tree

5 files changed

+107
-68
lines changed

5 files changed

+107
-68
lines changed

.github/workflows/rust.yml

+31-14
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,39 @@ jobs:
3434
DO_LINT: true
3535
run: ./contrib/test.sh
3636

37-
Int-tests:
38-
name: Integration tests
37+
Integration: # 1 job for each bitcoind version we support.
38+
name: Integration tests - stable toolchain
3939
runs-on: ubuntu-latest
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
feature:
44+
[
45+
"26_0",
46+
"25_2",
47+
"25_1",
48+
"25_0",
49+
"24_2",
50+
"24_1",
51+
"24_0_1",
52+
"23_2",
53+
"23_1",
54+
"23_0",
55+
"22_1",
56+
"22_0",
57+
"0_21_2",
58+
"0_20_2",
59+
"0_19_1",
60+
"0_18_1",
61+
"0_17_1",
62+
]
4063
steps:
41-
- name: Checkout Crate
42-
uses: actions/checkout@v2
43-
- name: Checkout Toolchain
44-
uses: actions-rs/toolchain@v1
45-
with:
46-
profile: minimal
47-
toolchain: stable
48-
override: true
49-
- name: Running integration tests
50-
env:
51-
DO_BITCOIND_TESTS: true
52-
run: ./contrib/test.sh
64+
- name: "Checkout repo"
65+
uses: actions/checkout@v4
66+
- name: "Select toolchain"
67+
uses: dtolnay/rust-toolchain@stable
68+
- name: "Run integration tests"
69+
run: cd bitcoind-tests && cargo test --features=${{ matrix.feature }}
5370

5471
Tests:
5572
name: Tests

bitcoind-tests/Cargo.toml

+21-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ publish = false
99

1010
[dependencies]
1111
miniscript = {path = "../"}
12-
bitcoind = { version = "0.36.0" }
12+
bitcoind = { package = "bitcoind-json-rpc-regtest", version = "0.3.0" }
1313
actual-rand = { package = "rand", version = "0.8.4"}
1414
secp256k1 = {version = "0.29.0", features = ["rand-std"]}
15+
16+
[features]
17+
# Enable the same feature in `bitcoind`.
18+
"26_0" = ["bitcoind/26_0"]
19+
"25_2" = ["bitcoind/25_2"]
20+
"25_1" = ["bitcoind/25_1"]
21+
"25_0" = ["bitcoind/25_0"]
22+
"24_2" = ["bitcoind/24_2"]
23+
"24_1" = ["bitcoind/24_1"]
24+
"24_0_1" = ["bitcoind/24_0_1"]
25+
"23_2" = ["bitcoind/23_2"]
26+
"23_1" = ["bitcoind/23_1"]
27+
"23_0" = ["bitcoind/23_0"]
28+
"22_1" = ["bitcoind/22_1"]
29+
"22_0" = ["bitcoind/22_0"]
30+
"0_21_2" = ["bitcoind/0_21_2"]
31+
"0_20_2" = ["bitcoind/0_20_2"]
32+
"0_19_1" = ["bitcoind/0_19_1"]
33+
"0_18_1" = ["bitcoind/0_18_1"]
34+
"0_17_1" = ["bitcoind/0_17_1"]

bitcoind-tests/tests/setup/mod.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
extern crate miniscript;
22

3-
use bitcoind::bitcoincore_rpc::RpcApi;
4-
use bitcoind::BitcoinD;
5-
use miniscript::bitcoin;
3+
use bitcoind::client::bitcoin;
64

75
pub mod test_util;
86

97
// Launch an instance of bitcoind with
10-
pub fn setup() -> BitcoinD {
8+
pub fn setup() -> bitcoind::BitcoinD {
119
// Create env var BITCOIND_EXE_PATH to point to the ../bitcoind/bin/bitcoind binary
1210
let key = "BITCOIND_EXE";
1311
if std::env::var(key).is_err() {
@@ -29,13 +27,18 @@ pub fn setup() -> BitcoinD {
2927
let bitcoind = bitcoind::BitcoinD::new(exe_path).unwrap();
3028
let cl = &bitcoind.client;
3129
// generate to an address by the wallet. And wait for funds to mature
32-
let addr = cl.get_new_address(None, None).unwrap().assume_checked();
30+
let addr = cl.new_address().unwrap();
3331
let blks = cl.generate_to_address(101, &addr).unwrap();
34-
assert_eq!(blks.len(), 101);
32+
assert_eq!(blks.0.len(), 101);
3533

34+
let balance = cl
35+
.get_balance()
36+
.expect("failed to get balance")
37+
.balance()
38+
.unwrap();
3639
assert_eq!(
37-
cl.get_balance(Some(1) /*min conf*/, None).unwrap(),
38-
bitcoin::Amount::from_sat(100_000_000 * 50)
40+
balance,
41+
bitcoin::Amount::from_sat(100_000_000 * 50),
3942
);
4043
bitcoind
4144
}

bitcoind-tests/tests/test_cpp.rs

+22-27
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use bitcoin::psbt::Psbt;
1414
use bitcoin::{
1515
psbt, secp256k1, transaction, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid,
1616
};
17-
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
17+
use bitcoind::{Client, AddressType};
1818
use miniscript::bitcoin::absolute;
1919
use miniscript::psbt::PsbtExt;
2020
use miniscript::{bitcoin, DefiniteDescriptorKey, Descriptor};
@@ -52,11 +52,12 @@ fn btc<F: Into<f64>>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() }
5252
// Ideally, we should find by scriptPubkey, but this
5353
// works for temp test case
5454
fn get_vout(cl: &Client, txid: Txid, value: Amount) -> (OutPoint, TxOut) {
55-
let tx = cl
56-
.get_transaction(&txid, None)
57-
.unwrap()
58-
.transaction()
59-
.unwrap();
55+
let model = cl.get_transaction(txid)
56+
.expect("rpc call failed")
57+
.into_model()
58+
.expect("conversion to model type failed");
59+
let tx = model.tx;
60+
6061
for (i, txout) in tx.output.into_iter().enumerate() {
6162
if txout.value == value {
6263
return (OutPoint::new(txid, i as u32), txout);
@@ -72,32 +73,25 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
7273
let pks = &testdata.pubdata.pks;
7374
// Generate some blocks
7475
let blocks = cl
75-
.generate_to_address(500, &cl.get_new_address(None, None).unwrap().assume_checked())
76+
.generate_to_address(500, &cl.new_address().unwrap())
7677
.unwrap();
77-
assert_eq!(blocks.len(), 500);
78+
assert_eq!(blocks.0.len(), 500);
7879

7980
// Next send some btc to each address corresponding to the miniscript
8081
let mut txids = vec![];
8182
for wsh in desc_vec.iter() {
8283
let txid = cl
83-
.send_to_address(
84-
&wsh.address(bitcoin::Network::Regtest).unwrap(),
85-
btc(1),
86-
None,
87-
None,
88-
None,
89-
None,
90-
None,
91-
None,
92-
)
93-
.unwrap();
84+
.send_to_address(&wsh.address(bitcoin::Network::Regtest).unwrap(), btc(1))
85+
.expect("rpc call failed")
86+
.txid()
87+
.expect("conversion to model failed");
9488
txids.push(txid);
9589
}
9690
// Wait for the funds to mature.
9791
let blocks = cl
98-
.generate_to_address(50, &cl.get_new_address(None, None).unwrap().assume_checked())
92+
.generate_to_address(50, &cl.new_address().unwrap())
9993
.unwrap();
100-
assert_eq!(blocks.len(), 50);
94+
assert_eq!(blocks.0.len(), 50);
10195
// Create a PSBT for each transaction.
10296
// Spend one input and spend one output for simplicity.
10397
let mut psbts = vec![];
@@ -131,9 +125,8 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
131125
// the node wallet tracks the receiving transaction
132126
// and we can check it by gettransaction RPC.
133127
let addr = cl
134-
.get_new_address(None, Some(json::AddressType::Bech32))
135-
.unwrap()
136-
.assume_checked();
128+
.new_address_with_type(AddressType::Bech32)
129+
.unwrap();
137130
psbt.unsigned_tx.output.push(TxOut {
138131
value: Amount::from_sat(99_999_000),
139132
script_pubkey: addr.script_pubkey(),
@@ -215,19 +208,21 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
215208
// Check whether the node accepts the transactions
216209
let txid = cl
217210
.send_raw_transaction(&tx)
218-
.unwrap_or_else(|_| panic!("{} send tx failed for ms {}", i, ms));
211+
.unwrap_or_else(|_| panic!("{} send tx failed for ms {}", i, ms))
212+
.txid()
213+
.expect("conversion to model failed");
219214
spend_txids.push(txid);
220215
}
221216
}
222217
// Finally mine the blocks and await confirmations
223218
let _blocks = cl
224-
.generate_to_address(10, &cl.get_new_address(None, None).unwrap().assume_checked())
219+
.generate_to_address(10, &cl.new_address().unwrap())
225220
.unwrap();
226221
// Get the required transactions from the node mined in the blocks.
227222
for txid in spend_txids {
228223
// Check whether the transaction is mined in blocks
229224
// Assert that the confirmations are > 0.
230-
let num_conf = cl.get_transaction(&txid, None).unwrap().info.confirmations;
225+
let num_conf = cl.get_transaction(txid).unwrap().confirmations;
231226
assert!(num_conf > 0);
232227
}
233228
}

bitcoind-tests/tests/test_desc.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use bitcoin::{
1717
absolute, psbt, secp256k1, sighash, transaction, Amount, OutPoint, Sequence, Transaction, TxIn,
1818
TxOut, Txid,
1919
};
20-
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
20+
use bitcoind::{Client, AddressType};
2121
use miniscript::bitcoin::{self, ecdsa, taproot, ScriptBuf};
2222
use miniscript::psbt::{PsbtExt, PsbtInputExt};
2323
use miniscript::{Descriptor, Miniscript, ScriptContext, ToPublicKey};
@@ -30,11 +30,12 @@ fn btc<F: Into<f64>>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() }
3030

3131
// Find the Outpoint by spk
3232
fn get_vout(cl: &Client, txid: Txid, value: Amount, spk: ScriptBuf) -> (OutPoint, TxOut) {
33-
let tx = cl
34-
.get_transaction(&txid, None)
35-
.unwrap()
36-
.transaction()
37-
.unwrap();
33+
let model = cl.get_transaction(txid)
34+
.expect("rpc call failed")
35+
.into_model()
36+
.expect("conversion to model type failed");
37+
let tx = model.tx;
38+
3839
for (i, txout) in tx.output.into_iter().enumerate() {
3940
if txout.value == value && spk == txout.script_pubkey {
4041
return (OutPoint::new(txid, i as u32), txout);
@@ -77,9 +78,9 @@ pub fn test_desc_satisfy(
7778
let x_only_pks = &testdata.pubdata.x_only_pks;
7879
// Generate some blocks
7980
let blocks = cl
80-
.generate_to_address(1, &cl.get_new_address(None, None).unwrap().assume_checked())
81+
.generate_to_address(1, &cl.new_address().unwrap())
8182
.unwrap();
82-
assert_eq!(blocks.len(), 1);
83+
assert_eq!(blocks.0.len(), 1);
8384

8485
let definite_desc = test_util::parse_test_desc(descriptor, &testdata.pubdata)
8586
.map_err(|_| DescError::DescParseError)?
@@ -92,13 +93,15 @@ pub fn test_desc_satisfy(
9293

9394
// Next send some btc to each address corresponding to the miniscript
9495
let txid = cl
95-
.send_to_address(&desc_address, btc(1), None, None, None, None, None, None)
96-
.unwrap();
96+
.send_to_address(&desc_address, btc(1))
97+
.expect("rpc call failed")
98+
.txid()
99+
.expect("conversion to model failed");
97100
// Wait for the funds to mature.
98101
let blocks = cl
99-
.generate_to_address(2, &cl.get_new_address(None, None).unwrap().assume_checked())
102+
.generate_to_address(2, &cl.new_address().unwrap())
100103
.unwrap();
101-
assert_eq!(blocks.len(), 2);
104+
assert_eq!(blocks.0.len(), 2);
102105
// Create a PSBT for each transaction.
103106
// Spend one input and spend one output for simplicity.
104107
let mut psbt = Psbt {
@@ -130,9 +133,8 @@ pub fn test_desc_satisfy(
130133
// the node wallet tracks the receiving transaction
131134
// and we can check it by gettransaction RPC.
132135
let addr = cl
133-
.get_new_address(None, Some(json::AddressType::Bech32))
134-
.unwrap()
135-
.assume_checked();
136+
.new_address_with_type(AddressType::Bech32)
137+
.unwrap();
136138
// Had to decrease 'value', so that fees can be increased
137139
// (Was getting insufficient fees error, for deep script trees)
138140
psbt.unsigned_tx
@@ -287,16 +289,18 @@ pub fn test_desc_satisfy(
287289
// Check whether the node accepts the transactions
288290
let txid = cl
289291
.send_raw_transaction(&tx)
290-
.unwrap_or_else(|_| panic!("send tx failed for desc {}", definite_desc));
292+
.unwrap_or_else(|_| panic!("send tx failed for desc {}", definite_desc))
293+
.txid()
294+
.expect("conversion to model failed");
291295

292296
// Finally mine the blocks and await confirmations
293297
let _blocks = cl
294-
.generate_to_address(1, &cl.get_new_address(None, None).unwrap().assume_checked())
298+
.generate_to_address(1, &cl.new_address().unwrap())
295299
.unwrap();
296300
// Get the required transactions from the node mined in the blocks.
297301
// Check whether the transaction is mined in blocks
298302
// Assert that the confirmations are > 0.
299-
let num_conf = cl.get_transaction(&txid, None).unwrap().info.confirmations;
303+
let num_conf = cl.get_transaction(txid).unwrap().confirmations;
300304
assert!(num_conf > 0);
301305
Ok(tx.input[0].witness.clone())
302306
}

0 commit comments

Comments
 (0)