9
9
from test_framework .mininode import CTransaction , CTxIn , CTxOut , COutPoint , ToHex , COIN
10
10
from test_framework .script import CScript , OP_1 , OP_DROP , OP_2 , OP_HASH160 , OP_EQUAL , hash160 , OP_TRUE
11
11
from test_framework .test_framework import BitcoinTestFramework
12
- from test_framework .util import satoshi_round , sync_mempools , sync_blocks , connect_nodes , assert_greater_than
12
+ from test_framework .util import (
13
+ assert_equal ,
14
+ assert_greater_than ,
15
+ assert_greater_than_or_equal ,
16
+ connect_nodes ,
17
+ satoshi_round ,
18
+ sync_blocks ,
19
+ sync_mempools ,
20
+ )
13
21
14
22
# Construct 2 trivial P2SH's and the ScriptSigs that spend them
15
23
# So we can create many transactions without needing to spend
22
30
# Associated ScriptSig's to spend satisfy P2SH_1 and P2SH_2
23
31
SCRIPT_SIG = [CScript ([OP_TRUE , REDEEM_SCRIPT_1 ]), CScript ([OP_TRUE , REDEEM_SCRIPT_2 ])]
24
32
25
- global log
26
-
27
33
def small_txpuzzle_randfee (from_node , conflist , unconflist , amount , min_fee , fee_increment ):
28
34
"""Create and send a transaction with a random fee.
29
35
@@ -93,52 +99,28 @@ def split_inputs(from_node, txins, txouts, initial_split=False):
93
99
txouts .append ({"txid" : txid , "vout" : 0 , "amount" : half_change })
94
100
txouts .append ({"txid" : txid , "vout" : 1 , "amount" : rem_change })
95
101
96
- def check_estimates (node , fees_seen , max_invalid , print_estimates = True ):
97
- """Call estimatefee and verify that the estimates meet certain invariants."""
102
+ def check_estimates (node , fees_seen , max_invalid ):
103
+ """Call estimatesmartfee and verify that the estimates meet certain invariants."""
98
104
99
- all_estimates = [node .estimatefee (i ) for i in range (1 , 26 )]
100
- if print_estimates :
101
- log .info ([str (all_estimates [e - 1 ]) for e in [1 , 2 , 3 , 6 , 15 , 25 ]])
102
105
delta = 1.0e-6 # account for rounding error
103
- last_e = max (fees_seen )
104
- for e in [x for x in all_estimates if x >= 0 ]:
105
- # Estimates should be within the bounds of what transactions fees actually were:
106
- if float (e ) + delta < min (fees_seen ) or float (e ) - delta > max (fees_seen ):
106
+ last_feerate = float (max (fees_seen ))
107
+ all_smart_estimates = [node .estimatesmartfee (i ) for i in range (1 , 26 )]
108
+ for i , e in enumerate (all_smart_estimates ): # estimate is for i+1
109
+ feerate = float (e ["feerate" ])
110
+ assert_greater_than (feerate , 0 )
111
+
112
+ if feerate + delta < min (fees_seen ) or feerate - delta > max (fees_seen ):
107
113
raise AssertionError ("Estimated fee (%f) out of range (%f,%f)"
108
- % (float (e ), min (fees_seen ), max (fees_seen )))
109
- # Estimates should be monotonically decreasing
110
- if float (e ) - delta > last_e :
114
+ % (feerate , min (fees_seen ), max (fees_seen )))
115
+ if feerate - delta > last_feerate :
111
116
raise AssertionError ("Estimated fee (%f) larger than last fee (%f) for lower number of confirms"
112
- % (float (e ), float (last_e )))
113
- last_e = e
114
- valid_estimate = False
115
- invalid_estimates = 0
116
- for i , e in enumerate (all_estimates ): # estimate is for i+1
117
- if e >= 0 :
118
- valid_estimate = True
119
- if i >= 13 : # for n>=14 estimatesmartfee(n/2) should be at least as high as estimatefee(n)
120
- assert_greater_than (node .estimatesmartfee ((i + 1 ) // 2 )["feerate" ], float (e ) - delta )
117
+ % (feerate , last_feerate ))
118
+ last_feerate = feerate
121
119
120
+ if i == 0 :
121
+ assert_equal (e ["blocks" ], 2 )
122
122
else :
123
- invalid_estimates += 1
124
-
125
- # estimatesmartfee should still be valid
126
- approx_estimate = node .estimatesmartfee (i + 1 )["feerate" ]
127
- answer_found = node .estimatesmartfee (i + 1 )["blocks" ]
128
- assert_greater_than (approx_estimate , 0 )
129
- assert_greater_than (answer_found , i + 1 )
130
-
131
- # Once we're at a high enough confirmation count that we can give an estimate
132
- # We should have estimates for all higher confirmation counts
133
- if valid_estimate :
134
- raise AssertionError ("Invalid estimate appears at higher confirm count than valid estimate" )
135
-
136
- # Check on the expected number of different confirmation counts
137
- # that we might not have valid estimates for
138
- if invalid_estimates > max_invalid :
139
- raise AssertionError ("More than (%d) invalid estimates" % (max_invalid ))
140
- return all_estimates
141
-
123
+ assert_greater_than_or_equal (i + 1 , e ["blocks" ])
142
124
143
125
class EstimateFeeTest (BitcoinTestFramework ):
144
126
def set_test_params (self ):
@@ -151,7 +133,7 @@ def setup_network(self):
151
133
which we will use to generate our transactions.
152
134
"""
153
135
self .add_nodes (3 , extra_args = [["-maxorphantx=1000" , "-whitelist=127.0.0.1" ],
154
- ["-blockmaxsize=17000" , "-maxorphantx=1000" , "-deprecatedrpc=estimatefee" ],
136
+ ["-blockmaxsize=17000" , "-maxorphantx=1000" ],
155
137
["-blockmaxsize=8000" , "-maxorphantx=1000" ]])
156
138
# Use node0 to mine blocks for input splitting
157
139
# Node1 mines small blocks but that are bigger than the expected transaction rate.
@@ -190,10 +172,6 @@ def run_test(self):
190
172
self .log .info ("This test is time consuming, please be patient" )
191
173
self .log .info ("Splitting inputs so we can generate tx's" )
192
174
193
- # Make log handler available to helper functions
194
- global log
195
- log = self .log
196
-
197
175
# Start node0
198
176
self .start_node (0 )
199
177
self .txouts = []
0 commit comments