Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-p2p-avalanche.py
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Create a fake node and connect it to our real node. | # Create a fake node and connect it to our real node. | ||||
poll_node = TestNode() | poll_node = TestNode() | ||||
node.add_p2p_connection(poll_node) | node.add_p2p_connection(poll_node) | ||||
poll_node.wait_for_verack() | poll_node.wait_for_verack() | ||||
poll_node.sync_with_ping() | poll_node.sync_with_ping() | ||||
# Generate many block and poll for them. | # Generate many block and poll for them. | ||||
node.generate(100) | address = node.get_deterministic_priv_key().address | ||||
node.generatetoaddress(100, address) | |||||
self.log.info("Poll for the chain tip...") | self.log.info("Poll for the chain tip...") | ||||
best_block_hash = int(node.getbestblockhash(), 16) | best_block_hash = int(node.getbestblockhash(), 16) | ||||
poll_node.send_poll([best_block_hash]) | poll_node.send_poll([best_block_hash]) | ||||
poll_node.wait_for_avaresponse() | poll_node.wait_for_avaresponse() | ||||
def assert_response(response, expected): | def assert_response(response, expected): | ||||
votes = response.votes | votes = response.votes | ||||
Show All 21 Lines | def run_test(self): | ||||
poll_node.wait_for_avaresponse() | poll_node.wait_for_avaresponse() | ||||
assert_response(poll_node.last_avaresponse, | assert_response(poll_node.last_avaresponse, | ||||
[AvalancheVote(BLOCK_ACCEPTED, h) for h in various_block_hashes]) | [AvalancheVote(BLOCK_ACCEPTED, h) for h in various_block_hashes]) | ||||
self.log.info( | self.log.info( | ||||
"Poll for a selection of blocks, but some are now invalid...") | "Poll for a selection of blocks, but some are now invalid...") | ||||
invalidated_block = node.getblockhash(75) | invalidated_block = node.getblockhash(75) | ||||
node.invalidateblock(invalidated_block) | node.invalidateblock(invalidated_block) | ||||
node.generate(30) | # We need to send the coin to a new address in order to make sure we do | ||||
# not regenerate the same block. | |||||
node.generatetoaddress( | |||||
30, 'bchreg:pqv2r67sgz3qumufap3h2uuj0zfmnzuv8v7ej0fffv') | |||||
node.reconsiderblock(invalidated_block) | node.reconsiderblock(invalidated_block) | ||||
poll_node.send_poll(various_block_hashes) | poll_node.send_poll(various_block_hashes) | ||||
poll_node.wait_for_avaresponse() | poll_node.wait_for_avaresponse() | ||||
assert_response(poll_node.last_avaresponse, | assert_response(poll_node.last_avaresponse, | ||||
[AvalancheVote(BLOCK_ACCEPTED, h) for h in various_block_hashes[:5]] + | [AvalancheVote(BLOCK_ACCEPTED, h) for h in various_block_hashes[:5]] + | ||||
[AvalancheVote(BLOCK_REJECTED, h) for h in various_block_hashes[-3:]]) | [AvalancheVote(BLOCK_REJECTED, h) for h in various_block_hashes[-3:]]) | ||||
Show All 22 Lines |