Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_avalanche_peer_discovery.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2020-2021 The Bitcoin developers | # Copyright (c) 2020-2021 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test the peer discovery behavior of avalanche nodes. | """Test the peer discovery behavior of avalanche nodes. | ||||
This includes tests for the service flag, avahello handshake and | This includes tests for the service flag, avahello handshake and | ||||
proof exchange. | proof exchange. | ||||
""" | """ | ||||
import time | import time | ||||
from test_framework.address import ADDRESS_BCHREG_UNSPENDABLE | from test_framework.address import ADDRESS_ECREG_UNSPENDABLE | ||||
from test_framework.avatools import ( | from test_framework.avatools import ( | ||||
get_ava_p2p_interface, | get_ava_p2p_interface, | ||||
create_coinbase_stakes, | create_coinbase_stakes, | ||||
get_proof_ids, | get_proof_ids, | ||||
) | ) | ||||
from test_framework.key import ( | from test_framework.key import ( | ||||
bytes_to_wif, | bytes_to_wif, | ||||
ECKey, | ECKey, | ||||
▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.log.info("Invalidate the proof and check the nodes are removed") | self.log.info("Invalidate the proof and check the nodes are removed") | ||||
tip = node.getbestblockhash() | tip = node.getbestblockhash() | ||||
# Invalidate the block with the proof utxo | # Invalidate the block with the proof utxo | ||||
node.invalidateblock(blockhashes[1]) | node.invalidateblock(blockhashes[1]) | ||||
# Change the address to make sure we don't generate a block identical | # Change the address to make sure we don't generate a block identical | ||||
# to the one we just invalidated. Can be generate(1) after D9694 or | # to the one we just invalidated. Can be generate(1) after D9694 or | ||||
# D9697 is landed. | # D9697 is landed. | ||||
forked_tip = node.generatetoaddress(1, ADDRESS_BCHREG_UNSPENDABLE)[0] | forked_tip = node.generatetoaddress(1, ADDRESS_ECREG_UNSPENDABLE)[0] | ||||
wait_until(lambda: node.getbestblockhash() == forked_tip) | wait_until(lambda: node.getbestblockhash() == forked_tip) | ||||
wait_until(lambda: len(node.getavalanchepeerinfo()) == 1) | wait_until(lambda: len(node.getavalanchepeerinfo()) == 1) | ||||
assert peer_proofid not in get_proof_ids(node) | assert peer_proofid not in get_proof_ids(node) | ||||
self.log.info("Reorg back and check the nodes are added back") | self.log.info("Reorg back and check the nodes are added back") | ||||
node.invalidateblock(forked_tip) | node.invalidateblock(forked_tip) | ||||
node.reconsiderblock(tip) | node.reconsiderblock(tip) | ||||
wait_until(lambda: has_node_count(2), timeout=2) | wait_until(lambda: has_node_count(2), timeout=2) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
AvalancheTest().main() | AvalancheTest().main() |