Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_resendwallettransactions.py
Show All 16 Lines | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def run_test(self): | def run_test(self): | ||||
node = self.nodes[0] # alias | node = self.nodes[0] # alias | ||||
node.add_p2p_connection(P2PTxInvStore()) | peer_first = node.add_p2p_connection(P2PTxInvStore()) | ||||
self.log.info("Create a new transaction and wait until it's broadcast") | self.log.info("Create a new transaction and wait until it's broadcast") | ||||
txid = node.sendtoaddress(node.getnewaddress(), 1_000_000) | txid = node.sendtoaddress(node.getnewaddress(), 1_000_000) | ||||
# Wallet rebroadcast is first scheduled 1 sec after startup (see | # Wallet rebroadcast is first scheduled 1 sec after startup (see | ||||
# nNextResend in ResendWalletTransactions()). Tell scheduler to call | # nNextResend in ResendWalletTransactions()). Tell scheduler to call | ||||
# MaybeResendWalletTxn now to initialize nNextResend before the first | # MaybeResendWalletTxn now to initialize nNextResend before the first | ||||
# setmocktime call below. | # setmocktime call below. | ||||
node.mockscheduler(1) | node.mockscheduler(1) | ||||
# Can take a few seconds due to transaction trickling | # Can take a few seconds due to transaction trickling | ||||
node.p2p.wait_for_broadcast([txid]) | peer_first.wait_for_broadcast([txid]) | ||||
# 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()) | peer_second = 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 | ||||
# after the last time we tried to broadcast. Use mocktime and give an | # after the last time we tried to broadcast. Use mocktime and give an | ||||
# extra minute to be sure. | # extra minute to be sure. | ||||
block_time = int(time.time()) + 6 * 60 | block_time = int(time.time()) + 6 * 60 | ||||
node.setmocktime(block_time) | node.setmocktime(block_time) | ||||
Show All 19 Lines | def run_test(self): | ||||
# Transaction should be rebroadcast approximately 24 hours in the future, | # Transaction should be rebroadcast approximately 24 hours in the future, | ||||
# 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. | ||||
with node.assert_debug_log(['ResendWalletTransactions: resubmit 1 unconfirmed transactions']): | with node.assert_debug_log(['ResendWalletTransactions: resubmit 1 unconfirmed transactions']): | ||||
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) | ||||
node.p2p.wait_for_broadcast([txid]) | peer_second.wait_for_broadcast([txid]) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
ResendWalletTransactionsTest().main() | ResendWalletTransactionsTest().main() |