Skip to content

Commit

Permalink
Merge pull request #1012 from qtumproject/neil/core24
Browse files Browse the repository at this point in the history
Fix Python tests
  • Loading branch information
qtum-neil authored Aug 26, 2023
2 parents 0d7f3ca + 260d815 commit 3c0bc05
Show file tree
Hide file tree
Showing 34 changed files with 188 additions and 137 deletions.
2 changes: 1 addition & 1 deletion src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ static RPCHelpMan getblocktemplate()
result.pushKV("mutable", aMutable);
result.pushKV("noncerange", "00000000ffffffff");
int64_t nSigOpLimit = dgpMaxBlockSigOps;
int64_t nSizeLimit = dgpMaxBlockSigOps;
int64_t nSizeLimit = dgpMaxBlockSerSize;
if (fPreSegWit) {
CHECK_NONFATAL(nSigOpLimit % WITNESS_SCALE_FACTOR == 0);
nSigOpLimit /= WITNESS_SCALE_FACTOR;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ def run_test(self):
blocks2 = []
for i in range(89, LARGE_REORG_SIZE + 89):
blocks2.append(self.next_block("alt" + str(i)))
self.send_blocks(blocks2, False, force_send=False)
self.send_blocks(blocks2, False, force_send=True)

# extend alt chain to trigger re-org
block = self.next_block("alt" + str(chain1_tip + 1))
Expand Down
28 changes: 14 additions & 14 deletions test/functional/feature_coinstatsindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ def _test_coin_stats_index(self):
res5 = index_node.gettxoutsetinfo(hash_option, 2002)
assert_equal(res5['total_unspendable_amount'], 20000)
assert_equal(res5['block_info'], {
'unspendable': 0,
'prevout_spent': 20000,
'new_outputs_ex_coinbase': Decimal('19999.99911200'),
'coinbase': Decimal('20000.00088800'),
'unspendable': Decimal('0E-8'),
'prevout_spent': Decimal('20000.00000000'),
'new_outputs_ex_coinbase': Decimal('19999.99688000'),
'coinbase': Decimal('20000.00312000'),
'unspendables': {
'genesis_block': 0,
'bip30': 0,
'scripts': 0,
'unclaimed_rewards': 0,
'genesis_block': Decimal('0E-8'),
'bip30': Decimal('0E-8'),
'scripts': Decimal('0E-8'),
'unclaimed_rewards': Decimal('0E-8'),
}
})
self.block_sanity_check(res5['block_info'])
Expand Down Expand Up @@ -169,14 +169,14 @@ def _test_coin_stats_index(self):
assert_equal(res6['total_unspendable_amount'], Decimal('20020.99000000'))
assert_equal(res6['block_info'], {
'unspendable': Decimal('20.99000000'),
'prevout_spent': 20011,
'new_outputs_ex_coinbase': Decimal('19989.99931200'),
'coinbase': Decimal('20000.01068800'),
'prevout_spent': Decimal('20021.00000000'),
'new_outputs_ex_coinbase': Decimal('19999.99920000'),
'coinbase': Decimal('20000.01080000'),
'unspendables': {
'genesis_block': 0,
'bip30': 0,
'genesis_block': Decimal('0E-8'),
'bip30': Decimal('0E-8'),
'scripts': Decimal('20.99000000'),
'unclaimed_rewards': 0,
'unclaimed_rewards': Decimal('0E-8'),
}
})
self.block_sanity_check(res6['block_info'])
Expand Down
40 changes: 19 additions & 21 deletions test/functional/feature_index_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def sync_index(self, height):
'basic block filter index': {'synced': True, 'best_block_height': height},
}
self.wait_until(lambda: self.nodes[0].getindexinfo() == expected_filter)

expected_stats = {
'coinstatsindex': {'synced': True, 'best_block_height': height}
}
Expand Down Expand Up @@ -57,23 +56,22 @@ def run_test(self):
stats_nodes = [self.nodes[1], self.nodes[2]]

self.log.info("check if we can access blockfilters and coinstats when pruning is enabled but no blocks are actually pruned")
self.sync_index(height=200)
self.sync_index(height=2100)
tip = self.nodes[0].getbestblockhash()
for node in filter_nodes:
assert_greater_than(len(node.getblockfilter(tip)['filter']), 0)
for node in stats_nodes:
assert(node.gettxoutsetinfo(hash_type="muhash", hash_or_height=tip)['muhash'])

self.mine_batches(500)
self.sync_index(height=700)

self.mine_batches(1000)
self.sync_index(height=3100)
self.log.info("prune some blocks")
for node in self.nodes[:2]:
with node.assert_debug_log(['limited pruning to height 689']):
pruneheight_new = node.pruneblockchain(400)
with node.assert_debug_log(['limited pruning to height 3089']):
pruneheight_new = node.pruneblockchain(2600)
# the prune heights used here and below are magic numbers that are determined by the
# thresholds at which block files wrap, so they depend on disk serialization and default block file size.
assert_equal(pruneheight_new, 248)
assert_equal(pruneheight_new, 2461)

self.log.info("check if we can access the tips blockfilter and coinstats when we have pruned some blocks")
tip = self.nodes[0].getbestblockhash()
Expand All @@ -91,8 +89,8 @@ def run_test(self):

# mine and sync index up to a height that will later be the pruneheight
self.generate(self.nodes[0], 51)
self.sync_index(height=751)

self.sync_index(height=3151)
self.restart_without_indices()

self.log.info("make sure trying to access the indices throws errors")
Expand All @@ -107,20 +105,20 @@ def run_test(self):

self.log.info("prune exactly up to the indices best blocks while the indices are disabled")
for i in range(3):
pruneheight_2 = self.nodes[i].pruneblockchain(1000)
assert_equal(pruneheight_2, 750)
pruneheight_2 = self.nodes[i].pruneblockchain(2850)
assert_equal(pruneheight_2, 2823)
# Restart the nodes again with the indices activated
self.restart_node(i, extra_args=self.extra_args[i])

self.log.info("make sure that we can continue with the partially synced indices after having pruned up to the index height")
self.sync_index(height=1500)
self.sync_index(height=3900)

self.log.info("prune further than the indices best blocks while the indices are disabled")
self.restart_without_indices()
self.mine_batches(1000)
self.mine_batches(3000)

for i in range(3):
pruneheight_3 = self.nodes[i].pruneblockchain(2000)
pruneheight_3 = self.nodes[i].pruneblockchain(4400)
assert_greater_than(pruneheight_3, pruneheight_2)
self.stop_node(i)

Expand All @@ -136,17 +134,17 @@ def run_test(self):
self.restart_node(i, extra_args=restart_args)
# The nodes need to be reconnected to the non-pruning node upon restart, otherwise they will be stuck
self.connect_nodes(i, 3)

self.sync_blocks(timeout=300)

for node in self.nodes[:2]:
with node.assert_debug_log(['limited pruning to height 2489']):
pruneheight_new = node.pruneblockchain(2500)
assert_equal(pruneheight_new, 2005)
with node.assert_debug_log(['limited pruning to height 6889']):
pruneheight_new = node.pruneblockchain(4900)
assert_equal(pruneheight_new, 4885)

self.log.info("ensure that prune locks don't prevent indices from failing in a reorg scenario")
with self.nodes[0].assert_debug_log(['basic block filter index prune lock moved back to 2480']):
self.nodes[3].invalidateblock(self.nodes[0].getblockhash(2480))
with self.nodes[0].assert_debug_log(['basic block filter index prune lock moved back to 6880']):
self.nodes[3].invalidateblock(self.nodes[0].getblockhash(6880))
self.generate(self.nodes[3], 30)
self.sync_blocks()

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 @@ -309,7 +309,7 @@ def has_block(index):
assert_equal(node.getblockchaininfo()["blocks"], 3546)

# prune parameter in the future (block or timestamp) should raise an exception
future_parameter = height(1001) + 5
future_parameter = height(3546) + 5
if use_timestamp:
assert_raises_rpc_error(-8, "Could not find block with at least the specified timestamp", node.pruneblockchain, future_parameter)
else:
Expand Down
8 changes: 4 additions & 4 deletions test/functional/feature_rbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def test_replacement_feeperkb(self):
utxos_to_spend=[tx0_outpoint],
sequence=0,
num_outputs=100,
amount_per_output=1000,
amount_per_output=99900,
)["hex"]

# This will raise an exception due to insufficient fee
Expand Down Expand Up @@ -345,7 +345,7 @@ def test_too_many_replacements(self):
# Start by creating a single transaction with many outputs
initial_nValue = 1000 * COIN
utxo = self.make_utxo(self.nodes[0], initial_nValue)
fee = int(0.01 * COIN)
fee = 1761601 # int(0.01 * COIN)
split_value = int((initial_nValue - fee) / (MAX_REPLACEMENT_LIMIT + 1))

splitting_tx_utxos = self.wallet.send_self_transfer_multi(
Expand Down Expand Up @@ -455,7 +455,7 @@ def test_too_many_replacements_with_default_mempool_params(self):
# would invalidate `num_txs_invalidated` transactions.
tx_hex = wallet.create_self_transfer_multi(
utxos_to_spend=root_utxos,
fee_per_output=10_000_000, # absurdly high feerate
fee_per_output=36_000_000, # absurdly high feerate
)["hex"]

if failure_expected:
Expand Down Expand Up @@ -697,7 +697,7 @@ def test_replacement_relay_fee(self):

# Higher fee, higher feerate, different txid, but the replacement does not provide a relay
# fee conforming to node's `incrementalrelayfee` policy of 1000 sat per KB.
assert_equal(self.nodes[0].getmempoolinfo()["incrementalrelayfee"], Decimal("0.00001"))
assert_equal(self.nodes[0].getmempoolinfo()["incrementalrelayfee"], Decimal("0.00010000"))
tx.vout[0].nValue -= 1
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx.serialize().hex())

Expand Down
6 changes: 3 additions & 3 deletions test/functional/feature_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ def set_test_params(self):
[
"-acceptnonstdtxn=1",
"-rpcserialversion=0",
"-testactivationheight=segwit@2364" if ENABLE_REDUCED_BLOCK_TIME else "-testactivationheight=segwit@864",
"-testactivationheight=segwit@2357" if ENABLE_REDUCED_BLOCK_TIME else "-testactivationheight=segwit@857",
"-addresstype=legacy",
],
[
"-acceptnonstdtxn=1",
"-rpcserialversion=1",
"-testactivationheight=segwit@2364" if ENABLE_REDUCED_BLOCK_TIME else "-testactivationheight=segwit@864",
"-testactivationheight=segwit@2357" if ENABLE_REDUCED_BLOCK_TIME else "-testactivationheight=segwit@857",
"-addresstype=legacy",
],
[
"-acceptnonstdtxn=1",
"-testactivationheight=segwit@2364" if ENABLE_REDUCED_BLOCK_TIME else "-testactivationheight=segwit@864",
"-testactivationheight=segwit@2357" if ENABLE_REDUCED_BLOCK_TIME else "-testactivationheight=segwit@857",
"-addresstype=legacy",
],
]
Expand Down
2 changes: 1 addition & 1 deletion test/functional/mempool_datacarrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def set_test_params(self):
]

def test_null_data_transaction(self, node: TestNode, data: bytes, success: bool) -> None:
tx = self.wallet.create_self_transfer(fee_rate=0)["tx"]
tx = self.wallet.create_self_transfer(fee_rate=78400)["tx"]
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, data])))
tx.vout[0].nValue -= tx.get_vsize() # simply pay 1sat/vbyte fee

Expand Down
12 changes: 6 additions & 6 deletions test/functional/mempool_package_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ def test_anc_count_limits_bushy(self):
for _ in range(4): # Make mempool transactions M(4i+1)...M(4i+4)
pc_grandparent_utxos.append(self.wallet.send_self_transfer(from_node=node)["new_utxo"])
# Package transaction Pi
pi_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=pc_grandparent_utxos)
pi_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=pc_grandparent_utxos, fee_per_output=int(Decimal("0.2") * COIN))
package_hex.append(pi_tx["hex"])
pc_parent_utxos.append(pi_tx["new_utxos"][0])
# Package transaction PC
pc_hex = self.wallet.create_self_transfer_multi(utxos_to_spend=pc_parent_utxos)["hex"]
pc_hex = self.wallet.create_self_transfer_multi(utxos_to_spend=pc_parent_utxos, fee_per_output=int(Decimal("0.2") * COIN))["hex"]
package_hex.append(pc_hex)

assert_equal(20, node.getmempoolinfo()["size"])
Expand Down Expand Up @@ -309,15 +309,15 @@ def test_anc_size_limits(self):
self.log.info("Check that in-mempool and in-package ancestor size limits are calculated properly in packages")
# Mempool transactions A and B
for _ in range(2):
bulked_tx = self.wallet.create_self_transfer(target_weight=target_weight)
bulked_tx = self.wallet.create_self_transfer(target_weight=target_weight, fee=high_fee)
self.wallet.sendrawtransaction(from_node=node, tx_hex=bulked_tx["hex"])
parent_utxos.append(bulked_tx["new_utxo"])

# Package transaction C
pc_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=parent_utxos, fee_per_output=int(high_fee * COIN), target_weight=target_weight)

# Package transaction D
pd_tx = self.wallet.create_self_transfer(utxo_to_spend=pc_tx["new_utxos"][0], target_weight=target_weight)
pd_tx = self.wallet.create_self_transfer(utxo_to_spend=pc_tx["new_utxos"][0], target_weight=target_weight, fee=high_fee)

assert_equal(2, node.getmempoolinfo()["size"])
testres_too_heavy = node.testmempoolaccept(rawtxs=[pc_tx["hex"], pd_tx["hex"]])
Expand Down Expand Up @@ -350,11 +350,11 @@ def test_desc_size_limits(self):
package_hex = []
for j in range(2): # Two legs (left and right)
# Mempool transaction (Mb and Mc)
mempool_tx = self.wallet.create_self_transfer(utxo_to_spend=ma_tx["new_utxos"][j], target_weight=target_weight)
mempool_tx = self.wallet.create_self_transfer(utxo_to_spend=ma_tx["new_utxos"][j], target_weight=target_weight, fee=high_fee)
self.wallet.sendrawtransaction(from_node=node, tx_hex=mempool_tx["hex"])

# Package transaction (Pd and Pe)
package_tx = self.wallet.create_self_transfer(utxo_to_spend=mempool_tx["new_utxo"], target_weight=target_weight)
package_tx = self.wallet.create_self_transfer(utxo_to_spend=mempool_tx["new_utxo"], target_weight=target_weight, fee=high_fee)
package_hex.append(package_tx["hex"])

assert_equal(3, node.getmempoolinfo()["size"])
Expand Down
2 changes: 1 addition & 1 deletion test/functional/mining_prioritisetransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def run_test(self):
assert x not in mempool

# Create a free transaction. Should be rejected.
tx_res = self.wallet.create_self_transfer(fee_rate=0)
tx_res = self.wallet.create_self_transfer(fee_rate=0, sort_by_height=True)
tx_hex = tx_res['hex']
tx_id = tx_res['txid']

Expand Down
1 change: 1 addition & 0 deletions test/functional/mocks/multi_signers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def enumerate(args):
{"fingerprint": "00000002", "type": "trezor", "model": "trezor_one"}]))

parser = argparse.ArgumentParser(prog='./multi_signers.py', description='External multi-signer mock')
parser.add_argument('--chain', default='main')

subparsers = parser.add_subparsers(description='Commands', dest='command')
subparsers.required = True
Expand Down
2 changes: 1 addition & 1 deletion test/functional/p2p_compactblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def test_getblocktxn_handler(self, test_node):
def test_low_work_compactblocks(self, test_node):
# A compactblock with insufficient work won't get its header included
node = self.nodes[0]
hashPrevBlock = int(node.getblockhash(node.getblockcount() - 150), 16)
hashPrevBlock = int(node.getblockhash(node.getblockcount() - 2050), 16)
block = self.build_block_on_tip(node)
block.hashPrevBlock = hashPrevBlock
block.solve()
Expand Down
10 changes: 5 additions & 5 deletions test/functional/p2p_invalid_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,24 @@ def run_test(self):
SCRIPT_PUB_KEY_OP_TRUE = b'\x51\x75' * 15 + b'\x51'
tx_withhold = CTransaction()
tx_withhold.vin.append(CTxIn(outpoint=COutPoint(block1.vtx[0].sha256, 0)))
tx_withhold.vout = [CTxOut(nValue=INITIAL_BLOCK_REWARD * COIN - 1200000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 2
tx_withhold.vout = [CTxOut(nValue=INITIAL_BLOCK_REWARD//2 * COIN - 600000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 2
tx_withhold.calc_sha256()

# Our first orphan tx with some outputs to create further orphan txs
tx_orphan_1 = CTransaction()
tx_orphan_1.vin.append(CTxIn(outpoint=COutPoint(tx_withhold.sha256, 0)))
tx_orphan_1.vout = [CTxOut(nValue=8 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 3
tx_orphan_1.vout = [CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)] * 3
tx_orphan_1.calc_sha256()

# A valid transaction with low fee
tx_orphan_2_no_fee = CTransaction()
tx_orphan_2_no_fee.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 0)))
tx_orphan_2_no_fee.vout.append(CTxOut(nValue=8 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
tx_orphan_2_no_fee.vout.append(CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))

# A valid transaction with sufficient fee
tx_orphan_2_valid = CTransaction()
tx_orphan_2_valid.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 1)))
tx_orphan_2_valid.vout.append(CTxOut(nValue=8 * COIN - 1200000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
tx_orphan_2_valid.vout.append(CTxOut(nValue=10 * COIN - 1200000, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
tx_orphan_2_valid.calc_sha256()

# An invalid transaction with negative fee
Expand Down Expand Up @@ -166,7 +166,7 @@ def run_test(self):
node.p2ps[0].send_txs_and_test([rejected_parent], node, success=False)

self.log.info('Test that a peer disconnection causes erase its transactions from the orphan pool')
with node.assert_debug_log(['Erased 2000 orphan tx from peer=25']):
with node.assert_debug_log(['Erased 100 orphan tx from peer=25']):
self.reconnect_p2p(num_connections=1)

self.log.info('Test that a transaction in the orphan pool is included in a new tip block causes erase this transaction from the orphan pool')
Expand Down
5 changes: 3 additions & 2 deletions test/functional/p2p_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ def test_premature_coinbase_witness_spend(self):
spend_tx.rehash()

# Now test a premature spend.
generatesynchronized(self.nodes[0], COINBASE_MATURITY-2, None, self.nodes)
self.generate(self.nodes[0], COINBASE_MATURITY-2)
block2 = self.build_next_block()
self.update_witness_block_with_transactions(block2, [spend_tx])
test_witness_block(self.nodes[0], self.test_node, block2, accepted=False, reason='bad-txns-premature-spend-of-coinbase')
Expand Down Expand Up @@ -2032,7 +2032,8 @@ def serialize_with_bogus_witness(tx):
class msg_bogus_tx(msg_tx):
def serialize(self):
return serialize_with_bogus_witness(self.tx)


self.wallet.generate(1)
tx = self.wallet.create_self_transfer()['tx']
assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)
with self.nodes[0].assert_debug_log(['Unknown transaction optional data']):
Expand Down
Loading

0 comments on commit 3c0bc05

Please sign in to comment.