diff --git a/test/functional/llmq-is-cl-conflicts.py b/test/functional/llmq-is-cl-conflicts.py index 9853704a4bde..7fe8db01caba 100755 --- a/test/functional/llmq-is-cl-conflicts.py +++ b/test/functional/llmq-is-cl-conflicts.py @@ -9,7 +9,7 @@ from test_framework.blocktools import get_masternode_payment, create_coinbase, create_block from test_framework.mininode import * from test_framework.test_framework import DashTestFramework -from test_framework.util import sync_blocks, p2p_port, assert_raises_rpc_error, set_node_times +from test_framework.util import sync_blocks, sync_mempools, p2p_port, assert_raises_rpc_error, set_node_times ''' llmq-is-cl-conflicts.py @@ -102,6 +102,8 @@ def test_chainlock_overrides_islock(self, test_block_conflict): rawtx4 = self.nodes[0].signrawtransaction(rawtx4)['hex'] rawtx4_txid = self.nodes[0].sendrawtransaction(rawtx4) + # wait for transactions to propagate + sync_mempools(self.nodes) for node in self.nodes: self.wait_for_instantlock(rawtx1_txid, node) self.wait_for_instantlock(rawtx4_txid, node) @@ -143,6 +145,8 @@ def test_chainlock_overrides_islock(self, test_block_conflict): rawtx5 = self.nodes[0].createrawtransaction(inputs, {self.nodes[0].getnewaddress(): 0.999}) rawtx5 = self.nodes[0].signrawtransaction(rawtx5)['hex'] rawtx5_txid = self.nodes[0].sendrawtransaction(rawtx5) + # wait for the transaction to propagate + sync_mempools(self.nodes) for node in self.nodes: self.wait_for_instantlock(rawtx5_txid, node) diff --git a/test/functional/p2p-instantsend.py b/test/functional/p2p-instantsend.py index 6b83ee4a4277..8f50439b83ee 100755 --- a/test/functional/p2p-instantsend.py +++ b/test/functional/p2p-instantsend.py @@ -5,7 +5,7 @@ from test_framework.mininode import * from test_framework.test_framework import DashTestFramework -from test_framework.util import isolate_node, set_node_times, reconnect_isolated_node, assert_equal, \ +from test_framework.util import isolate_node, sync_mempools, set_node_times, reconnect_isolated_node, assert_equal, \ assert_raises_rpc_error ''' @@ -50,9 +50,12 @@ def test_block_doublespend(self): # instantsend to receiver receiver_addr = receiver.getnewaddress() is_id = sender.sendtoaddress(receiver_addr, 0.9) - for node in self.nodes: - if node is not isolated: - self.wait_for_instantlock(is_id, node) + # wait for the transaction to propagate + connected_nodes = self.nodes.copy() + del connected_nodes[self.isolated_idx] + sync_mempools(connected_nodes) + for node in connected_nodes: + self.wait_for_instantlock(is_id, node) # send doublespend transaction to isolated node isolated.sendrawtransaction(dblspnd_tx['hex']) # generate block on isolated node with doublespend transaction @@ -109,6 +112,8 @@ def test_mempool_doublespend(self): # TX from other nodes. receiver_addr = receiver.getnewaddress() is_id = sender.sendtoaddress(receiver_addr, 0.9) + # wait for the transaction to propagate + sync_mempools(self.nodes) for node in self.nodes: self.wait_for_instantlock(is_id, node) assert_raises_rpc_error(-5, "No such mempool or blockchain transaction", isolated.getrawtransaction, dblspnd_txid) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index c59b6277d223..9e7c289b7f96 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -38,7 +38,9 @@ sync_blocks, sync_mempools, sync_masternodes, - wait_to_sync) + wait_to_sync, + wait_until, +) class TestStatus(Enum): PASSED = 1 @@ -687,22 +689,12 @@ def create_raw_tx(self, node_from, node_to, amount, min_inputs, max_inputs): return ret def wait_for_instantlock(self, txid, node): - # wait for instantsend locks - start = time.time() - locked = False - while True: + def check_instantlock(): try: - is_tx = node.getrawtransaction(txid, True) - if is_tx['instantlock']: - locked = True - break + return node.getrawtransaction(txid, True)["instantlock"] except: - # TX not received yet? - pass - if time.time() > start + 10: - break - time.sleep(0.5) - return locked + return False + wait_until(check_instantlock, timeout=10, sleep=0.5) def wait_for_sporks_same(self, timeout=30): st = time.time()