Skip to content

Commit 111880a

Browse files
committed
[test] Add coverage to estimaterawfee and estimatesmartfee
This adds light functional coverage to estimaterawfee - a subset of the testing applied to estimatesmartfee, and argument validation testing to both estimaterawfee and estimatesmartfee. One valid estimatesmartfee signature test is commented out because it fails currently.
1 parent c08bf2b commit 111880a

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

test/functional/feature_fee_estimation.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,20 @@ def split_inputs(from_node, txins, txouts, initial_split=False):
9999
txouts.append({"txid": txid, "vout": 0, "amount": half_change})
100100
txouts.append({"txid": txid, "vout": 1, "amount": rem_change})
101101

102+
def check_raw_estimates(node, fees_seen):
103+
"""Call estimaterawfee and verify that the estimates meet certain invariants."""
102104

103-
def check_estimates(node, fees_seen):
105+
delta = 1.0e-6 # account for rounding error
106+
for i in range(1, 26):
107+
for _, e in node.estimaterawfee(i).items():
108+
feerate = float(e["feerate"])
109+
assert_greater_than(feerate, 0)
110+
111+
if feerate + delta < min(fees_seen) or feerate - delta > max(fees_seen):
112+
raise AssertionError("Estimated fee (%f) out of range (%f,%f)"
113+
% (feerate, min(fees_seen), max(fees_seen)))
114+
115+
def check_smart_estimates(node, fees_seen):
104116
"""Call estimatesmartfee and verify that the estimates meet certain invariants."""
105117

106118
delta = 1.0e-6 # account for rounding error
@@ -123,6 +135,9 @@ def check_estimates(node, fees_seen):
123135
else:
124136
assert_greater_than_or_equal(i + 1, e["blocks"])
125137

138+
def check_estimates(node, fees_seen):
139+
check_raw_estimates(node, fees_seen)
140+
check_smart_estimates(node, fees_seen)
126141

127142
class EstimateFeeTest(BitcoinTestFramework):
128143
def set_test_params(self):

test/functional/rpc_estimatefee.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test the estimatefee RPCs.
6+
7+
Test the following RPCs:
8+
- estimatesmartfee
9+
- estimaterawfee
10+
"""
11+
12+
from test_framework.test_framework import BitcoinTestFramework
13+
from test_framework.util import assert_raises_rpc_error
14+
15+
class EstimateFeeTest(BitcoinTestFramework):
16+
def set_test_params(self):
17+
self.setup_clean_chain = False
18+
self.num_nodes = 1
19+
20+
def run_test(self):
21+
# missing required params
22+
assert_raises_rpc_error(-1, "estimatesmartfee", self.nodes[0].estimatesmartfee)
23+
assert_raises_rpc_error(-1, "estimaterawfee", self.nodes[0].estimaterawfee)
24+
25+
# wrong type for conf_target
26+
assert_raises_rpc_error(-3, "Expected type number, got string", self.nodes[0].estimatesmartfee, 'foo')
27+
assert_raises_rpc_error(-3, "Expected type number, got string", self.nodes[0].estimaterawfee, 'foo')
28+
29+
# wrong type for estimatesmartfee(estimate_mode)
30+
assert_raises_rpc_error(-3, "Expected type string, got number", self.nodes[0].estimatesmartfee, 1, 1)
31+
assert_raises_rpc_error(-8, "Invalid estimate_mode parameter", self.nodes[0].estimatesmartfee, 1, 'foo')
32+
33+
# wrong type for estimaterawfee(threshold)
34+
assert_raises_rpc_error(-3, "Expected type number, got string", self.nodes[0].estimaterawfee, 1, 'foo')
35+
36+
# extra params
37+
assert_raises_rpc_error(-1, "estimatesmartfee", self.nodes[0].estimatesmartfee, 1, 'ECONOMICAL', 1)
38+
assert_raises_rpc_error(-1, "estimaterawfee", self.nodes[0].estimaterawfee, 1, 1, 1)
39+
40+
# valid calls
41+
self.nodes[0].estimatesmartfee(1)
42+
# self.nodes[0].estimatesmartfee(1, None)
43+
self.nodes[0].estimatesmartfee(1, 'ECONOMICAL')
44+
45+
self.nodes[0].estimaterawfee(1)
46+
self.nodes[0].estimaterawfee(1, None)
47+
self.nodes[0].estimaterawfee(1, 1)
48+
49+
50+
if __name__ == '__main__':
51+
EstimateFeeTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
'wallet_resendwallettransactions.py',
192192
'wallet_fallbackfee.py',
193193
'feature_minchainwork.py',
194+
'rpc_estimatefee.py',
194195
'rpc_getblockstats.py',
195196
'wallet_create_tx.py',
196197
'p2p_fingerprint.py',

0 commit comments

Comments
 (0)