Skip to content

Commit 251f414

Browse files
committed
feat: add validation for conf_target argument in estimaterawfee RPC
The conf_target argument only takes in values from 1 to 1008 inclusive all values outside these ranges are not valid calls. This commit adds validation for it in all versions from v17 to v30 with tests.
1 parent 20b58c4 commit 251f414

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

client/src/client_sync/v17/hidden.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
macro_rules! impl_client_v17__estimate_raw_fee {
1515
() => {
1616
impl Client {
17+
/// # Panics
18+
///
19+
/// * Panics if `conf_target` is outside the range [1, 1008].
1720
pub fn estimate_raw_fee(&self, conf_target: u32) -> Result<EstimateRawFee> {
21+
assert!(
22+
(1..=1008).contains(&conf_target),
23+
"invalid conf_target, must be between 1 and 1008 inclusive"
24+
);
25+
1826
self.call("estimaterawfee", &[conf_target.into()])
1927
}
2028
}

integration_test/tests/hidden.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ fn hidden__estimate_raw_fee__modelled() {
7474
let estimate = model.unwrap();
7575

7676
assert!(estimate.long.scale > 0);
77+
78+
// Boundary checks enforced by the client:
79+
// conf_target must be between 1 and 1008 inclusive.
80+
// 0 is invalid
81+
assert!(node.client.estimate_raw_fee(0).is_err(), "conf_target 0 must be invalid");
82+
// 1009 is invalid
83+
assert!(node.client.estimate_raw_fee(1009).is_err(), "conf_target > 1008 must be invalid");
84+
85+
// Check inclusive bounds are accepted by the client
86+
let _ = node.client.estimate_raw_fee(1).expect("conf_target 1 must be valid");
87+
let _ = node.client.estimate_raw_fee(1008).expect("conf_target 1008 must be valid");
7788
}
7889

7990
#[test]

0 commit comments

Comments
 (0)