Skip to content

Commit dccf3d2

Browse files
committed
Merge bitcoin/bitcoin#23117: test: Use assert_equal over assert for easier debugging
fa8f3ba test: pep-8 (MarcoFalke) fac5708 test: Use assert_equal over assert for easier debugging (MarcoFalke) Pull request description: See #23116 ACKs for top commit: jonatack: Light code review ACK fa8f3ba hebasto: ACK fa8f3ba, I have reviewed the code and it looks OK, I agree it can be merged. theStack: Code-review ACK fa8f3ba Tree-SHA512: bfdb91fd72144f05c38ed9aa8e40e17f59dcb90ac164b8bd01e241296a6c91a01f79a95a5eb97cc8445fdabe8605ef5b8062219a683613627c776feb7433a460
2 parents a9d0cec + fa8f3ba commit dccf3d2

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

test/functional/feature_segwit.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from test_framework.test_framework import BitcoinTestFramework
4545
from test_framework.util import (
4646
assert_equal,
47+
assert_greater_than_or_equal,
4748
assert_is_hex_string,
4849
assert_raises_rpc_error,
4950
try_rpc,
@@ -54,20 +55,24 @@
5455
P2WPKH = 0
5556
P2WSH = 1
5657

58+
5759
def getutxo(txid):
5860
utxo = {}
5961
utxo["vout"] = 0
6062
utxo["txid"] = txid
6163
return utxo
6264

65+
6366
def find_spendable_utxo(node, min_value):
6467
for utxo in node.listunspent(query_options={'minimumAmount': min_value}):
6568
if utxo['spendable']:
6669
return utxo
6770

6871
raise AssertionError(f"Unspent output equal or higher than {min_value} not found")
6972

70-
txs_mined = {} # txindex from txid to blockhash
73+
74+
txs_mined = {} # txindex from txid to blockhash
75+
7176

7277
class SegWitTest(BitcoinTestFramework):
7378
def set_test_params(self):
@@ -124,18 +129,18 @@ def run_test(self):
124129
self.log.info("Verify sigops are counted in GBT with pre-BIP141 rules before the fork")
125130
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
126131
tmpl = self.nodes[0].getblocktemplate({'rules': ['segwit']})
127-
assert tmpl['sizelimit'] == 1000000
132+
assert_equal(tmpl['sizelimit'], 1000000)
128133
assert 'weightlimit' not in tmpl
129-
assert tmpl['sigoplimit'] == 20000
130-
assert tmpl['transactions'][0]['hash'] == txid
131-
assert tmpl['transactions'][0]['sigops'] == 2
134+
assert_equal(tmpl['sigoplimit'], 20000)
135+
assert_equal(tmpl['transactions'][0]['hash'], txid)
136+
assert_equal(tmpl['transactions'][0]['sigops'], 2)
132137
assert '!segwit' not in tmpl['rules']
133138
self.generate(self.nodes[0], 1) # block 162
134139

135140
balance_presetup = self.nodes[0].getbalance()
136141
self.pubkey = []
137-
p2sh_ids = [] # p2sh_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE embedded in p2sh
138-
wit_ids = [] # wit_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE via bare witness
142+
p2sh_ids = [] # p2sh_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE embedded in p2sh
143+
wit_ids = [] # wit_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE via bare witness
139144
for i in range(3):
140145
newaddress = self.nodes[i].getnewaddress()
141146
self.pubkey.append(self.nodes[i].getaddressinfo(newaddress)["pubkey"])
@@ -215,7 +220,7 @@ def run_test(self):
215220
witnesses = coinbase_tx["decoded"]["vin"][0]["txinwitness"]
216221
assert_equal(len(witnesses), 1)
217222
assert_is_hex_string(witnesses[0])
218-
assert_equal(witnesses[0], '00'*32)
223+
assert_equal(witnesses[0], '00' * 32)
219224

220225
self.log.info("Verify witness txs without witness data are invalid after the fork")
221226
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program hash mismatch)', wit_ids[NODE_2][P2WPKH][2], sign=False)
@@ -232,11 +237,11 @@ def run_test(self):
232237
self.log.info("Verify sigops are counted in GBT with BIP141 rules after the fork")
233238
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
234239
tmpl = self.nodes[0].getblocktemplate({'rules': ['segwit']})
235-
assert tmpl['sizelimit'] >= 3999577 # actual maximum size is lower due to minimum mandatory non-witness data
236-
assert tmpl['weightlimit'] == 4000000
237-
assert tmpl['sigoplimit'] == 80000
238-
assert tmpl['transactions'][0]['txid'] == txid
239-
assert tmpl['transactions'][0]['sigops'] == 8
240+
assert_greater_than_or_equal(tmpl['sizelimit'], 3999577) # actual maximum size is lower due to minimum mandatory non-witness data
241+
assert_equal(tmpl['weightlimit'], 4000000)
242+
assert_equal(tmpl['sigoplimit'], 80000)
243+
assert_equal(tmpl['transactions'][0]['txid'], txid)
244+
assert_equal(tmpl['transactions'][0]['sigops'], 8)
240245
assert '!segwit' in tmpl['rules']
241246

242247
self.generate(self.nodes[0], 1) # Mine a block to clear the gbt cache
@@ -356,7 +361,7 @@ def run_test(self):
356361

357362
for i in compressed_spendable_address:
358363
v = self.nodes[0].getaddressinfo(i)
359-
if (v['isscript']):
364+
if v['isscript']:
360365
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
361366
# p2sh multisig with compressed keys should always be spendable
362367
spendable_anytime.extend([p2sh])
@@ -375,7 +380,7 @@ def run_test(self):
375380

376381
for i in uncompressed_spendable_address:
377382
v = self.nodes[0].getaddressinfo(i)
378-
if (v['isscript']):
383+
if v['isscript']:
379384
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
380385
# p2sh multisig with uncompressed keys should always be spendable
381386
spendable_anytime.extend([p2sh])
@@ -394,7 +399,7 @@ def run_test(self):
394399

395400
for i in compressed_solvable_address:
396401
v = self.nodes[0].getaddressinfo(i)
397-
if (v['isscript']):
402+
if v['isscript']:
398403
# Multisig without private is not seen after addmultisigaddress, but seen after importaddress
399404
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
400405
solvable_after_importaddress.extend([bare, p2sh, p2wsh, p2sh_p2wsh])
@@ -407,7 +412,7 @@ def run_test(self):
407412

408413
for i in uncompressed_solvable_address:
409414
v = self.nodes[0].getaddressinfo(i)
410-
if (v['isscript']):
415+
if v['isscript']:
411416
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
412417
# Base uncompressed multisig without private is not seen after addmultisigaddress, but seen after importaddress
413418
solvable_after_importaddress.extend([bare, p2sh])
@@ -446,7 +451,7 @@ def run_test(self):
446451
importlist = []
447452
for i in compressed_spendable_address + uncompressed_spendable_address + compressed_solvable_address + uncompressed_solvable_address:
448453
v = self.nodes[0].getaddressinfo(i)
449-
if (v['isscript']):
454+
if v['isscript']:
450455
bare = bytes.fromhex(v['hex'])
451456
importlist.append(bare.hex())
452457
importlist.append(script_to_p2wsh_script(bare).hex())
@@ -509,7 +514,7 @@ def run_test(self):
509514

510515
for i in compressed_spendable_address:
511516
v = self.nodes[0].getaddressinfo(i)
512-
if (v['isscript']):
517+
if v['isscript']:
513518
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
514519
premature_witaddress.append(script_to_p2sh(p2wsh))
515520
else:
@@ -519,7 +524,7 @@ def run_test(self):
519524

520525
for i in uncompressed_spendable_address + uncompressed_solvable_address:
521526
v = self.nodes[0].getaddressinfo(i)
522-
if (v['isscript']):
527+
if v['isscript']:
523528
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
524529
# P2WSH and P2SH(P2WSH) multisig with uncompressed keys are never seen
525530
unseen_anytime.extend([p2wsh, p2sh_p2wsh])
@@ -530,7 +535,7 @@ def run_test(self):
530535

531536
for i in compressed_solvable_address:
532537
v = self.nodes[0].getaddressinfo(i)
533-
if (v['isscript']):
538+
if v['isscript']:
534539
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
535540
premature_witaddress.append(script_to_p2sh(p2wsh))
536541
else:
@@ -597,13 +602,13 @@ def mine_and_test_listunspent(self, script_list, ismine):
597602
watchcount = 0
598603
spendcount = 0
599604
for i in self.nodes[0].listunspent():
600-
if (i['txid'] == txid):
605+
if i['txid'] == txid:
601606
watchcount += 1
602607
if i['spendable']:
603608
spendcount += 1
604-
if (ismine == 2):
609+
if ismine == 2:
605610
assert_equal(spendcount, len(script_list))
606-
elif (ismine == 1):
611+
elif ismine == 1:
607612
assert_equal(watchcount, len(script_list))
608613
assert_equal(spendcount, 0)
609614
else:
@@ -615,7 +620,7 @@ def p2sh_address_to_script(self, v):
615620
p2sh = CScript(bytes.fromhex(v['scriptPubKey']))
616621
p2wsh = script_to_p2wsh_script(bare)
617622
p2sh_p2wsh = script_to_p2sh_script(p2wsh)
618-
return([bare, p2sh, p2wsh, p2sh_p2wsh])
623+
return [bare, p2sh, p2wsh, p2sh_p2wsh]
619624

620625
def p2pkh_address_to_script(self, v):
621626
pubkey = bytes.fromhex(v['pubkey'])

0 commit comments

Comments
 (0)