~ubuntu-branches/debian/stretch/bitcoin/stretch

« back to all changes in this revision

Viewing changes to qa/rpc-tests/test_framework/comptool.py

  • Committer: Package Import Robot
  • Author(s): Anthony Towns
  • Date: 2016-10-21 17:13:13 UTC
  • mfrom: (1.3.2)
  • Revision ID: package-import@ubuntu.com-20161021171313-7eu2ltpbk0xag3q1
Tags: 0.13.0-0.1
* Non-maintainer upload.
* New upstream release.
* Allow compilation with gcc/g++ 6. (Closes: Bug#835963)
* Additional fixes for openssl 1.1 compatibility. (See Bug#828248)
* Check if -latomic is needed (it is on mips*).
* Remove reproducible build patch, since leveldb build system is
  no longer used in 0.13. (See Bug#791834)
* Update description since the blockchain is much more than "several GB"
  now. (Closes: Bug#835809)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python2
2
 
#
3
 
# Distributed under the MIT/X11 software license, see the accompanying
 
1
#!/usr/bin/env python3
 
2
# Copyright (c) 2015-2016 The Bitcoin Core developers
 
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
 
#
6
5
 
7
 
from mininode import *
8
 
from blockstore import BlockStore, TxStore
9
 
from util import p2p_port
 
6
from .mininode import *
 
7
from .blockstore import BlockStore, TxStore
 
8
from .util import p2p_port
10
9
 
11
10
'''
12
11
This is a tool for comparing two or more bitcoinds to each other
27
26
 
28
27
global mininode_lock
29
28
 
30
 
def wait_until(predicate, attempts=float('inf'), timeout=float('inf')):
31
 
    attempt = 0
32
 
    elapsed = 0
33
 
 
34
 
    while attempt < attempts and elapsed < timeout:
35
 
        with mininode_lock:
36
 
            if predicate():
37
 
                return True
38
 
        attempt += 1
39
 
        elapsed += 0.05
40
 
        time.sleep(0.05)
41
 
 
42
 
    return False
43
 
 
44
29
class RejectResult(object):
45
30
    '''
46
31
    Outcome that expects rejection of a transaction or block.
47
32
    '''
48
 
    def __init__(self, code, reason=''):
 
33
    def __init__(self, code, reason=b''):
49
34
        self.code = code
50
35
        self.reason = reason
51
36
    def match(self, other):
111
96
            raise AssertionError("Got pong for unknown ping [%s]" % repr(message))
112
97
 
113
98
    def on_reject(self, conn, message):
114
 
        if message.message == 'tx':
 
99
        if message.message == b'tx':
115
100
            self.tx_reject_map[message.data] = RejectResult(message.code, message.reason)
116
 
        if message.message == 'block':
 
101
        if message.message == b'block':
117
102
            self.block_reject_map[message.data] = RejectResult(message.code, message.reason)
118
103
 
119
104
    def send_inv(self, obj):
273
258
                    if c.cb.bestblockhash == blockhash:
274
259
                        return False
275
260
                    if blockhash not in c.cb.block_reject_map:
276
 
                        print 'Block not in reject map: %064x' % (blockhash)
 
261
                        print('Block not in reject map: %064x' % (blockhash))
277
262
                        return False
278
263
                    if not outcome.match(c.cb.block_reject_map[blockhash]):
279
 
                        print 'Block rejected with %s instead of expected %s: %064x' % (c.cb.block_reject_map[blockhash], outcome, blockhash)
 
264
                        print('Block rejected with %s instead of expected %s: %064x' % (c.cb.block_reject_map[blockhash], outcome, blockhash))
280
265
                        return False
281
266
                elif ((c.cb.bestblockhash == blockhash) != outcome):
282
267
                    # print c.cb.bestblockhash, blockhash, outcome
301
286
                    if txhash in c.cb.lastInv:
302
287
                        return False
303
288
                    if txhash not in c.cb.tx_reject_map:
304
 
                        print 'Tx not in reject map: %064x' % (txhash)
 
289
                        print('Tx not in reject map: %064x' % (txhash))
305
290
                        return False
306
291
                    if not outcome.match(c.cb.tx_reject_map[txhash]):
307
 
                        print 'Tx rejected with %s instead of expected %s: %064x' % (c.cb.tx_reject_map[txhash], outcome, txhash)
 
292
                        print('Tx rejected with %s instead of expected %s: %064x' % (c.cb.tx_reject_map[txhash], outcome, txhash))
308
293
                        return False
309
294
                elif ((txhash in c.cb.lastInv) != outcome):
310
295
                    # print c.rpc.getrawmempool(), c.cb.lastInv
407
392
                if (not self.check_mempool(tx.sha256, tx_outcome)):
408
393
                    raise AssertionError("Mempool test failed at test %d" % test_number)
409
394
 
410
 
            print "Test %d: PASS" % test_number, [ c.rpc.getblockcount() for c in self.connections ]
 
395
            print("Test %d: PASS" % test_number, [ c.rpc.getblockcount() for c in self.connections ])
411
396
            test_number += 1
412
397
 
413
398
        [ c.disconnect_node() for c in self.connections ]