mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
4aa197dbdb
fa4632c41714dfaa699bacc6a947d72668a4deef test: Move boost/stdlib includes last (MarcoFalke) fa488f131fd4f5bab0d01376c5a5013306f1abcd scripted-diff: Bump copyright headers (MarcoFalke) fac5c373006a9e4bcbb56843bb85f1aca4d87599 scripted-diff: Sort test includes (MarcoFalke) Pull request description: When writing tests, often includes need to be added or removed. Currently the list of includes is not sorted, so developers that write tests and have `clang-format` installed will either have an unrelated change (sorting) included in their commit or they will have to manually undo the sort. This pull preempts both issues by just sorting all includes in one commit. Please be aware that this is **NOT** a change to policy to enforce clang-format or any other developer guideline or process. Developers are free to use whatever tool they want, see also #18651. Edit: Also includes a commit to bump the copyright headers, so that the touched files don't need to be touched again for that. ACKs for top commit: practicalswift: ACK fa4632c41714dfaa699bacc6a947d72668a4deef jonatack: ACK fa4632c41714dfaa, light review and sanity checks with gcc build and clang fuzz build Tree-SHA512: 130a8d073a379ba556b1e64104d37c46b671425c0aef0ed725fd60156a95e8dc83fb6f0b5330b2f8152cf5daaf3983b4aca5e75812598f2626c39fd12b88b180
82 lines
3.4 KiB
Python
Executable File
82 lines
3.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2017-2020 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test that the wallet resends transactions periodically."""
|
|
import time
|
|
|
|
from test_framework.blocktools import create_block, create_coinbase
|
|
from test_framework.messages import ToHex
|
|
from test_framework.mininode import P2PTxInvStore, mininode_lock
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import assert_equal, wait_until
|
|
|
|
class ResendWalletTransactionsTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.num_nodes = 1
|
|
|
|
def skip_test_if_missing_module(self):
|
|
self.skip_if_no_wallet()
|
|
|
|
def run_test(self):
|
|
node = self.nodes[0] # alias
|
|
|
|
node.add_p2p_connection(P2PTxInvStore())
|
|
|
|
self.log.info("Create a new transaction and wait until it's broadcast")
|
|
txid = int(node.sendtoaddress(node.getnewaddress(), 1), 16)
|
|
|
|
# Wallet rebroadcast is first scheduled 1 sec after startup (see
|
|
# nNextResend in ResendWalletTransactions()). Sleep for just over a
|
|
# second to be certain that it has been called before the first
|
|
# setmocktime call below.
|
|
time.sleep(1.1)
|
|
|
|
# Can take a few seconds due to transaction trickling
|
|
def wait_p2p():
|
|
self.bump_mocktime(1)
|
|
return node.p2p.tx_invs_received[txid] >= 1
|
|
wait_until(wait_p2p, lock=mininode_lock)
|
|
|
|
# Add a second peer since txs aren't rebroadcast to the same peer (see filterInventoryKnown)
|
|
node.add_p2p_connection(P2PTxInvStore())
|
|
|
|
self.log.info("Create a block")
|
|
# Create and submit a block without the transaction.
|
|
# 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 extra minute to be sure.
|
|
block_time = self.mocktime + 6 * 60
|
|
node.setmocktime(block_time)
|
|
block = create_block(int(node.getbestblockhash(), 16), create_coinbase(node.getblockcount() + 1), block_time)
|
|
block.rehash()
|
|
block.solve()
|
|
node.submitblock(ToHex(block))
|
|
|
|
# Set correct m_best_block_time, which is used in ResendWalletTransactions
|
|
node.syncwithvalidationinterfacequeue()
|
|
|
|
# Transaction should not be rebroadcast within first 12 hours
|
|
# Leave 2 mins for buffer
|
|
twelve_hrs = 12 * 60 * 60
|
|
two_min = 2 * 60
|
|
node.setmocktime(self.mocktime + twelve_hrs - two_min)
|
|
self.mocktime = self.mocktime + twelve_hrs - two_min
|
|
time.sleep(2) # ensure enough time has passed for rebroadcast attempt to occur
|
|
assert_equal(txid in node.p2ps[1].get_invs(), False)
|
|
|
|
self.log.info("Bump time & check that transaction is rebroadcast")
|
|
# Transaction should be rebroadcast approximately 2 hours in the future,
|
|
# but can range from 1-3. So bump 3 hours to be sure.
|
|
rebroadcast_time = self.mocktime + 3 * 60 * 60
|
|
node.setmocktime(rebroadcast_time)
|
|
self.mocktime = rebroadcast_time
|
|
|
|
def wait_p2p_1():
|
|
self.bump_mocktime(1)
|
|
return node.p2ps[1].tx_invs_received[txid] >= 1
|
|
wait_until(wait_p2p_1, lock=mininode_lock)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
ResendWalletTransactionsTest().main()
|