Skip to content

Commit c6a073c

Browse files
authored
Merge pull request #83 from tcharding/03-10-getblockstats
Refactor `getblockstats` tests and enable for v18
2 parents 9f7c463 + 626938c commit c6a073c

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed

integration_test/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ pub trait NodeExt {
2525
Self::new(conf, None)
2626
}
2727

28+
/// Returns a handle to a `bitcoind` instance with "default" wallet loaded and `-txindex` enabled.
29+
fn new_with_default_wallet_txindex() -> Node {
30+
let mut conf = node::Conf::default();
31+
conf.args.push("-txindex");
32+
Self::new(conf, None)
33+
}
34+
2835
/// Returns a handle to a `bitcoind` instance with `wallet` loaded.
2936
fn new_with_wallet(wallet: String) -> Node {
3037
let conf = node::Conf::default();

integration_test/tests/blockchain.rs

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,55 +70,41 @@ fn get_block_header_verbose() { // verbose = true
7070
assert!(json.into_model().is_ok());
7171
}
7272

73-
#[cfg(not(any(feature = "v18", feature = "v19", feature = "v20", feature = "v21", feature = "v22", feature = "v23", feature = "v24")))]
73+
#[cfg(not(any(feature = "v19", feature = "v20", feature = "v21", feature = "v22", feature = "v23", feature = "v24")))]
7474
// `getblockstats` used to not work on the genesis block as it doesn't have undo data saved to disk
7575
// (see https://github.com/bitcoin/bitcoin/pull/19888). We therefore only run tests for versions
7676
// allowing to.
7777
#[test]
7878
fn get_block_stats() {
79-
get_block_stats_by_height();
80-
get_block_stats_by_hash();
79+
// Version 18 cannot getblockstats if -txindex is not enabled.
80+
#[cfg(not(feature = "v18"))]
81+
getblockstats();
82+
83+
// All non-feature gated versions including 18 can getblockstats if -txindex is enabled.
84+
getblockstats_txindex();
8185
}
8286

8387
#[cfg(not(any(feature = "v18", feature = "v19", feature = "v20", feature = "v21", feature = "v22", feature = "v23", feature = "v24")))]
84-
// `getblockstats` used to not work on the genesis block as it doesn't have undo data saved to disk
85-
// (see https://github.com/bitcoin/bitcoin/pull/19888). We therefore only run tests for versions
86-
// allowing to.
87-
fn get_block_stats_by_height() {
88-
let node = Node::new_no_wallet();
89-
let json = node.client.get_block_stats_by_height(0).expect("getblockstats");
88+
fn getblockstats() {
89+
let node = Node::new_with_default_wallet();
90+
node.mine_a_block();
91+
92+
let json = node.client.get_block_stats_by_height(1).expect("getblockstats");
9093
assert!(json.into_model().is_ok());
91-
}
9294

93-
#[cfg(not(any(feature = "v18", feature = "v19", feature = "v20", feature = "v21", feature = "v22", feature = "v23", feature = "v24")))]
94-
// `getblockstats` used to not work on the genesis block as it doesn't have undo data saved to disk
95-
// (see https://github.com/bitcoin/bitcoin/pull/19888). We therefore only run tests for versions
96-
// allowing to.
97-
fn get_block_stats_by_hash() { // verbose = true
98-
let node = Node::new_no_wallet();
9995
let block_hash = best_block_hash();
10096
let json = node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
10197
assert!(json.into_model().is_ok());
10298
}
10399

104100
#[cfg(not(any(feature = "v19", feature = "v20", feature = "v21", feature = "v22", feature = "v23", feature = "v24")))]
105-
// `getblockstats` used to not work on the genesis block as it doesn't have undo data saved to disk
106-
// (see https://github.com/bitcoin/bitcoin/pull/19888). We therefore only run tests for versions
107-
// allowing to.
108-
#[test]
109-
fn get_block_stats_by_height_txindex() {
110-
let node = Node::new_no_wallet_txindex();
111-
let json = node.client.get_block_stats_by_height(0).expect("getblockstats");
101+
fn getblockstats_txindex() {
102+
let node = Node::new_with_default_wallet_txindex();
103+
node.mine_a_block();
104+
105+
let json = node.client.get_block_stats_by_height(1).expect("getblockstats");
112106
assert!(json.into_model().is_ok());
113-
}
114107

115-
#[cfg(not(any(feature = "v19", feature = "v20", feature = "v21", feature = "v22", feature = "v23", feature = "v24")))]
116-
// `getblockstats` used to not work on the genesis block as it doesn't have undo data saved to disk
117-
// (see https://github.com/bitcoin/bitcoin/pull/19888). We therefore only run tests for versions
118-
// allowing to.
119-
#[test]
120-
fn get_block_stats_by_hash_txindex() { // verbose = true
121-
let node = Node::new_no_wallet_txindex();
122108
let block_hash = best_block_hash();
123109
let json = node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
124110
assert!(json.into_model().is_ok());

types/src/v18/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//! | getblockcount | done |
2929
//! | getblockhash | done |
3030
//! | getblockheader | done |
31-
//! | getblockstats | done (untested) |
31+
//! | getblockstats | done |
3232
//! | getchaintips | done |
3333
//! | getchaintxstats | done |
3434
//! | getdifficulty | done |

0 commit comments

Comments
 (0)