Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_resendwallettransactions.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2017-2019 The Bitcoin Core developers | # Copyright (c) 2017-2019 The Bitcoin Core 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 that the wallet resends transactions periodically.""" | """Test that the wallet resends transactions periodically.""" | ||||
import time | import time | ||||
from test_framework.blocktools import create_block, create_coinbase | from test_framework.blocktools import create_block, create_coinbase | ||||
from test_framework.messages import ToHex | from test_framework.messages import ToHex | ||||
from test_framework.mininode import P2PTxInvStore, mininode_lock | from test_framework.mininode import P2PTxInvStore, p2p_lock | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal, wait_until | from test_framework.util import assert_equal, wait_until | ||||
class ResendWalletTransactionsTest(BitcoinTestFramework): | class ResendWalletTransactionsTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
Show All 12 Lines | def run_test(self): | ||||
# nNextResend in ResendWalletTransactions()). Sleep for just over a | # nNextResend in ResendWalletTransactions()). Sleep for just over a | ||||
# second to be certain that it has been called before the first | # second to be certain that it has been called before the first | ||||
# setmocktime call below. | # setmocktime call below. | ||||
time.sleep(1.1) | time.sleep(1.1) | ||||
# Can take a few seconds due to transaction trickling | # Can take a few seconds due to transaction trickling | ||||
wait_until( | wait_until( | ||||
lambda: node.p2p.tx_invs_received[txid] >= 1, | lambda: node.p2p.tx_invs_received[txid] >= 1, | ||||
lock=mininode_lock) | lock=p2p_lock) | ||||
# Add a second peer since txs aren't rebroadcast to the same peer (see | # Add a second peer since txs aren't rebroadcast to the same peer (see | ||||
# filterInventoryKnown) | # filterInventoryKnown) | ||||
node.add_p2p_connection(P2PTxInvStore()) | node.add_p2p_connection(P2PTxInvStore()) | ||||
self.log.info("Create a block") | self.log.info("Create a block") | ||||
# Create and submit a block without the transaction. | # Create and submit a block without the transaction. | ||||
# Transactions are only rebroadcast if there has been a block at least five minutes | # Transactions are only rebroadcast if there has been a block at least five minutes | ||||
Show All 24 Lines | def run_test(self): | ||||
# but can range from 12-36. So bump 36 hours to be sure. | # but can range from 12-36. So bump 36 hours to be sure. | ||||
node.setmocktime(now + 36 * 60 * 60) | node.setmocktime(now + 36 * 60 * 60) | ||||
# Tell scheduler to call MaybeResendWalletTxn now. | # Tell scheduler to call MaybeResendWalletTxn now. | ||||
node.mockscheduler(1) | node.mockscheduler(1) | ||||
# Give some time for trickle to occur | # Give some time for trickle to occur | ||||
node.setmocktime(now + 36 * 60 * 60 + 600) | node.setmocktime(now + 36 * 60 * 60 + 600) | ||||
wait_until( | wait_until( | ||||
lambda: node.p2ps[1].tx_invs_received[txid] >= 1, | lambda: node.p2ps[1].tx_invs_received[txid] >= 1, | ||||
lock=mininode_lock) | lock=p2p_lock) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
ResendWalletTransactionsTest().main() | ResendWalletTransactionsTest().main() |