Skip to content

Commit 0e3f028

Browse files
committed
Merge #349: Unify the into_model style in integration tests
4fcbef1 Unify test version feature gate placement (Jamil Lambert, PhD) eeb4f30 Unify integration_test into_model() calls (Jamil Lambert, PhD) Pull request description: #348 describes the problem. - There is a variation in the way `into_model()` is used, e.g. `unwrap()` vs `expect()`, `using let _ =` or not, explicit error typing. Make all occurrences in `integration_test` the same. Explicitly state the error type, this required some new imports in the test files and exports in types. - `NumericError` exported in types v17 and reexported up to v29. - `WalletProcessPsbtError` exported in v26 and reexported up to v29. - There is a variation in placing the version feature gate above or below the test attribute. Change them all to be consistent. ACKs for top commit: tcharding: ACK 4fcbef1 Tree-SHA512: 6d91614c7f01fecfcba87a8c9481fbbdc62c64edeedfd394115845e9360d15bdae117f9335d952178a7fbc21d0a49e51aaf8920a16d1f711322a702df755ef09
2 parents 648d812 + 4fcbef1 commit 0e3f028

File tree

20 files changed

+308
-265
lines changed

20 files changed

+308
-265
lines changed

integration_test/tests/blockchain.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
#![allow(non_snake_case)] // Test names intentionally use double underscore.
66

7+
use bitcoin::hex;
8+
use bitcoin::consensus::encode;
79
use integration_test::{Node, NodeExt as _, Wallet};
810
use node::client::client_sync;
911
use node::vtype::*; // All the version specific types.
@@ -38,8 +40,8 @@ fn blockchain__dump_tx_out_set__modelled() {
3840
fn blockchain__get_best_block_hash__modelled() {
3941
let node = Node::with_wallet(Wallet::None, &[]);
4042

41-
let json = node.client.get_best_block_hash().expect("rpc");
42-
let model: Result<mtype::GetBestBlockHash, _> = json.into_model();
43+
let json: GetBestBlockHash = node.client.get_best_block_hash().expect("getbestblockhash");
44+
let model: Result<mtype::GetBestBlockHash, hex::HexToArrayError> = json.into_model();
4345
model.unwrap();
4446
}
4547

@@ -49,12 +51,12 @@ fn blockchain__get_block__modelled() {
4951
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
5052

5153
let json: GetBlockVerboseZero = node.client.get_block_verbose_zero(block_hash).expect("getblock verbose=0");
52-
let model: Result<mtype::GetBlockVerboseZero, _> = json.into_model();
53-
model.expect("GetBlock into model");
54+
let model: Result<mtype::GetBlockVerboseZero, encode::FromHexError> = json.into_model();
55+
model.unwrap();
5456

5557
let json: GetBlockVerboseOne = node.client.get_block_verbose_one(block_hash).expect("getblock verbose=1");
5658
let model: Result<mtype::GetBlockVerboseOne, GetBlockVerboseOneError> = json.into_model();
57-
model.expect("GetBlockVerbose into model");
59+
model.unwrap();
5860

5961
// TODO: Test getblock 2
6062
// let json = node.client.get_block_with_verbosity(block_hash, 2).expect("getblock verbosity 2");
@@ -126,7 +128,7 @@ fn blockchain__get_block_hash__modelled() {
126128
let node = Node::with_wallet(Wallet::None, &[]);
127129

128130
let json: GetBlockHash = node.client.get_block_hash(0).expect("getblockhash");
129-
let model: Result<mtype::GetBlockHash, _> = json.into_model();
131+
let model: Result<mtype::GetBlockHash, hex::HexToArrayError> = json.into_model();
130132
model.unwrap();
131133
}
132134

@@ -161,13 +163,15 @@ fn getblockstats() {
161163
let node = Node::with_wallet(Wallet::Default, &[]);
162164
node.fund_wallet();
163165

164-
let json = node.client.get_block_stats_by_height(1).expect("getblockstats");
165-
json.into_model().unwrap();
166+
let json: GetBlockStats = node.client.get_block_stats_by_height(1).expect("getblockstats");
167+
let model: Result<mtype::GetBlockStats, GetBlockStatsError> = json.into_model();
168+
model.unwrap();
166169

167170
// No need for explicit types, used explicitly in test below.
168171
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
169-
let json = node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
170-
json.into_model().unwrap();
172+
let json: GetBlockStats = node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
173+
let model: Result<mtype::GetBlockStats, GetBlockStatsError> = json.into_model();
174+
model.unwrap();
171175
}
172176

173177
fn getblockstats_txindex() {
@@ -177,12 +181,13 @@ fn getblockstats_txindex() {
177181
// Get block stats by height.
178182
let json: GetBlockStats = node.client.get_block_stats_by_height(101).expect("getblockstats");
179183
let model: Result<mtype::GetBlockStats, GetBlockStatsError> = json.into_model();
180-
model.expect("GetBlockStats into model");
184+
model.unwrap();
181185

182186
// Get block stats by block hash.
183187
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
184-
let json = node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
185-
json.into_model().unwrap();
188+
let json: GetBlockStats = node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
189+
let model: Result<mtype::GetBlockStats, GetBlockStatsError> = json.into_model();
190+
model.unwrap();
186191
}
187192

188193
#[test]
@@ -193,7 +198,7 @@ fn blockchain__get_chain_states__modelled() {
193198
let (_address, _tx) = node.create_mined_transaction();
194199

195200
let json: GetChainStates = node.client.get_chain_states().expect("getchainstates");
196-
let model: Result<mtype::GetChainStates, _> = json.into_model();
201+
let model: Result<mtype::GetChainStates, GetChainStatesError> = json.into_model();
197202
let chain_states = model.unwrap();
198203

199204
assert!(chain_states.chain_states[0].blocks > 0);
@@ -255,7 +260,7 @@ fn blockchain__get_mempool_ancestors__modelled() {
255260

256261
let json: GetMempoolAncestors =
257262
node.client.get_mempool_ancestors(child_txid).expect("getmempoolancestors");
258-
let model: Result<mtype::GetMempoolAncestors, _> = json.into_model();
263+
let model: Result<mtype::GetMempoolAncestors, hex::HexToArrayError> = json.into_model();
259264
let ancestors = model.unwrap();
260265

261266
assert!(ancestors.0.contains(&parent_txid));
@@ -272,7 +277,7 @@ fn blockchain__get_mempool_ancestors_verbose__modelled() {
272277
.client
273278
.get_mempool_ancestors_verbose(child_txid)
274279
.expect("getmempoolancestors verbose");
275-
let model: Result<mtype::GetMempoolAncestorsVerbose, _> = json.into_model();
280+
let model: Result<mtype::GetMempoolAncestorsVerbose, MapMempoolEntryError> = json.into_model();
276281
let ancestors = model.unwrap();
277282

278283
assert!(ancestors.0.contains_key(&parent_txid));
@@ -287,7 +292,7 @@ fn blockchain__get_mempool_descendants__modelled() {
287292

288293
let json: GetMempoolDescendants =
289294
node.client.get_mempool_descendants(parent_txid).expect("getmempooldescendants");
290-
let model: Result<mtype::GetMempoolDescendants, _> = json.into_model();
295+
let model: Result<mtype::GetMempoolDescendants, hex::HexToArrayError> = json.into_model();
291296
let descendants = model.unwrap();
292297

293298
assert!(descendants.0.contains(&child_txid));
@@ -304,7 +309,7 @@ fn blockchain__get_mempool_descendants_verbose__modelled() {
304309
.client
305310
.get_mempool_descendants_verbose(parent_txid)
306311
.expect("getmempooldescendants verbose");
307-
let model: Result<mtype::GetMempoolDescendantsVerbose, _> = json.into_model();
312+
let model: Result<mtype::GetMempoolDescendantsVerbose, MapMempoolEntryError> = json.into_model();
308313
let descendants = model.unwrap();
309314

310315
assert!(descendants.0.contains_key(&child_txid));
@@ -343,7 +348,7 @@ fn blockchain__get_raw_mempool__modelled() {
343348

344349
// verbose = false
345350
let json: GetRawMempool = node.client.get_raw_mempool().expect("getrawmempool");
346-
let model: Result<mtype::GetRawMempool, _> = json.clone().into_model();
351+
let model: Result<mtype::GetRawMempool, hex::HexToArrayError> = json.clone().into_model();
347352
let mempool = model.unwrap();
348353
// Sanity check.
349354
assert_eq!(mempool.0.len(), 1);
@@ -474,8 +479,8 @@ fn blockchain__savemempool() {
474479
}
475480
}
476481

477-
#[cfg(not(feature = "v24_and_below"))]
478482
#[test]
483+
#[cfg(not(feature = "v24_and_below"))]
479484
fn blockchain__scan_blocks_modelled() {
480485
let node = Node::with_wallet(Wallet::None, &["-blockfilterindex=1"]);
481486

@@ -519,7 +524,7 @@ fn verify_tx_out_proof(node: &Node) -> Result<(), client_sync::Error> {
519524
let proof = node.client.get_tx_out_proof(&[txid])?;
520525

521526
let json: VerifyTxOutProof = node.client.verify_tx_out_proof(&proof)?;
522-
let model: Result<mtype::VerifyTxOutProof, _> = json.into_model();
527+
let model: Result<mtype::VerifyTxOutProof, hex::HexToArrayError> = json.into_model();
523528
let txids = model.unwrap();
524529

525530
// sanity check
@@ -547,9 +552,9 @@ fn create_child_spending_parent(node: &Node, parent_txid: bitcoin::Txid) -> bitc
547552
.client
548553
.sign_raw_transaction_with_wallet(&funded_tx)
549554
.expect("signrawtransactionwithwallet");
550-
let model = signed.into_model().expect("SignRawTransactionWithWallet into model");
551-
let child_txid = model.tx.compute_txid();
552-
let _ = node.client.send_raw_transaction(&model.tx).expect("sendrawtransaction");
555+
let sign_raw_transaction = signed.into_model().expect("SignRawTransactionWithWallet into model");
556+
let child_txid = sign_raw_transaction.tx.compute_txid();
557+
let _ = node.client.send_raw_transaction(&sign_raw_transaction.tx).expect("sendrawtransaction");
553558

554559
child_txid
555560
}

integration_test/tests/control.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fn control__get_memory_info() {
1313
let _: GetMemoryInfoStats = node.client.get_memory_info().unwrap();
1414
}
1515

16-
#[cfg(not(feature = "v17"))]
1716
#[test]
17+
#[cfg(not(feature = "v17"))]
1818
fn control__get_rpc_info() {
1919
let node = Node::with_wallet(Wallet::None, &[]);
2020
let _ = node.client.get_rpc_info().unwrap();

integration_test/tests/generating.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
55
#![allow(non_snake_case)] // Test names intentionally use double underscore.
66

7+
use bitcoin::hex;
78
use integration_test::{Node, NodeExt as _, Wallet};
89
use node::vtype::*; // All the version specific types.
910
use node::mtype;
1011

11-
#[cfg(not(feature = "v20_and_below"))]
1212
#[test]
13+
#[cfg(not(feature = "v20_and_below"))]
1314
fn generating__generate_block__modelled() {
1415
let node = Node::with_wallet(Wallet::Default, &[]);
1516
node.fund_wallet();
@@ -29,7 +30,7 @@ fn generating__generate_block__modelled() {
2930
{
3031
// No `submit` argument
3132
json = node.client.generate_block(&mining_addr.to_string(), &transactions).expect("generateblock");
32-
let model: Result<mtype::GenerateBlock, _> = json.into_model();
33+
let model: Result<mtype::GenerateBlock, hex::HexToArrayError> = json.into_model();
3334
model.unwrap();
3435
}
3536

@@ -43,15 +44,14 @@ fn generating__generate_block__modelled() {
4344
}
4445

4546
#[test]
46-
// The `generate` method was deprecated in Core v0.18 and was removed in v0.19.
4747
#[cfg(feature = "v17")]
4848
fn generating__generate__modelled() {
4949
const NBLOCKS: usize = 10;
5050
let node = Node::with_wallet(Wallet::Default, &[]);
5151

5252
let json: Generate = node.client.generate(NBLOCKS).expect("generate");
5353

54-
let model: Result<mtype::Generate, _> = json.into_model();
54+
let model: Result<mtype::Generate, hex::HexToArrayError> = json.into_model();
5555
model.unwrap();
5656
}
5757

@@ -64,12 +64,12 @@ fn generating__generate_to_address__modelled() {
6464

6565
let json: GenerateToAddress = node.client.generate_to_address(NBLOCKS, &address).expect("generatetoaddress");
6666

67-
let model: Result<mtype::GenerateToAddress, _> = json.into_model();
68-
let _ = model.unwrap();
67+
let model: Result<mtype::GenerateToAddress, hex::HexToArrayError> = json.into_model();
68+
model.unwrap();
6969
}
7070

71-
#[cfg(not(feature = "v19_and_below"))]
7271
#[test]
72+
#[cfg(not(feature = "v19_and_below"))]
7373
fn generating__generate_to_descriptor__modelled() {
7474
const NBLOCKS: usize = 1;
7575

@@ -78,8 +78,8 @@ fn generating__generate_to_descriptor__modelled() {
7878
let descriptor = format!("addr({})", address);
7979

8080
let json: GenerateToDescriptor = node.client.generate_to_descriptor(NBLOCKS, &descriptor).expect("generatetodescriptor");
81-
let model: Result<mtype::GenerateToDescriptor, _> = json.into_model();
82-
let _ = model.unwrap();
81+
let model: Result<mtype::GenerateToDescriptor, hex::HexToArrayError> = json.into_model();
82+
model.unwrap();
8383
}
8484

8585
// This method does not appear in the output of `bitcoin-cli help`.
@@ -103,7 +103,10 @@ fn generating__invalidate_block() {
103103
assert_ne!(old_best_block, new_best_block);
104104

105105
node.client.invalidate_block(new_best_block).expect("invalidateblock");
106-
let best_block =
107-
node.client.get_best_block_hash().expect("getbestblockhash").into_model().unwrap().0;
108-
assert_eq!(old_best_block, best_block);
106+
107+
let json: GetBestBlockHash = node.client.get_best_block_hash().expect("getbestblockhash");
108+
let model: Result<mtype::GetBestBlockHash, hex::HexToArrayError> = json.into_model();
109+
let best_block = model.unwrap();
110+
111+
assert_eq!(old_best_block, best_block.0);
109112
}

integration_test/tests/mining.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ fn mining__get_block_template__modelled() {
3232

3333
let json: GetBlockTemplate = node1.client.get_block_template(&options)
3434
.expect("get_block_template RPC failed");
35-
let _: Result<mtype::GetBlockTemplate, GetBlockTemplateError> = json.into_model();
35+
let model: Result<mtype::GetBlockTemplate, GetBlockTemplateError> = json.into_model();
36+
model.unwrap();
3637
}
3738

3839
#[test]
@@ -61,7 +62,6 @@ fn mining__get_network_hash_ps() {
6162
}
6263

6364
#[test]
64-
// Core version 26 onwards.
6565
#[cfg(not(feature = "v25_and_below"))]
6666
fn mining__get_prioritised_transactions() {
6767
let node = Node::with_wallet(Wallet::Default, &[]);
@@ -77,8 +77,8 @@ fn mining__prioritise_transaction() {
7777

7878
let (_addr, txid) = node.create_mempool_transaction();
7979
let fee_delta = SignedAmount::from_sat(10_000);
80-
let res = node.client.prioritise_transaction(&txid, fee_delta).expect("prioritisetransaction");
81-
assert!(res) // According to docs always returns true.
80+
let json = node.client.prioritise_transaction(&txid, fee_delta).expect("prioritisetransaction");
81+
assert!(json) // According to docs always returns true.
8282
}
8383

8484
#[test]
@@ -93,8 +93,8 @@ fn mining__submit_block() {
9393
node3.mine_a_block();
9494

9595
let options = TemplateRequest { rules: vec![TemplateRules::Segwit] };
96-
let json = node1.client.get_block_template(&options).expect("getblocktemplate");
97-
let template = json.into_model().expect("GetBlockTemplate into model");
96+
let json: GetBlockTemplate = node1.client.get_block_template(&options).expect("getblocktemplate");
97+
let template: mtype::GetBlockTemplate = json.into_model().unwrap();
9898

9999
submit_empty_block(&node1, &template);
100100
// submit_block_with_dummy_coinbase(&node1, &template);
@@ -211,8 +211,8 @@ fn mining__submit_block_with_dummy_coinbase(node: &Node, bt: &mtype::GetBlockTem
211211
let _: () = node.client.submit_block(&block).expect("submitblock");
212212
}
213213

214-
#[cfg(not(feature = "v17"))]
215214
#[test]
215+
#[cfg(not(feature = "v17"))]
216216
fn mining__submit_header() {
217217
let node = Node::with_wallet(Wallet::Default, &[]);
218218
node.fund_wallet();

0 commit comments

Comments
 (0)