Skip to content

Commit 89ae854

Browse files
author
MarcoFalke
committed
Merge bitcoin#7811: [0.12.2] qa Backports
6862627 Add listunspent() test for spendable/unspendable UTXO (Joao Fonseca) 28ba22c [qa] Remove misleading "errorString syntax" (MarcoFalke) f1f1b82 [qa] py2: Unfiddle strings into bytes explicitly (MarcoFalke) c0d9e31 Tests: make prioritise_transaction.py more robust (Suhas Daftuar) ff9b436 [qa] Bug fixes and refactor (MarcoFalke) b1dd64b [qa] wallet: Wait for reindex to catch up (MarcoFalke) f23cb7c [qa] Add tests verifychain, lockunspent, getbalance, listsinceblock (MarcoFalke) 3316552 [qa] Test walletpassphrase timeout (MarcoFalke) 6aae129 [qa] wallet: Print maintenance (MarcoFalke) ad8c743 [qa] Extend tests (MarcoFalke) d89fbfe [qa] rpc-test: Normalize assert() (MarcoFalke)
2 parents 9779e1e + 6862627 commit 89ae854

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+563
-573
lines changed

qa/pull-tester/rpc-tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
from tests_config import *
3333

3434
#If imported values are not defined then set to zero (or disabled)
35-
if not vars().has_key('ENABLE_WALLET'):
35+
if 'ENABLE_WALLET' not in vars():
3636
ENABLE_WALLET=0
37-
if not vars().has_key('ENABLE_BITCOIND'):
37+
if 'ENABLE_BITCOIND' not in vars():
3838
ENABLE_BITCOIND=0
39-
if not vars().has_key('ENABLE_UTILS'):
39+
if 'ENABLE_UTILS' not in vars():
4040
ENABLE_UTILS=0
41-
if not vars().has_key('ENABLE_ZMQ'):
41+
if 'ENABLE_ZMQ' not in vars():
4242
ENABLE_ZMQ=0
4343

4444
ENABLE_COVERAGE=0

qa/rpc-tests/bip65-cltv-p2p.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from test_framework.blocktools import create_coinbase, create_block
1111
from test_framework.comptool import TestInstance, TestManager
1212
from test_framework.script import CScript, OP_1NEGATE, OP_CHECKLOCKTIMEVERIFY, OP_DROP
13-
from binascii import unhexlify
14-
import cStringIO
13+
from io import BytesIO
1514
import time
1615

1716
def cltv_invalidate(tx):
@@ -60,7 +59,7 @@ def create_transaction(self, node, coinbase, to_address, amount):
6059
rawtx = node.createrawtransaction(inputs, outputs)
6160
signresult = node.signrawtransaction(rawtx)
6261
tx = CTransaction()
63-
f = cStringIO.StringIO(unhexlify(signresult['hex']))
62+
f = BytesIO(hex_str_to_bytes(signresult['hex']))
6463
tx.deserialize(f)
6564
return tx
6665

@@ -70,7 +69,7 @@ def get_tests(self):
7069
height = 3 # height of the next block to build
7170
self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
7271
self.nodeaddress = self.nodes[0].getnewaddress()
73-
self.last_block_time = time.time()
72+
self.last_block_time = int(time.time())
7473

7574
''' 98 more version 3 blocks '''
7675
test_blocks = []

qa/rpc-tests/bip68-112-113-p2p.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from test_framework.blocktools import create_coinbase, create_block
1111
from test_framework.comptool import TestInstance, TestManager
1212
from test_framework.script import *
13-
from binascii import unhexlify
14-
import cStringIO
13+
from io import BytesIO
1514
import time
1615

1716
'''
@@ -119,15 +118,15 @@ def create_transaction(self, node, txid, to_address, amount):
119118
outputs = { to_address : amount }
120119
rawtx = node.createrawtransaction(inputs, outputs)
121120
tx = CTransaction()
122-
f = cStringIO.StringIO(unhexlify(rawtx))
121+
f = BytesIO(hex_str_to_bytes(rawtx))
123122
tx.deserialize(f)
124123
return tx
125124

126125
def sign_transaction(self, node, unsignedtx):
127126
rawtx = ToHex(unsignedtx)
128127
signresult = node.signrawtransaction(rawtx)
129128
tx = CTransaction()
130-
f = cStringIO.StringIO(unhexlify(signresult['hex']))
129+
f = BytesIO(hex_str_to_bytes(signresult['hex']))
131130
tx.deserialize(f)
132131
return tx
133132

qa/rpc-tests/bip68-sequence.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from test_framework.mininode import *
1414
from test_framework.blocktools import *
1515

16-
COIN = 100000000
1716
SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31)
1817
SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22) # this means use time (0 means height)
1918
SEQUENCE_LOCKTIME_GRANULARITY = 9 # this is a bit-shift

qa/rpc-tests/bip9-softforks.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from test_framework.blocktools import create_coinbase, create_block
1111
from test_framework.comptool import TestInstance, TestManager
1212
from test_framework.script import CScript, OP_1NEGATE, OP_NOP3, OP_DROP
13-
from binascii import hexlify, unhexlify
14-
import cStringIO
13+
from io import BytesIO
1514
import time
1615
import itertools
1716

@@ -30,7 +29,6 @@
3029
'''
3130

3231

33-
3432
class BIP9SoftForksTest(ComparisonTestFramework):
3533

3634
def __init__(self):
@@ -53,15 +51,15 @@ def create_transaction(self, node, coinbase, to_address, amount):
5351
outputs = { to_address : amount }
5452
rawtx = node.createrawtransaction(inputs, outputs)
5553
tx = CTransaction()
56-
f = cStringIO.StringIO(unhexlify(rawtx))
54+
f = BytesIO(hex_str_to_bytes(rawtx))
5755
tx.deserialize(f)
5856
tx.nVersion = 2
5957
return tx
6058

6159
def sign_transaction(self, node, tx):
62-
signresult = node.signrawtransaction(hexlify(tx.serialize()))
60+
signresult = node.signrawtransaction(bytes_to_hex_str(tx.serialize()))
6361
tx = CTransaction()
64-
f = cStringIO.StringIO(unhexlify(signresult['hex']))
62+
f = BytesIO(hex_str_to_bytes(signresult['hex']))
6563
tx.deserialize(f)
6664
return tx
6765

@@ -184,7 +182,6 @@ def test_BIP(self, bipName, activated_version, invalidate, invalidatePostSignatu
184182
NetworkThread().start() # Start up network handling in another thread
185183

186184

187-
188185
def get_tests(self):
189186
for test in itertools.chain(
190187
self.test_BIP('csv', 536870913, self.sequence_lock_invalidate, self.donothing),
@@ -217,4 +214,4 @@ def mtp_invalidate(self, tx):
217214
tx.nLockTime = self.last_block_time
218215

219216
if __name__ == '__main__':
220-
BIP9SoftForksTest().main()
217+
BIP9SoftForksTest().main()

qa/rpc-tests/bipdersig-p2p.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from test_framework.blocktools import create_coinbase, create_block
1111
from test_framework.comptool import TestInstance, TestManager
1212
from test_framework.script import CScript
13-
from binascii import unhexlify
14-
import cStringIO
13+
from io import BytesIO
1514
import time
1615

1716
# A canonical signature consists of:
@@ -25,7 +24,7 @@ def unDERify(tx):
2524
newscript = []
2625
for i in scriptSig:
2726
if (len(newscript) == 0):
28-
newscript.append(i[0:-1] + '\0' + i[-1])
27+
newscript.append(i[0:-1] + b'\0' + i[-1:])
2928
else:
3029
newscript.append(i)
3130
tx.vin[0].scriptSig = CScript(newscript)
@@ -68,7 +67,7 @@ def create_transaction(self, node, coinbase, to_address, amount):
6867
rawtx = node.createrawtransaction(inputs, outputs)
6968
signresult = node.signrawtransaction(rawtx)
7069
tx = CTransaction()
71-
f = cStringIO.StringIO(unhexlify(signresult['hex']))
70+
f = BytesIO(hex_str_to_bytes(signresult['hex']))
7271
tx.deserialize(f)
7372
return tx
7473

@@ -78,7 +77,7 @@ def get_tests(self):
7877
height = 3 # height of the next block to build
7978
self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
8079
self.nodeaddress = self.nodes[0].getnewaddress()
81-
self.last_block_time = time.time()
80+
self.last_block_time = int(time.time())
8281

8382
''' 98 more version 2 blocks '''
8483
test_blocks = []

qa/rpc-tests/blockchain.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class BlockchainTest(BitcoinTestFramework):
2828
Test blockchain-related RPC calls:
2929
3030
- gettxoutsetinfo
31+
- verifychain
3132
3233
"""
3334

@@ -44,6 +45,7 @@ def setup_network(self, split=False):
4445
def run_test(self):
4546
self._test_gettxoutsetinfo()
4647
self._test_getblockheader()
48+
self.nodes[0].verifychain(4, 0)
4749

4850
def _test_gettxoutsetinfo(self):
4951
node = self.nodes[0]

qa/rpc-tests/decodescript.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from test_framework.test_framework import BitcoinTestFramework
77
from test_framework.util import *
88
from test_framework.mininode import *
9-
from binascii import hexlify, unhexlify
10-
from cStringIO import StringIO
9+
from io import BytesIO
1110

1211
class DecodeScriptTest(BitcoinTestFramework):
1312
"""Tests decoding scripts via RPC command "decodescript"."""
@@ -131,7 +130,7 @@ def decoderawtransaction_asm_sighashtype(self):
131130
assert_equal('OP_DUP OP_HASH160 dc863734a218bfe83ef770ee9d41a27f824a6e56 OP_EQUALVERIFY OP_CHECKSIG', rpc_result['vout'][0]['scriptPubKey']['asm'])
132131
assert_equal('OP_HASH160 2a5edea39971049a540474c6a99edf0aa4074c58 OP_EQUAL', rpc_result['vout'][1]['scriptPubKey']['asm'])
133132
txSave = CTransaction()
134-
txSave.deserialize(StringIO(unhexlify(tx)))
133+
txSave.deserialize(BytesIO(hex_str_to_bytes(tx)))
135134

136135
# make sure that a specifically crafted op_return value will not pass all the IsDERSignature checks and then get decoded as a sighash type
137136
tx = '01000000015ded05872fdbda629c7d3d02b194763ce3b9b1535ea884e3c8e765d42e316724020000006b48304502204c10d4064885c42638cbff3585915b322de33762598321145ba033fc796971e2022100bb153ad3baa8b757e30a2175bd32852d2e1cb9080f84d7e32fcdfd667934ef1b012103163c0ff73511ea1743fb5b98384a2ff09dd06949488028fd819f4d83f56264efffffffff0200000000000000000b6a0930060201000201000180380100000000001976a9141cabd296e753837c086da7a45a6c2fe0d49d7b7b88ac00000000'
@@ -147,7 +146,7 @@ def decoderawtransaction_asm_sighashtype(self):
147146
# some more full transaction tests of varying specific scriptSigs. used instead of
148147
# tests in decodescript_script_sig because the decodescript RPC is specifically
149148
# for working on scriptPubKeys (argh!).
150-
push_signature = hexlify(txSave.vin[0].scriptSig)[2:(0x48*2+4)]
149+
push_signature = bytes_to_hex_str(txSave.vin[0].scriptSig)[2:(0x48*2+4)]
151150
signature = push_signature[2:]
152151
der_signature = signature[:-2]
153152
signature_sighash_decoded = der_signature + '[ALL]'
@@ -156,25 +155,24 @@ def decoderawtransaction_asm_sighashtype(self):
156155
signature_2_sighash_decoded = der_signature + '[NONE|ANYONECANPAY]'
157156

158157
# 1) P2PK scriptSig
159-
txSave.vin[0].scriptSig = unhexlify(push_signature)
160-
rpc_result = self.nodes[0].decoderawtransaction(hexlify(txSave.serialize()))
158+
txSave.vin[0].scriptSig = hex_str_to_bytes(push_signature)
159+
rpc_result = self.nodes[0].decoderawtransaction(bytes_to_hex_str(txSave.serialize()))
161160
assert_equal(signature_sighash_decoded, rpc_result['vin'][0]['scriptSig']['asm'])
162161

163162
# make sure that the sighash decodes come out correctly for a more complex / lesser used case.
164-
txSave.vin[0].scriptSig = unhexlify(push_signature_2)
165-
rpc_result = self.nodes[0].decoderawtransaction(hexlify(txSave.serialize()))
163+
txSave.vin[0].scriptSig = hex_str_to_bytes(push_signature_2)
164+
rpc_result = self.nodes[0].decoderawtransaction(bytes_to_hex_str(txSave.serialize()))
166165
assert_equal(signature_2_sighash_decoded, rpc_result['vin'][0]['scriptSig']['asm'])
167166

168167
# 2) multisig scriptSig
169-
txSave.vin[0].scriptSig = unhexlify('00' + push_signature + push_signature_2)
170-
rpc_result = self.nodes[0].decoderawtransaction(hexlify(txSave.serialize()))
168+
txSave.vin[0].scriptSig = hex_str_to_bytes('00' + push_signature + push_signature_2)
169+
rpc_result = self.nodes[0].decoderawtransaction(bytes_to_hex_str(txSave.serialize()))
171170
assert_equal('0 ' + signature_sighash_decoded + ' ' + signature_2_sighash_decoded, rpc_result['vin'][0]['scriptSig']['asm'])
172171

173172
# 3) test a scriptSig that contains more than push operations.
174173
# in fact, it contains an OP_RETURN with data specially crafted to cause improper decode if the code does not catch it.
175-
txSave.vin[0].scriptSig = unhexlify('6a143011020701010101010101020601010101010101')
176-
rpc_result = self.nodes[0].decoderawtransaction(hexlify(txSave.serialize()))
177-
print(hexlify('636174'))
174+
txSave.vin[0].scriptSig = hex_str_to_bytes('6a143011020701010101010101020601010101010101')
175+
rpc_result = self.nodes[0].decoderawtransaction(bytes_to_hex_str(txSave.serialize()))
178176
assert_equal('OP_RETURN 3011020701010101010101020601010101010101', rpc_result['vin'][0]['scriptSig']['asm'])
179177

180178
def run_test(self):

0 commit comments

Comments
 (0)