6
6
from decimal import Decimal
7
7
from test_framework .test_framework import BitcoinTestFramework
8
8
from test_framework .util import (
9
+ assert_approx ,
9
10
assert_equal ,
10
11
)
11
12
@@ -81,14 +82,10 @@ def run_test(self):
81
82
assert_equal (tx ['fee' ]['bitcoin' ], Decimal ('-0.00000326' ))
82
83
assert_equal (decoded ['vsize' ], 326 )
83
84
# tx weight can be 1301 or 1302, accept both
84
- if decoded ['weight' ] == 1301 :
85
- expectedweight = 1301
86
- else :
87
- expectedweight = 1302
88
- assert_equal (decoded ['weight' ], expectedweight )
85
+ assert_approx (decoded ['weight' ], 1301 , 1 )
89
86
self .generate (node0 , 1 )
90
87
tx = node1 .getrawtransaction (txid , True )
91
- assert_equal (tx ['discountweight' ], expectedweight )
88
+ assert_approx (tx ['discountweight' ], 1301 , 1 )
92
89
assert_equal (tx ['discountvsize' ], 326 )
93
90
94
91
self .log .info ("Send confidential tx to node 0" )
@@ -104,16 +101,10 @@ def run_test(self):
104
101
assert_equal (tx ['fee' ]['bitcoin' ], Decimal ('-0.00002575' ))
105
102
assert_equal (decoded ['vsize' ], 2575 )
106
103
# tx weight can be 10299 or 10300, accept both
107
- if decoded ['weight' ] == 10299 :
108
- expectedweight = 10299
109
- expecteddiscountweight = 1301
110
- else :
111
- expectedweight = 10300
112
- expecteddiscountweight = 1302
113
- assert_equal (decoded ['weight' ], expectedweight )
104
+ assert_approx (decoded ['weight' ], 10299 , 1 )
114
105
self .generate (node0 , 1 )
115
106
tx = node1 .getrawtransaction (txid , True )
116
- assert_equal (tx ['discountweight' ], expecteddiscountweight )
107
+ assert_approx (tx ['discountweight' ], 1301 , 1 )
117
108
assert_equal (tx ['discountvsize' ], 326 ) # node1 has discountvsize
118
109
119
110
self .log .info ("Send explicit tx to node 1" )
@@ -129,14 +120,10 @@ def run_test(self):
129
120
assert_equal (tx ['fee' ]['bitcoin' ], Decimal ('-0.00000326' ))
130
121
assert_equal (decoded ['vsize' ], 326 )
131
122
# tx weight can be 1301 or 1302, accept both
132
- if decoded ['weight' ] == 1301 :
133
- expectedweight = 1301
134
- else :
135
- expectedweight = 1302
136
- assert_equal (decoded ['weight' ], expectedweight )
123
+ assert_approx (decoded ['weight' ], 1301 , 1 )
137
124
self .generate (node0 , 1 )
138
125
tx = node1 .getrawtransaction (txid , True )
139
- assert_equal (tx ['discountweight' ], expectedweight )
126
+ assert_approx (tx ['discountweight' ], 1301 , 1 )
140
127
assert_equal (tx ['discountvsize' ], 326 )
141
128
142
129
self .log .info ("Send confidential (undiscounted) tx to node 1" )
@@ -152,16 +139,10 @@ def run_test(self):
152
139
assert_equal (tx ['fee' ]['bitcoin' ], Decimal ('-0.00002575' ))
153
140
assert_equal (decoded ['vsize' ], 2575 )
154
141
# tx weight can be 10299 or 10300, accept both
155
- if decoded ['weight' ] == 10299 :
156
- expectedweight = 10299
157
- expecteddiscountweight = 1301
158
- else :
159
- expectedweight = 10300
160
- expecteddiscountweight = 1302
161
- assert_equal (decoded ['weight' ], expectedweight )
142
+ assert_approx (decoded ['weight' ], 10299 , 1 )
162
143
self .generate (node0 , 1 )
163
144
tx = node1 .getrawtransaction (txid , True )
164
- assert_equal (tx ['discountweight' ], expecteddiscountweight )
145
+ assert_approx (tx ['discountweight' ], 1301 , 1 )
165
146
assert_equal (tx ['discountvsize' ], 326 ) # node1 has discountvsize
166
147
167
148
self .log .info ("Send confidential (discounted) tx to node 1" )
@@ -186,14 +167,8 @@ def run_test(self):
186
167
assert_equal (decoded ['fee' ][bitcoin ], Decimal ('0.00000326' ))
187
168
assert_equal (decoded ['vsize' ], 2575 )
188
169
# tx weight can be 10299 or 10300, accept both
189
- if decoded ['weight' ] == 10299 :
190
- expectedweight = 10299
191
- expecteddiscountweight = 1301
192
- else :
193
- expectedweight = 10300
194
- expecteddiscountweight = 1302
195
- assert_equal (decoded ['weight' ], expectedweight )
196
- assert_equal (decoded ['discountweight' ], expecteddiscountweight )
170
+ assert_approx (decoded ['weight' ], 10299 , 1 )
171
+ assert_approx (decoded ['discountweight' ], 1301 , 1 )
197
172
assert_equal (decoded ['discountvsize' ], 326 )
198
173
199
174
# node0 only has vsize
@@ -223,14 +198,8 @@ def run_test(self):
223
198
assert_equal (decoded ['fee' ][bitcoin ], Decimal ('0.00000033' ))
224
199
assert_equal (decoded ['vsize' ], 2575 )
225
200
# tx weight can be 10299 or 10300, accept both
226
- if decoded ['weight' ] == 10299 :
227
- expectedweight = 10299
228
- expecteddiscountweight = 1301
229
- else :
230
- expectedweight = 10300
231
- expecteddiscountweight = 1302
232
- assert_equal (decoded ['weight' ], expectedweight )
233
- assert_equal (decoded ['discountweight' ], expecteddiscountweight )
201
+ assert_approx (decoded ['weight' ], 10299 , 1 )
202
+ assert_approx (decoded ['discountweight' ], 1301 , 1 )
234
203
assert_equal (decoded ['discountvsize' ], 326 )
235
204
# node0 only has vsize
236
205
tx = node0 .getrawtransaction (txid , True )
0 commit comments