Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 38 additions & 29 deletions integration_test/tests/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

#![allow(non_snake_case)] // Test names intentionally use double underscore.

use bitcoin::hex;
use bitcoin::consensus::encode;
use bitcoin::hex;
use integration_test::{Node, NodeExt as _, Wallet};
use node::client::client_sync;
use node::vtype::*; // All the version specific types.
use node::mtype;
use node::{Input, Output};
use node::vtype::*; // All the version specific types.
use node::{mtype, Input, Output};

#[test]
#[cfg(not(feature = "v25_and_below"))]
Expand Down Expand Up @@ -50,11 +49,13 @@ fn blockchain__get_block__modelled() {
let node = Node::with_wallet(Wallet::None, &[]);
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");

let json: GetBlockVerboseZero = node.client.get_block_verbose_zero(block_hash).expect("getblock verbose=0");
let json: GetBlockVerboseZero =
node.client.get_block_verbose_zero(block_hash).expect("getblock verbose=0");
let model: Result<mtype::GetBlockVerboseZero, encode::FromHexError> = json.into_model();
model.unwrap();

let json: GetBlockVerboseOne = node.client.get_block_verbose_one(block_hash).expect("getblock verbose=1");
let json: GetBlockVerboseOne =
node.client.get_block_verbose_one(block_hash).expect("getblock verbose=1");
let model: Result<mtype::GetBlockVerboseOne, GetBlockVerboseOneError> = json.into_model();
model.unwrap();

Expand Down Expand Up @@ -143,7 +144,8 @@ fn blockchain__get_block_header__modelled() {
model.unwrap();

// verbose = true
let json:GetBlockHeaderVerbose = node.client.get_block_header_verbose(&block_hash).expect("getblockheader");
let json: GetBlockHeaderVerbose =
node.client.get_block_header_verbose(&block_hash).expect("getblockheader");
let model: Result<mtype::GetBlockHeaderVerbose, GetBlockHeaderVerboseError> = json.into_model();
model.unwrap();
}
Expand All @@ -169,7 +171,8 @@ fn getblockstats() {

// No need for explicit types, used explicitly in test below.
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
let json: GetBlockStats = node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
let json: GetBlockStats =
node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
let model: Result<mtype::GetBlockStats, GetBlockStatsError> = json.into_model();
model.unwrap();
}
Expand All @@ -185,7 +188,8 @@ fn getblockstats_txindex() {

// Get block stats by block hash.
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
let json: GetBlockStats = node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
let json: GetBlockStats =
node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
let model: Result<mtype::GetBlockStats, GetBlockStatsError> = json.into_model();
model.unwrap();
}
Expand Down Expand Up @@ -228,7 +232,8 @@ fn blockchain__get_deployment_info__modelled() {
let node = Node::with_wallet(Wallet::None, &[]);
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");

let json: GetDeploymentInfo = node.client.get_deployment_info(&block_hash).expect("getdeploymentinfo");
let json: GetDeploymentInfo =
node.client.get_deployment_info(&block_hash).expect("getdeploymentinfo");
let model: Result<mtype::GetDeploymentInfo, GetDeploymentInfoError> = json.into_model();
model.unwrap();
}
Expand All @@ -238,7 +243,8 @@ fn blockchain__get_deployment_info__modelled() {
fn blockchain__get_descriptor_activity__modelled() {
let node = Node::with_wallet(Wallet::None, &["-coinstatsindex=1", "-txindex=1"]);

let json: GetDescriptorActivity = node.client.get_descriptor_activity().expect("getdescriptoractivity");
let json: GetDescriptorActivity =
node.client.get_descriptor_activity().expect("getdescriptoractivity");
let model: Result<mtype::GetDescriptorActivity, GetDescriptorActivityError> = json.into_model();
model.unwrap();
}
Expand Down Expand Up @@ -273,10 +279,8 @@ fn blockchain__get_mempool_ancestors_verbose__modelled() {
let (_address, parent_txid) = node.create_mempool_transaction();
let child_txid = create_child_spending_parent(&node, parent_txid);

let json: GetMempoolAncestorsVerbose = node
.client
.get_mempool_ancestors_verbose(child_txid)
.expect("getmempoolancestors verbose");
let json: GetMempoolAncestorsVerbose =
node.client.get_mempool_ancestors_verbose(child_txid).expect("getmempoolancestors verbose");
let model: Result<mtype::GetMempoolAncestorsVerbose, MapMempoolEntryError> = json.into_model();
let ancestors = model.unwrap();

Expand Down Expand Up @@ -309,7 +313,8 @@ fn blockchain__get_mempool_descendants_verbose__modelled() {
.client
.get_mempool_descendants_verbose(parent_txid)
.expect("getmempooldescendants verbose");
let model: Result<mtype::GetMempoolDescendantsVerbose, MapMempoolEntryError> = json.into_model();
let model: Result<mtype::GetMempoolDescendantsVerbose, MapMempoolEntryError> =
json.into_model();
let descendants = model.unwrap();

assert!(descendants.0.contains_key(&child_txid));
Expand Down Expand Up @@ -406,17 +411,12 @@ fn blockchain__get_tx_spending_prevout__modelled() {
let (_address2, txid_2) = node.create_mempool_transaction();

let inputs = vec![
bitcoin::OutPoint {
txid: txid_1,
vout: 0,
},
bitcoin::OutPoint {
txid: txid_2,
vout: 0,
},
bitcoin::OutPoint { txid: txid_1, vout: 0 },
bitcoin::OutPoint { txid: txid_2, vout: 0 },
];

let json: GetTxSpendingPrevout = node.client.get_tx_spending_prevout(&inputs).expect("gettxspendingprevout");
let json: GetTxSpendingPrevout =
node.client.get_tx_spending_prevout(&inputs).expect("gettxspendingprevout");
let model: Result<mtype::GetTxSpendingPrevout, GetTxSpendingPrevoutError> = json.into_model();
let spending_prevout = model.unwrap();

Expand Down Expand Up @@ -454,8 +454,15 @@ fn blockchain__prune_blockchain() {
let node = Node::with_wallet(Wallet::Default, &["-prune=550"]);
let address = node.client.new_address().expect("Failed to get new address");

let gen_result = node.client.generate_to_address(NBLOCKS, &address).expect("generate_to_address RPC call failed");
assert_eq!(gen_result.0.len(), NBLOCKS, "generate_to_address did not return the expected number of block hashes");
let gen_result = node
.client
.generate_to_address(NBLOCKS, &address)
.expect("generate_to_address RPC call failed");
assert_eq!(
gen_result.0.len(),
NBLOCKS,
"generate_to_address did not return the expected number of block hashes"
);

let target_height: u64 = 500;

Expand Down Expand Up @@ -487,7 +494,8 @@ fn blockchain__scan_blocks_modelled() {
// Arbitrary scan descriptor
let scan_desc = "pkh(022afc20bf379bc96a2f4e9e63ffceb8652b2b6a097f63fbee6ecec2a49a48010e)";

let json: ScanBlocksStart = node.client.scan_blocks_start(&[scan_desc]).expect("scanblocks start");
let json: ScanBlocksStart =
node.client.scan_blocks_start(&[scan_desc]).expect("scanblocks start");
let model: Result<mtype::ScanBlocksStart, ScanBlocksStartError> = json.into_model();
model.unwrap();

Expand Down Expand Up @@ -552,7 +560,8 @@ fn create_child_spending_parent(node: &Node, parent_txid: bitcoin::Txid) -> bitc
.client
.sign_raw_transaction_with_wallet(&funded_tx)
.expect("signrawtransactionwithwallet");
let sign_raw_transaction = signed.into_model().expect("SignRawTransactionWithWallet into model");
let sign_raw_transaction =
signed.into_model().expect("SignRawTransactionWithWallet into model");
let child_txid = sign_raw_transaction.tx.compute_txid();
let _ = node.client.send_raw_transaction(&sign_raw_transaction.tx).expect("sendrawtransaction");

Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![allow(non_snake_case)] // Test names intentionally use double underscore.

use integration_test::{Node, NodeExt as _, Wallet};
use node::vtype::*; // All the version specific types.
use node::vtype::*; // All the version specific types.

#[test]
fn control__get_memory_info() {
Expand Down
20 changes: 14 additions & 6 deletions integration_test/tests/generating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

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

#[test]
#[cfg(not(feature = "v20_and_below"))]
Expand All @@ -29,15 +29,21 @@ fn generating__generate_block__modelled() {
#[cfg(feature = "v24_and_below")]
{
// No `submit` argument
json = node.client.generate_block(&mining_addr.to_string(), &transactions).expect("generateblock");
json = node
.client
.generate_block(&mining_addr.to_string(), &transactions)
.expect("generateblock");
let model: Result<mtype::GenerateBlock, hex::HexToArrayError> = json.into_model();
model.unwrap();
}

#[cfg(not(feature = "v24_and_below"))]
{
// Check with `submit = false` so that `hex` is returned. v25 and later only.
json = node.client.generate_block(&mining_addr.to_string(), &transactions, false).expect("generateblock");
json = node
.client
.generate_block(&mining_addr.to_string(), &transactions, false)
.expect("generateblock");
let model: Result<mtype::GenerateBlock, GenerateBlockError> = json.into_model();
model.unwrap();
}
Expand All @@ -62,9 +68,10 @@ fn generating__generate_to_address__modelled() {
let node = Node::with_wallet(Wallet::Default, &[]);
let address = node.client.new_address().expect("failed to get new address");

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

let model: Result<mtype::GenerateToAddress, hex::HexToArrayError> = json.into_model();
let model: Result<mtype::GenerateToAddress, hex::HexToArrayError> = json.into_model();
model.unwrap();
}

Expand All @@ -77,7 +84,8 @@ fn generating__generate_to_descriptor__modelled() {
let address = node.client.new_address().expect("failed to get new address");
let descriptor = format!("addr({})", address);

let json: GenerateToDescriptor = node.client.generate_to_descriptor(NBLOCKS, &descriptor).expect("generatetodescriptor");
let json: GenerateToDescriptor =
node.client.generate_to_descriptor(NBLOCKS, &descriptor).expect("generatetodescriptor");
let model: Result<mtype::GenerateToDescriptor, hex::HexToArrayError> = json.into_model();
model.unwrap();
}
Expand Down
34 changes: 20 additions & 14 deletions integration_test/tests/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use bitcoin::SignedAmount;
use integration_test::{Node, NodeExt as _, Wallet};
use node::{mtype, TemplateRequest, TemplateRules};
use node::vtype::*; // All the version specific types.
use node::vtype::*;
use node::{mtype, TemplateRequest, TemplateRules}; // All the version specific types.

#[test]
fn mining__get_block_template__modelled() {
Expand All @@ -27,11 +27,11 @@ fn mining__get_block_template__modelled() {
rules: vec![TemplateRules::Segwit],
mode: Some("template".to_string()),
..Default::default()
}
},
};

let json: GetBlockTemplate = node1.client.get_block_template(&options)
.expect("get_block_template RPC failed");
let json: GetBlockTemplate =
node1.client.get_block_template(&options).expect("get_block_template RPC failed");
let model: Result<mtype::GetBlockTemplate, GetBlockTemplateError> = json.into_model();
model.unwrap();
}
Expand Down Expand Up @@ -82,7 +82,7 @@ fn mining__prioritise_transaction() {
}

#[test]
#[cfg(feature = "TODO")] // This test is flaky - no clue why.
#[cfg(feature = "TODO")] // This test is flaky - no clue why.
fn mining__submit_block() {
// Requires connected nodes otherwise the RPC call errors.
let (node1, node2, node3) = integration_test::three_node_network();
Expand All @@ -93,7 +93,8 @@ fn mining__submit_block() {
node3.mine_a_block();

let options = TemplateRequest { rules: vec![TemplateRules::Segwit] };
let json: GetBlockTemplate = node1.client.get_block_template(&options).expect("getblocktemplate");
let json: GetBlockTemplate =
node1.client.get_block_template(&options).expect("getblocktemplate");
let template: mtype::GetBlockTemplate = json.into_model().unwrap();

submit_empty_block(&node1, &template);
Expand All @@ -106,8 +107,8 @@ fn mining__submit_block() {
fn submit_empty_block(node: &Node, bt: &mtype::GetBlockTemplate) {
use bitcoin::hashes::Hash as _;
use bitcoin::{
absolute, block, transaction, Amount, Block, OutPoint, ScriptBuf, Sequence,
Transaction, TxIn, TxOut, Witness, ScriptHash, TxMerkleNode,
absolute, block, transaction, Amount, Block, OutPoint, ScriptBuf, ScriptHash, Sequence,
Transaction, TxIn, TxMerkleNode, TxOut, Witness,
};

let txdata = vec![Transaction {
Expand All @@ -134,7 +135,10 @@ fn submit_empty_block(node: &Node, bt: &mtype::GetBlockTemplate) {
version: block::Version::default(),
prev_blockhash: bt.previous_block_hash,
merkle_root: TxMerkleNode::all_zeros(),
time: Ord::max(bt.min_time, std::time::UNIX_EPOCH.elapsed().expect("elapsed").as_secs() as u32),
time: Ord::max(
bt.min_time,
std::time::UNIX_EPOCH.elapsed().expect("elapsed").as_secs() as u32,
),
bits: bt.bits,
nonce: 0,
},
Expand All @@ -158,8 +162,8 @@ fn submit_empty_block(node: &Node, bt: &mtype::GetBlockTemplate) {
fn mining__submit_block_with_dummy_coinbase(node: &Node, bt: &mtype::GetBlockTemplate) {
use bitcoin::hashes::Hash as _;
use bitcoin::{
absolute, block, transaction, Amount, Block, OutPoint, ScriptBuf, Sequence,
Transaction, TxIn, TxOut, Witness, TxMerkleNode,
absolute, block, transaction, Amount, Block, OutPoint, ScriptBuf, Sequence, Transaction,
TxIn, TxMerkleNode, TxOut, Witness,
};

let address = node.client.new_address().expect("failed to get new address");
Expand Down Expand Up @@ -218,8 +222,10 @@ fn mining__submit_header() {
node.fund_wallet();
node.mine_a_block();

let best_block = node.client.get_best_block_hash().expect("getbestblockhash").into_model().unwrap().0;
let mut header = node.client.get_block_header(&best_block).expect("getblockheader").into_model().unwrap().0;
let best_block =
node.client.get_best_block_hash().expect("getbestblockhash").into_model().unwrap().0;
let mut header =
node.client.get_block_header(&best_block).expect("getblockheader").into_model().unwrap().0;

for _ in 1..=u32::MAX {
header.nonce = header.nonce.wrapping_add(1);
Expand Down
12 changes: 7 additions & 5 deletions integration_test/tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#![allow(non_snake_case)] // Test names intentionally use double underscore.

use integration_test::{Node, NodeExt as _, Wallet};
use node::vtype::*; // All the version specific types.
use node::{AddNodeCommand, mtype, SetBanCommand};
use node::vtype::*; // All the version specific types.
use node::{mtype, AddNodeCommand, SetBanCommand};

#[test]
fn network__add_node() {
Expand Down Expand Up @@ -59,7 +59,7 @@ fn network__get_addr_man_info() {
for (network_name, network_info) in &json.0 {
assert!(!network_name.is_empty());
assert_eq!(network_info.total, network_info.new + network_info.tried);
};
}
}

#[test]
Expand Down Expand Up @@ -169,9 +169,11 @@ fn network__set_ban() {
#[test]
fn network__set_network_active() {
let node = Node::with_wallet(Wallet::None, &[]);
let json: SetNetworkActive = node.client.set_network_active(false).expect("setnetworkactive false");
let json: SetNetworkActive =
node.client.set_network_active(false).expect("setnetworkactive false");
assert!(!json.0);

let json: SetNetworkActive = node.client.set_network_active(true).expect("setnetworkactive true");
let json: SetNetworkActive =
node.client.set_network_active(true).expect("setnetworkactive true");
assert!(json.0);
}
Loading