mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-30 10:42:23 +02:00
test: pep-8
This commit is contained in:
@ -55,12 +55,14 @@ NODE_2 = 2
|
|||||||
P2WPKH = 0
|
P2WPKH = 0
|
||||||
P2WSH = 1
|
P2WSH = 1
|
||||||
|
|
||||||
|
|
||||||
def getutxo(txid):
|
def getutxo(txid):
|
||||||
utxo = {}
|
utxo = {}
|
||||||
utxo["vout"] = 0
|
utxo["vout"] = 0
|
||||||
utxo["txid"] = txid
|
utxo["txid"] = txid
|
||||||
return utxo
|
return utxo
|
||||||
|
|
||||||
|
|
||||||
def find_spendable_utxo(node, min_value):
|
def find_spendable_utxo(node, min_value):
|
||||||
for utxo in node.listunspent(query_options={'minimumAmount': min_value}):
|
for utxo in node.listunspent(query_options={'minimumAmount': min_value}):
|
||||||
if utxo['spendable']:
|
if utxo['spendable']:
|
||||||
@ -68,7 +70,9 @@ def find_spendable_utxo(node, min_value):
|
|||||||
|
|
||||||
raise AssertionError(f"Unspent output equal or higher than {min_value} not found")
|
raise AssertionError(f"Unspent output equal or higher than {min_value} not found")
|
||||||
|
|
||||||
txs_mined = {} # txindex from txid to blockhash
|
|
||||||
|
txs_mined = {} # txindex from txid to blockhash
|
||||||
|
|
||||||
|
|
||||||
class SegWitTest(BitcoinTestFramework):
|
class SegWitTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
@ -135,8 +139,8 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
balance_presetup = self.nodes[0].getbalance()
|
balance_presetup = self.nodes[0].getbalance()
|
||||||
self.pubkey = []
|
self.pubkey = []
|
||||||
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
|
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
|
||||||
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
|
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
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
newaddress = self.nodes[i].getnewaddress()
|
newaddress = self.nodes[i].getnewaddress()
|
||||||
self.pubkey.append(self.nodes[i].getaddressinfo(newaddress)["pubkey"])
|
self.pubkey.append(self.nodes[i].getaddressinfo(newaddress)["pubkey"])
|
||||||
@ -216,7 +220,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
witnesses = coinbase_tx["decoded"]["vin"][0]["txinwitness"]
|
witnesses = coinbase_tx["decoded"]["vin"][0]["txinwitness"]
|
||||||
assert_equal(len(witnesses), 1)
|
assert_equal(len(witnesses), 1)
|
||||||
assert_is_hex_string(witnesses[0])
|
assert_is_hex_string(witnesses[0])
|
||||||
assert_equal(witnesses[0], '00'*32)
|
assert_equal(witnesses[0], '00' * 32)
|
||||||
|
|
||||||
self.log.info("Verify witness txs without witness data are invalid after the fork")
|
self.log.info("Verify witness txs without witness data are invalid after the fork")
|
||||||
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program hash mismatch)', wit_ids[NODE_2][P2WPKH][2], sign=False)
|
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program hash mismatch)', wit_ids[NODE_2][P2WPKH][2], sign=False)
|
||||||
@ -357,7 +361,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
for i in compressed_spendable_address:
|
for i in compressed_spendable_address:
|
||||||
v = self.nodes[0].getaddressinfo(i)
|
v = self.nodes[0].getaddressinfo(i)
|
||||||
if (v['isscript']):
|
if v['isscript']:
|
||||||
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
||||||
# p2sh multisig with compressed keys should always be spendable
|
# p2sh multisig with compressed keys should always be spendable
|
||||||
spendable_anytime.extend([p2sh])
|
spendable_anytime.extend([p2sh])
|
||||||
@ -376,7 +380,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
for i in uncompressed_spendable_address:
|
for i in uncompressed_spendable_address:
|
||||||
v = self.nodes[0].getaddressinfo(i)
|
v = self.nodes[0].getaddressinfo(i)
|
||||||
if (v['isscript']):
|
if v['isscript']:
|
||||||
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
||||||
# p2sh multisig with uncompressed keys should always be spendable
|
# p2sh multisig with uncompressed keys should always be spendable
|
||||||
spendable_anytime.extend([p2sh])
|
spendable_anytime.extend([p2sh])
|
||||||
@ -395,7 +399,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
for i in compressed_solvable_address:
|
for i in compressed_solvable_address:
|
||||||
v = self.nodes[0].getaddressinfo(i)
|
v = self.nodes[0].getaddressinfo(i)
|
||||||
if (v['isscript']):
|
if v['isscript']:
|
||||||
# Multisig without private is not seen after addmultisigaddress, but seen after importaddress
|
# Multisig without private is not seen after addmultisigaddress, but seen after importaddress
|
||||||
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
||||||
solvable_after_importaddress.extend([bare, p2sh, p2wsh, p2sh_p2wsh])
|
solvable_after_importaddress.extend([bare, p2sh, p2wsh, p2sh_p2wsh])
|
||||||
@ -408,7 +412,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
for i in uncompressed_solvable_address:
|
for i in uncompressed_solvable_address:
|
||||||
v = self.nodes[0].getaddressinfo(i)
|
v = self.nodes[0].getaddressinfo(i)
|
||||||
if (v['isscript']):
|
if v['isscript']:
|
||||||
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
||||||
# Base uncompressed multisig without private is not seen after addmultisigaddress, but seen after importaddress
|
# Base uncompressed multisig without private is not seen after addmultisigaddress, but seen after importaddress
|
||||||
solvable_after_importaddress.extend([bare, p2sh])
|
solvable_after_importaddress.extend([bare, p2sh])
|
||||||
@ -447,7 +451,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
importlist = []
|
importlist = []
|
||||||
for i in compressed_spendable_address + uncompressed_spendable_address + compressed_solvable_address + uncompressed_solvable_address:
|
for i in compressed_spendable_address + uncompressed_spendable_address + compressed_solvable_address + uncompressed_solvable_address:
|
||||||
v = self.nodes[0].getaddressinfo(i)
|
v = self.nodes[0].getaddressinfo(i)
|
||||||
if (v['isscript']):
|
if v['isscript']:
|
||||||
bare = bytes.fromhex(v['hex'])
|
bare = bytes.fromhex(v['hex'])
|
||||||
importlist.append(bare.hex())
|
importlist.append(bare.hex())
|
||||||
importlist.append(script_to_p2wsh_script(bare).hex())
|
importlist.append(script_to_p2wsh_script(bare).hex())
|
||||||
@ -510,7 +514,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
for i in compressed_spendable_address:
|
for i in compressed_spendable_address:
|
||||||
v = self.nodes[0].getaddressinfo(i)
|
v = self.nodes[0].getaddressinfo(i)
|
||||||
if (v['isscript']):
|
if v['isscript']:
|
||||||
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
||||||
premature_witaddress.append(script_to_p2sh(p2wsh))
|
premature_witaddress.append(script_to_p2sh(p2wsh))
|
||||||
else:
|
else:
|
||||||
@ -520,7 +524,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
for i in uncompressed_spendable_address + uncompressed_solvable_address:
|
for i in uncompressed_spendable_address + uncompressed_solvable_address:
|
||||||
v = self.nodes[0].getaddressinfo(i)
|
v = self.nodes[0].getaddressinfo(i)
|
||||||
if (v['isscript']):
|
if v['isscript']:
|
||||||
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
||||||
# P2WSH and P2SH(P2WSH) multisig with uncompressed keys are never seen
|
# P2WSH and P2SH(P2WSH) multisig with uncompressed keys are never seen
|
||||||
unseen_anytime.extend([p2wsh, p2sh_p2wsh])
|
unseen_anytime.extend([p2wsh, p2sh_p2wsh])
|
||||||
@ -531,7 +535,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
for i in compressed_solvable_address:
|
for i in compressed_solvable_address:
|
||||||
v = self.nodes[0].getaddressinfo(i)
|
v = self.nodes[0].getaddressinfo(i)
|
||||||
if (v['isscript']):
|
if v['isscript']:
|
||||||
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
[bare, p2sh, p2wsh, p2sh_p2wsh] = self.p2sh_address_to_script(v)
|
||||||
premature_witaddress.append(script_to_p2sh(p2wsh))
|
premature_witaddress.append(script_to_p2sh(p2wsh))
|
||||||
else:
|
else:
|
||||||
@ -598,13 +602,13 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
watchcount = 0
|
watchcount = 0
|
||||||
spendcount = 0
|
spendcount = 0
|
||||||
for i in self.nodes[0].listunspent():
|
for i in self.nodes[0].listunspent():
|
||||||
if (i['txid'] == txid):
|
if i['txid'] == txid:
|
||||||
watchcount += 1
|
watchcount += 1
|
||||||
if i['spendable']:
|
if i['spendable']:
|
||||||
spendcount += 1
|
spendcount += 1
|
||||||
if (ismine == 2):
|
if ismine == 2:
|
||||||
assert_equal(spendcount, len(script_list))
|
assert_equal(spendcount, len(script_list))
|
||||||
elif (ismine == 1):
|
elif ismine == 1:
|
||||||
assert_equal(watchcount, len(script_list))
|
assert_equal(watchcount, len(script_list))
|
||||||
assert_equal(spendcount, 0)
|
assert_equal(spendcount, 0)
|
||||||
else:
|
else:
|
||||||
@ -616,7 +620,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
p2sh = CScript(bytes.fromhex(v['scriptPubKey']))
|
p2sh = CScript(bytes.fromhex(v['scriptPubKey']))
|
||||||
p2wsh = script_to_p2wsh_script(bare)
|
p2wsh = script_to_p2wsh_script(bare)
|
||||||
p2sh_p2wsh = script_to_p2sh_script(p2wsh)
|
p2sh_p2wsh = script_to_p2sh_script(p2wsh)
|
||||||
return([bare, p2sh, p2wsh, p2sh_p2wsh])
|
return [bare, p2sh, p2wsh, p2sh_p2wsh]
|
||||||
|
|
||||||
def p2pkh_address_to_script(self, v):
|
def p2pkh_address_to_script(self, v):
|
||||||
pubkey = bytes.fromhex(v['pubkey'])
|
pubkey = bytes.fromhex(v['pubkey'])
|
||||||
|
Reference in New Issue
Block a user