Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions test/functional/data/invalid_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
OP_SUBSTR,
OP_XOR,
)
from test_framework.util import assert_equal
from test_framework.script_util import (
MIN_PADDING,
MIN_STANDARD_TX_NONWITNESS_SIZE,
Expand Down Expand Up @@ -122,8 +123,8 @@ def get_tx(self):
tx = CTransaction()
tx.vin.append(self.valid_txin)
tx.vout.append(CTxOut(0, CScript([OP_RETURN] + ([OP_0] * (MIN_PADDING - 2)))))
assert len(tx.serialize_without_witness()) == 64
assert MIN_STANDARD_TX_NONWITNESS_SIZE - 1 == 64
assert_equal(len(tx.serialize_without_witness()), 64)
assert_equal(MIN_STANDARD_TX_NONWITNESS_SIZE - 1, 64)
return tx

# reject a transaction that contains a witness
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_assumeutxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def run_test(self):

# Generate a series of blocks that `n0` will have in the snapshot,
# but that n1 and n2 don't yet see.
assert n0.getblockcount() == START_HEIGHT
assert_equal(n0.getblockcount(), START_HEIGHT)
blocks = {START_HEIGHT: Block(n0.getbestblockhash(), 1, START_HEIGHT + 1)}
for i in range(100):
block_tx = 1
Expand Down
5 changes: 3 additions & 2 deletions test/functional/feature_posix_fs_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import stat

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal


class PosixFsPermissionsTest(BitcoinTestFramework):
Expand All @@ -22,12 +23,12 @@ def skip_test_if_missing_module(self):
def check_directory_permissions(self, dir):
mode = os.lstat(dir).st_mode
self.log.info(f"{stat.filemode(mode)} {dir}")
assert mode == (stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
assert_equal(mode, (stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR))

def check_file_permissions(self, file):
mode = os.lstat(file).st_mode
self.log.info(f"{stat.filemode(mode)} {file}")
assert mode == (stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR)
assert_equal(mode, (stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR))

def run_test(self):
self.stop_node(0)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def reorg_test(self):
self.nodes[1].invalidateblock(curhash)
curhash = self.nodes[1].getblockhash(self.forkheight - 1)

assert self.nodes[1].getblockcount() == self.forkheight - 1
assert_equal(self.nodes[1].getblockcount(), self.forkheight - 1)
self.log.info(f"New best height: {self.nodes[1].getblockcount()}")

# Disconnect node1 and generate the new chain
Expand Down
3 changes: 2 additions & 1 deletion test/functional/feature_reindex_readonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import stat
import subprocess
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal


class BlockstoreReindexTest(BitcoinTestFramework):
Expand Down Expand Up @@ -77,7 +78,7 @@ def reindex_readonly(self):
self.log.debug("Attempt to restart and reindex the node with the unwritable block file")
with self.nodes[0].assert_debug_log(["Reindexing finished"], timeout=60):
self.start_node(0, extra_args=['-reindex', '-fastprune'])
assert block_count == self.nodes[0].getblockcount()
assert_equal(block_count, self.nodes[0].getblockcount())
undo_immutable()

filename.chmod(0o777)
Expand Down
12 changes: 6 additions & 6 deletions test/functional/feature_taproot.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ def spenders_taproot_active():
for witlen in [20, 31, 32, 33]:
def mutate(spk):
prog = spk[2:]
assert len(prog) == 32
assert_equal(len(prog), 32)
if witlen < 32:
prog = prog[0:witlen]
elif witlen > 32:
Expand Down Expand Up @@ -1532,7 +1532,7 @@ def test_spenders(self, node, spenders, input_counts):
self.log.info("- Running %i spending tests" % done)
random.shuffle(normal_utxos)
random.shuffle(mismatching_utxos)
assert done == len(normal_utxos) + len(mismatching_utxos)
assert_equal(done, len(normal_utxos) + len(mismatching_utxos))

left = done
while left:
Expand Down Expand Up @@ -1645,9 +1645,9 @@ def test_spenders(self, node, spenders, input_counts):
if (len(spenders) - left) // 200 > (len(spenders) - left - len(input_utxos)) // 200:
self.log.info(" - %i tests done" % (len(spenders) - left))

assert left == 0
assert len(normal_utxos) == 0
assert len(mismatching_utxos) == 0
assert_equal(left, 0)
assert not normal_utxos
assert not mismatching_utxos
self.log.info(" - Done")

def gen_test_vectors(self):
Expand All @@ -1662,7 +1662,7 @@ def gen_test_vectors(self):
coinbase.vin = [CTxIn(COutPoint(0, 0xffffffff), CScript([OP_1, OP_1]), SEQUENCE_FINAL)]
coinbase.vout = [CTxOut(5000000000, CScript([OP_1]))]
coinbase.nLockTime = 0
assert coinbase.txid_hex == "f60c73405d499a956d3162e3483c395526ef78286458a4cb17b125aa92e49b20"
assert_equal(coinbase.txid_hex, "f60c73405d499a956d3162e3483c395526ef78286458a4cb17b125aa92e49b20")
# Mine it
block = create_block(hashprev=int(self.nodes[0].getbestblockhash(), 16), coinbase=coinbase)
block.solve()
Expand Down
6 changes: 3 additions & 3 deletions test/functional/interface_zmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def receive_sequence(self):
label = chr(body[32])
mempool_sequence = None if len(body) != 32+1+8 else struct.unpack("<Q", body[32+1:])[0]
if mempool_sequence is not None:
assert label == "A" or label == "R"
assert label in ("A", "R")
else:
assert label == "D" or label == "C"
assert label in ("D", "C")
return (hash, label, mempool_sequence)


Expand Down Expand Up @@ -480,7 +480,7 @@ def test_mempool_sync(self):
while zmq_mem_seq is None:
(hash_str, label, zmq_mem_seq) = seq.receive_sequence()

assert label == "A" or label == "R"
assert label in ("A", "R")
assert hash_str is not None

# 2) We need to "seed" our view of the mempool
Expand Down
4 changes: 2 additions & 2 deletions test/functional/mempool_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def add_chain_cluster(self, node, cluster_count, target_vsize=None):
all_txids.append(next_tx["txid"])
utxo_to_spend = next_tx["new_utxo"]

assert node.getmempoolcluster(parent_tx['txid'])['txcount'] == cluster_count
assert_equal(node.getmempoolcluster(parent_tx['txid'])['txcount'], cluster_count)
return all_results

def check_feerate_diagram(self, node):
Expand All @@ -81,7 +81,7 @@ def check_feerate_diagram(self, node):
last_val = {"weight": 0, "fee": 0}
for x in feeratediagram:
# The weight is always positive, except for the first iteration
assert x['weight'] > 0 or x['fee'] == 0
assert x['weight'] > 0 or not x['fee']
# Monotonically decreasing fee per weight
assert_greater_than_or_equal(last_val['fee'] * x['weight'], x['fee'] * last_val['weight'])
last_val = x
Expand Down
2 changes: 1 addition & 1 deletion test/functional/mempool_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_mid_package_replacement(self):
# Package should be submitted, temporarily exceeding maxmempool, and then evicted.
res = node.submitpackage(package_hex)
assert_equal(res["package_msg"], "transaction failed")
assert len([tx_res for _, tx_res in res["tx-results"].items() if "error" in tx_res and tx_res["error"] == "bad-txns-inputs-missingorspent"])
assert "bad-txns-inputs-missingorspent" in [tx_res["error"] for _, tx_res in res["tx-results"].items() if "error" in tx_res]

# Maximum size must never be exceeded.
assert_greater_than(node.getmempoolinfo()["maxmempool"], node.getmempoolinfo()["bytes"])
Expand Down
18 changes: 12 additions & 6 deletions test/functional/mempool_truc.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ def test_truc_ancestors_package(self):
tx_v3_child = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_parent["new_utxo"], version=3)
tx_v3_grandchild = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_child["new_utxo"], version=3)
result = node.testmempoolaccept([tx_v3_parent["hex"], tx_v3_child["hex"], tx_v3_grandchild["hex"]])
assert all([txresult["package-error"] == f"TRUC-violation, tx {tx_v3_grandchild['txid']} (wtxid={tx_v3_grandchild['wtxid']}) would have too many ancestors" for txresult in result])
for txresult in result:
assert_equal(txresult["package-error"], f"TRUC-violation, tx {tx_v3_grandchild['txid']} (wtxid={tx_v3_grandchild['wtxid']}) would have too many ancestors")

@cleanup(extra_args=None)
def test_truc_ancestors_package_and_mempool(self):
Expand Down Expand Up @@ -440,11 +441,13 @@ def test_truc_in_testmempoolaccept(self):

test_accept_v3_from_v2 = node.testmempoolaccept([tx_v2["hex"], tx_v3_from_v2["hex"]])
expected_error_v3_from_v2 = f"TRUC-violation, version=3 tx {tx_v3_from_v2['txid']} (wtxid={tx_v3_from_v2['wtxid']}) cannot spend from non-version=3 tx {tx_v2['txid']} (wtxid={tx_v2['wtxid']})"
assert all([result["package-error"] == expected_error_v3_from_v2 for result in test_accept_v3_from_v2])
for result in test_accept_v3_from_v2:
assert_equal(result["package-error"], expected_error_v3_from_v2)

test_accept_v2_from_v3 = node.testmempoolaccept([tx_v3["hex"], tx_v2_from_v3["hex"]])
expected_error_v2_from_v3 = f"TRUC-violation, non-version=3 tx {tx_v2_from_v3['txid']} (wtxid={tx_v2_from_v3['wtxid']}) cannot spend from version=3 tx {tx_v3['txid']} (wtxid={tx_v3['wtxid']})"
assert all([result["package-error"] == expected_error_v2_from_v3 for result in test_accept_v2_from_v3])
for result in test_accept_v2_from_v3:
assert_equal(result["package-error"], expected_error_v2_from_v3)

test_accept_pairs = node.testmempoolaccept([tx_v2["hex"], tx_v3["hex"], tx_v2_from_v2["hex"], tx_v3_from_v3["hex"]])
assert all([result["allowed"] for result in test_accept_pairs])
Expand All @@ -456,7 +459,8 @@ def test_truc_in_testmempoolaccept(self):
tx_v3_child_2 = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_parent["new_utxos"][1], version=3)
test_accept_2children = node.testmempoolaccept([tx_v3_parent["hex"], tx_v3_child_1["hex"], tx_v3_child_2["hex"]])
expected_error_2children = f"TRUC-violation, tx {tx_v3_parent['txid']} (wtxid={tx_v3_parent['wtxid']}) would exceed descendant count limit"
assert all([result["package-error"] == expected_error_2children for result in test_accept_2children])
for result in test_accept_2children:
assert_equal(result["package-error"], expected_error_2children)

# Extra TRUC transaction does not get incorrectly marked as extra descendant
test_accept_1child_with_exra = node.testmempoolaccept([tx_v3_parent["hex"], tx_v3_child_1["hex"], tx_v3_independent["hex"]])
Expand All @@ -465,11 +469,13 @@ def test_truc_in_testmempoolaccept(self):
# Extra TRUC transaction does not make us ignore the extra descendant
test_accept_2children_with_exra = node.testmempoolaccept([tx_v3_parent["hex"], tx_v3_child_1["hex"], tx_v3_child_2["hex"], tx_v3_independent["hex"]])
expected_error_extra = f"TRUC-violation, tx {tx_v3_parent['txid']} (wtxid={tx_v3_parent['wtxid']}) would exceed descendant count limit"
assert all([result["package-error"] == expected_error_extra for result in test_accept_2children_with_exra])
for result in test_accept_2children_with_exra:
assert_equal(result["package-error"], expected_error_extra)
# Same result if the parent is already in mempool
node.sendrawtransaction(tx_v3_parent["hex"])
test_accept_2children_with_in_mempool_parent = node.testmempoolaccept([tx_v3_child_1["hex"], tx_v3_child_2["hex"]])
assert all([result["package-error"] == expected_error_extra for result in test_accept_2children_with_in_mempool_parent])
for result in test_accept_2children_with_in_mempool_parent:
assert_equal(result["package-error"], expected_error_extra)

@cleanup(extra_args=None)
def test_reorg_2child_rbf(self):
Expand Down
4 changes: 2 additions & 2 deletions test/functional/mining_getblocktemplate_longpoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import threading

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import get_rpc_proxy
from test_framework.util import assert_equal, get_rpc_proxy
from test_framework.wallet import MiniWallet


Expand Down Expand Up @@ -37,7 +37,7 @@ def run_test(self):
template = self.nodes[0].getblocktemplate({'rules': ['segwit']})
longpollid = template['longpollid']
template2 = self.nodes[0].getblocktemplate({'rules': ['segwit']})
assert template2['longpollid'] == longpollid
assert_equal(template2['longpollid'], longpollid)

self.log.info("Test that longpoll waits if we do nothing")
thr = LongpollThread(self.nodes[0])
Expand Down
4 changes: 2 additions & 2 deletions test/functional/p2p_addrfetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def run_test(self):
self.log.info("Check that we send getaddr but don't try to sync headers with the addr-fetch peer")
peer.sync_with_ping()
with p2p_lock:
assert peer.message_count['getaddr'] == 1
assert peer.message_count['getheaders'] == 0
assert_equal(peer.message_count['getaddr'], 1)
assert_equal(peer.message_count['getheaders'], 0)

self.log.info("Check that answering the getaddr with a single address does not lead to disconnect")
# This prevents disconnecting on self-announcements
Expand Down
4 changes: 2 additions & 2 deletions test/functional/p2p_blockfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def run_test(self):

# Check that nodes have signalled NODE_COMPACT_FILTERS correctly.
assert_not_equal(peer_0.nServices & NODE_COMPACT_FILTERS, 0)
assert peer_1.nServices & NODE_COMPACT_FILTERS == 0
assert_equal(peer_1.nServices & NODE_COMPACT_FILTERS, 0)

# Check that the localservices is as expected.
assert_not_equal(int(self.nodes[0].getnetworkinfo()['localservices'], 16) & NODE_COMPACT_FILTERS, 0)
assert int(self.nodes[1].getnetworkinfo()['localservices'], 16) & NODE_COMPACT_FILTERS == 0
assert_equal(int(self.nodes[1].getnetworkinfo()['localservices'], 16) & NODE_COMPACT_FILTERS, 0)

self.log.info("get cfcheckpt on chain to be re-orged out.")
request = msg_getcfcheckpt(
Expand Down
6 changes: 2 additions & 4 deletions test/functional/p2p_compactblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,7 @@ def test_incorrect_blocktxn_response(self, test_node):

# We should receive a getdata request
test_node.wait_for_getdata([block.hash_int], timeout=10)
assert test_node.last_message["getdata"].inv[0].type == MSG_BLOCK or \
test_node.last_message["getdata"].inv[0].type == MSG_BLOCK | MSG_WITNESS_FLAG
assert test_node.last_message["getdata"].inv[0].type in (MSG_BLOCK, MSG_BLOCK | MSG_WITNESS_FLAG)

# Deliver the block
test_node.send_and_ping(msg_block(block))
Expand Down Expand Up @@ -586,8 +585,7 @@ def test_multiple_blocktxn_response(self, test_node):

# We should receive a getdata request
test_node.wait_for_getdata([block.hash_int], timeout=10)
assert test_node.last_message["getdata"].inv[0].type == MSG_BLOCK or \
test_node.last_message["getdata"].inv[0].type == MSG_BLOCK | MSG_WITNESS_FLAG
assert test_node.last_message["getdata"].inv[0].type in (MSG_BLOCK, MSG_BLOCK | MSG_WITNESS_FLAG)

# Send the same blocktxn and assert the sender gets disconnected.
with node.assert_debug_log(['previous compact block reconstruction attempt failed']):
Expand Down
6 changes: 3 additions & 3 deletions test/functional/p2p_disconnect_ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ def run_test(self):
address1 = self.nodes[0].getpeerinfo()[0]['addr']
self.nodes[0].disconnectnode(address=address1)
self.wait_until(lambda: len(self.nodes[1].getpeerinfo()) == 1, timeout=10)
assert not [node for node in self.nodes[0].getpeerinfo() if node['addr'] == address1]
assert address1 not in [node['addr'] for node in self.nodes[0].getpeerinfo()]

self.log.info("disconnectnode: successfully reconnect node")
self.connect_nodes(0, 1) # reconnect the node
assert_equal(len(self.nodes[0].getpeerinfo()), 2)
assert [node for node in self.nodes[0].getpeerinfo() if node['addr'] == address1]
assert address1 in [node['addr'] for node in self.nodes[0].getpeerinfo()]

self.log.info("disconnectnode: successfully disconnect node by node id")
id1 = self.nodes[0].getpeerinfo()[0]['id']
self.nodes[0].disconnectnode(nodeid=id1)
self.wait_until(lambda: len(self.nodes[1].getpeerinfo()) == 1, timeout=10)
assert not [node for node in self.nodes[0].getpeerinfo() if node['id'] == id1]
assert id1 not in [node['id'] for node in self.nodes[0].getpeerinfo()]

if __name__ == '__main__':
DisconnectBanTest(__file__).main()
4 changes: 2 additions & 2 deletions test/functional/p2p_handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import time

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_not_equal
from test_framework.util import assert_equal, assert_not_equal
from test_framework.messages import (
NODE_NETWORK,
NODE_NETWORK_LIMITED,
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_desirable_service_flags(self, node, service_flag_tests, desirable_servi
with node.assert_debug_log([expected_debug_log]):
self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=True)
else:
assert (services & desirable_service_flags) == desirable_service_flags
assert_equal((services & desirable_service_flags), desirable_service_flags)
self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)

def generate_at_mocktime(self, time):
Expand Down
6 changes: 3 additions & 3 deletions test/functional/p2p_headers_sync_with_minchainwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_chains_sync_when_long_enough(self):

def check_node3_chaintips(num_tips, tip_hash, height):
node3_chaintips = self.nodes[3].getchaintips()
assert len(node3_chaintips) == num_tips
assert_equal(len(node3_chaintips), num_tips)
assert {
'height': height,
'hash': tip_hash,
Expand All @@ -80,7 +80,7 @@ def check_node3_chaintips(num_tips, tip_hash, height):

for node in self.nodes[1:3]:
chaintips = node.getchaintips()
assert len(chaintips) == 1
assert_equal(len(chaintips), 1)
assert {
'height': 0,
'hash': '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206',
Expand All @@ -103,7 +103,7 @@ def check_node3_chaintips(num_tips, tip_hash, height):
'status': 'active',
} in self.nodes[2].getchaintips()

assert len(self.nodes[2].getchaintips()) == 1
assert_equal(len(self.nodes[2].getchaintips()), 1)

self.log.info("Check that node3 accepted these headers as well")
check_node3_chaintips(2, self.nodes[0].getbestblockhash(), NODE1_BLOCKS_REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/p2p_invalid_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def test_resource_exhaustion(self):
conn = self.nodes[0].add_p2p_connection(P2PDataStore(), supports_v2_p2p=False)
conn2 = self.nodes[0].add_p2p_connection(P2PDataStore(), supports_v2_p2p=False)
msg_at_size = msg_unrecognized(str_data="b" * VALID_DATA_LIMIT)
assert len(msg_at_size.serialize()) == MAX_PROTOCOL_MESSAGE_LENGTH
assert_equal(len(msg_at_size.serialize()), MAX_PROTOCOL_MESSAGE_LENGTH)

self.log.info("(a) Send 80 messages, each of maximum valid data size (4MB)")
for _ in range(80):
Expand Down
2 changes: 1 addition & 1 deletion test/functional/p2p_private_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def set_tx_returner_and_other():
self.log.info("Checking abortprivatebroadcast removes a pending private-broadcast transaction")
tx_abort = wallet.create_self_transfer()
tx_originator.sendrawtransaction(hexstring=tx_abort["hex"], maxfeerate=0.1)
assert any(t["wtxid"] == tx_abort["wtxid"] for t in tx_originator.getprivatebroadcastinfo()["transactions"])
assert tx_abort["wtxid"] in [t["wtxid"] for t in tx_originator.getprivatebroadcastinfo()["transactions"]]
abort_res = tx_originator.abortprivatebroadcast(tx_abort["txid"])
assert_equal(len(abort_res["removed_transactions"]), 1)
assert_equal(abort_res["removed_transactions"][0]["txid"], tx_abort["txid"])
Expand Down
Loading
Loading