diff --git a/test/functional/rpc_listtransactions.py b/test/functional/rpc_listtransactions.py --- a/test/functional/rpc_listtransactions.py +++ b/test/functional/rpc_listtransactions.py @@ -8,7 +8,7 @@ from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_array_result +from test_framework.util import assert_array_result, wait_until class ListTransactionsTest(BitcoinTestFramework): @@ -16,11 +16,23 @@ self.num_nodes = 2 def run_test(self): + def wait_for_tip(node, tip): + def check_tip(): + return node.getbestblockhash() == tip + wait_until(check_tip) + # Leave IBD - self.nodes[0].generate(1) + tip = self.nodes[0].generate(1)[-1] + wait_for_tip(self.nodes[1], tip) + + def wait_for_tx(node, tx): + def check_tx(): + return tx in node.getrawmempool() + wait_until(check_tx) + # Simple send, 0 to 1: txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1) - self.sync_all() + wait_for_tx(self.nodes[1], txid) assert_array_result(self.nodes[0].listtransactions(), {"txid": txid}, {"category": "send", "account": "", "amount": Decimal("-0.1"), "confirmations": 0}) @@ -28,8 +40,8 @@ {"txid": txid}, {"category": "receive", "account": "", "amount": Decimal("0.1"), "confirmations": 0}) # mine a block, confirmations should change: - self.nodes[0].generate(1) - self.sync_all() + tip = self.nodes[0].generate(1)[-1] + wait_for_tip(self.nodes[1], tip) assert_array_result(self.nodes[0].listtransactions(), {"txid": txid}, {"category": "send", "account": "", "amount": Decimal("-0.1"), "confirmations": 1}) @@ -52,7 +64,7 @@ self.nodes[0].getaccountaddress("from1"): 0.33, self.nodes[1].getaccountaddress("toself"): 0.44} txid = self.nodes[1].sendmany("", send_to) - self.sync_all() + wait_for_tx(self.nodes[0], txid) assert_array_result(self.nodes[1].listtransactions(), {"category": "send", "amount": Decimal("-0.11")}, {"txid": txid}) @@ -83,8 +95,8 @@ self.nodes[0].importaddress( multisig["redeemScript"], "watchonly", False, True) txid = self.nodes[1].sendtoaddress(multisig["address"], 0.1) - self.nodes[1].generate(1) - self.sync_all() + tip = self.nodes[1].generate(1)[-1] + wait_for_tip(self.nodes[0], tip) assert( len(self.nodes[0].listtransactions("watchonly", 100, 0, False)) == 0) assert_array_result(