Skip to content

Commit a86b0c0

Browse files
committed
fixup! feature_discount_ct: some txs can return 2 different weights, adapt the test to it
1 parent 825a6c6 commit a86b0c0

File tree

1 file changed

+13
-44
lines changed

1 file changed

+13
-44
lines changed

test/functional/feature_discount_ct.py

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from decimal import Decimal
77
from test_framework.test_framework import BitcoinTestFramework
88
from test_framework.util import (
9+
assert_approx,
910
assert_equal,
1011
)
1112

@@ -81,14 +82,10 @@ def run_test(self):
8182
assert_equal(tx['fee']['bitcoin'], Decimal('-0.00000326'))
8283
assert_equal(decoded['vsize'], 326)
8384
# 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)
8986
self.generate(node0, 1)
9087
tx = node1.getrawtransaction(txid, True)
91-
assert_equal(tx['discountweight'], expectedweight)
88+
assert_approx(tx['discountweight'], 1301, 1)
9289
assert_equal(tx['discountvsize'], 326)
9390

9491
self.log.info("Send confidential tx to node 0")
@@ -104,16 +101,10 @@ def run_test(self):
104101
assert_equal(tx['fee']['bitcoin'], Decimal('-0.00002575'))
105102
assert_equal(decoded['vsize'], 2575)
106103
# 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)
114105
self.generate(node0, 1)
115106
tx = node1.getrawtransaction(txid, True)
116-
assert_equal(tx['discountweight'], expecteddiscountweight)
107+
assert_approx(tx['discountweight'], 1301, 1)
117108
assert_equal(tx['discountvsize'], 326) # node1 has discountvsize
118109

119110
self.log.info("Send explicit tx to node 1")
@@ -129,14 +120,10 @@ def run_test(self):
129120
assert_equal(tx['fee']['bitcoin'], Decimal('-0.00000326'))
130121
assert_equal(decoded['vsize'], 326)
131122
# 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)
137124
self.generate(node0, 1)
138125
tx = node1.getrawtransaction(txid, True)
139-
assert_equal(tx['discountweight'], expectedweight)
126+
assert_approx(tx['discountweight'], 1301, 1)
140127
assert_equal(tx['discountvsize'], 326)
141128

142129
self.log.info("Send confidential (undiscounted) tx to node 1")
@@ -152,16 +139,10 @@ def run_test(self):
152139
assert_equal(tx['fee']['bitcoin'], Decimal('-0.00002575'))
153140
assert_equal(decoded['vsize'], 2575)
154141
# 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)
162143
self.generate(node0, 1)
163144
tx = node1.getrawtransaction(txid, True)
164-
assert_equal(tx['discountweight'], expecteddiscountweight)
145+
assert_approx(tx['discountweight'], 1301, 1)
165146
assert_equal(tx['discountvsize'], 326) # node1 has discountvsize
166147

167148
self.log.info("Send confidential (discounted) tx to node 1")
@@ -186,14 +167,8 @@ def run_test(self):
186167
assert_equal(decoded['fee'][bitcoin], Decimal('0.00000326'))
187168
assert_equal(decoded['vsize'], 2575)
188169
# 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)
197172
assert_equal(decoded['discountvsize'], 326)
198173

199174
# node0 only has vsize
@@ -223,14 +198,8 @@ def run_test(self):
223198
assert_equal(decoded['fee'][bitcoin], Decimal('0.00000033'))
224199
assert_equal(decoded['vsize'], 2575)
225200
# 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)
234203
assert_equal(decoded['discountvsize'], 326)
235204
# node0 only has vsize
236205
tx = node0.getrawtransaction(txid, True)

0 commit comments

Comments
 (0)