Skip to content

Commit 002fc77

Browse files
committed
integration_test: Add explicit types everywhere
Fixes #612
1 parent 2a3a3b8 commit 002fc77

15 files changed

Lines changed: 208 additions & 183 deletions

integration_test/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ use std::path::PathBuf;
44

55
use bitcoin::bip32::{Fingerprint, Xpriv, Xpub};
66
use bitcoin::secp256k1::{Secp256k1, XOnlyPublicKey};
7-
use bitcoin::Network;
7+
use bitcoin::{Address, Block, BlockHash, Network, Transaction};
8+
use bitcoind::vtype::GetPeerInfo;
89
use bitcoind::{Conf, P2P};
910
use rand::distributions::Alphanumeric;
1011
use rand::Rng;
1112

1213
#[rustfmt::skip] // Keep public re-exports separate.
13-
pub use bitcoind::BitcoinD; // Re-export this to make test imports more terse.
14+
pub use bitcoind::BitcoinD;
15+
// Re-export this to make test imports more terse.
1416

1517
/// Initialize a logger (configure with `RUST_LOG=trace cargo test`).
1618
#[allow(dead_code)] // Not all tests use this function.
@@ -76,19 +78,19 @@ impl BitcoinDExt for BitcoinD {
7678
}
7779

7880
fn fund_wallet(&self) {
79-
let address = self.client.new_address().expect("failed to get new address");
81+
let address: Address = self.client.new_address().expect("failed to get new address");
8082
self.client.generate_to_address(101, &address).expect("failed to generate to address");
8183
}
8284

8385
fn mine_a_block(&self) {
84-
let address = self.client.new_address().expect("failed to get new address");
86+
let address: Address = self.client.new_address().expect("failed to get new address");
8587
self.client.generate_to_address(1, &address).expect("failed to generate to address");
8688
}
8789

8890
fn create_mempool_transaction(&self) -> (bitcoin::Address, bitcoin::Txid) {
8991
const MILLION_SATS: bitcoin::Amount = bitcoin::Amount::from_sat(1000000);
9092

91-
let address = self.client.new_address().expect("failed to get new address");
93+
let address: Address = self.client.new_address().expect("failed to get new address");
9294

9395
let txid = self
9496
.client
@@ -103,15 +105,15 @@ impl BitcoinDExt for BitcoinD {
103105
let (address, _) = self.create_mempool_transaction();
104106
self.mine_a_block();
105107

106-
let best_block_hash = self.client.best_block_hash().expect("best_block_hash");
107-
let best_block = self.client.get_block(best_block_hash).expect("best_block");
108-
let tx = best_block.txdata[1].clone();
108+
let best_block_hash: BlockHash = self.client.best_block_hash().expect("best_block_hash");
109+
let best_block: Block = self.client.get_block(best_block_hash).expect("best_block");
110+
let tx: Transaction = best_block.txdata[1].clone();
109111

110112
(address, tx)
111113
}
112114

113115
fn peers_connected(&self) -> usize {
114-
let json = self.client.get_peer_info().expect("get_peer_info");
116+
let json: GetPeerInfo = self.client.get_peer_info().expect("get_peer_info");
115117
json.0.len()
116118
}
117119
}

integration_test/tests/blockchain.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#[cfg(feature = "v30_and_below")]
88
use bitcoin::consensus::encode;
9-
use bitcoin::hex;
9+
use bitcoin::{hex, Address, BlockHash, Transaction, Txid};
1010
use bitcoind::vtype::*; // All the version specific types.
1111
use bitcoind::{mtype, Input, Output};
1212
use integration_test::{BitcoinD, BitcoinDExt as _, Wallet};
@@ -144,7 +144,7 @@ fn blockchain__get_best_block_hash__modelled() {
144144
#[cfg(feature = "v30_and_below")]
145145
fn blockchain__get_block__modelled() {
146146
let node = BitcoinD::with_wallet(Wallet::None, &[]);
147-
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
147+
let block_hash: BlockHash = node.client.best_block_hash().expect("best_block_hash failed");
148148

149149
let json: GetBlockVerboseZero =
150150
node.client.get_block_verbose_zero(block_hash).expect("getblock verbose=0");
@@ -161,7 +161,7 @@ fn blockchain__get_block__modelled() {
161161
let node = BitcoinD::with_wallet(Wallet::Default, &[]);
162162
node.fund_wallet();
163163
let (_address, mined_tx) = node.create_mined_transaction();
164-
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
164+
let block_hash: BlockHash = node.client.best_block_hash().expect("best_block_hash failed");
165165

166166
let json: GetBlockVerboseTwo =
167167
node.client.get_block_verbose_two(block_hash).expect("getblock verbose=2");
@@ -228,7 +228,7 @@ fn blockchain__get_block_count__modelled() {
228228
fn blockchain__get_block_filter__modelled() {
229229
let node = BitcoinD::with_wallet(Wallet::Default, &["-blockfilterindex"]);
230230
node.mine_a_block();
231-
let hash = node.client.best_block_hash().expect("best_block_hash failed");
231+
let hash: BlockHash = node.client.best_block_hash().expect("best_block_hash failed");
232232

233233
let json: GetBlockFilter = node.client.get_block_filter(hash).expect("getblockfilter");
234234
let model: Result<mtype::GetBlockFilter, GetBlockFilterError> = json.into_model();
@@ -279,7 +279,7 @@ fn blockchain__get_block_hash__modelled() {
279279
#[test]
280280
fn blockchain__get_block_header__modelled() {
281281
let node = BitcoinD::with_wallet(Wallet::None, &[]);
282-
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
282+
let block_hash: BlockHash = node.client.best_block_hash().expect("best_block_hash failed");
283283

284284
// verbose = false
285285
let json: GetBlockHeader = node.client.get_block_header(&block_hash).expect("getblockheader");
@@ -321,7 +321,7 @@ fn get_block_stats_by_height(node: &BitcoinD) {
321321
}
322322

323323
fn get_block_stats_by_block_hash(node: &BitcoinD) {
324-
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
324+
let block_hash: BlockHash = node.client.best_block_hash().expect("best_block_hash failed");
325325
let json: GetBlockStats =
326326
node.client.get_block_stats_by_block_hash(&block_hash, None).expect("getblockstats");
327327

@@ -396,7 +396,7 @@ fn blockchain__get_deployment_info__modelled() {
396396
.expect("best_block_hash failed")
397397
.block_hash()
398398
.expect("block_hash parse failed");
399-
let tip_block_hash = node.client.best_block_hash().expect("best_block_hash failed");
399+
let tip_block_hash: BlockHash = node.client.best_block_hash().expect("best_block_hash failed");
400400

401401
let json: GetDeploymentInfo =
402402
node.client.get_deployment_info(&first_block_hash).expect("getdeploymentinfo");
@@ -427,7 +427,8 @@ fn blockchain__get_descriptor_activity__modelled() {
427427

428428
#[cfg(not(feature = "v29_and_below"))]
429429
{
430-
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
430+
let block_hash: BlockHash =
431+
node.client.best_block_hash().expect("best_block_hash failed");
431432
node.client
432433
.get_descriptor_activity(
433434
&[block_hash],
@@ -639,7 +640,7 @@ fn blockchain__import_mempool() {
639640
node.fund_wallet();
640641
let (_address, _tx) = node.create_mined_transaction();
641642

642-
let mempool_path = node.client.save_mempool().expect("savemempool");
643+
let mempool_path: () = node.client.save_mempool().expect("savemempool");
643644

644645
let _: () = node.client.import_mempool(&mempool_path.filename).expect("importmempool");
645646
}
@@ -648,7 +649,7 @@ fn blockchain__import_mempool() {
648649
fn blockchain__precious_block() {
649650
let node = BitcoinD::with_wallet(Wallet::Default, &[]);
650651
node.mine_a_block();
651-
let hash = node.client.best_block_hash().expect("best_block_hash failed");
652+
let hash: BlockHash = node.client.best_block_hash().expect("best_block_hash failed");
652653
node.mine_a_block();
653654

654655
let _: () = node.client.precious_block(hash).expect("preciousblock");
@@ -659,7 +660,7 @@ fn blockchain__prune_blockchain() {
659660
const NBLOCKS: usize = 1;
660661

661662
let node = BitcoinD::with_wallet(Wallet::Default, &["-prune=550"]);
662-
let address = node.client.new_address().expect("Failed to get new address");
663+
let address: Address = node.client.new_address().expect("Failed to get new address");
663664

664665
let gen_result = node
665666
.client
@@ -754,13 +755,13 @@ fn blockchain__verify_tx_out_proof__modelled() {
754755
node.fund_wallet();
755756

756757
let (_address, tx) = node.create_mined_transaction();
757-
let txid = tx.compute_txid();
758+
let txid: Txid = tx.compute_txid();
758759

759-
let proof = node.client.get_tx_out_proof(&[txid]).expect("gettxoutproof");
760+
let proof: String = node.client.get_tx_out_proof(&[txid]).expect("gettxoutproof");
760761

761762
let json: VerifyTxOutProof = node.client.verify_tx_out_proof(&proof).expect("verifytxoutproof");
762763
let model: Result<mtype::VerifyTxOutProof, hex::HexToArrayError> = json.into_model();
763-
let txids = model.unwrap();
764+
let txids: mtype::VerifyTxOutProof = model.unwrap();
764765

765766
// sanity check
766767
assert_eq!(txids.0.len(), 1);
@@ -771,7 +772,7 @@ fn blockchain__wait_for_block__modelled() {
771772
let node = BitcoinD::with_wallet(Wallet::Default, &[]);
772773
node.fund_wallet();
773774
let (_address, _tx) = node.create_mined_transaction();
774-
let block_hash = node.client.best_block_hash().expect("bestblockhash");
775+
let block_hash: BlockHash = node.client.best_block_hash().expect("bestblockhash");
775776

776777
let json: WaitForBlock = node.client.wait_for_block(&block_hash).expect("waitforblock");
777778
let model: Result<mtype::WaitForBlock, WaitForBlockError> = json.into_model();
@@ -784,8 +785,8 @@ fn blockchain__wait_for_block_height__modelled() {
784785
let node = BitcoinD::with_wallet(Wallet::Default, &[]);
785786
node.fund_wallet();
786787
let (_address, _tx) = node.create_mined_transaction();
787-
let height = node.client.get_block_count().expect("getblockcount").0;
788-
let block_hash = node.client.best_block_hash().expect("bestblockhash");
788+
let height: u64 = node.client.get_block_count().expect("getblockcount").0;
789+
let block_hash: BlockHash = node.client.best_block_hash().expect("bestblockhash");
789790
let target_height = height;
790791

791792
let json: WaitForBlockHeight =
@@ -826,16 +827,16 @@ fn blockchain__wait_for_new_block__modelled() {
826827
/// Returns the child's txid.
827828
fn create_child_spending_parent(node: &BitcoinD, parent_txid: bitcoin::Txid) -> bitcoin::Txid {
828829
let inputs = vec![Input { txid: parent_txid, vout: 0, sequence: None }];
829-
let spend_address = node.client.new_address().expect("newaddress");
830+
let spend_address: Address = node.client.new_address().expect("newaddress");
830831
let outputs = vec![Output::new(spend_address, bitcoin::Amount::from_sat(100_000))];
831832

832833
let raw: CreateRawTransaction =
833834
node.client.create_raw_transaction(&inputs, &outputs).expect("createrawtransaction");
834-
let unsigned = raw.transaction().expect("raw.transaction");
835+
let unsigned: Transaction = raw.transaction().expect("raw.transaction");
835836

836837
let funded: FundRawTransaction =
837838
node.client.fund_raw_transaction(&unsigned).expect("fundrawtransaction");
838-
let funded_tx = funded.transaction().expect("funded.transaction");
839+
let funded_tx: Transaction = funded.transaction().expect("funded.transaction");
839840

840841
let signed: SignRawTransaction = node
841842
.client
@@ -844,7 +845,8 @@ fn create_child_spending_parent(node: &BitcoinD, parent_txid: bitcoin::Txid) ->
844845
let sign_raw_transaction =
845846
signed.into_model().expect("SignRawTransactionWithWallet into model");
846847
let child_txid = sign_raw_transaction.tx.compute_txid();
847-
let _ = node.client.send_raw_transaction(&sign_raw_transaction.tx).expect("sendrawtransaction");
848+
let _: SendRawTransaction =
849+
node.client.send_raw_transaction(&sign_raw_transaction.tx).expect("sendrawtransaction");
848850

849851
child_txid
850852
}

0 commit comments

Comments
 (0)