Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_block.py
Show First 20 Lines • Show All 894 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# use canonical serialization to calculate size | # use canonical serialization to calculate size | ||||
script_length = LEGACY_MAX_BLOCK_SIZE - \ | script_length = LEGACY_MAX_BLOCK_SIZE - \ | ||||
len(b64a.normal_serialize()) - 69 | len(b64a.normal_serialize()) - 69 | ||||
script_output = CScript([b'\x00' * script_length]) | script_output = CScript([b'\x00' * script_length]) | ||||
tx.vout.append(CTxOut(0, script_output)) | tx.vout.append(CTxOut(0, script_output)) | ||||
tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].sha256, 0))) | tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].sha256, 0))) | ||||
b64a = self.update_block("64a", [tx]) | b64a = self.update_block("64a", [tx]) | ||||
assert_equal(len(b64a.serialize()), LEGACY_MAX_BLOCK_SIZE + 8) | assert_equal(len(b64a.serialize()), LEGACY_MAX_BLOCK_SIZE + 8) | ||||
self.sync_blocks([b64a], success=False, reject_code=1, | self.sync_blocks([b64a], success=False, | ||||
reject_reason=b'error parsing message') | reject_reason='non-canonical ReadCompactSize(): iostream error') | ||||
# bitcoind doesn't disconnect us for sending a bloated block, but if we subsequently | # bitcoind doesn't disconnect us for sending a bloated block, but if we subsequently | ||||
# resend the header message, it won't send us the getdata message again. Just | # resend the header message, it won't send us the getdata message again. Just | ||||
# disconnect and reconnect and then call sync_blocks. | # disconnect and reconnect and then call sync_blocks. | ||||
# TODO: improve this test to be less dependent on P2P DOS behaviour. | # TODO: improve this test to be less dependent on P2P DOS behaviour. | ||||
node.disconnect_p2ps() | node.disconnect_p2ps() | ||||
self.reconnect_p2p() | self.reconnect_p2p() | ||||
▲ Show 20 Lines • Show All 503 Lines • ▼ Show 20 Lines | def reconnect_p2p(self): | ||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
network_thread_join() | network_thread_join() | ||||
self.bootstrap_p2p() | self.bootstrap_p2p() | ||||
def sync_blocks(self, blocks, success=True, reject_code=None, reject_reason=None, request_block=True, reconnect=False, timeout=60): | def sync_blocks(self, blocks, success=True, reject_code=None, reject_reason=None, request_block=True, reconnect=False, timeout=60): | ||||
"""Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block. | """Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block. | ||||
Call with success = False if the tip shouldn't advance to the most recent block.""" | Call with success = False if the tip shouldn't advance to the most recent block.""" | ||||
self.nodes[0].p2p.send_blocks_and_test(blocks, self.nodes[0], success=success, reject_code=reject_code, | self.nodes[0].p2p.send_blocks_and_test(blocks, self.nodes[0], success=success, | ||||
reject_reason=reject_reason, request_block=request_block, timeout=timeout) | reject_reason=reject_reason, request_block=request_block, timeout=timeout, expect_disconnect=reconnect) | ||||
if reconnect: | if reconnect: | ||||
self.reconnect_p2p() | self.reconnect_p2p() | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
FullBlockTest().main() | FullBlockTest().main() |