mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
[qa] Test that invalid compactblocks don't result in ban
This commit is contained in:
parent
3665483be7
commit
c93beac43f
@ -708,6 +708,33 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||||||
l.last_cmpctblock.header_and_shortids.header.calc_sha256()
|
l.last_cmpctblock.header_and_shortids.header.calc_sha256()
|
||||||
assert_equal(l.last_cmpctblock.header_and_shortids.header.sha256, block.sha256)
|
assert_equal(l.last_cmpctblock.header_and_shortids.header.sha256, block.sha256)
|
||||||
|
|
||||||
|
# Test that we don't get disconnected if we relay a compact block with valid header,
|
||||||
|
# but invalid transactions.
|
||||||
|
def test_invalid_tx_in_compactblock(self, node, test_node, use_segwit):
|
||||||
|
assert(len(self.utxos))
|
||||||
|
utxo = self.utxos[0]
|
||||||
|
|
||||||
|
block = self.build_block_with_transactions(node, utxo, 5)
|
||||||
|
del block.vtx[3]
|
||||||
|
block.hashMerkleRoot = block.calc_merkle_root()
|
||||||
|
if use_segwit:
|
||||||
|
# If we're testing with segwit, also drop the coinbase witness,
|
||||||
|
# but include the witness commitment.
|
||||||
|
add_witness_commitment(block)
|
||||||
|
block.vtx[0].wit.vtxinwit = []
|
||||||
|
block.solve()
|
||||||
|
|
||||||
|
# Now send the compact block with all transactions prefilled, and
|
||||||
|
# verify that we don't get disconnected.
|
||||||
|
comp_block = HeaderAndShortIDs()
|
||||||
|
comp_block.initialize_from_block(block, prefill_list=[0, 1, 2, 3, 4], use_witness=use_segwit)
|
||||||
|
msg = msg_cmpctblock(comp_block.to_p2p())
|
||||||
|
test_node.send_and_ping(msg)
|
||||||
|
|
||||||
|
# Check that the tip didn't advance
|
||||||
|
assert(int(node.getbestblockhash(), 16) is not block.sha256)
|
||||||
|
test_node.sync_with_ping()
|
||||||
|
|
||||||
# Helper for enabling cb announcements
|
# Helper for enabling cb announcements
|
||||||
# Send the sendcmpct request and sync headers
|
# Send the sendcmpct request and sync headers
|
||||||
def request_cb_announcements(self, peer, node, version):
|
def request_cb_announcements(self, peer, node, version):
|
||||||
@ -798,6 +825,11 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||||||
self.test_end_to_end_block_relay(self.nodes[0], [self.segwit_node, self.test_node, self.old_node])
|
self.test_end_to_end_block_relay(self.nodes[0], [self.segwit_node, self.test_node, self.old_node])
|
||||||
self.test_end_to_end_block_relay(self.nodes[1], [self.segwit_node, self.test_node, self.old_node])
|
self.test_end_to_end_block_relay(self.nodes[1], [self.segwit_node, self.test_node, self.old_node])
|
||||||
|
|
||||||
|
print("\tTesting handling of invalid compact blocks...")
|
||||||
|
self.test_invalid_tx_in_compactblock(self.nodes[0], self.test_node, False)
|
||||||
|
self.test_invalid_tx_in_compactblock(self.nodes[1], self.segwit_node, False)
|
||||||
|
self.test_invalid_tx_in_compactblock(self.nodes[1], self.old_node, False)
|
||||||
|
|
||||||
# Advance to segwit activation
|
# Advance to segwit activation
|
||||||
print ("\nAdvancing to segwit activation\n")
|
print ("\nAdvancing to segwit activation\n")
|
||||||
self.activate_segwit(self.nodes[1])
|
self.activate_segwit(self.nodes[1])
|
||||||
@ -844,6 +876,11 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||||||
self.request_cb_announcements(self.segwit_node, self.nodes[1], 2)
|
self.request_cb_announcements(self.segwit_node, self.nodes[1], 2)
|
||||||
self.test_end_to_end_block_relay(self.nodes[1], [self.segwit_node, self.test_node, self.old_node])
|
self.test_end_to_end_block_relay(self.nodes[1], [self.segwit_node, self.test_node, self.old_node])
|
||||||
|
|
||||||
|
print("\tTesting handling of invalid compact blocks...")
|
||||||
|
self.test_invalid_tx_in_compactblock(self.nodes[0], self.test_node, False)
|
||||||
|
self.test_invalid_tx_in_compactblock(self.nodes[1], self.segwit_node, True)
|
||||||
|
self.test_invalid_tx_in_compactblock(self.nodes[1], self.old_node, True)
|
||||||
|
|
||||||
print("\tTesting invalid index in cmpctblock message...")
|
print("\tTesting invalid index in cmpctblock message...")
|
||||||
self.test_invalid_cmpctblock_message()
|
self.test_invalid_cmpctblock_message()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user