[qa] Bug fixes and refactor
Github-Pull: #7778 Rebased-From: fa524d9ddbad0a03f9eb974100fb3b6001045645 fa2cea163b49a97e2a18aa125e41170d60ce59cc faaa3c9b6546d9a64cece4ff0223f0b167feb6ff 444480649f08e6037f8ac178224b30a82e9ad72e
This commit is contained in:
parent
b1dd64bffe
commit
ff9b436163
@ -32,13 +32,13 @@ import re
|
|||||||
from tests_config import *
|
from tests_config import *
|
||||||
|
|
||||||
#If imported values are not defined then set to zero (or disabled)
|
#If imported values are not defined then set to zero (or disabled)
|
||||||
if not vars().has_key('ENABLE_WALLET'):
|
if 'ENABLE_WALLET' not in vars():
|
||||||
ENABLE_WALLET=0
|
ENABLE_WALLET=0
|
||||||
if not vars().has_key('ENABLE_BITCOIND'):
|
if 'ENABLE_BITCOIND' not in vars():
|
||||||
ENABLE_BITCOIND=0
|
ENABLE_BITCOIND=0
|
||||||
if not vars().has_key('ENABLE_UTILS'):
|
if 'ENABLE_UTILS' not in vars():
|
||||||
ENABLE_UTILS=0
|
ENABLE_UTILS=0
|
||||||
if not vars().has_key('ENABLE_ZMQ'):
|
if 'ENABLE_ZMQ' not in vars():
|
||||||
ENABLE_ZMQ=0
|
ENABLE_ZMQ=0
|
||||||
|
|
||||||
ENABLE_COVERAGE=0
|
ENABLE_COVERAGE=0
|
||||||
|
@ -11,7 +11,7 @@ from test_framework.blocktools import create_coinbase, create_block
|
|||||||
from test_framework.comptool import TestInstance, TestManager
|
from test_framework.comptool import TestInstance, TestManager
|
||||||
from test_framework.script import CScript, OP_1NEGATE, OP_CHECKLOCKTIMEVERIFY, OP_DROP
|
from test_framework.script import CScript, OP_1NEGATE, OP_CHECKLOCKTIMEVERIFY, OP_DROP
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
import cStringIO
|
from io import BytesIO
|
||||||
import time
|
import time
|
||||||
|
|
||||||
def cltv_invalidate(tx):
|
def cltv_invalidate(tx):
|
||||||
@ -60,7 +60,7 @@ class BIP65Test(ComparisonTestFramework):
|
|||||||
rawtx = node.createrawtransaction(inputs, outputs)
|
rawtx = node.createrawtransaction(inputs, outputs)
|
||||||
signresult = node.signrawtransaction(rawtx)
|
signresult = node.signrawtransaction(rawtx)
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
f = cStringIO.StringIO(unhexlify(signresult['hex']))
|
f = BytesIO(unhexlify(signresult['hex']))
|
||||||
tx.deserialize(f)
|
tx.deserialize(f)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ class BIP65Test(ComparisonTestFramework):
|
|||||||
height = 3 # height of the next block to build
|
height = 3 # height of the next block to build
|
||||||
self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
|
self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
|
||||||
self.nodeaddress = self.nodes[0].getnewaddress()
|
self.nodeaddress = self.nodes[0].getnewaddress()
|
||||||
self.last_block_time = time.time()
|
self.last_block_time = int(time.time())
|
||||||
|
|
||||||
''' 98 more version 3 blocks '''
|
''' 98 more version 3 blocks '''
|
||||||
test_blocks = []
|
test_blocks = []
|
||||||
|
@ -11,7 +11,7 @@ from test_framework.blocktools import create_coinbase, create_block
|
|||||||
from test_framework.comptool import TestInstance, TestManager
|
from test_framework.comptool import TestInstance, TestManager
|
||||||
from test_framework.script import *
|
from test_framework.script import *
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
import cStringIO
|
from io import BytesIO
|
||||||
import time
|
import time
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@ -119,7 +119,7 @@ class BIP68_112_113Test(ComparisonTestFramework):
|
|||||||
outputs = { to_address : amount }
|
outputs = { to_address : amount }
|
||||||
rawtx = node.createrawtransaction(inputs, outputs)
|
rawtx = node.createrawtransaction(inputs, outputs)
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
f = cStringIO.StringIO(unhexlify(rawtx))
|
f = BytesIO(unhexlify(rawtx))
|
||||||
tx.deserialize(f)
|
tx.deserialize(f)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ class BIP68_112_113Test(ComparisonTestFramework):
|
|||||||
rawtx = ToHex(unsignedtx)
|
rawtx = ToHex(unsignedtx)
|
||||||
signresult = node.signrawtransaction(rawtx)
|
signresult = node.signrawtransaction(rawtx)
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
f = cStringIO.StringIO(unhexlify(signresult['hex']))
|
f = BytesIO(unhexlify(signresult['hex']))
|
||||||
tx.deserialize(f)
|
tx.deserialize(f)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ from test_framework.blocktools import create_coinbase, create_block
|
|||||||
from test_framework.comptool import TestInstance, TestManager
|
from test_framework.comptool import TestInstance, TestManager
|
||||||
from test_framework.script import CScript, OP_1NEGATE, OP_NOP3, OP_DROP
|
from test_framework.script import CScript, OP_1NEGATE, OP_NOP3, OP_DROP
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
import cStringIO
|
from io import BytesIO
|
||||||
import time
|
import time
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ class BIP9SoftForksTest(ComparisonTestFramework):
|
|||||||
outputs = { to_address : amount }
|
outputs = { to_address : amount }
|
||||||
rawtx = node.createrawtransaction(inputs, outputs)
|
rawtx = node.createrawtransaction(inputs, outputs)
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
f = cStringIO.StringIO(unhexlify(rawtx))
|
f = BytesIO(unhexlify(rawtx))
|
||||||
tx.deserialize(f)
|
tx.deserialize(f)
|
||||||
tx.nVersion = 2
|
tx.nVersion = 2
|
||||||
return tx
|
return tx
|
||||||
@ -61,7 +61,7 @@ class BIP9SoftForksTest(ComparisonTestFramework):
|
|||||||
def sign_transaction(self, node, tx):
|
def sign_transaction(self, node, tx):
|
||||||
signresult = node.signrawtransaction(hexlify(tx.serialize()))
|
signresult = node.signrawtransaction(hexlify(tx.serialize()))
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
f = cStringIO.StringIO(unhexlify(signresult['hex']))
|
f = BytesIO(unhexlify(signresult['hex']))
|
||||||
tx.deserialize(f)
|
tx.deserialize(f)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ from test_framework.blocktools import create_coinbase, create_block
|
|||||||
from test_framework.comptool import TestInstance, TestManager
|
from test_framework.comptool import TestInstance, TestManager
|
||||||
from test_framework.script import CScript
|
from test_framework.script import CScript
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
import cStringIO
|
from io import BytesIO
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# A canonical signature consists of:
|
# A canonical signature consists of:
|
||||||
@ -68,7 +68,7 @@ class BIP66Test(ComparisonTestFramework):
|
|||||||
rawtx = node.createrawtransaction(inputs, outputs)
|
rawtx = node.createrawtransaction(inputs, outputs)
|
||||||
signresult = node.signrawtransaction(rawtx)
|
signresult = node.signrawtransaction(rawtx)
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
f = cStringIO.StringIO(unhexlify(signresult['hex']))
|
f = BytesIO(unhexlify(signresult['hex']))
|
||||||
tx.deserialize(f)
|
tx.deserialize(f)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ class BIP66Test(ComparisonTestFramework):
|
|||||||
height = 3 # height of the next block to build
|
height = 3 # height of the next block to build
|
||||||
self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
|
self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
|
||||||
self.nodeaddress = self.nodes[0].getnewaddress()
|
self.nodeaddress = self.nodes[0].getnewaddress()
|
||||||
self.last_block_time = time.time()
|
self.last_block_time = int(time.time())
|
||||||
|
|
||||||
''' 98 more version 2 blocks '''
|
''' 98 more version 2 blocks '''
|
||||||
test_blocks = []
|
test_blocks = []
|
||||||
|
@ -7,7 +7,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||||||
from test_framework.util import *
|
from test_framework.util import *
|
||||||
from test_framework.mininode import *
|
from test_framework.mininode import *
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from cStringIO import StringIO
|
from io import BytesIO
|
||||||
|
|
||||||
class DecodeScriptTest(BitcoinTestFramework):
|
class DecodeScriptTest(BitcoinTestFramework):
|
||||||
"""Tests decoding scripts via RPC command "decodescript"."""
|
"""Tests decoding scripts via RPC command "decodescript"."""
|
||||||
@ -131,7 +131,7 @@ class DecodeScriptTest(BitcoinTestFramework):
|
|||||||
assert_equal('OP_DUP OP_HASH160 dc863734a218bfe83ef770ee9d41a27f824a6e56 OP_EQUALVERIFY OP_CHECKSIG', rpc_result['vout'][0]['scriptPubKey']['asm'])
|
assert_equal('OP_DUP OP_HASH160 dc863734a218bfe83ef770ee9d41a27f824a6e56 OP_EQUALVERIFY OP_CHECKSIG', rpc_result['vout'][0]['scriptPubKey']['asm'])
|
||||||
assert_equal('OP_HASH160 2a5edea39971049a540474c6a99edf0aa4074c58 OP_EQUAL', rpc_result['vout'][1]['scriptPubKey']['asm'])
|
assert_equal('OP_HASH160 2a5edea39971049a540474c6a99edf0aa4074c58 OP_EQUAL', rpc_result['vout'][1]['scriptPubKey']['asm'])
|
||||||
txSave = CTransaction()
|
txSave = CTransaction()
|
||||||
txSave.deserialize(StringIO(unhexlify(tx)))
|
txSave.deserialize(BytesIO(unhexlify(tx)))
|
||||||
|
|
||||||
# make sure that a specifically crafted op_return value will not pass all the IsDERSignature checks and then get decoded as a sighash type
|
# make sure that a specifically crafted op_return value will not pass all the IsDERSignature checks and then get decoded as a sighash type
|
||||||
tx = '01000000015ded05872fdbda629c7d3d02b194763ce3b9b1535ea884e3c8e765d42e316724020000006b48304502204c10d4064885c42638cbff3585915b322de33762598321145ba033fc796971e2022100bb153ad3baa8b757e30a2175bd32852d2e1cb9080f84d7e32fcdfd667934ef1b012103163c0ff73511ea1743fb5b98384a2ff09dd06949488028fd819f4d83f56264efffffffff0200000000000000000b6a0930060201000201000180380100000000001976a9141cabd296e753837c086da7a45a6c2fe0d49d7b7b88ac00000000'
|
tx = '01000000015ded05872fdbda629c7d3d02b194763ce3b9b1535ea884e3c8e765d42e316724020000006b48304502204c10d4064885c42638cbff3585915b322de33762598321145ba033fc796971e2022100bb153ad3baa8b757e30a2175bd32852d2e1cb9080f84d7e32fcdfd667934ef1b012103163c0ff73511ea1743fb5b98384a2ff09dd06949488028fd819f4d83f56264efffffffff0200000000000000000b6a0930060201000201000180380100000000001976a9141cabd296e753837c086da7a45a6c2fe0d49d7b7b88ac00000000'
|
||||||
|
@ -48,7 +48,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
watchonly_address = self.nodes[0].getnewaddress()
|
watchonly_address = self.nodes[0].getnewaddress()
|
||||||
watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"]
|
watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"]
|
||||||
watchonly_amount = 200
|
watchonly_amount = Decimal(200)
|
||||||
self.nodes[3].importpubkey(watchonly_pubkey, "", True)
|
self.nodes[3].importpubkey(watchonly_pubkey, "", True)
|
||||||
watchonly_txid = self.nodes[0].sendtoaddress(watchonly_address, watchonly_amount)
|
watchonly_txid = self.nodes[0].sendtoaddress(watchonly_address, watchonly_amount)
|
||||||
self.nodes[0].sendtoaddress(self.nodes[3].getnewaddress(), watchonly_amount / 10)
|
self.nodes[0].sendtoaddress(self.nodes[3].getnewaddress(), watchonly_amount / 10)
|
||||||
@ -209,7 +209,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||||||
matchingOuts = 0
|
matchingOuts = 0
|
||||||
for i, out in enumerate(dec_tx['vout']):
|
for i, out in enumerate(dec_tx['vout']):
|
||||||
totalOut += out['value']
|
totalOut += out['value']
|
||||||
if outputs.has_key(out['scriptPubKey']['addresses'][0]):
|
if out['scriptPubKey']['addresses'][0] in outputs:
|
||||||
matchingOuts+=1
|
matchingOuts+=1
|
||||||
else:
|
else:
|
||||||
assert_equal(i, rawtxfund['changepos'])
|
assert_equal(i, rawtxfund['changepos'])
|
||||||
@ -249,7 +249,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||||||
matchingOuts = 0
|
matchingOuts = 0
|
||||||
for out in dec_tx['vout']:
|
for out in dec_tx['vout']:
|
||||||
totalOut += out['value']
|
totalOut += out['value']
|
||||||
if outputs.has_key(out['scriptPubKey']['addresses'][0]):
|
if out['scriptPubKey']['addresses'][0] in outputs:
|
||||||
matchingOuts+=1
|
matchingOuts+=1
|
||||||
|
|
||||||
assert_equal(matchingOuts, 1)
|
assert_equal(matchingOuts, 1)
|
||||||
@ -291,7 +291,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||||||
matchingOuts = 0
|
matchingOuts = 0
|
||||||
for out in dec_tx['vout']:
|
for out in dec_tx['vout']:
|
||||||
totalOut += out['value']
|
totalOut += out['value']
|
||||||
if outputs.has_key(out['scriptPubKey']['addresses'][0]):
|
if out['scriptPubKey']['addresses'][0] in outputs:
|
||||||
matchingOuts+=1
|
matchingOuts+=1
|
||||||
|
|
||||||
assert_equal(matchingOuts, 2)
|
assert_equal(matchingOuts, 2)
|
||||||
@ -309,7 +309,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||||||
try:
|
try:
|
||||||
rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
|
rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
|
||||||
raise AssertionError("Spent more than available")
|
raise AssertionError("Spent more than available")
|
||||||
except JSONRPCException,e:
|
except JSONRPCException as e:
|
||||||
assert("Insufficient" in e.error['message'])
|
assert("Insufficient" in e.error['message'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class KeyPoolTest(BitcoinTestFramework):
|
|||||||
try:
|
try:
|
||||||
addr = nodes[0].getnewaddress()
|
addr = nodes[0].getnewaddress()
|
||||||
raise AssertionError('Keypool should be exhausted after one address')
|
raise AssertionError('Keypool should be exhausted after one address')
|
||||||
except JSONRPCException,e:
|
except JSONRPCException as e:
|
||||||
assert(e.error['code']==-12)
|
assert(e.error['code']==-12)
|
||||||
|
|
||||||
# put three new keys in the keypool
|
# put three new keys in the keypool
|
||||||
@ -66,7 +66,7 @@ class KeyPoolTest(BitcoinTestFramework):
|
|||||||
try:
|
try:
|
||||||
addr = nodes[0].getrawchangeaddress()
|
addr = nodes[0].getrawchangeaddress()
|
||||||
raise AssertionError('Keypool should be exhausted after three addresses')
|
raise AssertionError('Keypool should be exhausted after three addresses')
|
||||||
except JSONRPCException,e:
|
except JSONRPCException as e:
|
||||||
assert(e.error['code']==-12)
|
assert(e.error['code']==-12)
|
||||||
|
|
||||||
# refill keypool with three new addresses
|
# refill keypool with three new addresses
|
||||||
@ -84,7 +84,7 @@ class KeyPoolTest(BitcoinTestFramework):
|
|||||||
try:
|
try:
|
||||||
nodes[0].generate(1)
|
nodes[0].generate(1)
|
||||||
raise AssertionError('Keypool should be exhausted after three addesses')
|
raise AssertionError('Keypool should be exhausted after three addesses')
|
||||||
except JSONRPCException,e:
|
except JSONRPCException as e:
|
||||||
assert(e.error['code']==-12)
|
assert(e.error['code']==-12)
|
||||||
|
|
||||||
def setup_chain(self):
|
def setup_chain(self):
|
||||||
|
@ -8,12 +8,12 @@
|
|||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import *
|
from test_framework.util import *
|
||||||
from test_framework.mininode import CTransaction, COIN
|
from test_framework.mininode import CTransaction, COIN
|
||||||
import cStringIO
|
from io import BytesIO
|
||||||
import binascii
|
import binascii
|
||||||
|
|
||||||
def txFromHex(hexstring):
|
def txFromHex(hexstring):
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
f = cStringIO.StringIO(binascii.unhexlify(hexstring))
|
f = BytesIO(binascii.unhexlify(hexstring))
|
||||||
tx.deserialize(f)
|
tx.deserialize(f)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ class ListTransactionsTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
# Replace tx3, and check that tx4 becomes unknown
|
# Replace tx3, and check that tx4 becomes unknown
|
||||||
tx3_b = tx3_modified
|
tx3_b = tx3_modified
|
||||||
tx3_b.vout[0].nValue -= 0.004 * COIN # bump the fee
|
tx3_b.vout[0].nValue -= int(Decimal("0.004") * COIN) # bump the fee
|
||||||
tx3_b = binascii.hexlify(tx3_b.serialize()).decode('utf-8')
|
tx3_b = binascii.hexlify(tx3_b.serialize()).decode('utf-8')
|
||||||
tx3_b_signed = self.nodes[0].signrawtransaction(tx3_b)['hex']
|
tx3_b_signed = self.nodes[0].signrawtransaction(tx3_b)['hex']
|
||||||
txid_3b = self.nodes[0].sendrawtransaction(tx3_b_signed, True)
|
txid_3b = self.nodes[0].sendrawtransaction(tx3_b_signed, True)
|
||||||
|
@ -178,7 +178,7 @@ class MaxUploadTest(BitcoinTestFramework):
|
|||||||
max_bytes_per_day = 200*1024*1024
|
max_bytes_per_day = 200*1024*1024
|
||||||
daily_buffer = 144 * MAX_BLOCK_SIZE
|
daily_buffer = 144 * MAX_BLOCK_SIZE
|
||||||
max_bytes_available = max_bytes_per_day - daily_buffer
|
max_bytes_available = max_bytes_per_day - daily_buffer
|
||||||
success_count = max_bytes_available / old_block_size
|
success_count = max_bytes_available // old_block_size
|
||||||
|
|
||||||
# 144MB will be reserved for relaying new blocks, so expect this to
|
# 144MB will be reserved for relaying new blocks, so expect this to
|
||||||
# succeed for ~70 tries.
|
# succeed for ~70 tries.
|
||||||
|
@ -150,7 +150,7 @@ class AcceptBlockTest(BitcoinTestFramework):
|
|||||||
# 2. Send one block that builds on each tip.
|
# 2. Send one block that builds on each tip.
|
||||||
# This should be accepted.
|
# This should be accepted.
|
||||||
blocks_h2 = [] # the height 2 blocks on each node's chain
|
blocks_h2 = [] # the height 2 blocks on each node's chain
|
||||||
block_time = time.time() + 1
|
block_time = int(time.time()) + 1
|
||||||
for i in xrange(2):
|
for i in xrange(2):
|
||||||
blocks_h2.append(create_block(tips[i], create_coinbase(2), block_time))
|
blocks_h2.append(create_block(tips[i], create_coinbase(2), block_time))
|
||||||
blocks_h2[i].solve()
|
blocks_h2[i].solve()
|
||||||
|
@ -270,7 +270,7 @@ class FullBlockTest(ComparisonTestFramework):
|
|||||||
# \-> b3 (1) -> b4 (2)
|
# \-> b3 (1) -> b4 (2)
|
||||||
|
|
||||||
# Test that a block with a lot of checksigs is okay
|
# Test that a block with a lot of checksigs is okay
|
||||||
lots_of_checksigs = CScript([OP_CHECKSIG] * (1000000 / 50 - 1))
|
lots_of_checksigs = CScript([OP_CHECKSIG] * (1000000 // 50 - 1))
|
||||||
tip(13)
|
tip(13)
|
||||||
block(15, spend=out5, script=lots_of_checksigs)
|
block(15, spend=out5, script=lots_of_checksigs)
|
||||||
yield accepted()
|
yield accepted()
|
||||||
@ -278,7 +278,7 @@ class FullBlockTest(ComparisonTestFramework):
|
|||||||
|
|
||||||
# Test that a block with too many checksigs is rejected
|
# Test that a block with too many checksigs is rejected
|
||||||
out6 = get_spendable_output()
|
out6 = get_spendable_output()
|
||||||
too_many_checksigs = CScript([OP_CHECKSIG] * (1000000 / 50))
|
too_many_checksigs = CScript([OP_CHECKSIG] * (1000000 // 50))
|
||||||
block(16, spend=out6, script=too_many_checksigs)
|
block(16, spend=out6, script=too_many_checksigs)
|
||||||
yield rejected(RejectResult(16, 'bad-blk-sigops'))
|
yield rejected(RejectResult(16, 'bad-blk-sigops'))
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||||||
from test_framework.util import *
|
from test_framework.util import *
|
||||||
|
|
||||||
def calc_usage(blockdir):
|
def calc_usage(blockdir):
|
||||||
return sum(os.path.getsize(blockdir+f) for f in os.listdir(blockdir) if os.path.isfile(blockdir+f))/(1024*1024)
|
return sum(os.path.getsize(blockdir+f) for f in os.listdir(blockdir) if os.path.isfile(blockdir+f)) / (1024. * 1024.)
|
||||||
|
|
||||||
class PruneTest(BitcoinTestFramework):
|
class PruneTest(BitcoinTestFramework):
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ class PruneTest(BitcoinTestFramework):
|
|||||||
self.nodes[1].generate(200)
|
self.nodes[1].generate(200)
|
||||||
sync_blocks(self.nodes[0:2])
|
sync_blocks(self.nodes[0:2])
|
||||||
self.nodes[0].generate(150)
|
self.nodes[0].generate(150)
|
||||||
# Then mine enough full blocks to create more than 550MB of data
|
# Then mine enough full blocks to create more than 550MiB of data
|
||||||
for i in xrange(645):
|
for i in xrange(645):
|
||||||
self.mine_full_block(self.nodes[0], self.address[0])
|
self.mine_full_block(self.nodes[0], self.address[0])
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ class PruneTest(BitcoinTestFramework):
|
|||||||
if not os.path.isfile(self.prunedir+"blk00000.dat"):
|
if not os.path.isfile(self.prunedir+"blk00000.dat"):
|
||||||
raise AssertionError("blk00000.dat is missing, pruning too early")
|
raise AssertionError("blk00000.dat is missing, pruning too early")
|
||||||
print "Success"
|
print "Success"
|
||||||
print "Though we're already using more than 550MB, current usage:", calc_usage(self.prunedir)
|
print "Though we're already using more than 550MiB, current usage:", calc_usage(self.prunedir)
|
||||||
print "Mining 25 more blocks should cause the first block file to be pruned"
|
print "Mining 25 more blocks should cause the first block file to be pruned"
|
||||||
# Pruning doesn't run until we're allocating another chunk, 20 full blocks past the height cutoff will ensure this
|
# Pruning doesn't run until we're allocating another chunk, 20 full blocks past the height cutoff will ensure this
|
||||||
for i in xrange(25):
|
for i in xrange(25):
|
||||||
|
@ -59,7 +59,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||||||
errorString = ""
|
errorString = ""
|
||||||
try:
|
try:
|
||||||
rawtx = self.nodes[2].sendrawtransaction(rawtx['hex'])
|
rawtx = self.nodes[2].sendrawtransaction(rawtx['hex'])
|
||||||
except JSONRPCException,e:
|
except JSONRPCException as e:
|
||||||
errorString = e.error['message']
|
errorString = e.error['message']
|
||||||
|
|
||||||
assert("Missing inputs" in errorString)
|
assert("Missing inputs" in errorString)
|
||||||
|
@ -119,7 +119,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
def test_simple_doublespend(self):
|
def test_simple_doublespend(self):
|
||||||
"""Simple doublespend"""
|
"""Simple doublespend"""
|
||||||
tx0_outpoint = make_utxo(self.nodes[0], 1.1*COIN)
|
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
|
||||||
|
|
||||||
tx1a = CTransaction()
|
tx1a = CTransaction()
|
||||||
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
||||||
@ -143,7 +143,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
# Extra 0.1 BTC fee
|
# Extra 0.1 BTC fee
|
||||||
tx1b = CTransaction()
|
tx1b = CTransaction()
|
||||||
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
||||||
tx1b.vout = [CTxOut(0.9*COIN, CScript([b'b']))]
|
tx1b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
|
||||||
tx1b_hex = txToHex(tx1b)
|
tx1b_hex = txToHex(tx1b)
|
||||||
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
|
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
_total_txs=_total_txs):
|
_total_txs=_total_txs):
|
||||||
yield x
|
yield x
|
||||||
|
|
||||||
fee = 0.0001*COIN
|
fee = int(0.0001*COIN)
|
||||||
n = MAX_REPLACEMENT_LIMIT
|
n = MAX_REPLACEMENT_LIMIT
|
||||||
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
|
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
|
||||||
assert_equal(len(tree_txs), n)
|
assert_equal(len(tree_txs), n)
|
||||||
@ -268,7 +268,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
# Try again, but with more total transactions than the "max txs
|
# Try again, but with more total transactions than the "max txs
|
||||||
# double-spent at once" anti-DoS limit.
|
# double-spent at once" anti-DoS limit.
|
||||||
for n in (MAX_REPLACEMENT_LIMIT+1, MAX_REPLACEMENT_LIMIT*2):
|
for n in (MAX_REPLACEMENT_LIMIT+1, MAX_REPLACEMENT_LIMIT*2):
|
||||||
fee = 0.0001*COIN
|
fee = int(0.0001*COIN)
|
||||||
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
|
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
|
||||||
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
|
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
|
||||||
assert_equal(len(tree_txs), n)
|
assert_equal(len(tree_txs), n)
|
||||||
@ -291,7 +291,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
def test_replacement_feeperkb(self):
|
def test_replacement_feeperkb(self):
|
||||||
"""Replacement requires fee-per-KB to be higher"""
|
"""Replacement requires fee-per-KB to be higher"""
|
||||||
tx0_outpoint = make_utxo(self.nodes[0], 1.1*COIN)
|
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
|
||||||
|
|
||||||
tx1a = CTransaction()
|
tx1a = CTransaction()
|
||||||
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
||||||
@ -303,7 +303,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
# rejected.
|
# rejected.
|
||||||
tx1b = CTransaction()
|
tx1b = CTransaction()
|
||||||
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
||||||
tx1b.vout = [CTxOut(0.001*COIN, CScript([b'a'*999000]))]
|
tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*999000]))]
|
||||||
tx1b_hex = txToHex(tx1b)
|
tx1b_hex = txToHex(tx1b)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -315,12 +315,12 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
def test_spends_of_conflicting_outputs(self):
|
def test_spends_of_conflicting_outputs(self):
|
||||||
"""Replacements that spend conflicting tx outputs are rejected"""
|
"""Replacements that spend conflicting tx outputs are rejected"""
|
||||||
utxo1 = make_utxo(self.nodes[0], 1.2*COIN)
|
utxo1 = make_utxo(self.nodes[0], int(1.2*COIN))
|
||||||
utxo2 = make_utxo(self.nodes[0], 3.0*COIN)
|
utxo2 = make_utxo(self.nodes[0], 3*COIN)
|
||||||
|
|
||||||
tx1a = CTransaction()
|
tx1a = CTransaction()
|
||||||
tx1a.vin = [CTxIn(utxo1, nSequence=0)]
|
tx1a.vin = [CTxIn(utxo1, nSequence=0)]
|
||||||
tx1a.vout = [CTxOut(1.1*COIN, CScript([b'a']))]
|
tx1a.vout = [CTxOut(int(1.1*COIN), CScript([b'a']))]
|
||||||
tx1a_hex = txToHex(tx1a)
|
tx1a_hex = txToHex(tx1a)
|
||||||
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
|
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
|
||||||
|
|
||||||
@ -343,7 +343,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
# Spend tx1a's output to test the indirect case.
|
# Spend tx1a's output to test the indirect case.
|
||||||
tx1b = CTransaction()
|
tx1b = CTransaction()
|
||||||
tx1b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]
|
tx1b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]
|
||||||
tx1b.vout = [CTxOut(1.0*COIN, CScript([b'a']))]
|
tx1b.vout = [CTxOut(1*COIN, CScript([b'a']))]
|
||||||
tx1b_hex = txToHex(tx1b)
|
tx1b_hex = txToHex(tx1b)
|
||||||
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
|
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
|
||||||
tx1b_txid = int(tx1b_txid, 16)
|
tx1b_txid = int(tx1b_txid, 16)
|
||||||
@ -363,12 +363,12 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
def test_new_unconfirmed_inputs(self):
|
def test_new_unconfirmed_inputs(self):
|
||||||
"""Replacements that add new unconfirmed inputs are rejected"""
|
"""Replacements that add new unconfirmed inputs are rejected"""
|
||||||
confirmed_utxo = make_utxo(self.nodes[0], 1.1*COIN)
|
confirmed_utxo = make_utxo(self.nodes[0], int(1.1*COIN))
|
||||||
unconfirmed_utxo = make_utxo(self.nodes[0], 0.1*COIN, False)
|
unconfirmed_utxo = make_utxo(self.nodes[0], int(0.1*COIN), False)
|
||||||
|
|
||||||
tx1 = CTransaction()
|
tx1 = CTransaction()
|
||||||
tx1.vin = [CTxIn(confirmed_utxo)]
|
tx1.vin = [CTxIn(confirmed_utxo)]
|
||||||
tx1.vout = [CTxOut(1.0*COIN, CScript([b'a']))]
|
tx1.vout = [CTxOut(1*COIN, CScript([b'a']))]
|
||||||
tx1_hex = txToHex(tx1)
|
tx1_hex = txToHex(tx1)
|
||||||
tx1_txid = self.nodes[0].sendrawtransaction(tx1_hex, True)
|
tx1_txid = self.nodes[0].sendrawtransaction(tx1_hex, True)
|
||||||
|
|
||||||
@ -392,7 +392,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
# Start by creating a single transaction with many outputs
|
# Start by creating a single transaction with many outputs
|
||||||
initial_nValue = 10*COIN
|
initial_nValue = 10*COIN
|
||||||
utxo = make_utxo(self.nodes[0], initial_nValue)
|
utxo = make_utxo(self.nodes[0], initial_nValue)
|
||||||
fee = 0.0001*COIN
|
fee = int(0.0001*COIN)
|
||||||
split_value = int((initial_nValue-fee)/(MAX_REPLACEMENT_LIMIT+1))
|
split_value = int((initial_nValue-fee)/(MAX_REPLACEMENT_LIMIT+1))
|
||||||
actual_fee = initial_nValue - split_value*(MAX_REPLACEMENT_LIMIT+1)
|
actual_fee = initial_nValue - split_value*(MAX_REPLACEMENT_LIMIT+1)
|
||||||
|
|
||||||
@ -445,7 +445,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
def test_opt_in(self):
|
def test_opt_in(self):
|
||||||
""" Replacing should only work if orig tx opted in """
|
""" Replacing should only work if orig tx opted in """
|
||||||
tx0_outpoint = make_utxo(self.nodes[0], 1.1*COIN)
|
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
|
||||||
|
|
||||||
# Create a non-opting in transaction
|
# Create a non-opting in transaction
|
||||||
tx1a = CTransaction()
|
tx1a = CTransaction()
|
||||||
@ -457,7 +457,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
# Shouldn't be able to double-spend
|
# Shouldn't be able to double-spend
|
||||||
tx1b = CTransaction()
|
tx1b = CTransaction()
|
||||||
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
||||||
tx1b.vout = [CTxOut(0.9*COIN, CScript([b'b']))]
|
tx1b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
|
||||||
tx1b_hex = txToHex(tx1b)
|
tx1b_hex = txToHex(tx1b)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -468,7 +468,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
print tx1b_txid
|
print tx1b_txid
|
||||||
assert(False)
|
assert(False)
|
||||||
|
|
||||||
tx1_outpoint = make_utxo(self.nodes[0], 1.1*COIN)
|
tx1_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
|
||||||
|
|
||||||
# Create a different non-opting in transaction
|
# Create a different non-opting in transaction
|
||||||
tx2a = CTransaction()
|
tx2a = CTransaction()
|
||||||
@ -480,7 +480,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
# Still shouldn't be able to double-spend
|
# Still shouldn't be able to double-spend
|
||||||
tx2b = CTransaction()
|
tx2b = CTransaction()
|
||||||
tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)]
|
tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)]
|
||||||
tx2b.vout = [CTxOut(0.9*COIN, CScript([b'b']))]
|
tx2b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
|
||||||
tx2b_hex = txToHex(tx2b)
|
tx2b_hex = txToHex(tx2b)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -500,19 +500,19 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
tx3a = CTransaction()
|
tx3a = CTransaction()
|
||||||
tx3a.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0xffffffff),
|
tx3a.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0xffffffff),
|
||||||
CTxIn(COutPoint(tx2a_txid, 0), nSequence=0xfffffffd)]
|
CTxIn(COutPoint(tx2a_txid, 0), nSequence=0xfffffffd)]
|
||||||
tx3a.vout = [CTxOut(0.9*COIN, CScript([b'c'])), CTxOut(0.9*COIN, CScript([b'd']))]
|
tx3a.vout = [CTxOut(int(0.9*COIN), CScript([b'c'])), CTxOut(int(0.9*COIN), CScript([b'd']))]
|
||||||
tx3a_hex = txToHex(tx3a)
|
tx3a_hex = txToHex(tx3a)
|
||||||
|
|
||||||
self.nodes[0].sendrawtransaction(tx3a_hex, True)
|
self.nodes[0].sendrawtransaction(tx3a_hex, True)
|
||||||
|
|
||||||
tx3b = CTransaction()
|
tx3b = CTransaction()
|
||||||
tx3b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]
|
tx3b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]
|
||||||
tx3b.vout = [CTxOut(0.5*COIN, CScript([b'e']))]
|
tx3b.vout = [CTxOut(int(0.5*COIN), CScript([b'e']))]
|
||||||
tx3b_hex = txToHex(tx3b)
|
tx3b_hex = txToHex(tx3b)
|
||||||
|
|
||||||
tx3c = CTransaction()
|
tx3c = CTransaction()
|
||||||
tx3c.vin = [CTxIn(COutPoint(tx2a_txid, 0), nSequence=0)]
|
tx3c.vin = [CTxIn(COutPoint(tx2a_txid, 0), nSequence=0)]
|
||||||
tx3c.vout = [CTxOut(0.5*COIN, CScript([b'f']))]
|
tx3c.vout = [CTxOut(int(0.5*COIN), CScript([b'f']))]
|
||||||
tx3c_hex = txToHex(tx3c)
|
tx3c_hex = txToHex(tx3c)
|
||||||
|
|
||||||
self.nodes[0].sendrawtransaction(tx3b_hex, True)
|
self.nodes[0].sendrawtransaction(tx3b_hex, True)
|
||||||
@ -525,7 +525,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
# correctly used by replacement logic
|
# correctly used by replacement logic
|
||||||
|
|
||||||
# 1. Check that feeperkb uses modified fees
|
# 1. Check that feeperkb uses modified fees
|
||||||
tx0_outpoint = make_utxo(self.nodes[0], 1.1*COIN)
|
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
|
||||||
|
|
||||||
tx1a = CTransaction()
|
tx1a = CTransaction()
|
||||||
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
||||||
@ -536,7 +536,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
# Higher fee, but the actual fee per KB is much lower.
|
# Higher fee, but the actual fee per KB is much lower.
|
||||||
tx1b = CTransaction()
|
tx1b = CTransaction()
|
||||||
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
||||||
tx1b.vout = [CTxOut(0.001*COIN, CScript([b'a'*740000]))]
|
tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*740000]))]
|
||||||
tx1b_hex = txToHex(tx1b)
|
tx1b_hex = txToHex(tx1b)
|
||||||
|
|
||||||
# Verify tx1b cannot replace tx1a.
|
# Verify tx1b cannot replace tx1a.
|
||||||
@ -556,7 +556,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
assert(tx1b_txid in self.nodes[0].getrawmempool())
|
assert(tx1b_txid in self.nodes[0].getrawmempool())
|
||||||
|
|
||||||
# 2. Check that absolute fee checks use modified fee.
|
# 2. Check that absolute fee checks use modified fee.
|
||||||
tx1_outpoint = make_utxo(self.nodes[0], 1.1*COIN)
|
tx1_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
|
||||||
|
|
||||||
tx2a = CTransaction()
|
tx2a = CTransaction()
|
||||||
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0)]
|
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0)]
|
||||||
@ -567,7 +567,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||||||
# Lower fee, but we'll prioritise it
|
# Lower fee, but we'll prioritise it
|
||||||
tx2b = CTransaction()
|
tx2b = CTransaction()
|
||||||
tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)]
|
tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)]
|
||||||
tx2b.vout = [CTxOut(1.01*COIN, CScript([b'a']))]
|
tx2b.vout = [CTxOut(int(1.01*COIN), CScript([b'a']))]
|
||||||
tx2b.rehash()
|
tx2b.rehash()
|
||||||
tx2b_hex = txToHex(tx2b)
|
tx2b_hex = txToHex(tx2b)
|
||||||
|
|
||||||
|
@ -11,8 +11,9 @@
|
|||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import *
|
from test_framework.util import *
|
||||||
from struct import *
|
from struct import *
|
||||||
|
from io import BytesIO
|
||||||
|
from codecs import encode
|
||||||
import binascii
|
import binascii
|
||||||
import StringIO
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import http.client as httplib
|
import http.client as httplib
|
||||||
@ -146,7 +147,7 @@ class RESTTest (BitcoinTestFramework):
|
|||||||
binaryRequest += pack("i", 0)
|
binaryRequest += pack("i", 0)
|
||||||
|
|
||||||
bin_response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'bin', binaryRequest)
|
bin_response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'bin', binaryRequest)
|
||||||
output = StringIO.StringIO()
|
output = BytesIO()
|
||||||
output.write(bin_response)
|
output.write(bin_response)
|
||||||
output.seek(0)
|
output.seek(0)
|
||||||
chainHeight = unpack("i", output.read(4))[0]
|
chainHeight = unpack("i", output.read(4))[0]
|
||||||
@ -233,7 +234,7 @@ class RESTTest (BitcoinTestFramework):
|
|||||||
assert_equal(response_hex.status, 200)
|
assert_equal(response_hex.status, 200)
|
||||||
assert_greater_than(int(response_hex.getheader('content-length')), 160)
|
assert_greater_than(int(response_hex.getheader('content-length')), 160)
|
||||||
response_hex_str = response_hex.read()
|
response_hex_str = response_hex.read()
|
||||||
assert_equal(response_str.encode("hex")[0:160], response_hex_str[0:160])
|
assert_equal(encode(response_str, "hex")[0:160], response_hex_str[0:160])
|
||||||
|
|
||||||
# compare with hex block header
|
# compare with hex block header
|
||||||
response_header_hex = http_get_call(url.hostname, url.port, '/rest/headers/1/'+bb_hash+self.FORMAT_SEPARATOR+"hex", True)
|
response_header_hex = http_get_call(url.hostname, url.port, '/rest/headers/1/'+bb_hash+self.FORMAT_SEPARATOR+"hex", True)
|
||||||
@ -241,7 +242,7 @@ class RESTTest (BitcoinTestFramework):
|
|||||||
assert_greater_than(int(response_header_hex.getheader('content-length')), 160)
|
assert_greater_than(int(response_header_hex.getheader('content-length')), 160)
|
||||||
response_header_hex_str = response_header_hex.read()
|
response_header_hex_str = response_header_hex.read()
|
||||||
assert_equal(response_hex_str[0:160], response_header_hex_str[0:160])
|
assert_equal(response_hex_str[0:160], response_header_hex_str[0:160])
|
||||||
assert_equal(response_header_str.encode("hex")[0:160], response_header_hex_str[0:160])
|
assert_equal(encode(response_header_str, "hex")[0:160], response_header_hex_str[0:160])
|
||||||
|
|
||||||
# check json format
|
# check json format
|
||||||
block_json_string = http_get_call(url.hostname, url.port, '/rest/block/'+bb_hash+self.FORMAT_SEPARATOR+'json')
|
block_json_string = http_get_call(url.hostname, url.port, '/rest/block/'+bb_hash+self.FORMAT_SEPARATOR+'json')
|
||||||
|
@ -105,7 +105,7 @@ def check_estimates(node, fees_seen, max_invalid, print_estimates = True):
|
|||||||
print([str(all_estimates[e-1]) for e in [1,2,3,6,15,25]])
|
print([str(all_estimates[e-1]) for e in [1,2,3,6,15,25]])
|
||||||
delta = 1.0e-6 # account for rounding error
|
delta = 1.0e-6 # account for rounding error
|
||||||
last_e = max(fees_seen)
|
last_e = max(fees_seen)
|
||||||
for e in filter(lambda x: x >= 0, all_estimates):
|
for e in [x for x in all_estimates if x >= 0]:
|
||||||
# Estimates should be within the bounds of what transactions fees actually were:
|
# Estimates should be within the bounds of what transactions fees actually were:
|
||||||
if float(e)+delta < min(fees_seen) or float(e)-delta > max(fees_seen):
|
if float(e)+delta < min(fees_seen) or float(e)-delta > max(fees_seen):
|
||||||
raise AssertionError("Estimated fee (%f) out of range (%f,%f)"
|
raise AssertionError("Estimated fee (%f) out of range (%f,%f)"
|
||||||
@ -219,7 +219,7 @@ class EstimateFeeTest(BitcoinTestFramework):
|
|||||||
from_index = random.randint(1,2)
|
from_index = random.randint(1,2)
|
||||||
(txhex, fee) = small_txpuzzle_randfee(self.nodes[from_index], self.confutxo,
|
(txhex, fee) = small_txpuzzle_randfee(self.nodes[from_index], self.confutxo,
|
||||||
self.memutxo, Decimal("0.005"), min_fee, min_fee)
|
self.memutxo, Decimal("0.005"), min_fee, min_fee)
|
||||||
tx_kbytes = (len(txhex)/2)/1000.0
|
tx_kbytes = (len(txhex) // 2) / 1000.0
|
||||||
self.fees_per_kb.append(float(fee)/tx_kbytes)
|
self.fees_per_kb.append(float(fee)/tx_kbytes)
|
||||||
sync_mempools(self.nodes[0:3],.1)
|
sync_mempools(self.nodes[0:3],.1)
|
||||||
mined = mining_node.getblock(mining_node.generate(1)[0],True)["tx"]
|
mined = mining_node.getblock(mining_node.generate(1)[0],True)["tx"]
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
# and for constructing a getheaders message
|
# and for constructing a getheaders message
|
||||||
#
|
#
|
||||||
|
|
||||||
from mininode import *
|
from .mininode import *
|
||||||
import dbm
|
import dbm
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
class BlockStore(object):
|
class BlockStore(object):
|
||||||
def __init__(self, datadir):
|
def __init__(self, datadir):
|
||||||
@ -21,7 +22,7 @@ class BlockStore(object):
|
|||||||
serialized_block = self.blockDB[repr(blockhash)]
|
serialized_block = self.blockDB[repr(blockhash)]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
f = cStringIO.StringIO(serialized_block)
|
f = BytesIO(serialized_block)
|
||||||
ret = CBlock()
|
ret = CBlock()
|
||||||
ret.deserialize(f)
|
ret.deserialize(f)
|
||||||
ret.calc_sha256()
|
ret.calc_sha256()
|
||||||
@ -115,7 +116,7 @@ class TxStore(object):
|
|||||||
serialized_tx = self.txDB[repr(txhash)]
|
serialized_tx = self.txDB[repr(txhash)]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
f = cStringIO.StringIO(serialized_tx)
|
f = BytesIO(serialized_tx)
|
||||||
ret = CTransaction()
|
ret = CTransaction()
|
||||||
ret.deserialize(f)
|
ret.deserialize(f)
|
||||||
ret.calc_sha256()
|
ret.calc_sha256()
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
#
|
#
|
||||||
|
|
||||||
from mininode import *
|
from .mininode import *
|
||||||
from script import CScript, OP_TRUE, OP_CHECKSIG
|
from .script import CScript, OP_TRUE, OP_CHECKSIG
|
||||||
|
|
||||||
# Create a block (with regtest difficulty)
|
# Create a block (with regtest difficulty)
|
||||||
def create_block(hashprev, coinbase, nTime=None):
|
def create_block(hashprev, coinbase, nTime=None):
|
||||||
@ -29,7 +29,7 @@ def serialize_script_num(value):
|
|||||||
neg = value < 0
|
neg = value < 0
|
||||||
absvalue = -value if neg else value
|
absvalue = -value if neg else value
|
||||||
while (absvalue):
|
while (absvalue):
|
||||||
r.append(chr(absvalue & 0xff))
|
r.append(int(absvalue & 0xff))
|
||||||
absvalue >>= 8
|
absvalue >>= 8
|
||||||
if r[-1] & 0x80:
|
if r[-1] & 0x80:
|
||||||
r.append(0x80 if neg else 0)
|
r.append(0x80 if neg else 0)
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
#
|
#
|
||||||
|
|
||||||
from mininode import *
|
from .mininode import *
|
||||||
from blockstore import BlockStore, TxStore
|
from .blockstore import BlockStore, TxStore
|
||||||
from util import p2p_port
|
from .util import p2p_port
|
||||||
|
|
||||||
'''
|
'''
|
||||||
This is a tool for comparing two or more bitcoinds to each other
|
This is a tool for comparing two or more bitcoinds to each other
|
||||||
|
@ -24,7 +24,8 @@ import binascii
|
|||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
import cStringIO
|
from io import BytesIO
|
||||||
|
from codecs import encode
|
||||||
import hashlib
|
import hashlib
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
@ -75,12 +76,12 @@ def deser_string(f):
|
|||||||
|
|
||||||
def ser_string(s):
|
def ser_string(s):
|
||||||
if len(s) < 253:
|
if len(s) < 253:
|
||||||
return chr(len(s)) + s
|
return struct.pack("B", len(s)) + s
|
||||||
elif len(s) < 0x10000:
|
elif len(s) < 0x10000:
|
||||||
return chr(253) + struct.pack("<H", len(s)) + s
|
return struct.pack("<BH", 253, len(s)) + s
|
||||||
elif len(s) < 0x100000000L:
|
elif len(s) < 0x100000000L:
|
||||||
return chr(254) + struct.pack("<I", len(s)) + s
|
return struct.pack("<BI", 254, len(s)) + s
|
||||||
return chr(255) + struct.pack("<Q", len(s)) + s
|
return struct.pack("<BQ", 255, len(s)) + s
|
||||||
|
|
||||||
|
|
||||||
def deser_uint256(f):
|
def deser_uint256(f):
|
||||||
@ -132,13 +133,13 @@ def deser_vector(f, c):
|
|||||||
def ser_vector(l):
|
def ser_vector(l):
|
||||||
r = ""
|
r = ""
|
||||||
if len(l) < 253:
|
if len(l) < 253:
|
||||||
r = chr(len(l))
|
r = struct.pack("B", len(l))
|
||||||
elif len(l) < 0x10000:
|
elif len(l) < 0x10000:
|
||||||
r = chr(253) + struct.pack("<H", len(l))
|
r = struct.pack("<BH", 253, len(l))
|
||||||
elif len(l) < 0x100000000L:
|
elif len(l) < 0x100000000L:
|
||||||
r = chr(254) + struct.pack("<I", len(l))
|
r = struct.pack("<BI", 254, len(l))
|
||||||
else:
|
else:
|
||||||
r = chr(255) + struct.pack("<Q", len(l))
|
r = struct.pack("<BQ", 255, len(l))
|
||||||
for i in l:
|
for i in l:
|
||||||
r += i.serialize()
|
r += i.serialize()
|
||||||
return r
|
return r
|
||||||
@ -162,13 +163,13 @@ def deser_uint256_vector(f):
|
|||||||
def ser_uint256_vector(l):
|
def ser_uint256_vector(l):
|
||||||
r = ""
|
r = ""
|
||||||
if len(l) < 253:
|
if len(l) < 253:
|
||||||
r = chr(len(l))
|
r = struct.pack("B", len(l))
|
||||||
elif len(l) < 0x10000:
|
elif len(l) < 0x10000:
|
||||||
r = chr(253) + struct.pack("<H", len(l))
|
r = struct.pack("<BH", 253, len(l))
|
||||||
elif len(l) < 0x100000000L:
|
elif len(l) < 0x100000000L:
|
||||||
r = chr(254) + struct.pack("<I", len(l))
|
r = struct.pack("<BI", 254, len(l))
|
||||||
else:
|
else:
|
||||||
r = chr(255) + struct.pack("<Q", len(l))
|
r = struct.pack("<BQ", 255, len(l))
|
||||||
for i in l:
|
for i in l:
|
||||||
r += ser_uint256(i)
|
r += ser_uint256(i)
|
||||||
return r
|
return r
|
||||||
@ -192,13 +193,13 @@ def deser_string_vector(f):
|
|||||||
def ser_string_vector(l):
|
def ser_string_vector(l):
|
||||||
r = ""
|
r = ""
|
||||||
if len(l) < 253:
|
if len(l) < 253:
|
||||||
r = chr(len(l))
|
r = struct.pack("B", len(l))
|
||||||
elif len(l) < 0x10000:
|
elif len(l) < 0x10000:
|
||||||
r = chr(253) + struct.pack("<H", len(l))
|
r = struct.pack("<BH", 253, len(l))
|
||||||
elif len(l) < 0x100000000L:
|
elif len(l) < 0x100000000L:
|
||||||
r = chr(254) + struct.pack("<I", len(l))
|
r = struct.pack("<BI", 254, len(l))
|
||||||
else:
|
else:
|
||||||
r = chr(255) + struct.pack("<Q", len(l))
|
r = struct.pack("<BQ", 255, len(l))
|
||||||
for sv in l:
|
for sv in l:
|
||||||
r += ser_string(sv)
|
r += ser_string(sv)
|
||||||
return r
|
return r
|
||||||
@ -222,20 +223,20 @@ def deser_int_vector(f):
|
|||||||
def ser_int_vector(l):
|
def ser_int_vector(l):
|
||||||
r = ""
|
r = ""
|
||||||
if len(l) < 253:
|
if len(l) < 253:
|
||||||
r = chr(len(l))
|
r = struct.pack("B", len(l))
|
||||||
elif len(l) < 0x10000:
|
elif len(l) < 0x10000:
|
||||||
r = chr(253) + struct.pack("<H", len(l))
|
r = struct.pack("<BH", 253, len(l))
|
||||||
elif len(l) < 0x100000000L:
|
elif len(l) < 0x100000000L:
|
||||||
r = chr(254) + struct.pack("<I", len(l))
|
r = struct.pack("<BI", 254, len(l))
|
||||||
else:
|
else:
|
||||||
r = chr(255) + struct.pack("<Q", len(l))
|
r = struct.pack("<BQ", 255, len(l))
|
||||||
for i in l:
|
for i in l:
|
||||||
r += struct.pack("<i", i)
|
r += struct.pack("<i", i)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
# Deserialize from a hex string representation (eg from RPC)
|
# Deserialize from a hex string representation (eg from RPC)
|
||||||
def FromHex(obj, hex_string):
|
def FromHex(obj, hex_string):
|
||||||
obj.deserialize(cStringIO.StringIO(binascii.unhexlify(hex_string)))
|
obj.deserialize(BytesIO(binascii.unhexlify(hex_string)))
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
# Convert a binary-serializable object to hex (eg for submission via RPC)
|
# Convert a binary-serializable object to hex (eg for submission via RPC)
|
||||||
@ -423,7 +424,7 @@ class CTransaction(object):
|
|||||||
def calc_sha256(self):
|
def calc_sha256(self):
|
||||||
if self.sha256 is None:
|
if self.sha256 is None:
|
||||||
self.sha256 = uint256_from_str(hash256(self.serialize()))
|
self.sha256 = uint256_from_str(hash256(self.serialize()))
|
||||||
self.hash = hash256(self.serialize())[::-1].encode('hex_codec')
|
self.hash = encode(hash256(self.serialize())[::-1], 'hex')
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
self.calc_sha256()
|
self.calc_sha256()
|
||||||
@ -492,7 +493,7 @@ class CBlockHeader(object):
|
|||||||
r += struct.pack("<I", self.nBits)
|
r += struct.pack("<I", self.nBits)
|
||||||
r += struct.pack("<I", self.nNonce)
|
r += struct.pack("<I", self.nNonce)
|
||||||
self.sha256 = uint256_from_str(hash256(r))
|
self.sha256 = uint256_from_str(hash256(r))
|
||||||
self.hash = hash256(r)[::-1].encode('hex_codec')
|
self.hash = encode(hash256(r)[::-1], 'hex')
|
||||||
|
|
||||||
def rehash(self):
|
def rehash(self):
|
||||||
self.sha256 = None
|
self.sha256 = None
|
||||||
@ -640,7 +641,7 @@ class msg_version(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.nVersion = MY_VERSION
|
self.nVersion = MY_VERSION
|
||||||
self.nServices = 1
|
self.nServices = 1
|
||||||
self.nTime = time.time()
|
self.nTime = int(time.time())
|
||||||
self.addrTo = CAddress()
|
self.addrTo = CAddress()
|
||||||
self.addrFrom = CAddress()
|
self.addrFrom = CAddress()
|
||||||
self.nNonce = random.getrandbits(64)
|
self.nNonce = random.getrandbits(64)
|
||||||
@ -985,7 +986,7 @@ class msg_reject(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.message = ""
|
self.message = ""
|
||||||
self.code = ""
|
self.code = 0
|
||||||
self.reason = ""
|
self.reason = ""
|
||||||
self.data = 0L
|
self.data = 0L
|
||||||
|
|
||||||
@ -1192,6 +1193,7 @@ class NodeConn(asyncore.dispatcher):
|
|||||||
self.sendbuf = self.sendbuf[sent:]
|
self.sendbuf = self.sendbuf[sent:]
|
||||||
|
|
||||||
def got_data(self):
|
def got_data(self):
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
if len(self.recvbuf) < 4:
|
if len(self.recvbuf) < 4:
|
||||||
return
|
return
|
||||||
@ -1222,13 +1224,15 @@ class NodeConn(asyncore.dispatcher):
|
|||||||
raise ValueError("got bad checksum " + repr(self.recvbuf))
|
raise ValueError("got bad checksum " + repr(self.recvbuf))
|
||||||
self.recvbuf = self.recvbuf[4+12+4+4+msglen:]
|
self.recvbuf = self.recvbuf[4+12+4+4+msglen:]
|
||||||
if command in self.messagemap:
|
if command in self.messagemap:
|
||||||
f = cStringIO.StringIO(msg)
|
f = BytesIO(msg)
|
||||||
t = self.messagemap[command]()
|
t = self.messagemap[command]()
|
||||||
t.deserialize(f)
|
t.deserialize(f)
|
||||||
self.got_message(t)
|
self.got_message(t)
|
||||||
else:
|
else:
|
||||||
self.show_debug_msg("Unknown command: '" + command + "' " +
|
self.show_debug_msg("Unknown command: '" + command + "' " +
|
||||||
repr(msg))
|
repr(msg))
|
||||||
|
except Exception as e:
|
||||||
|
print 'got_data:', repr(e)
|
||||||
|
|
||||||
def send_message(self, message, pushbuf=False):
|
def send_message(self, message, pushbuf=False):
|
||||||
if self.state != "connected" and not pushbuf:
|
if self.state != "connected" and not pushbuf:
|
||||||
|
@ -45,7 +45,7 @@ def _convert_ip_port(array):
|
|||||||
# convert host from mangled-per-four-bytes form as used by kernel
|
# convert host from mangled-per-four-bytes form as used by kernel
|
||||||
host = binascii.unhexlify(host)
|
host = binascii.unhexlify(host)
|
||||||
host_out = ''
|
host_out = ''
|
||||||
for x in range(0, len(host)/4):
|
for x in range(0, len(host) // 4):
|
||||||
(val,) = struct.unpack('=I', host[x*4:(x+1)*4])
|
(val,) = struct.unpack('=I', host[x*4:(x+1)*4])
|
||||||
host_out += '%08x' % val
|
host_out += '%08x' % val
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ class Socks5Connection(object):
|
|||||||
self.serv.queue.put(cmdin)
|
self.serv.queue.put(cmdin)
|
||||||
print('Proxy: ', cmdin)
|
print('Proxy: ', cmdin)
|
||||||
# Fall through to disconnect
|
# Fall through to disconnect
|
||||||
except Exception,e:
|
except Exception as e:
|
||||||
traceback.print_exc(file=sys.stderr)
|
traceback.print_exc(file=sys.stderr)
|
||||||
self.serv.queue.put(e)
|
self.serv.queue.put(e)
|
||||||
finally:
|
finally:
|
||||||
|
@ -26,7 +26,7 @@ from .util import (
|
|||||||
check_json_precision,
|
check_json_precision,
|
||||||
initialize_chain_clean,
|
initialize_chain_clean,
|
||||||
)
|
)
|
||||||
from authproxy import AuthServiceProxy, JSONRPCException
|
from .authproxy import AuthServiceProxy, JSONRPCException
|
||||||
|
|
||||||
|
|
||||||
class BitcoinTestFramework(object):
|
class BitcoinTestFramework(object):
|
||||||
@ -140,7 +140,7 @@ class BitcoinTestFramework(object):
|
|||||||
print("JSONRPC error: "+e.error['message'])
|
print("JSONRPC error: "+e.error['message'])
|
||||||
traceback.print_tb(sys.exc_info()[2])
|
traceback.print_tb(sys.exc_info()[2])
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
print("Assertion failed: "+e.message)
|
print("Assertion failed: "+ str(e))
|
||||||
traceback.print_tb(sys.exc_info()[2])
|
traceback.print_tb(sys.exc_info()[2])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Unexpected exception caught during testing: "+str(e))
|
print("Unexpected exception caught during testing: "+str(e))
|
||||||
|
@ -250,7 +250,7 @@ class WalletTest (BitcoinTestFramework):
|
|||||||
errorString = ""
|
errorString = ""
|
||||||
try:
|
try:
|
||||||
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "1f-4")
|
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "1f-4")
|
||||||
except JSONRPCException,e:
|
except JSONRPCException as e:
|
||||||
errorString = e.error['message']
|
errorString = e.error['message']
|
||||||
|
|
||||||
assert("Invalid amount" in errorString)
|
assert("Invalid amount" in errorString)
|
||||||
@ -258,7 +258,7 @@ class WalletTest (BitcoinTestFramework):
|
|||||||
errorString = ""
|
errorString = ""
|
||||||
try:
|
try:
|
||||||
self.nodes[0].generate("2") #use a string to as block amount parameter must fail because it's not interpreted as amount
|
self.nodes[0].generate("2") #use a string to as block amount parameter must fail because it's not interpreted as amount
|
||||||
except JSONRPCException,e:
|
except JSONRPCException as e:
|
||||||
errorString = e.error['message']
|
errorString = e.error['message']
|
||||||
|
|
||||||
assert("not an integer" in errorString)
|
assert("not an integer" in errorString)
|
||||||
|
Loading…
Reference in New Issue
Block a user