diff --git a/test/functional/abc_rpc_avalancheproof.py b/test/functional/abc_rpc_avalancheproof.py --- a/test/functional/abc_rpc_avalancheproof.py +++ b/test/functional/abc_rpc_avalancheproof.py @@ -11,6 +11,7 @@ create_coinbase_stakes, create_stakes, get_proof_ids, + wait_for_proof, ) from test_framework.key import ECKey, bytes_to_wif from test_framework.messages import ( @@ -25,6 +26,7 @@ from test_framework.util import ( append_config, assert_equal, + connect_nodes, wait_until, assert_raises_rpc_error, ) @@ -48,12 +50,17 @@ class AvalancheProofTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True - self.num_nodes = 1 - self.extra_args = [['-enableavalanche=1', '-avacooldown=0'], ] + self.num_nodes = 2 + self.extra_args = [['-enableavalanche=1', '-avacooldown=0'], + ['-enableavalanche=1', '-avacooldown=0']] self.supports_cli = False self.rpc_timeout = 120 def run_test(self): + # Turn off node 1 while node 0 mines blocks to generate stakes, + # so that we can later try starting node 1 with an orphan proof. + self.stop_node(1) + node = self.nodes[0] addrkey0 = node.get_deterministic_priv_key() @@ -112,6 +119,27 @@ node.generate(1) wait_until(lambda: len(node.getavalanchepeerinfo()) == 1, timeout=5) + # The following case will be common, with users building proofs + # with an external tool (e.g. Electrum ABC) and then starting a + # new node that does not yet know of the stakes + self.log.info("Start a node with an orphan proof") + + self.add_nodes(1) + self.start_node(1, self.extra_args[0] + [ + "-avaproof={}".format(proof), + "-avamasterkey=cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN", + ]) + # Mine a block to trigger an attempt at registering the proof + self.nodes[1].generate(1) + wait_for_proof(self.nodes[1], f"{proofobj.proofid:0{64}x}", + expect_orphan=True) + + self.log.info("Connect to a up-to-date node to unorphan the proof") + connect_nodes(self.nodes[1], node) + node.generate(1) + wait_for_proof(self.nodes[1], f"{proofobj.proofid:0{64}x}", + expect_orphan=False) + if self.is_wallet_compiled(): self.log.info( "A proof using the maximum number of stakes is accepted...")