Skip to content

Commit eeb4f30

Browse files
committed
Unify integration_test into_model() calls
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.
1 parent 648d812 commit eeb4f30

File tree

19 files changed

+288
-243
lines changed

19 files changed

+288
-243
lines changed

integration_test/tests/blockchain.rs

Lines changed: 28 additions & 23 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);
@@ -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/generating.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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;
@@ -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

@@ -51,7 +52,7 @@ fn generating__generate__modelled() {
5152

5253
let json: Generate = node.client.generate(NBLOCKS).expect("generate");
5354

54-
let model: Result<mtype::Generate, _> = json.into_model();
55+
let model: Result<mtype::Generate, hex::HexToArrayError> = json.into_model();
5556
model.unwrap();
5657
}
5758

@@ -64,8 +65,8 @@ fn generating__generate_to_address__modelled() {
6465

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

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

7172
#[cfg(not(feature = "v19_and_below"))]
@@ -78,8 +79,8 @@ fn generating__generate_to_descriptor__modelled() {
7879
let descriptor = format!("addr({})", address);
7980

8081
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();
82+
let model: Result<mtype::GenerateToDescriptor, hex::HexToArrayError> = json.into_model();
83+
model.unwrap();
8384
}
8485

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

105106
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);
107+
108+
let json: GetBestBlockHash = node.client.get_best_block_hash().expect("getbestblockhash");
109+
let model: Result<mtype::GetBestBlockHash, hex::HexToArrayError> = json.into_model();
110+
let best_block = model.unwrap();
111+
112+
assert_eq!(old_best_block, best_block.0);
109113
}

integration_test/tests/mining.rs

Lines changed: 6 additions & 5 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]
@@ -77,8 +78,8 @@ fn mining__prioritise_transaction() {
7778

7879
let (_addr, txid) = node.create_mempool_transaction();
7980
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.
81+
let json = node.client.prioritise_transaction(&txid, fee_delta).expect("prioritisetransaction");
82+
assert!(json) // According to docs always returns true.
8283
}
8384

8485
#[test]
@@ -93,8 +94,8 @@ fn mining__submit_block() {
9394
node3.mine_a_block();
9495

9596
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");
97+
let json: GetBlockTemplate = node1.client.get_block_template(&options).expect("getblocktemplate");
98+
let template: mtype::GetBlockTemplate = json.into_model().unwrap();
9899

99100
submit_empty_block(&node1, &template);
100101
// submit_block_with_dummy_coinbase(&node1, &template);

0 commit comments

Comments
 (0)