Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_rpc_avalancheproof.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2021 The Bitcoin developers | # Copyright (c) 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 building avalanche proofs and using them to add avalanche peers.""" | """Test building avalanche proofs and using them to add avalanche peers.""" | ||||
from test_framework.avatools import get_stakes | from test_framework.avatools import get_stakes | ||||
from test_framework.key import ECKey | from test_framework.key import ECKey | ||||
from test_framework.mininode import P2PInterface | from test_framework.mininode import P2PInterface | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.test_node import ErrorMatch | from test_framework.test_node import ErrorMatch | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
append_config, | append_config, | ||||
assert_equal, | wait_until, | ||||
) | ) | ||||
AVALANCHE_MAX_PROOF_STAKES = 1000 | AVALANCHE_MAX_PROOF_STAKES = 1000 | ||||
def add_interface_node(test_node) -> str: | def add_interface_node(test_node) -> str: | ||||
"""Create a mininode, connect it to test_node, return the nodeid | """Create a mininode, connect it to test_node, return the nodeid | ||||
of the mininode as registered by test_node. | of the mininode as registered by test_node. | ||||
""" | """ | ||||
n = P2PInterface() | n = P2PInterface() | ||||
test_node.add_p2p_connection(n) | test_node.add_p2p_connection(n) | ||||
n.wait_for_verack() | n.wait_for_verack() | ||||
return test_node.getpeerinfo()[-1]['id'] | return test_node.getpeerinfo()[-1]['id'] | ||||
class AvalancheProofTest(BitcoinTestFramework): | class AvalancheProofTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.extra_args = [['-enableavalanche=1', '-avacooldown=0'], ] | self.extra_args = [['-enableavalanche=1', '-avacooldown=0'], ] | ||||
self.supports_cli = False | |||||
self.rpc_timeout = 120 | |||||
def run_test(self): | def run_test(self): | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
addrkey0 = node.get_deterministic_priv_key() | addrkey0 = node.get_deterministic_priv_key() | ||||
blockhashes = node.generatetoaddress(100, addrkey0.address) | blockhashes = node.generatetoaddress(100, addrkey0.address) | ||||
self.log.info( | self.log.info( | ||||
Show All 21 Lines | def run_test(self): | ||||
"The proof verification should be delayed until IBD is complete") | "The proof verification should be delayed until IBD is complete") | ||||
assert node.getblockchaininfo()["initialblockdownload"] is True | assert node.getblockchaininfo()["initialblockdownload"] is True | ||||
# Our proof cannot be verified during IBD, so we should have no peer | # Our proof cannot be verified during IBD, so we should have no peer | ||||
assert not node.getavalanchepeerinfo() | assert not node.getavalanchepeerinfo() | ||||
# Mining a few more blocks should cause us to leave IBD | # Mining a few more blocks should cause us to leave IBD | ||||
node.generate(2) | node.generate(2) | ||||
# Our proof is now verified and our node is added as a peer | # Our proof is now verified and our node is added as a peer | ||||
assert node.getblockchaininfo()["initialblockdownload"] is False | assert node.getblockchaininfo()["initialblockdownload"] is False | ||||
assert_equal(len(node.getavalanchepeerinfo()), 1) | wait_until(lambda: len(node.getavalanchepeerinfo()) == 1, timeout=5) | ||||
self.log.info( | self.log.info( | ||||
"A proof using the maximum number of stakes is accepted...") | "A proof using the maximum number of stakes is accepted...") | ||||
blockhashes = node.generatetoaddress(AVALANCHE_MAX_PROOF_STAKES + 1, | blockhashes = node.generatetoaddress(AVALANCHE_MAX_PROOF_STAKES + 1, | ||||
addrkey0.address) | addrkey0.address) | ||||
too_many_stakes = get_stakes(node, blockhashes, addrkey0.key) | too_many_stakes = get_stakes(node, blockhashes, addrkey0.key) | ||||
maximum_stakes = get_stakes(node, blockhashes[:-1], addrkey0.key) | maximum_stakes = get_stakes(node, blockhashes[:-1], addrkey0.key) | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |