diff --git a/test/functional/abc-finalize-block.py b/test/functional/abc-finalize-block.py --- a/test/functional/abc-finalize-block.py +++ b/test/functional/abc-finalize-block.py @@ -11,7 +11,6 @@ assert_equal, assert_raises_rpc_error, set_node_times, - wait_until, ) RPC_FINALIZE_INVALID_BLOCK_ERROR = 'finalize-invalid-block' @@ -41,7 +40,7 @@ def wait_for_tip(node, tip): def check_tip(): return node.getbestblockhash() == tip - wait_until(check_tip) + self.wait_until(check_tip) alt_node = self.nodes[1] wait_for_tip(alt_node, tip) @@ -78,7 +77,7 @@ assert tip["status"] != "active" return tip["status"] == status return False - wait_until(check_block) + self.wait_until(check_block) # First block header is accepted as valid-header alt_node.generatetoaddress( diff --git a/test/functional/abc-invalid-message.py b/test/functional/abc-invalid-message.py --- a/test/functional/abc-invalid-message.py +++ b/test/functional/abc-invalid-message.py @@ -17,7 +17,6 @@ P2PInterface, ) from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import wait_until def msg_bad_checksum(connection, original_message): @@ -82,7 +81,7 @@ if not interface.last_message.get("pong"): return False return interface.last_message["pong"].nonce == interface.ping_counter - wait_until(check_ping, lock=p2p_lock) + self.wait_until(check_ping, lock=p2p_lock) interface.ping_counter += 1 # The valid message is accepted diff --git a/test/functional/abc-parkedchain.py b/test/functional/abc-parkedchain.py --- a/test/functional/abc-parkedchain.py +++ b/test/functional/abc-parkedchain.py @@ -8,7 +8,6 @@ from test_framework.util import ( assert_equal, connect_nodes, - wait_until ) @@ -35,7 +34,7 @@ def wait_for_tip(node, tip): def check_tip(): return node.getbestblockhash() == tip - wait_until(check_tip) + self.wait_until(check_tip) node = self.nodes[0] parking_node = self.nodes[1] @@ -167,7 +166,7 @@ assert tip["status"] != "active" return tip["status"] == "parked" return False - wait_until(check_block) + self.wait_until(check_block) def check_reorg_protection(depth, extra_blocks): self.log.info( @@ -189,8 +188,8 @@ # If we mine one more block, the node reorgs. node.generate(1) - wait_until(lambda: parking_node.getbestblockhash() - == node.getbestblockhash()) + self.wait_until(lambda: parking_node.getbestblockhash() + == node.getbestblockhash()) check_reorg_protection(1, 0) check_reorg_protection(2, 0) @@ -214,8 +213,8 @@ node.generatetoaddress( nblocks=20, address=node.getnewaddress(label='coinbase')) - wait_until(lambda: parking_node.getbestblockhash() == - node.getbestblockhash()) + self.wait_until(lambda: parking_node.getbestblockhash() == + node.getbestblockhash()) except AssertionError as exc: # good, we want an absence of "Park block" messages assert "does not partially match log" in exc.args[0] @@ -242,8 +241,8 @@ wait_for_parked_block(node.getbestblockhash()) # Final block pushes over the edge, and should unpark. node.generate(1) - wait_until(lambda: parking_node.getbestblockhash() == - node.getbestblockhash(), timeout=5) + self.wait_until(lambda: parking_node.getbestblockhash() == + node.getbestblockhash(), timeout=5) # Do not append tests after this point without restarting node again. # Parking node is no longer parking. diff --git a/test/functional/abc-sync-chain.py b/test/functional/abc-sync-chain.py --- a/test/functional/abc-sync-chain.py +++ b/test/functional/abc-sync-chain.py @@ -15,7 +15,6 @@ from test_framework.messages import CBlockHeader, msg_block, msg_headers from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import wait_until NUM_IBD_BLOCKS = 50 @@ -66,7 +65,7 @@ # The node should eventually, completely sync without getting stuck def node_synced(): return node0.getbestblockhash() == blocks[-1].hash - wait_until(node_synced) + self.wait_until(node_synced) if __name__ == '__main__': diff --git a/test/functional/abc_p2p_avalanche_peer_discovery.py b/test/functional/abc_p2p_avalanche_peer_discovery.py --- a/test/functional/abc_p2p_avalanche_peer_discovery.py +++ b/test/functional/abc_p2p_avalanche_peer_discovery.py @@ -31,10 +31,7 @@ NODE_NETWORK, ) from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - wait_until, -) +from test_framework.util import assert_equal from test_framework.wallet_util import bytes_to_wif UNCONDITIONAL_RELAY_DELAY = 2 * 60 @@ -155,7 +152,7 @@ with p2p_lock: return good_interface.last_message.get( "getdata") and good_interface.last_message["getdata"].inv[-1].hash == proofid - wait_until(lambda: getdata_found(good_interface, proofid)) + self.wait_until(lambda: getdata_found(good_interface, proofid)) self.log.info('Check that we can download the proof from our peer') @@ -164,7 +161,7 @@ def wait_for_proof_validation(): # Connect some blocks to trigger the proof verification node.generate(1) - wait_until(lambda: node_proofid in get_proof_ids(node)) + self.wait_until(lambda: node_proofid in get_proof_ids(node)) wait_for_proof_validation() @@ -178,7 +175,7 @@ with p2p_lock: return peer.last_message.get( "avaproof") and peer.last_message["avaproof"].proof.proofid == node_proofid - wait_until(lambda: proof_received(good_interface)) + self.wait_until(lambda: proof_received(good_interface)) # Restart the node self.restart_node(0, self.extra_args[0] + [ @@ -202,7 +199,7 @@ node.setmocktime(current_time + UNCONDITIONAL_RELAY_DELAY) peer.send_message(getdata) - wait_until(lambda: proof_received(peer)) + self.wait_until(lambda: proof_received(peer)) # Restart the node self.restart_node(0, self.extra_args[0] + [ @@ -218,7 +215,7 @@ peer_proofid = peer.send_avahello( interface_delegation_hex, delegated_key) - wait_until(lambda: getdata_found(peer, peer_proofid)) + self.wait_until(lambda: getdata_found(peer, peer_proofid)) assert peer_proofid not in get_proof_ids(node) self.log.info( @@ -231,7 +228,7 @@ peerinfo[-1]["proof"] == interface_proof_hex and peerinfo[-1]["nodecount"] == count) - wait_until(lambda: has_node_count(1)) + self.wait_until(lambda: has_node_count(1)) self.log.info( "Check that the peer gets added immediately if the proof is already known") @@ -240,7 +237,7 @@ peer_proof_known = get_ava_p2p_interface(node) peer_proof_known.send_avahello(interface_delegation_hex, delegated_key) - wait_until(lambda: has_node_count(2)) + self.wait_until(lambda: has_node_count(2)) self.log.info("Invalidate the proof and check the nodes are removed") tip = node.getbestblockhash() @@ -250,15 +247,15 @@ # to the one we just invalidated. Can be generate(1) after D9694 or # D9697 is landed. forked_tip = node.generatetoaddress(1, ADDRESS_ECREG_UNSPENDABLE)[0] - wait_until(lambda: node.getbestblockhash() == forked_tip) + self.wait_until(lambda: node.getbestblockhash() == forked_tip) - wait_until(lambda: len(node.getavalanchepeerinfo()) == 1) + self.wait_until(lambda: len(node.getavalanchepeerinfo()) == 1) assert peer_proofid not in get_proof_ids(node) self.log.info("Reorg back and check the nodes are added back") node.invalidateblock(forked_tip) node.reconsiderblock(tip) - wait_until(lambda: has_node_count(2), timeout=2) + self.wait_until(lambda: has_node_count(2), timeout=2) if __name__ == '__main__': diff --git a/test/functional/abc_p2p_avalanche_voting.py b/test/functional/abc_p2p_avalanche_voting.py --- a/test/functional/abc_p2p_avalanche_voting.py +++ b/test/functional/abc_p2p_avalanche_voting.py @@ -15,10 +15,7 @@ ) from test_framework.messages import AvalancheVote from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - wait_until, -) +from test_framework.util import assert_equal from test_framework.wallet_util import bytes_to_wif BLOCK_ACCEPTED = 0 @@ -181,7 +178,7 @@ # Now that we have a peer, we should start polling for the tip. hash_tip = int(node.getbestblockhash(), 16) - wait_until(lambda: can_find_block_in_poll(hash_tip), timeout=5) + self.wait_until(lambda: can_find_block_in_poll(hash_tip), timeout=5) # Make sure the fork node has synced the blocks self.sync_blocks([node, fork_node]) @@ -201,7 +198,7 @@ return False fork_tip = fork_node.getbestblockhash() - wait_until(lambda: parked_block(fork_tip)) + self.wait_until(lambda: parked_block(fork_tip)) self.log.info("Answer all polls to finalize...") @@ -212,7 +209,7 @@ return node.getbestblockhash() == fork_tip # Because everybody answers yes, the node will accept that block. - wait_until(has_accepted_new_tip, timeout=15) + self.wait_until(has_accepted_new_tip, timeout=15) assert_equal(node.getbestblockhash(), fork_tip) self.log.info("Answer all polls to park...") @@ -227,7 +224,7 @@ return node.getbestblockhash() == fork_tip # Because everybody answers no, the node will park that block. - wait_until(has_parked_new_tip, timeout=15) + self.wait_until(has_parked_new_tip, timeout=15) assert_equal(node.getbestblockhash(), fork_tip) self.log.info( diff --git a/test/functional/abc_p2p_compactblocks.py b/test/functional/abc_p2p_compactblocks.py --- a/test/functional/abc_p2p_compactblocks.py +++ b/test/functional/abc_p2p_compactblocks.py @@ -40,10 +40,7 @@ from test_framework.script import CScript, OP_RETURN, OP_TRUE from test_framework.test_framework import BitcoinTestFramework from test_framework.txtools import pad_tx -from test_framework.util import ( - assert_equal, - wait_until -) +from test_framework.util import assert_equal class PreviousSpendableOutput(): @@ -284,7 +281,7 @@ # Wait for SENDCMPCT def received_sendcmpct(): return (test_p2p.last_sendcmpct is not None) - wait_until(received_sendcmpct, timeout=30) + self.wait_until(received_sendcmpct, timeout=30) sendcmpct = msg_sendcmpct() sendcmpct.version = 1 @@ -294,7 +291,7 @@ # Exchange headers def received_getheaders(): return (test_p2p.last_getheaders is not None) - wait_until(received_getheaders, timeout=30) + self.wait_until(received_getheaders, timeout=30) # Return the favor test_p2p.send_message(test_p2p.last_getheaders) @@ -302,7 +299,7 @@ # Wait for the header list def received_headers(): return (test_p2p.last_headers is not None) - wait_until(received_headers, timeout=30) + self.wait_until(received_headers, timeout=30) # It's like we know about the same headers ! test_p2p.send_message(test_p2p.last_headers) @@ -314,7 +311,7 @@ # Checks the node to forward it via compact block def received_block(): return (test_p2p.last_cmpctblock is not None) - wait_until(received_block, timeout=30) + self.wait_until(received_block, timeout=30) # Was it our block ? cmpctblk_header = test_p2p.last_cmpctblock.header_and_shortids.header @@ -328,7 +325,7 @@ default_p2p.send_blocks_and_test([self.tip], node) # Checks the node forwards it via compact block - wait_until(received_block, timeout=30) + self.wait_until(received_block, timeout=30) # Was it our block ? cmpctblk_header = test_p2p.last_cmpctblock.header_and_shortids.header diff --git a/test/functional/abc_p2p_proof_inventory.py b/test/functional/abc_p2p_proof_inventory.py --- a/test/functional/abc_p2p_proof_inventory.py +++ b/test/functional/abc_p2p_proof_inventory.py @@ -31,7 +31,6 @@ assert_equal, assert_greater_than, connect_nodes, - wait_until, ) from test_framework.wallet_util import bytes_to_wif @@ -76,7 +75,7 @@ return peer.last_message.get( "inv") and peer.last_message["inv"].inv[-1].hash == proof.proofid - wait_until(lambda: all(proof_inv_found(i) for i in node.p2ps)) + self.wait_until(lambda: all(proof_inv_found(i) for i in node.p2ps)) self.log.info("Test that we don't send the same inv several times") @@ -87,7 +86,7 @@ node.sendavalancheproof(proof.serialize().hex()) # Our new extra peer should receive it but not the others - wait_until(lambda: proof_inv_found(extra_peer)) + self.wait_until(lambda: proof_inv_found(extra_peer)) assert all(p.proof_invs_counter == 1 for p in node.p2ps) # Send the proof again and force the send loop to be processed @@ -109,7 +108,7 @@ msg.proof = proof peer.send_message(msg) - wait_until(lambda: proof.proofid in get_proof_ids(node)) + self.wait_until(lambda: proof.proofid in get_proof_ids(node)) self.log.info("Test receiving a proof with missing utxo is orphaned") @@ -168,7 +167,7 @@ # Connect a block to make the proof be added to our pool node.generate(1) - wait_until(lambda: proof.proofid in get_proof_ids(node)) + self.wait_until(lambda: proof.proofid in get_proof_ids(node)) [connect_nodes(node, n) for n in nodes[:i]] @@ -221,14 +220,14 @@ return all(p.last_message.get( "inv") and p.last_message["inv"].inv[-1].hash == proof.proofid for p in peers) - wait_until(lambda: proof_inv_received(peers)) + self.wait_until(lambda: proof_inv_received(peers)) # If no peer request the proof for download, the node should reattempt # broadcasting to all new peers after 10 to 15 minutes. peers = add_peers(3) node.mockscheduler(MAX_INITIAL_BROADCAST_DELAY + 1) peers[-1].sync_with_ping() - wait_until(lambda: proof_inv_received(peers)) + self.wait_until(lambda: proof_inv_received(peers)) # If at least one peer requests the proof, there is no more attempt to # broadcast it @@ -252,7 +251,7 @@ # Broadcast the proof peers = add_peers(3) assert node.sendavalancheproof(proof.serialize().hex()) - wait_until(lambda: proof_inv_received(peers)) + self.wait_until(lambda: proof_inv_received(peers)) # Sanity check our node knows the proof, and it is valid wait_for_proof(node, proofid_hex, expect_orphan=False) @@ -278,7 +277,7 @@ node.generate(1) # Wait for the proof to be orphaned - wait_until(lambda: node.getrawavalancheproof( + self.wait_until(lambda: node.getrawavalancheproof( proofid_hex)["orphan"] is True) # It should no longer be broadcasted 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 @@ -27,7 +27,6 @@ append_config, assert_equal, connect_nodes, - wait_until, assert_raises_rpc_error, ) from test_framework.wallet_util import bytes_to_wif @@ -119,7 +118,8 @@ self.log.info("The proof is registered at first chaintip update") assert_equal(len(node.getavalanchepeerinfo()), 0) node.generate(1) - wait_until(lambda: len(node.getavalanchepeerinfo()) == 1, timeout=5) + self.wait_until(lambda: len(node.getavalanchepeerinfo()) == 1, + timeout=5) # This case will occur for users building proofs with a third party # tool and then starting a new node that is not yet aware of the @@ -348,7 +348,7 @@ with p2p_lock: return peer.last_message.get( "inv") and peer.last_message["inv"].inv[-1].hash == proofid - wait_until(inv_found) + self.wait_until(inv_found) self.log.info("Check the getrawproof RPC") @@ -368,7 +368,7 @@ signed_tx = node.signrawtransactionwithkey(raw_tx, [addrkey0.key]) node.sendrawtransaction(signed_tx["hex"]) node.generate(1) - wait_until(lambda: proofid not in get_proof_ids(node)) + self.wait_until(lambda: proofid not in get_proof_ids(node)) raw_proof = node.getrawavalancheproof("{:064x}".format(proofid)) assert_equal(raw_proof['proof'], proof)