mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
37634112f2
faf6f156ffd1a8ed1aed047428d791a8c13c162b test: Add missing syncwithvalidationinterfacequeue (MarcoFalke) Pull request description: The wallet rebroadcast functionality learns about new blocks via the validation interface queue. To avoid test failures such as https://ci.appveyor.com/project/DrahtBot/bitcoin/builds/31119387#L466 , we can sync with the queue before advancing the test. ACKs for top commit: jonatack: ACK faf6f156 this makes sense; the fix was previously added to mempool_persist.py and wallet_zapwallettxes.py in #12217 and to wallet_balance.py in #16302. It is also used in src/test/validation_block_tests.cpp (processnewblock_signals_ordering) and src/bench/wallet_balance.cpp. Tree-SHA512: d72fd4b597b669d8111007902b523e946712913cd6eea6f9a695b0f04ecbe2321d05019873af999a95b9e0aa0f5c140a17109b37503723e40c9eab24ec358eb7
90 lines
3.4 KiB
Python
Executable File
90 lines
3.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2017 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."""
|
|
from collections import defaultdict
|
|
import time
|
|
|
|
from test_framework.blocktools import create_block, create_coinbase
|
|
from test_framework.messages import ToHex
|
|
from test_framework.mininode import P2PInterface, mininode_lock
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import assert_equal, wait_until
|
|
|
|
|
|
class P2PStoreTxInvs(P2PInterface):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.tx_invs_received = defaultdict(int)
|
|
|
|
def on_inv(self, message):
|
|
# Store how many times invs have been received for each tx.
|
|
for i in message.inv:
|
|
if i.type == 1:
|
|
# save txid
|
|
self.tx_invs_received[i.hash] += 1
|
|
|
|
|
|
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(P2PStoreTxInvs())
|
|
|
|
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(P2PStoreTxInvs())
|
|
|
|
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.getblockchaininfo()['blocks']), block_time)
|
|
block.nVersion = 3
|
|
block.rehash()
|
|
block.solve()
|
|
node.submitblock(ToHex(block))
|
|
|
|
# Transaction should not be rebroadcast
|
|
node.syncwithvalidationinterfacequeue()
|
|
node.p2ps[1].sync_with_ping()
|
|
assert_equal(node.p2ps[1].tx_invs_received[txid], 0)
|
|
|
|
self.log.info("Transaction should be rebroadcast after 30 minutes")
|
|
# Use mocktime and give an extra 5 minutes to be sure.
|
|
rebroadcast_time = self.mocktime + 41 * 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()
|