Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_getavaaddr.py
| #!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
| # Copyright (c) 2022 The Bitcoin developers | # Copyright (c) 2022 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 getavaaddr p2p message""" | """Test getavaaddr p2p message""" | ||||
| import time | import time | ||||
| from test_framework.avatools import AvaP2PInterface, gen_proof | from test_framework.avatools import AvaP2PInterface, gen_proof | ||||
| from test_framework.key import ECKey | |||||
| from test_framework.messages import ( | from test_framework.messages import ( | ||||
| NODE_AVALANCHE, | NODE_AVALANCHE, | ||||
| NODE_NETWORK, | NODE_NETWORK, | ||||
| AvalancheVote, | AvalancheVote, | ||||
| AvalancheVoteError, | AvalancheVoteError, | ||||
| msg_getavaaddr, | msg_getavaaddr, | ||||
| ) | ) | ||||
| from test_framework.p2p import P2PInterface, p2p_lock | from test_framework.p2p import P2PInterface, p2p_lock | ||||
| ▲ Show 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | def getavaaddr_outbound_test(self): | ||||
| # Because none of the avalanche peers is responding, our node should | # Because none of the avalanche peers is responding, our node should | ||||
| # fail out of option shortly and send a getavaaddr message to one of its | # fail out of option shortly and send a getavaaddr message to one of its | ||||
| # outbound avalanche peers. | # outbound avalanche peers. | ||||
| node.mockscheduler(10 * 60) | node.mockscheduler(10 * 60) | ||||
| self.wait_until( | self.wait_until( | ||||
| lambda: any([p.message_count.get("getavaaddr", 0) > 1 for p in avapeers])) | lambda: any([p.message_count.get("getavaaddr", 0) > 1 for p in avapeers])) | ||||
| def getavaaddr_noquorum(self): | |||||
| self.log.info( | |||||
| "Check we send a getavaaddr message while our quorum is not established") | |||||
| node = self.nodes[0] | |||||
| self.restart_node(0, extra_args=self.extra_args[0] + [ | |||||
| '-avaminquorumstake=100000000', | |||||
| '-avaminquorumconnectedstakeratio=0.8', | |||||
| ]) | |||||
| privkey = ECKey() | |||||
| privkey.generate() | |||||
| avapeers = [] | |||||
| for i in range(16): | |||||
| avapeer = AllYesAvaP2PInterface(privkey) | |||||
| node.add_outbound_p2p_connection( | |||||
| avapeer, | |||||
| p2p_idx=i, | |||||
| connection_type="avalanche", | |||||
| services=NODE_NETWORK | NODE_AVALANCHE, | |||||
| ) | |||||
| avapeers.append(avapeer) | |||||
| self.wait_until( | |||||
| lambda: all([p.last_message.get("getavaaddr") for p in avapeers])) | |||||
| assert all([p.message_count.get( | |||||
| "getavaaddr", 0) == 1 for p in avapeers]) | |||||
| # Because we have not enough stake to start polling, we keep requesting | |||||
| # more addresses | |||||
| for i in range(5): | |||||
| node.mockscheduler(10 * 60) | |||||
| self.wait_until( | |||||
| lambda: any([p.message_count.get("getavaaddr", 0) > 1 for p in avapeers])) | |||||
| def run_test(self): | def run_test(self): | ||||
| self.getavaaddr_interval_test() | self.getavaaddr_interval_test() | ||||
| # Limited by maxaddrtosend | # Limited by maxaddrtosend | ||||
| self.address_test(maxaddrtosend=3, num_proof=2, num_avanode=8) | self.address_test(maxaddrtosend=3, num_proof=2, num_avanode=8) | ||||
| # Limited by the number of good nodes | # Limited by the number of good nodes | ||||
| self.address_test(maxaddrtosend=100, num_proof=2, num_avanode=8) | self.address_test(maxaddrtosend=100, num_proof=2, num_avanode=8) | ||||
| self.getavaaddr_outbound_test() | self.getavaaddr_outbound_test() | ||||
| self.getavaaddr_noquorum() | |||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||
| AvaAddrTest().main() | AvaAddrTest().main() | ||||