diff options
Diffstat (limited to 'test/functional')
-rwxr-xr-x | test/functional/feature_assumeutxo.py | 23 | ||||
-rwxr-xr-x | test/functional/feature_loadblock.py | 4 | ||||
-rwxr-xr-x | test/functional/feature_rbf.py | 5 | ||||
-rwxr-xr-x | test/functional/feature_reindex.py | 18 | ||||
-rwxr-xr-x | test/functional/mempool_accept.py | 18 | ||||
-rwxr-xr-x | test/functional/mempool_truc.py | 2 | ||||
-rwxr-xr-x | test/functional/p2p_permissions.py | 5 | ||||
-rwxr-xr-x | test/functional/p2p_v2_misbehaving.py | 3 | ||||
-rwxr-xr-x | test/functional/rpc_validateaddress.py | 5 |
9 files changed, 59 insertions, 24 deletions
diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py index da7cabf87c..0acd4244a5 100755 --- a/test/functional/feature_assumeutxo.py +++ b/test/functional/feature_assumeutxo.py @@ -60,9 +60,8 @@ class AssumeutxoTest(BitcoinTestFramework): bad_snapshot_path = valid_snapshot_path + '.mod' node = self.nodes[1] - def expected_error(log_msg="", rpc_details=""): - with node.assert_debug_log([log_msg]): - assert_raises_rpc_error(-32603, f"Unable to load UTXO snapshot{rpc_details}", node.loadtxoutset, bad_snapshot_path) + def expected_error(msg): + assert_raises_rpc_error(-32603, f"Unable to load UTXO snapshot: Population failed: {msg}", node.loadtxoutset, bad_snapshot_path) self.log.info(" - snapshot file with invalid file magic") parsing_error_code = -22 @@ -114,19 +113,19 @@ class AssumeutxoTest(BitcoinTestFramework): f.write(valid_snapshot_contents[:47]) f.write((valid_num_coins + off).to_bytes(8, "little")) f.write(valid_snapshot_contents[47 + 8:]) - expected_error(log_msg=f"bad snapshot - coins left over after deserializing 298 coins" if off == -1 else f"bad snapshot format or truncated snapshot after deserializing 299 coins") + expected_error(msg="Bad snapshot - coins left over after deserializing 298 coins." if off == -1 else "Bad snapshot format or truncated snapshot after deserializing 299 coins.") self.log.info(" - snapshot file with alternated but parsable UTXO data results in different hash") cases = [ # (content, offset, wrong_hash, custom_message) [b"\xff" * 32, 0, "7d52155c9a9fdc4525b637ef6170568e5dad6fabd0b1fdbb9432010b8453095b", None], # wrong outpoint hash - [(2).to_bytes(1, "little"), 32, None, "[snapshot] bad snapshot data after deserializing 1 coins"], # wrong txid coins count - [b"\xfd\xff\xff", 32, None, "[snapshot] mismatch in coins count in snapshot metadata and actual snapshot data"], # txid coins count exceeds coins left + [(2).to_bytes(1, "little"), 32, None, "Bad snapshot data after deserializing 1 coins."], # wrong txid coins count + [b"\xfd\xff\xff", 32, None, "Mismatch in coins count in snapshot metadata and actual snapshot data"], # txid coins count exceeds coins left [b"\x01", 33, "9f4d897031ab8547665b4153317ae2fdbf0130c7840b66427ebc48b881cb80ad", None], # wrong outpoint index [b"\x81", 34, "3da966ba9826fb6d2604260e01607b55ba44e1a5de298606b08704bc62570ea8", None], # wrong coin code VARINT [b"\x80", 34, "091e893b3ccb4334378709578025356c8bcb0a623f37c7c4e493133c988648e5", None], # another wrong coin code - [b"\x84\x58", 34, None, "[snapshot] bad snapshot data after deserializing 0 coins"], # wrong coin case with height 364 and coinbase 0 - [b"\xCA\xD2\x8F\x5A", 39, None, "[snapshot] bad snapshot data after deserializing 0 coins - bad tx out value"], # Amount exceeds MAX_MONEY + [b"\x84\x58", 34, None, "Bad snapshot data after deserializing 0 coins"], # wrong coin case with height 364 and coinbase 0 + [b"\xCA\xD2\x8F\x5A", 39, None, "Bad snapshot data after deserializing 0 coins - bad tx out value"], # Amount exceeds MAX_MONEY ] for content, offset, wrong_hash, custom_message in cases: @@ -136,8 +135,8 @@ class AssumeutxoTest(BitcoinTestFramework): f.write(content) f.write(valid_snapshot_contents[(5 + 2 + 4 + 4 + 32 + 8 + offset + len(content)):]) - log_msg = custom_message if custom_message is not None else f"[snapshot] bad snapshot content hash: expected a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27, got {wrong_hash}" - expected_error(log_msg=log_msg) + msg = custom_message if custom_message is not None else f"Bad snapshot content hash: expected a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27, got {wrong_hash}." + expected_error(msg) def test_headers_not_synced(self, valid_snapshot_path): for node in self.nodes[1:]: @@ -188,8 +187,8 @@ class AssumeutxoTest(BitcoinTestFramework): def test_snapshot_with_less_work(self, dump_output_path): self.log.info("Test bitcoind should fail when snapshot has less accumulated work than this node.") node = self.nodes[0] - with node.assert_debug_log(expected_msgs=["[snapshot] activation failed - work does not exceed active chainstate"]): - assert_raises_rpc_error(-32603, "Unable to load UTXO snapshot", node.loadtxoutset, dump_output_path) + msg = "Unable to load UTXO snapshot: Population failed: Work does not exceed active chainstate." + assert_raises_rpc_error(-32603, msg, node.loadtxoutset, dump_output_path) def test_snapshot_block_invalidated(self, dump_output_path): self.log.info("Test snapshot is not loaded when base block is invalid.") diff --git a/test/functional/feature_loadblock.py b/test/functional/feature_loadblock.py index 1519c132b9..824308ac95 100755 --- a/test/functional/feature_loadblock.py +++ b/test/functional/feature_loadblock.py @@ -26,6 +26,10 @@ class LoadblockTest(BitcoinTestFramework): self.setup_clean_chain = True self.num_nodes = 2 self.supports_cli = False + self.extra_args = [ + ["-blocksxor=0"], # TODO: The linearize scripts should be adjusted to apply any XOR + [], + ] def run_test(self): self.nodes[1].setnetworkactive(state=False) diff --git a/test/functional/feature_rbf.py b/test/functional/feature_rbf.py index cd5f5734c9..b660b96935 100755 --- a/test/functional/feature_rbf.py +++ b/test/functional/feature_rbf.py @@ -26,15 +26,18 @@ class ReplaceByFeeTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 + # both nodes disable full-rbf to test BIP125 signaling self.extra_args = [ [ + "-mempoolfullrbf=0", "-limitancestorcount=50", "-limitancestorsize=101", "-limitdescendantcount=200", "-limitdescendantsize=101", ], - # second node has default mempool parameters + # second node has default mempool parameters, besides mempoolfullrbf being disabled [ + "-mempoolfullrbf=0", ], ] self.supports_cli = False diff --git a/test/functional/feature_reindex.py b/test/functional/feature_reindex.py index 50a9ae1c06..504b3dfff4 100755 --- a/test/functional/feature_reindex.py +++ b/test/functional/feature_reindex.py @@ -39,9 +39,19 @@ class ReindexTest(BitcoinTestFramework): # we're generating them rather than getting them from peers), so to # test out-of-order handling, swap blocks 1 and 2 on disk. blk0 = self.nodes[0].blocks_path / "blk00000.dat" + with open(self.nodes[0].blocks_path / "xor.dat", "rb") as xor_f: + NUM_XOR_BYTES = 8 # From InitBlocksdirXorKey::xor_key.size() + xor_dat = xor_f.read(NUM_XOR_BYTES) + + def util_xor(data, key, *, offset): + data = bytearray(data) + for i in range(len(data)): + data[i] ^= key[(i + offset) % len(key)] + return bytes(data) + with open(blk0, 'r+b') as bf: # Read at least the first few blocks (including genesis) - b = bf.read(2000) + b = util_xor(bf.read(2000), xor_dat, offset=0) # Find the offsets of blocks 2, 3, and 4 (the first 3 blocks beyond genesis) # by searching for the regtest marker bytes (see pchMessageStart). @@ -55,12 +65,12 @@ class ReindexTest(BitcoinTestFramework): b4_start = find_block(b, b3_start) # Blocks 2 and 3 should be the same size. - assert_equal(b3_start-b2_start, b4_start-b3_start) + assert_equal(b3_start - b2_start, b4_start - b3_start) # Swap the second and third blocks (don't disturb the genesis block). bf.seek(b2_start) - bf.write(b[b3_start:b4_start]) - bf.write(b[b2_start:b3_start]) + bf.write(util_xor(b[b3_start:b4_start], xor_dat, offset=b2_start)) + bf.write(util_xor(b[b2_start:b3_start], xor_dat, offset=b3_start)) # The reindexing code should detect and accommodate out of order blocks. with self.nodes[0].assert_debug_log([ diff --git a/test/functional/mempool_accept.py b/test/functional/mempool_accept.py index 4b9ff3d138..4d08575255 100755 --- a/test/functional/mempool_accept.py +++ b/test/functional/mempool_accept.py @@ -55,6 +55,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework): self.num_nodes = 1 self.extra_args = [[ '-txindex','-permitbaremultisig=0', + '-mempoolfullrbf=0', ]] * self.num_nodes self.supports_cli = False @@ -409,10 +410,19 @@ class MempoolAcceptanceTest(BitcoinTestFramework): maxfeerate=0, ) - # Clear witness stuffing - anchor_spend = anchor_nonempty_wit_spend - anchor_spend.wit.vtxinwit[0].scriptWitness.stack = [] - anchor_spend.rehash() + # but is consensus-legal + self.generateblock(node, self.wallet.get_address(), [anchor_nonempty_wit_spend.serialize().hex()]) + + # Without witness elements it is standard + create_anchor_tx = self.wallet.send_to(from_node=node, scriptPubKey=PAY_TO_ANCHOR, amount=anchor_value) + self.generate(node, 1) + + anchor_spend = CTransaction() + anchor_spend.vin.append(CTxIn(COutPoint(int(create_anchor_tx["txid"], 16), create_anchor_tx["sent_vout"]), b"")) + anchor_spend.vout.append(CTxOut(anchor_value - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE])))) + anchor_spend.wit.vtxinwit.append(CTxInWitness()) + # It's "segwit" but txid == wtxid since there is no witness data + assert_equal(anchor_spend.rehash(), anchor_spend.getwtxid()) self.check_mempool_result( result_expected=[{'txid': anchor_spend.rehash(), 'allowed': True, 'vsize': anchor_spend.get_vsize(), 'fees': { 'base': Decimal('0.00000700')}}], diff --git a/test/functional/mempool_truc.py b/test/functional/mempool_truc.py index 3f57b3e356..28f3256ef1 100755 --- a/test/functional/mempool_truc.py +++ b/test/functional/mempool_truc.py @@ -162,7 +162,7 @@ class MempoolTRUC(BitcoinTestFramework): self.check_mempool([tx_v3_bip125_rbf_v2["txid"], tx_v3_parent["txid"], tx_v3_child["txid"]]) - @cleanup(extra_args=None) + @cleanup(extra_args=["-mempoolfullrbf=0"]) def test_truc_bip125(self): node = self.nodes[0] self.log.info("Test TRUC transactions that don't signal BIP125 are replaceable") diff --git a/test/functional/p2p_permissions.py b/test/functional/p2p_permissions.py index a9b164b078..c881dd6ff4 100755 --- a/test/functional/p2p_permissions.py +++ b/test/functional/p2p_permissions.py @@ -119,6 +119,9 @@ class P2PPermissionsTests(BitcoinTestFramework): self.log.debug("Check that node[1] will not send an invalid tx to node[0]") tx.vout[0].nValue += 1 + # add dust to cause policy rejection but no disconnection + tx.vout.append(tx.vout[0]) + tx.vout[-1].nValue = 0 txid = tx.rehash() # Send the transaction twice. The first time, it'll be rejected by ATMP because it conflicts # with a mempool transaction. The second time, it'll be in the m_lazy_recent_rejects filter. @@ -126,7 +129,7 @@ class P2PPermissionsTests(BitcoinTestFramework): [tx], self.nodes[1], success=False, - reject_reason='{} (wtxid={}) from peer=0 was not accepted: txn-mempool-conflict'.format(txid, tx.getwtxid()) + reject_reason='{} (wtxid={}) from peer=0 was not accepted: dust'.format(txid, tx.getwtxid()) ) p2p_rebroadcast_wallet.send_txs_and_test( diff --git a/test/functional/p2p_v2_misbehaving.py b/test/functional/p2p_v2_misbehaving.py index 2bc7b43e1f..0af96a4f8c 100755 --- a/test/functional/p2p_v2_misbehaving.py +++ b/test/functional/p2p_v2_misbehaving.py @@ -140,7 +140,8 @@ class EncryptedP2PMisbehaving(BitcoinTestFramework): node0.setmocktime(int(time.time())) self.log.info('Sending first 4 bytes of ellswift which match network magic') self.log.info('If a response is received, assertion failure would happen in our custom data_received() function') - peer1 = node0.add_p2p_connection(MisbehavingV2Peer(TestType.EARLY_KEY_RESPONSE), wait_for_verack=False, send_version=False, supports_v2_p2p=True, wait_for_v2_handshake=False) + with node0.wait_for_new_peer(): + peer1 = node0.add_p2p_connection(MisbehavingV2Peer(TestType.EARLY_KEY_RESPONSE), wait_for_verack=False, send_version=False, supports_v2_p2p=True, wait_for_v2_handshake=False) peer1.send_raw_message(MAGIC_BYTES['regtest']) self.log.info('Sending remaining ellswift and garbage which are different from V1_PREFIX. Since a response is') self.log.info('expected now, our custom data_received() function wouldn\'t result in assertion failure') diff --git a/test/functional/rpc_validateaddress.py b/test/functional/rpc_validateaddress.py index dde07e7ead..bf094a7df8 100755 --- a/test/functional/rpc_validateaddress.py +++ b/test/functional/rpc_validateaddress.py @@ -166,6 +166,11 @@ VALID_DATA = [ "bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0", "512079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", ), + # PayToAnchor(P2A) + ( + "bc1pfeessrawgf", + "51024e73", + ), ] |