Changeset View
Changeset View
Standalone View
Standalone View
qa/rpc-tests/test_framework/util.py
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
BITCOIND_PROC_WAIT_TIMEOUT = 60 | BITCOIND_PROC_WAIT_TIMEOUT = 60 | ||||
class PortSeed: | class PortSeed: | ||||
# Must be initialized with a unique integer for each process | # Must be initialized with a unique integer for each process | ||||
n = None | n = None | ||||
# Set Mocktime default to OFF. | # Set Mocktime default to OFF. | ||||
# MOCKTIME is only needed for scripts that use the | # MOCKTIME is only needed for scripts that use the | ||||
# cached version of the blockchain. If the cached | # cached version of the blockchain. If the cached | ||||
# version of the blockchain is used without MOCKTIME | # version of the blockchain is used without MOCKTIME | ||||
# then the mempools will not sync due to IBD. | # then the mempools will not sync due to IBD. | ||||
MOCKTIME = 0 | MOCKTIME = 0 | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | while timeout > 0: | ||||
if set(rpc_connections[i].getrawmempool()) == pool: | if set(rpc_connections[i].getrawmempool()) == pool: | ||||
num_match = num_match + 1 | num_match = num_match + 1 | ||||
if num_match == len(rpc_connections): | if num_match == len(rpc_connections): | ||||
return | return | ||||
time.sleep(wait) | time.sleep(wait) | ||||
timeout -= wait | timeout -= wait | ||||
raise AssertionError("Mempool sync failed") | raise AssertionError("Mempool sync failed") | ||||
bitcoind_processes = {} | bitcoind_processes = {} | ||||
def initialize_datadir(dirname, n): | def initialize_datadir(dirname, n): | ||||
datadir = os.path.join(dirname, "node" + str(n)) | datadir = os.path.join(dirname, "node" + str(n)) | ||||
if not os.path.isdir(datadir): | if not os.path.isdir(datadir): | ||||
os.makedirs(datadir) | os.makedirs(datadir) | ||||
rpc_u, rpc_p = rpc_auth_pair(n) | rpc_u, rpc_p = rpc_auth_pair(n) | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | if create_cache: | ||||
os.remove(log_filename(cachedir, i, "db.log")) | os.remove(log_filename(cachedir, i, "db.log")) | ||||
os.remove(log_filename(cachedir, i, "peers.dat")) | os.remove(log_filename(cachedir, i, "peers.dat")) | ||||
os.remove(log_filename(cachedir, i, "fee_estimates.dat")) | os.remove(log_filename(cachedir, i, "fee_estimates.dat")) | ||||
for i in range(num_nodes): | for i in range(num_nodes): | ||||
from_dir = os.path.join(cachedir, "node" + str(i)) | from_dir = os.path.join(cachedir, "node" + str(i)) | ||||
to_dir = os.path.join(test_dir, "node" + str(i)) | to_dir = os.path.join(test_dir, "node" + str(i)) | ||||
shutil.copytree(from_dir, to_dir) | shutil.copytree(from_dir, to_dir) | ||||
initialize_datadir(test_dir, i) | |||||
# Overwrite port/rpcport in bitcoin.conf | # Overwrite port/rpcport in bitcoin.conf | ||||
initialize_datadir(test_dir, i) | |||||
def initialize_chain_clean(test_dir, num_nodes): | def initialize_chain_clean(test_dir, num_nodes): | ||||
""" | """ | ||||
Create an empty blockchain and num_nodes wallets. | Create an empty blockchain and num_nodes wallets. | ||||
Useful if a test case wants complete control over initialization. | Useful if a test case wants complete control over initialization. | ||||
""" | """ | ||||
for i in range(num_nodes): | for i in range(num_nodes): | ||||
▲ Show 20 Lines • Show All 287 Lines • ▼ Show 20 Lines | def assert_fee_amount(fee, tx_size, fee_per_kB): | ||||
if fee > (tx_size + 2) * fee_per_kB / 1000: | if fee > (tx_size + 2) * fee_per_kB / 1000: | ||||
raise AssertionError( | raise AssertionError( | ||||
"Fee of %s BTC too high! (Should be %s BTC)" % (str(fee), str(target_fee))) | "Fee of %s BTC too high! (Should be %s BTC)" % (str(fee), str(target_fee))) | ||||
def assert_equal(thing1, thing2, *args): | def assert_equal(thing1, thing2, *args): | ||||
if thing1 != thing2 or any(thing1 != arg for arg in args): | if thing1 != thing2 or any(thing1 != arg for arg in args): | ||||
raise AssertionError("not(%s)" % " == ".join(str(arg) | raise AssertionError("not(%s)" % " == ".join(str(arg) | ||||
for arg in (thing1, thing2) + args)) | for arg in (thing1, thing2) + args)) | ||||
def assert_greater_than(thing1, thing2): | def assert_greater_than(thing1, thing2): | ||||
if thing1 <= thing2: | if thing1 <= thing2: | ||||
raise AssertionError("%s <= %s" % (str(thing1), str(thing2))) | raise AssertionError("%s <= %s" % (str(thing1), str(thing2))) | ||||
def assert_greater_than_or_equal(thing1, thing2): | def assert_greater_than_or_equal(thing1, thing2): | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | |||||
def satoshi_round(amount): | def satoshi_round(amount): | ||||
return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN) | return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN) | ||||
# Helper to create at least "count" utxos | # Helper to create at least "count" utxos | ||||
# Pass in a fee that is sufficient for relay and mining new transactions. | # Pass in a fee that is sufficient for relay and mining new transactions. | ||||
def create_confirmed_utxos(fee, node, count): | def create_confirmed_utxos(fee, node, count, age=101): | ||||
node.generate(int(0.5 * count) + 101) | node.generate(int(0.5 * count) + age) | ||||
utxos = node.listunspent() | utxos = node.listunspent() | ||||
iterations = count - len(utxos) | iterations = count - len(utxos) | ||||
addr1 = node.getnewaddress() | addr1 = node.getnewaddress() | ||||
addr2 = node.getnewaddress() | addr2 = node.getnewaddress() | ||||
if iterations <= 0: | if iterations <= 0: | ||||
return utxos | return utxos | ||||
for i in range(iterations): | for i in range(iterations): | ||||
t = utxos.pop() | t = utxos.pop() | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |