Skip to content

Commit feddf4e

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 13b65fe commit feddf4e

File tree

5 files changed

+106
-70
lines changed

5 files changed

+106
-70
lines changed

.github/workflows/rust.yml

+31-12
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,39 @@ jobs:
182182
- name: "Check formatting"
183183
run: cargo +nightly fmt --all -- --check
184184

185-
Int-tests:
186-
name: Integration tests
185+
Integration: # 1 job for each bitcoind version we support.
186+
name: Integration tests - stable toolchain
187187
runs-on: ubuntu-latest
188+
strategy:
189+
fail-fast: false
190+
matrix:
191+
feature:
192+
[
193+
"26_0",
194+
"25_2",
195+
"25_1",
196+
"25_0",
197+
"24_2",
198+
"24_1",
199+
"24_0_1",
200+
"23_2",
201+
"23_1",
202+
"23_0",
203+
"22_1",
204+
"22_0",
205+
"0_21_2",
206+
"0_20_2",
207+
"0_19_1",
208+
"0_18_1",
209+
"0_17_1",
210+
]
188211
steps:
189-
- name: Checkout Crate
190-
uses: actions/checkout@v2
191-
- name: Checkout Toolchain
192-
uses: actions-rs/toolchain@v1
193-
with:
194-
profile: minimal
195-
toolchain: stable
196-
override: true
197-
- name: Running integration tests
198-
run: ./contrib/integration_test.sh
212+
- name: "Checkout repo"
213+
uses: actions/checkout@v4
214+
- name: "Select toolchain"
215+
uses: dtolnay/rust-toolchain@stable
216+
- name: "Run integration tests"
217+
run: cd bitcoind-tests && cargo test --features=${{ matrix.feature }}
199218

200219
Embedded:
201220
runs-on: ubuntu-latest

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

+10-10
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,15 @@ 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

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

bitcoind-tests/tests/test_cpp.rs

+22-28
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::{AddressType, Client};
1818
use miniscript::bitcoin::absolute;
1919
use miniscript::psbt::PsbtExt;
2020
use miniscript::{bitcoin, DefiniteDescriptorKey, Descriptor};
@@ -52,11 +52,13 @@ 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
56+
.get_transaction(txid)
57+
.expect("rpc call failed")
58+
.into_model()
59+
.expect("conversion to model type failed");
60+
let tx = model.tx;
61+
6062
for (i, txout) in tx.output.into_iter().enumerate() {
6163
if txout.value == value {
6264
return (OutPoint::new(txid, i as u32), txout);
@@ -72,32 +74,25 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
7274
let pks = &testdata.pubdata.pks;
7375
// Generate some blocks
7476
let blocks = cl
75-
.generate_to_address(500, &cl.get_new_address(None, None).unwrap().assume_checked())
77+
.generate_to_address(500, &cl.new_address().unwrap())
7678
.unwrap();
77-
assert_eq!(blocks.len(), 500);
79+
assert_eq!(blocks.0.len(), 500);
7880

7981
// Next send some btc to each address corresponding to the miniscript
8082
let mut txids = vec![];
8183
for wsh in desc_vec.iter() {
8284
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();
85+
.send_to_address(&wsh.address(bitcoin::Network::Regtest).unwrap(), btc(1))
86+
.expect("rpc call failed")
87+
.txid()
88+
.expect("conversion to model failed");
9489
txids.push(txid);
9590
}
9691
// Wait for the funds to mature.
9792
let blocks = cl
98-
.generate_to_address(50, &cl.get_new_address(None, None).unwrap().assume_checked())
93+
.generate_to_address(50, &cl.new_address().unwrap())
9994
.unwrap();
100-
assert_eq!(blocks.len(), 50);
95+
assert_eq!(blocks.0.len(), 50);
10196
// Create a PSBT for each transaction.
10297
// Spend one input and spend one output for simplicity.
10398
let mut psbts = vec![];
@@ -130,10 +125,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
130125
// Get a new script pubkey from the node so that
131126
// the node wallet tracks the receiving transaction
132127
// and we can check it by gettransaction RPC.
133-
let addr = cl
134-
.get_new_address(None, Some(json::AddressType::Bech32))
135-
.unwrap()
136-
.assume_checked();
128+
let addr = cl.new_address_with_type(AddressType::Bech32).unwrap();
137129
psbt.unsigned_tx.output.push(TxOut {
138130
value: Amount::from_sat(99_999_000),
139131
script_pubkey: addr.script_pubkey(),
@@ -215,19 +207,21 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
215207
// Check whether the node accepts the transactions
216208
let txid = cl
217209
.send_raw_transaction(&tx)
218-
.unwrap_or_else(|_| panic!("{} send tx failed for ms {}", i, ms));
210+
.unwrap_or_else(|_| panic!("{} send tx failed for ms {}", i, ms))
211+
.txid()
212+
.expect("conversion to model failed");
219213
spend_txids.push(txid);
220214
}
221215
}
222216
// Finally mine the blocks and await confirmations
223217
let _blocks = cl
224-
.generate_to_address(10, &cl.get_new_address(None, None).unwrap().assume_checked())
218+
.generate_to_address(10, &cl.new_address().unwrap())
225219
.unwrap();
226220
// Get the required transactions from the node mined in the blocks.
227221
for txid in spend_txids {
228222
// Check whether the transaction is mined in blocks
229223
// Assert that the confirmations are > 0.
230-
let num_conf = cl.get_transaction(&txid, None).unwrap().info.confirmations;
224+
let num_conf = cl.get_transaction(txid).unwrap().confirmations;
231225
assert!(num_conf > 0);
232226
}
233227
}

bitcoind-tests/tests/test_desc.rs

+22-19
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::{AddressType, Client};
2121
use miniscript::bitcoin::{self, ecdsa, taproot, ScriptBuf};
2222
use miniscript::psbt::{PsbtExt, PsbtInputExt};
2323
use miniscript::{Descriptor, Miniscript, ScriptContext, ToPublicKey};
@@ -30,11 +30,13 @@ 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
34+
.get_transaction(txid)
35+
.expect("rpc call failed")
36+
.into_model()
37+
.expect("conversion to model type failed");
38+
let tx = model.tx;
39+
3840
for (i, txout) in tx.output.into_iter().enumerate() {
3941
if txout.value == value && spk == txout.script_pubkey {
4042
return (OutPoint::new(txid, i as u32), txout);
@@ -77,9 +79,9 @@ pub fn test_desc_satisfy(
7779
let x_only_pks = &testdata.pubdata.x_only_pks;
7880
// Generate some blocks
7981
let blocks = cl
80-
.generate_to_address(1, &cl.get_new_address(None, None).unwrap().assume_checked())
82+
.generate_to_address(1, &cl.new_address().unwrap())
8183
.unwrap();
82-
assert_eq!(blocks.len(), 1);
84+
assert_eq!(blocks.0.len(), 1);
8385

8486
let definite_desc = test_util::parse_test_desc(descriptor, &testdata.pubdata)
8587
.map_err(|_| DescError::DescParseError)?
@@ -92,13 +94,15 @@ pub fn test_desc_satisfy(
9294

9395
// Next send some btc to each address corresponding to the miniscript
9496
let txid = cl
95-
.send_to_address(&desc_address, btc(1), None, None, None, None, None, None)
96-
.unwrap();
97+
.send_to_address(&desc_address, btc(1))
98+
.expect("rpc call failed")
99+
.txid()
100+
.expect("conversion to model failed");
97101
// Wait for the funds to mature.
98102
let blocks = cl
99-
.generate_to_address(2, &cl.get_new_address(None, None).unwrap().assume_checked())
103+
.generate_to_address(2, &cl.new_address().unwrap())
100104
.unwrap();
101-
assert_eq!(blocks.len(), 2);
105+
assert_eq!(blocks.0.len(), 2);
102106
// Create a PSBT for each transaction.
103107
// Spend one input and spend one output for simplicity.
104108
let mut psbt = Psbt {
@@ -129,10 +133,7 @@ pub fn test_desc_satisfy(
129133
// Get a new script pubkey from the node so that
130134
// the node wallet tracks the receiving transaction
131135
// and we can check it by gettransaction RPC.
132-
let addr = cl
133-
.get_new_address(None, Some(json::AddressType::Bech32))
134-
.unwrap()
135-
.assume_checked();
136+
let addr = cl.new_address_with_type(AddressType::Bech32).unwrap();
136137
// Had to decrease 'value', so that fees can be increased
137138
// (Was getting insufficient fees error, for deep script trees)
138139
psbt.unsigned_tx
@@ -287,16 +288,18 @@ pub fn test_desc_satisfy(
287288
// Check whether the node accepts the transactions
288289
let txid = cl
289290
.send_raw_transaction(&tx)
290-
.unwrap_or_else(|_| panic!("send tx failed for desc {}", definite_desc));
291+
.unwrap_or_else(|_| panic!("send tx failed for desc {}", definite_desc))
292+
.txid()
293+
.expect("conversion to model failed");
291294

292295
// Finally mine the blocks and await confirmations
293296
let _blocks = cl
294-
.generate_to_address(1, &cl.get_new_address(None, None).unwrap().assume_checked())
297+
.generate_to_address(1, &cl.new_address().unwrap())
295298
.unwrap();
296299
// Get the required transactions from the node mined in the blocks.
297300
// Check whether the transaction is mined in blocks
298301
// Assert that the confirmations are > 0.
299-
let num_conf = cl.get_transaction(&txid, None).unwrap().info.confirmations;
302+
let num_conf = cl.get_transaction(txid).unwrap().confirmations;
300303
assert!(num_conf > 0);
301304
Ok(tx.input[0].witness.clone())
302305
}

0 commit comments

Comments
 (0)