Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_resendwallettransactions.py
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
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) | ||||
block = create_block(int(node.getbestblockhash(), 16), create_coinbase( | block = create_block( | ||||
node.getblockcount() + 1), block_time) | int(node.getbestblockhash(), 16), | ||||
create_coinbase(node.getblockcount() + 1), | |||||
block_time, | |||||
) | |||||
block.rehash() | block.rehash() | ||||
block.solve() | block.solve() | ||||
node.submitblock(ToHex(block)) | node.submitblock(ToHex(block)) | ||||
# Set correct m_best_block_time, which is used in | # Set correct m_best_block_time, which is used in | ||||
# ResendWalletTransactions | # ResendWalletTransactions | ||||
node.syncwithvalidationinterfacequeue() | node.syncwithvalidationinterfacequeue() | ||||
now = int(time.time()) | now = int(time.time()) | ||||
# Transaction should not be rebroadcast within first 12 hours | # Transaction should not be rebroadcast within first 12 hours | ||||
# Leave 2 mins for buffer | # Leave 2 mins for buffer | ||||
twelve_hrs = 12 * 60 * 60 | twelve_hrs = 12 * 60 * 60 | ||||
two_min = 2 * 60 | two_min = 2 * 60 | ||||
node.setmocktime(now + twelve_hrs - two_min) | node.setmocktime(now + twelve_hrs - two_min) | ||||
# Tell scheduler to call MaybeResendWalletTxn now | # Tell scheduler to call MaybeResendWalletTxn now | ||||
node.mockscheduler(1) | node.mockscheduler(1) | ||||
assert_equal(int(txid, 16) in peer_second.get_invs(), False) | assert_equal(int(txid, 16) in peer_second.get_invs(), False) | ||||
self.log.info("Bump time & check that transaction is rebroadcast") | self.log.info("Bump time & check that transaction is rebroadcast") | ||||
# 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) | ||||
peer_second.wait_for_broadcast([txid]) | peer_second.wait_for_broadcast([txid]) | ||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
ResendWalletTransactionsTest().main() | ResendWalletTransactionsTest().main() |