test: Implicitly sync after generate*, unless opted out

This commit is contained in:
MarcoFalke 2020-11-10 18:02:31 +01:00
parent 5574881ce3
commit facc352648
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
46 changed files with 144 additions and 175 deletions

View file

@ -141,8 +141,7 @@ class ExampleTest(BitcoinTestFramework):
peer_messaging = self.nodes[0].add_p2p_connection(BaseNode()) peer_messaging = self.nodes[0].add_p2p_connection(BaseNode())
# Generating a block on one of the nodes will get us out of IBD # Generating a block on one of the nodes will get us out of IBD
blocks = [int(self.generate(self.nodes[0], nblocks=1)[0], 16)] blocks = [int(self.generate(self.nodes[0], sync_fun=lambda: self.sync_all(self.nodes[0:2]), nblocks=1)[0], 16)]
self.sync_all(self.nodes[0:2])
# Notice above how we called an RPC by calling a method with the same # Notice above how we called an RPC by calling a method with the same
# name on the node object. Notice also how we used a keyword argument # name on the node object. Notice also how we used a keyword argument

View file

@ -26,7 +26,7 @@ class AbortNodeTest(BitcoinTestFramework):
# We'll connect the nodes later # We'll connect the nodes later
def run_test(self): def run_test(self):
self.generate(self.nodes[0], 3) self.generate(self.nodes[0], 3, sync_fun=self.no_op)
datadir = get_datadir_path(self.options.tmpdir, 0) datadir = get_datadir_path(self.options.tmpdir, 0)
# Deleting the undo file will result in reorg failure # Deleting the undo file will result in reorg failure
@ -34,10 +34,10 @@ class AbortNodeTest(BitcoinTestFramework):
# Connecting to a node with a more work chain will trigger a reorg # Connecting to a node with a more work chain will trigger a reorg
# attempt. # attempt.
self.generate(self.nodes[1], 3) self.generate(self.nodes[1], 3, sync_fun=self.no_op)
with self.nodes[0].assert_debug_log(["Failed to disconnect block"]): with self.nodes[0].assert_debug_log(["Failed to disconnect block"]):
self.connect_nodes(0, 1) self.connect_nodes(0, 1)
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=self.no_op)
# Check that node0 aborted # Check that node0 aborted
self.log.info("Waiting for crash") self.log.info("Waiting for crash")

View file

@ -275,7 +275,7 @@ class BIP68Test(BitcoinTestFramework):
cur_time = int(time.time()) cur_time = int(time.time())
for _ in range(10): for _ in range(10):
self.nodes[0].setmocktime(cur_time + 600) self.nodes[0].setmocktime(cur_time + 600)
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
cur_time += 600 cur_time += 600
assert tx2.hash in self.nodes[0].getrawmempool() assert tx2.hash in self.nodes[0].getrawmempool()
@ -351,7 +351,7 @@ class BIP68Test(BitcoinTestFramework):
# Reset the chain and get rid of the mocktimed-blocks # Reset the chain and get rid of the mocktimed-blocks
self.nodes[0].setmocktime(0) self.nodes[0].setmocktime(0)
self.nodes[0].invalidateblock(self.nodes[0].getblockhash(cur_height+1)) self.nodes[0].invalidateblock(self.nodes[0].getblockhash(cur_height+1))
self.generate(self.nodes[0], 10) self.generate(self.nodes[0], 10, sync_fun=self.no_op)
# Make sure that BIP68 isn't being used to validate blocks prior to # Make sure that BIP68 isn't being used to validate blocks prior to
# activation height. If more blocks are mined prior to this test # activation height. If more blocks are mined prior to this test
@ -405,9 +405,9 @@ class BIP68Test(BitcoinTestFramework):
min_activation_height = 432 min_activation_height = 432
height = self.nodes[0].getblockcount() height = self.nodes[0].getblockcount()
assert_greater_than(min_activation_height - height, 2) assert_greater_than(min_activation_height - height, 2)
self.generate(self.nodes[0], min_activation_height - height - 2) self.generate(self.nodes[0], min_activation_height - height - 2, sync_fun=self.no_op)
assert not softfork_active(self.nodes[0], 'csv') assert not softfork_active(self.nodes[0], 'csv')
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
assert softfork_active(self.nodes[0], 'csv') assert softfork_active(self.nodes[0], 'csv')
self.sync_blocks() self.sync_blocks()

View file

@ -228,7 +228,7 @@ class CoinStatsIndexTest(BitcoinTestFramework):
res9 = index_node.gettxoutsetinfo('muhash') res9 = index_node.gettxoutsetinfo('muhash')
assert_equal(res8, res9) assert_equal(res8, res9)
self.generate(index_node, 1) self.generate(index_node, 1, sync_fun=self.no_op)
res10 = index_node.gettxoutsetinfo('muhash') res10 = index_node.gettxoutsetinfo('muhash')
assert(res8['txouts'] < res10['txouts']) assert(res8['txouts'] < res10['txouts'])
@ -254,7 +254,7 @@ class CoinStatsIndexTest(BitcoinTestFramework):
assert_equal(index_node.gettxoutsetinfo('muhash')['height'], 110) assert_equal(index_node.gettxoutsetinfo('muhash')['height'], 110)
# Add two new blocks # Add two new blocks
block = self.generate(index_node, 2)[1] block = self.generate(index_node, 2, sync_fun=self.no_op)[1]
res = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False) res = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)
# Test that the result of the reorged block is not returned for its old block height # Test that the result of the reorged block is not returned for its old block height

View file

@ -217,7 +217,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
# Start by creating a lot of utxos on node3 # Start by creating a lot of utxos on node3
initial_height = self.nodes[3].getblockcount() initial_height = self.nodes[3].getblockcount()
utxo_list = create_confirmed_utxos(self, self.nodes[3].getnetworkinfo()['relayfee'], self.nodes[3], 5000) utxo_list = create_confirmed_utxos(self, self.nodes[3].getnetworkinfo()['relayfee'], self.nodes[3], 5000, sync_fun=self.no_op)
self.log.info(f"Prepped {len(utxo_list)} utxo entries") self.log.info(f"Prepped {len(utxo_list)} utxo entries")
# Sync these blocks with the other nodes # Sync these blocks with the other nodes
@ -258,6 +258,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
nblocks=min(10, current_height + 1 - self.nodes[3].getblockcount()), nblocks=min(10, current_height + 1 - self.nodes[3].getblockcount()),
# new address to avoid mining a block that has just been invalidated # new address to avoid mining a block that has just been invalidated
address=self.nodes[3].getnewaddress(), address=self.nodes[3].getnewaddress(),
sync_fun=self.no_op,
)) ))
self.log.debug(f"Syncing {len(block_hashes)} new blocks...") self.log.debug(f"Syncing {len(block_hashes)} new blocks...")
self.sync_node3blocks(block_hashes) self.sync_node3blocks(block_hashes)

View file

@ -237,7 +237,7 @@ class EstimateFeeTest(BitcoinTestFramework):
# Mine # Mine
while len(node.getrawmempool()) > 0: while len(node.getrawmempool()) > 0:
self.generate(node, 1) self.generate(node, 1, sync_fun=self.no_op)
# Repeatedly split those 2 outputs, doubling twice for each rep # Repeatedly split those 2 outputs, doubling twice for each rep
# Use txouts to monitor the available utxo, since these won't be tracked in wallet # Use txouts to monitor the available utxo, since these won't be tracked in wallet
@ -247,12 +247,12 @@ class EstimateFeeTest(BitcoinTestFramework):
while len(self.txouts) > 0: while len(self.txouts) > 0:
split_inputs(node, self.txouts, self.txouts2) split_inputs(node, self.txouts, self.txouts2)
while len(node.getrawmempool()) > 0: while len(node.getrawmempool()) > 0:
self.generate(node, 1) self.generate(node, 1, sync_fun=self.no_op)
# Double txouts2 to txouts # Double txouts2 to txouts
while len(self.txouts2) > 0: while len(self.txouts2) > 0:
split_inputs(node, self.txouts2, self.txouts) split_inputs(node, self.txouts2, self.txouts)
while len(node.getrawmempool()) > 0: while len(node.getrawmempool()) > 0:
self.generate(node, 1) self.generate(node, 1, sync_fun=self.no_op)
reps += 1 reps += 1
def sanity_check_estimates_range(self): def sanity_check_estimates_range(self):

View file

@ -29,7 +29,7 @@ class LoadblockTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.nodes[1].setnetworkactive(state=False) self.nodes[1].setnetworkactive(state=False)
self.generate(self.nodes[0], COINBASE_MATURITY) self.generate(self.nodes[0], COINBASE_MATURITY, sync_fun=self.no_op)
# Parsing the url of our node to get settings for config file # Parsing the url of our node to get settings for config file
data_dir = self.nodes[0].datadir data_dir = self.nodes[0].datadir

View file

@ -51,8 +51,7 @@ class MinimumChainWorkTest(BitcoinTestFramework):
num_blocks_to_generate = int((self.node_min_work[1] - starting_chain_work) / REGTEST_WORK_PER_BLOCK) num_blocks_to_generate = int((self.node_min_work[1] - starting_chain_work) / REGTEST_WORK_PER_BLOCK)
self.log.info(f"Generating {num_blocks_to_generate} blocks on node0") self.log.info(f"Generating {num_blocks_to_generate} blocks on node0")
hashes = self.generatetoaddress(self.nodes[0], num_blocks_to_generate, hashes = self.generate(self.nodes[0], num_blocks_to_generate, sync_fun=self.no_op)
self.nodes[0].get_deterministic_priv_key().address)
self.log.info(f"Node0 current chain work: {self.nodes[0].getblockheader(hashes[-1])['chainwork']}") self.log.info(f"Node0 current chain work: {self.nodes[0].getblockheader(hashes[-1])['chainwork']}")
@ -73,7 +72,7 @@ class MinimumChainWorkTest(BitcoinTestFramework):
assert_equal(self.nodes[2].getblockcount(), starting_blockcount) assert_equal(self.nodes[2].getblockcount(), starting_blockcount)
self.log.info("Generating one more block") self.log.info("Generating one more block")
self.generatetoaddress(self.nodes[0], 1, self.nodes[0].get_deterministic_priv_key().address) self.generate(self.nodes[0], 1)
self.log.info("Verifying nodes are all synced") self.log.info("Verifying nodes are all synced")

View file

@ -149,7 +149,7 @@ class NotificationsTest(BitcoinTestFramework):
# about newly confirmed bump2 and newly conflicted tx2. # about newly confirmed bump2 and newly conflicted tx2.
self.disconnect_nodes(0, 1) self.disconnect_nodes(0, 1)
bump2 = self.nodes[0].bumpfee(tx2)["txid"] bump2 = self.nodes[0].bumpfee(tx2)["txid"]
blockhash2 = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)[0] blockhash2 = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE, sync_fun=self.no_op)[0]
blockheight2 = self.nodes[0].getblockcount() blockheight2 = self.nodes[0].getblockcount()
assert_equal(self.nodes[0].gettransaction(bump2)["confirmations"], 1) assert_equal(self.nodes[0].gettransaction(bump2)["confirmations"], 1)
assert_equal(tx2 in self.nodes[1].getrawmempool(), True) assert_equal(tx2 in self.nodes[1].getrawmempool(), True)

View file

@ -118,9 +118,8 @@ class PruneTest(BitcoinTestFramework):
def create_big_chain(self): def create_big_chain(self):
# Start by creating some coinbases we can spend later # Start by creating some coinbases we can spend later
self.generate(self.nodes[1], 200) self.generate(self.nodes[1], 200, sync_fun=lambda: self.sync_blocks(self.nodes[0:2]))
self.sync_blocks(self.nodes[0:2]) self.generate(self.nodes[0], 150, sync_fun=self.no_op)
self.generate(self.nodes[0], 150)
# Then mine enough full blocks to create more than 550MiB of data # Then mine enough full blocks to create more than 550MiB of data
mine_large_blocks(self.nodes[0], 645) mine_large_blocks(self.nodes[0], 645)
@ -211,7 +210,7 @@ class PruneTest(BitcoinTestFramework):
self.disconnect_nodes(1, 2) self.disconnect_nodes(1, 2)
self.log.info("Generating new longer chain of 300 more blocks") self.log.info("Generating new longer chain of 300 more blocks")
self.generate(self.nodes[1], 300) self.generate(self.nodes[1], 300, sync_fun=self.no_op)
self.log.info("Reconnect nodes") self.log.info("Reconnect nodes")
self.connect_nodes(0, 1) self.connect_nodes(0, 1)
@ -263,7 +262,7 @@ class PruneTest(BitcoinTestFramework):
self.nodes[0].invalidateblock(curchainhash) self.nodes[0].invalidateblock(curchainhash)
assert_equal(self.nodes[0].getblockcount(), self.mainchainheight) assert_equal(self.nodes[0].getblockcount(), self.mainchainheight)
assert_equal(self.nodes[0].getbestblockhash(), self.mainchainhash2) assert_equal(self.nodes[0].getbestblockhash(), self.mainchainhash2)
goalbesthash = self.generate(self.nodes[0], blocks_to_mine)[-1] goalbesthash = self.generate(self.nodes[0], blocks_to_mine, sync_fun=self.no_op)[-1]
goalbestheight = first_reorg_height + 1 goalbestheight = first_reorg_height + 1
self.log.info("Verify node 2 reorged back to the main chain, some blocks of which it had to redownload") self.log.info("Verify node 2 reorged back to the main chain, some blocks of which it had to redownload")
@ -306,7 +305,7 @@ class PruneTest(BitcoinTestFramework):
assert_equal(block1_details["nTx"], len(block1_details["tx"])) assert_equal(block1_details["nTx"], len(block1_details["tx"]))
# mine 6 blocks so we are at height 1001 (i.e., above PruneAfterHeight) # mine 6 blocks so we are at height 1001 (i.e., above PruneAfterHeight)
self.generate(node, 6) self.generate(node, 6, sync_fun=self.no_op)
assert_equal(node.getblockchaininfo()["blocks"], 1001) assert_equal(node.getblockchaininfo()["blocks"], 1001)
# Pruned block should still know the number of transactions # Pruned block should still know the number of transactions
@ -337,7 +336,7 @@ class PruneTest(BitcoinTestFramework):
assert has_block(2), "blk00002.dat is still there, should be pruned by now" assert has_block(2), "blk00002.dat is still there, should be pruned by now"
# advance the tip so blk00002.dat and blk00003.dat can be pruned (the last 288 blocks should now be in blk00004.dat) # advance the tip so blk00002.dat and blk00003.dat can be pruned (the last 288 blocks should now be in blk00004.dat)
self.generate(node, 288) self.generate(node, 288, sync_fun=self.no_op)
prune(1000) prune(1000)
assert not has_block(2), "blk00002.dat is still there, should be pruned by now" assert not has_block(2), "blk00002.dat is still there, should be pruned by now"
assert not has_block(3), "blk00003.dat is still there, should be pruned by now" assert not has_block(3), "blk00003.dat is still there, should be pruned by now"

View file

@ -51,7 +51,7 @@ class SignetBasicTest(BitcoinTestFramework):
assert_equal(mining_info['networkhashps'], Decimal('0')) assert_equal(mining_info['networkhashps'], Decimal('0'))
assert_equal(mining_info['pooledtx'], 0) assert_equal(mining_info['pooledtx'], 0)
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.log.info("pregenerated signet blocks check") self.log.info("pregenerated signet blocks check")

View file

@ -82,9 +82,8 @@ class ZMQTestSetupBlock:
the generated block's hash, it's (coinbase) transaction id, the raw block or the generated block's hash, it's (coinbase) transaction id, the raw block or
raw transaction data. raw transaction data.
""" """
def __init__(self, test_framework, node): def __init__(self, test_framework, node):
self.block_hash = test_framework.generate(node, 1)[0] self.block_hash = test_framework.generate(node, 1, sync_fun=test_framework.no_op)[0]
coinbase = node.getblock(self.block_hash, 2)['tx'][0] coinbase = node.getblock(self.block_hash, 2)['tx'][0]
self.tx_hash = coinbase['txid'] self.tx_hash = coinbase['txid']
self.raw_tx = coinbase['hex'] self.raw_tx = coinbase['hex']
@ -261,14 +260,14 @@ class ZMQTest (BitcoinTestFramework):
# Generate 1 block in nodes[0] with 1 mempool tx and receive all notifications # Generate 1 block in nodes[0] with 1 mempool tx and receive all notifications
payment_txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1.0) payment_txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1.0)
disconnect_block = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)[0] disconnect_block = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE, sync_fun=self.no_op)[0]
disconnect_cb = self.nodes[0].getblock(disconnect_block)["tx"][0] disconnect_cb = self.nodes[0].getblock(disconnect_block)["tx"][0]
assert_equal(self.nodes[0].getbestblockhash(), hashblock.receive().hex()) assert_equal(self.nodes[0].getbestblockhash(), hashblock.receive().hex())
assert_equal(hashtx.receive().hex(), payment_txid) assert_equal(hashtx.receive().hex(), payment_txid)
assert_equal(hashtx.receive().hex(), disconnect_cb) assert_equal(hashtx.receive().hex(), disconnect_cb)
# Generate 2 blocks in nodes[1] to a different address to ensure split # Generate 2 blocks in nodes[1] to a different address to ensure split
connect_blocks = self.generatetoaddress(self.nodes[1], 2, ADDRESS_BCRT1_P2WSH_OP_TRUE) connect_blocks = self.generatetoaddress(self.nodes[1], 2, ADDRESS_BCRT1_P2WSH_OP_TRUE, sync_fun=self.no_op)
# nodes[0] will reorg chain after connecting back nodes[1] # nodes[0] will reorg chain after connecting back nodes[1]
self.connect_nodes(0, 1) self.connect_nodes(0, 1)
@ -312,13 +311,13 @@ class ZMQTest (BitcoinTestFramework):
seq_num = 1 seq_num = 1
# Generate 1 block in nodes[0] and receive all notifications # Generate 1 block in nodes[0] and receive all notifications
dc_block = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)[0] dc_block = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE, sync_fun=self.no_op)[0]
# Note: We are not notified of any block transactions, coinbase or mined # Note: We are not notified of any block transactions, coinbase or mined
assert_equal((self.nodes[0].getbestblockhash(), "C", None), seq.receive_sequence()) assert_equal((self.nodes[0].getbestblockhash(), "C", None), seq.receive_sequence())
# Generate 2 blocks in nodes[1] to a different address to ensure a chain split # Generate 2 blocks in nodes[1] to a different address to ensure a chain split
self.generatetoaddress(self.nodes[1], 2, ADDRESS_BCRT1_P2WSH_OP_TRUE) self.generatetoaddress(self.nodes[1], 2, ADDRESS_BCRT1_P2WSH_OP_TRUE, sync_fun=self.no_op)
# nodes[0] will reorg chain after connecting back nodes[1] # nodes[0] will reorg chain after connecting back nodes[1]
self.connect_nodes(0, 1) self.connect_nodes(0, 1)
@ -474,7 +473,7 @@ class ZMQTest (BitcoinTestFramework):
# 1) Consume backlog until we get a mempool sequence number # 1) Consume backlog until we get a mempool sequence number
(hash_str, label, zmq_mem_seq) = seq.receive_sequence() (hash_str, label, zmq_mem_seq) = seq.receive_sequence()
while zmq_mem_seq is None: while zmq_mem_seq is None:
(hash_str, label, zmq_mem_seq) = seq.receive_sequence() (hash_str, label, zmq_mem_seq) = seq.receive_sequence()
assert label == "A" or label == "R" assert label == "A" or label == "R"
assert hash_str is not None assert hash_str is not None
@ -566,7 +565,7 @@ class ZMQTest (BitcoinTestFramework):
], sync_blocks=False) ], sync_blocks=False)
# Generate 1 block in nodes[0] and receive all notifications # Generate 1 block in nodes[0] and receive all notifications
self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE) self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE, sync_fun=self.no_op)
# Should receive the same block hash on both subscribers # Should receive the same block hash on both subscribers
assert_equal(self.nodes[0].getbestblockhash(), subscribers[0].receive().hex()) assert_equal(self.nodes[0].getbestblockhash(), subscribers[0].receive().hex())

View file

@ -38,8 +38,8 @@ class MempoolCompatibilityTest(BitcoinTestFramework):
old_node, new_node = self.nodes old_node, new_node = self.nodes
new_wallet = MiniWallet(new_node) new_wallet = MiniWallet(new_node)
self.generate(new_wallet, 1) self.generate(new_wallet, 1, sync_fun=self.no_op)
self.generate(new_node, COINBASE_MATURITY) self.generate(new_node, COINBASE_MATURITY, sync_fun=self.no_op)
# Sync the nodes to ensure old_node has the block that contains the coinbase that new_wallet will spend. # Sync the nodes to ensure old_node has the block that contains the coinbase that new_wallet will spend.
# Otherwise, because coinbases are only valid in a block and not as loose txns, if the nodes aren't synced # Otherwise, because coinbases are only valid in a block and not as loose txns, if the nodes aren't synced
# unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`. # unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`.

View file

@ -174,7 +174,7 @@ class MempoolPersistTest(BitcoinTestFramework):
self.start_node(0) self.start_node(0)
# clear out mempool # clear out mempool
self.generate(node0, 1) self.generate(node0, 1, sync_fun=self.no_op)
# ensure node0 doesn't have any connections # ensure node0 doesn't have any connections
# make a transaction that will remain in the unbroadcast set # make a transaction that will remain in the unbroadcast set

View file

@ -79,9 +79,8 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
spend_3_1_id = self.nodes[0].sendrawtransaction(spend_3_1['hex']) spend_3_1_id = self.nodes[0].sendrawtransaction(spend_3_1['hex'])
self.log.info("Generate a block") self.log.info("Generate a block")
last_block = self.generate(self.nodes[0], 1) last_block = self.generate(self.nodes[0], 1)
# Sync blocks, so that peer 1 gets the block before timelock_tx # generate() implicitly syncs blocks, so that peer 1 gets the block before timelock_tx
# Otherwise, peer 1 would put the timelock_tx in m_recent_rejects # Otherwise, peer 1 would put the timelock_tx in m_recent_rejects
self.sync_all()
self.log.info("The time-locked transaction can now be spent") self.log.info("The time-locked transaction can now be spent")
timelock_tx_id = self.nodes[0].sendrawtransaction(timelock_tx) timelock_tx_id = self.nodes[0].sendrawtransaction(timelock_tx)

View file

@ -109,7 +109,8 @@ class MempoolUnbroadcastTest(BitcoinTestFramework):
# a block # a block
removal_reason = "Removed {} from set of unbroadcast txns before confirmation that txn was sent out".format(txhsh) removal_reason = "Removed {} from set of unbroadcast txns before confirmation that txn was sent out".format(txhsh)
with node.assert_debug_log([removal_reason]): with node.assert_debug_log([removal_reason]):
self.generate(node, 1) self.generate(node, 1, sync_fun=self.no_op)
if __name__ == "__main__": if __name__ == "__main__":
MempoolUnbroadcastTest().main() MempoolUnbroadcastTest().main()

View file

@ -58,7 +58,7 @@ class MiningTest(BitcoinTestFramework):
self.log.info('Create some old blocks') self.log.info('Create some old blocks')
for t in range(TIME_GENESIS_BLOCK, TIME_GENESIS_BLOCK + 200 * 600, 600): for t in range(TIME_GENESIS_BLOCK, TIME_GENESIS_BLOCK + 200 * 600, 600):
self.nodes[0].setmocktime(t) self.nodes[0].setmocktime(t)
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
mining_info = self.nodes[0].getmininginfo() mining_info = self.nodes[0].getmininginfo()
assert_equal(mining_info['blocks'], 200) assert_equal(mining_info['blocks'], 200)
assert_equal(mining_info['currentblocktx'], 0) assert_equal(mining_info['currentblocktx'], 0)

View file

@ -105,7 +105,7 @@ class PrioritiseTransactionTest(BitcoinTestFramework):
# the other high fee transactions. Keep mining until our mempool has # the other high fee transactions. Keep mining until our mempool has
# decreased by all the high fee size that we calculated above. # decreased by all the high fee size that we calculated above.
while (self.nodes[0].getmempoolinfo()['bytes'] > sizes[0] + sizes[1]): while (self.nodes[0].getmempoolinfo()['bytes'] > sizes[0] + sizes[1]):
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
# High fee transaction should not have been mined, but other high fee rate # High fee transaction should not have been mined, but other high fee rate
# transactions should have been. # transactions should have been.

View file

@ -62,11 +62,11 @@ class CompactFiltersTest(BitcoinTestFramework):
# Stale blocks by disconnecting nodes 0 & 1, mining, then reconnecting # Stale blocks by disconnecting nodes 0 & 1, mining, then reconnecting
self.disconnect_nodes(0, 1) self.disconnect_nodes(0, 1)
stale_block_hash = self.generate(self.nodes[0], 1)[0] stale_block_hash = self.generate(self.nodes[0], 1, sync_fun=self.no_op)[0]
self.nodes[0].syncwithvalidationinterfacequeue() self.nodes[0].syncwithvalidationinterfacequeue()
assert_equal(self.nodes[0].getblockcount(), 1000) assert_equal(self.nodes[0].getblockcount(), 1000)
self.generate(self.nodes[1], 1001) self.generate(self.nodes[1], 1001, sync_fun=self.no_op)
assert_equal(self.nodes[1].getblockcount(), 2000) assert_equal(self.nodes[1].getblockcount(), 2000)
# Check that nodes have signalled NODE_COMPACT_FILTERS correctly. # Check that nodes have signalled NODE_COMPACT_FILTERS correctly.

View file

@ -33,7 +33,7 @@ class P2PCompactBlocksBlocksOnly(BitcoinTestFramework):
self.sync_all() self.sync_all()
def build_block_on_tip(self): def build_block_on_tip(self):
blockhash = self.generate(self.nodes[2], 1)[0] blockhash = self.generate(self.nodes[2], 1, sync_fun=self.no_op)[0]
block_hex = self.nodes[2].getblock(blockhash=blockhash, verbosity=0) block_hex = self.nodes[2].getblock(blockhash=blockhash, verbosity=0)
block = from_hex(CBlock(), block_hex) block = from_hex(CBlock(), block_hex)
block.rehash() block.rehash()

View file

@ -59,7 +59,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.") self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
self.connect_nodes(0, 1) self.connect_nodes(0, 1)
blocks = self.generatetoaddress(self.nodes[1], 292, self.nodes[1].get_deterministic_priv_key().address) blocks = self.generate(self.nodes[1], 292, sync_fun=self.no_op)
self.sync_blocks([self.nodes[0], self.nodes[1]]) self.sync_blocks([self.nodes[0], self.nodes[1]])
self.log.info("Make sure we can max retrieve block at tip-288.") self.log.info("Make sure we can max retrieve block at tip-288.")
@ -101,7 +101,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
self.disconnect_all() self.disconnect_all()
# mine 10 blocks on node 0 (pruned node) # mine 10 blocks on node 0 (pruned node)
self.generatetoaddress(self.nodes[0], 10, self.nodes[0].get_deterministic_priv_key().address) self.generate(self.nodes[0], 10, sync_fun=self.no_op)
# connect node1 (non pruned) with node0 (pruned) and check if the can sync # connect node1 (non pruned) with node0 (pruned) and check if the can sync
self.connect_nodes(0, 1) self.connect_nodes(0, 1)

View file

@ -77,7 +77,7 @@ class AcceptBlockTest(BitcoinTestFramework):
min_work_node = self.nodes[1].add_p2p_connection(P2PInterface()) min_work_node = self.nodes[1].add_p2p_connection(P2PInterface())
# 1. Have nodes mine a block (leave IBD) # 1. Have nodes mine a block (leave IBD)
[self.generatetoaddress(n, 1, n.get_deterministic_priv_key().address) for n in self.nodes] [self.generate(n, 1, sync_fun=self.no_op) for n in self.nodes]
tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes] tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes]
# 2. Send one block that builds on each tip. # 2. Send one block that builds on each tip.

View file

@ -376,7 +376,7 @@ class BlockchainTest(BitcoinTestFramework):
self.log.debug('Node should not stop at this height') self.log.debug('Node should not stop at this height')
assert_raises(subprocess.TimeoutExpired, lambda: self.nodes[0].process.wait(timeout=3)) assert_raises(subprocess.TimeoutExpired, lambda: self.nodes[0].process.wait(timeout=3))
try: try:
self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_P2WSH_OP_TRUE) self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_P2WSH_OP_TRUE, sync_fun=self.no_op)
except (ConnectionError, http.client.BadStatusLine): except (ConnectionError, http.client.BadStatusLine):
pass # The node already shut down before response pass # The node already shut down before response
self.log.debug('Node should stop at this height...') self.log.debug('Node should stop at this height...')

View file

@ -1096,7 +1096,7 @@ class RawTransactionsTest(BitcoinTestFramework):
# than any single input available, and require more than 1 input. So we make 3 outputs # than any single input available, and require more than 1 input. So we make 3 outputs
for i in range(0, 3): for i in range(0, 3):
funds.sendtoaddress(tester.getnewaddress(address_type="bech32"), 1) funds.sendtoaddress(tester.getnewaddress(address_type="bech32"), 1)
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
# Create transactions in order to calculate fees for the target bounds that can trigger this bug # Create transactions in order to calculate fees for the target bounds that can trigger this bug
change_tx = tester.fundrawtransaction(tester.createrawtransaction([], [{funds.getnewaddress(): 1.5}])) change_tx = tester.fundrawtransaction(tester.createrawtransaction([], [{funds.getnewaddress(): 1.5}]))

View file

@ -21,8 +21,8 @@ class GetBlockFilterTest(BitcoinTestFramework):
# Create two chains by disconnecting nodes 0 & 1, mining, then reconnecting # Create two chains by disconnecting nodes 0 & 1, mining, then reconnecting
self.disconnect_nodes(0, 1) self.disconnect_nodes(0, 1)
self.generate(self.nodes[0], 3) self.generate(self.nodes[0], 3, sync_fun=self.no_op)
self.generate(self.nodes[1], 4) self.generate(self.nodes[1], 4, sync_fun=self.no_op)
assert_equal(self.nodes[0].getblockcount(), 3) assert_equal(self.nodes[0].getblockcount(), 3)
chain0_hashes = [self.nodes[0].getblockhash(block_height) for block_height in range(4)] chain0_hashes = [self.nodes[0].getblockhash(block_height) for block_height in range(4)]

View file

@ -26,10 +26,8 @@ class GetChainTipsTest (BitcoinTestFramework):
# Split the network and build two chains of different lengths. # Split the network and build two chains of different lengths.
self.split_network() self.split_network()
self.generatetoaddress(self.nodes[0], 10, self.nodes[0].get_deterministic_priv_key().address) self.generate(self.nodes[0], 10, sync_fun=lambda: self.sync_all(self.nodes[:2]))
self.generatetoaddress(self.nodes[2], 20, self.nodes[2].get_deterministic_priv_key().address) self.generate(self.nodes[2], 20, sync_fun=lambda: self.sync_all(self.nodes[2:]))
self.sync_all(self.nodes[:2])
self.sync_all(self.nodes[2:])
tips = self.nodes[1].getchaintips () tips = self.nodes[1].getchaintips ()
assert_equal (len (tips), 1) assert_equal (len (tips), 1)

View file

@ -22,12 +22,12 @@ class InvalidateTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.log.info("Make sure we repopulate setBlockIndexCandidates after InvalidateBlock:") self.log.info("Make sure we repopulate setBlockIndexCandidates after InvalidateBlock:")
self.log.info("Mine 4 blocks on Node 0") self.log.info("Mine 4 blocks on Node 0")
self.generatetoaddress(self.nodes[0], 4, self.nodes[0].get_deterministic_priv_key().address) self.generate(self.nodes[0], 4, sync_fun=self.no_op)
assert_equal(self.nodes[0].getblockcount(), 4) assert_equal(self.nodes[0].getblockcount(), 4)
besthash_n0 = self.nodes[0].getbestblockhash() besthash_n0 = self.nodes[0].getbestblockhash()
self.log.info("Mine competing 6 blocks on Node 1") self.log.info("Mine competing 6 blocks on Node 1")
self.generatetoaddress(self.nodes[1], 6, self.nodes[1].get_deterministic_priv_key().address) self.generate(self.nodes[1], 6, sync_fun=self.no_op)
assert_equal(self.nodes[1].getblockcount(), 6) assert_equal(self.nodes[1].getblockcount(), 6)
self.log.info("Connect nodes to force a reorg") self.log.info("Connect nodes to force a reorg")
@ -53,14 +53,14 @@ class InvalidateTest(BitcoinTestFramework):
self.nodes[2].invalidateblock(self.nodes[2].getblockhash(3)) self.nodes[2].invalidateblock(self.nodes[2].getblockhash(3))
assert_equal(self.nodes[2].getblockcount(), 2) assert_equal(self.nodes[2].getblockcount(), 2)
self.log.info("..and then mine a block") self.log.info("..and then mine a block")
self.generatetoaddress(self.nodes[2], 1, self.nodes[2].get_deterministic_priv_key().address) self.generate(self.nodes[2], 1, sync_fun=self.no_op)
self.log.info("Verify all nodes are at the right height") self.log.info("Verify all nodes are at the right height")
self.wait_until(lambda: self.nodes[2].getblockcount() == 3, timeout=5) self.wait_until(lambda: self.nodes[2].getblockcount() == 3, timeout=5)
self.wait_until(lambda: self.nodes[0].getblockcount() == 4, timeout=5) self.wait_until(lambda: self.nodes[0].getblockcount() == 4, timeout=5)
self.wait_until(lambda: self.nodes[1].getblockcount() == 4, timeout=5) self.wait_until(lambda: self.nodes[1].getblockcount() == 4, timeout=5)
self.log.info("Verify that we reconsider all ancestors as well") self.log.info("Verify that we reconsider all ancestors as well")
blocks = self.generatetodescriptor(self.nodes[1], 10, ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR) blocks = self.generatetodescriptor(self.nodes[1], 10, ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR, sync_fun=self.no_op)
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) assert_equal(self.nodes[1].getbestblockhash(), blocks[-1])
# Invalidate the two blocks at the tip # Invalidate the two blocks at the tip
self.nodes[1].invalidateblock(blocks[-1]) self.nodes[1].invalidateblock(blocks[-1])
@ -72,7 +72,7 @@ class InvalidateTest(BitcoinTestFramework):
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) assert_equal(self.nodes[1].getbestblockhash(), blocks[-1])
self.log.info("Verify that we reconsider all descendants") self.log.info("Verify that we reconsider all descendants")
blocks = self.generatetodescriptor(self.nodes[1], 10, ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR) blocks = self.generatetodescriptor(self.nodes[1], 10, ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR, sync_fun=self.no_op)
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) assert_equal(self.nodes[1].getbestblockhash(), blocks[-1])
# Invalidate the two blocks at the tip # Invalidate the two blocks at the tip
self.nodes[1].invalidateblock(blocks[-2]) self.nodes[1].invalidateblock(blocks[-2])

View file

@ -42,19 +42,18 @@ class PreciousTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.log.info("Ensure submitblock can in principle reorg to a competing chain") self.log.info("Ensure submitblock can in principle reorg to a competing chain")
gen_address = lambda i: self.nodes[i].get_deterministic_priv_key().address # A non-wallet address to mine to self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.generatetoaddress(self.nodes[0], 1, gen_address(0))
assert_equal(self.nodes[0].getblockcount(), 1) assert_equal(self.nodes[0].getblockcount(), 1)
hashZ = self.generatetoaddress(self.nodes[1], 2, gen_address(1))[-1] hashZ = self.generate(self.nodes[1], 2, sync_fun=self.no_op)[-1]
assert_equal(self.nodes[1].getblockcount(), 2) assert_equal(self.nodes[1].getblockcount(), 2)
node_sync_via_rpc(self.nodes[0:3]) node_sync_via_rpc(self.nodes[0:3])
assert_equal(self.nodes[0].getbestblockhash(), hashZ) assert_equal(self.nodes[0].getbestblockhash(), hashZ)
self.log.info("Mine blocks A-B-C on Node 0") self.log.info("Mine blocks A-B-C on Node 0")
hashC = self.generatetoaddress(self.nodes[0], 3, gen_address(0))[-1] hashC = self.generate(self.nodes[0], 3, sync_fun=self.no_op)[-1]
assert_equal(self.nodes[0].getblockcount(), 5) assert_equal(self.nodes[0].getblockcount(), 5)
self.log.info("Mine competing blocks E-F-G on Node 1") self.log.info("Mine competing blocks E-F-G on Node 1")
hashG = self.generatetoaddress(self.nodes[1], 3, gen_address(1))[-1] hashG = self.generate(self.nodes[1], 3, sync_fun=self.no_op)[-1]
assert_equal(self.nodes[1].getblockcount(), 5) assert_equal(self.nodes[1].getblockcount(), 5)
assert hashC != hashG assert hashC != hashG
self.log.info("Connect nodes and check no reorg occurs") self.log.info("Connect nodes and check no reorg occurs")
@ -83,7 +82,7 @@ class PreciousTest(BitcoinTestFramework):
self.nodes[1].preciousblock(hashC) self.nodes[1].preciousblock(hashC)
assert_equal(self.nodes[1].getbestblockhash(), hashC) assert_equal(self.nodes[1].getbestblockhash(), hashC)
self.log.info("Mine another block (E-F-G-)H on Node 0 and reorg Node 1") self.log.info("Mine another block (E-F-G-)H on Node 0 and reorg Node 1")
self.generatetoaddress(self.nodes[0], 1, gen_address(0)) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
assert_equal(self.nodes[0].getblockcount(), 6) assert_equal(self.nodes[0].getblockcount(), 6)
self.sync_blocks(self.nodes[0:2]) self.sync_blocks(self.nodes[0:2])
hashH = self.nodes[0].getbestblockhash() hashH = self.nodes[0].getbestblockhash()
@ -92,7 +91,7 @@ class PreciousTest(BitcoinTestFramework):
self.nodes[1].preciousblock(hashC) self.nodes[1].preciousblock(hashC)
assert_equal(self.nodes[1].getbestblockhash(), hashH) assert_equal(self.nodes[1].getbestblockhash(), hashH)
self.log.info("Mine competing blocks I-J-K-L on Node 2") self.log.info("Mine competing blocks I-J-K-L on Node 2")
self.generatetoaddress(self.nodes[2], 4, gen_address(2)) self.generate(self.nodes[2], 4, sync_fun=self.no_op)
assert_equal(self.nodes[2].getblockcount(), 6) assert_equal(self.nodes[2].getblockcount(), 6)
hashL = self.nodes[2].getbestblockhash() hashL = self.nodes[2].getbestblockhash()
self.log.info("Connect nodes and check no reorg occurs") self.log.info("Connect nodes and check no reorg occurs")

View file

@ -43,7 +43,6 @@ class MerkleBlockTest(BitcoinTestFramework):
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1)
blockhash = self.nodes[0].getblockhash(chain_height + 1) blockhash = self.nodes[0].getblockhash(chain_height + 1)
self.sync_all()
txlist = [] txlist = []
blocktxn = self.nodes[0].getblock(blockhash, True)["tx"] blocktxn = self.nodes[0].getblock(blockhash, True)["tx"]

View file

@ -413,7 +413,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
# To ensure that all nodes are out of IBD, the most recent block # To ensure that all nodes are out of IBD, the most recent block
# must have a timestamp not too old (see IsInitialBlockDownload()). # must have a timestamp not too old (see IsInitialBlockDownload()).
self.log.debug('Generate a block with current time') self.log.debug('Generate a block with current time')
block_hash = self.generate(self.nodes[0], 1)[0] block_hash = self.generate(self.nodes[0], 1, sync_fun=self.no_op)[0]
block = self.nodes[0].getblock(blockhash=block_hash, verbosity=0) block = self.nodes[0].getblock(blockhash=block_hash, verbosity=0)
for n in self.nodes: for n in self.nodes:
n.submitblock(block) n.submitblock(block)
@ -627,20 +627,27 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
self.connect_nodes(1, 2) self.connect_nodes(1, 2)
self.sync_all() self.sync_all()
def generate(self, generator, *args, **kwargs): def no_op(self):
pass
def generate(self, generator, *args, sync_fun=None, **kwargs):
blocks = generator.generate(*args, invalid_call=False, **kwargs) blocks = generator.generate(*args, invalid_call=False, **kwargs)
sync_fun() if sync_fun else self.sync_all()
return blocks return blocks
def generateblock(self, generator, *args, **kwargs): def generateblock(self, generator, *args, sync_fun=None, **kwargs):
blocks = generator.generateblock(*args, invalid_call=False, **kwargs) blocks = generator.generateblock(*args, invalid_call=False, **kwargs)
sync_fun() if sync_fun else self.sync_all()
return blocks return blocks
def generatetoaddress(self, generator, *args, **kwargs): def generatetoaddress(self, generator, *args, sync_fun=None, **kwargs):
blocks = generator.generatetoaddress(*args, invalid_call=False, **kwargs) blocks = generator.generatetoaddress(*args, invalid_call=False, **kwargs)
sync_fun() if sync_fun else self.sync_all()
return blocks return blocks
def generatetodescriptor(self, generator, *args, **kwargs): def generatetodescriptor(self, generator, *args, sync_fun=None, **kwargs):
blocks = generator.generatetodescriptor(*args, invalid_call=False, **kwargs) blocks = generator.generatetodescriptor(*args, invalid_call=False, **kwargs)
sync_fun() if sync_fun else self.sync_all()
return blocks return blocks
def sync_blocks(self, nodes=None, wait=1, timeout=60): def sync_blocks(self, nodes=None, wait=1, timeout=60):

View file

@ -451,10 +451,10 @@ def find_output(node, txid, amount, *, blockhash=None):
# Helper to create at least "count" utxos # Helper to create at least "count" utxos
# Pass in a fee that is sufficient for relay and mining new transactions. # Pass in a fee that is sufficient for relay and mining new transactions.
def create_confirmed_utxos(test_framework, fee, node, count): def create_confirmed_utxos(test_framework, fee, node, count, **kwargs):
to_generate = int(0.5 * count) + 101 to_generate = int(0.5 * count) + 101
while to_generate > 0: while to_generate > 0:
test_framework.generate(node, min(25, to_generate)) test_framework.generate(node, min(25, to_generate), **kwargs)
to_generate -= 25 to_generate -= 25
utxos = node.listunspent() utxos = node.listunspent()
iterations = count - len(utxos) iterations = count - len(utxos)
@ -475,7 +475,7 @@ def create_confirmed_utxos(test_framework, fee, node, count):
node.sendrawtransaction(signed_tx) node.sendrawtransaction(signed_tx)
while (node.getmempoolinfo()['size'] > 0): while (node.getmempoolinfo()['size'] > 0):
test_framework.generate(node, 1) test_framework.generate(node, 1, **kwargs)
utxos = node.listunspent() utxos = node.listunspent()
assert len(utxos) >= count assert len(utxos) >= count

View file

@ -43,7 +43,6 @@ class AbandonConflictTest(BitcoinTestFramework):
# Can not abandon confirmed transaction # Can not abandon confirmed transaction
assert_raises_rpc_error(-5, 'Transaction not eligible for abandonment', lambda: self.nodes[0].abandontransaction(txid=txA)) assert_raises_rpc_error(-5, 'Transaction not eligible for abandonment', lambda: self.nodes[0].abandontransaction(txid=txA))
self.sync_blocks()
newbalance = self.nodes[0].getbalance() newbalance = self.nodes[0].getbalance()
assert balance - newbalance < Decimal("0.001") #no more than fees lost assert balance - newbalance < Decimal("0.001") #no more than fees lost
balance = newbalance balance = newbalance
@ -167,7 +166,7 @@ class AbandonConflictTest(BitcoinTestFramework):
tx = self.nodes[0].createrawtransaction(inputs, outputs) tx = self.nodes[0].createrawtransaction(inputs, outputs)
signed = self.nodes[0].signrawtransactionwithwallet(tx) signed = self.nodes[0].signrawtransactionwithwallet(tx)
self.nodes[1].sendrawtransaction(signed["hex"]) self.nodes[1].sendrawtransaction(signed["hex"])
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=self.no_op)
self.connect_nodes(0, 1) self.connect_nodes(0, 1)
self.sync_blocks() self.sync_blocks()

View file

@ -265,7 +265,7 @@ class WalletTest(BitcoinTestFramework):
self.nodes[0].invalidateblock(block_reorg) self.nodes[0].invalidateblock(block_reorg)
self.nodes[1].invalidateblock(block_reorg) self.nodes[1].invalidateblock(block_reorg)
assert_equal(self.nodes[0].getbalance(minconf=0), 0) # wallet txs not in the mempool are untrusted assert_equal(self.nodes[0].getbalance(minconf=0), 0) # wallet txs not in the mempool are untrusted
self.generatetoaddress(self.nodes[0], 1, ADDRESS_WATCHONLY) self.generatetoaddress(self.nodes[0], 1, ADDRESS_WATCHONLY, sync_fun=self.no_op)
assert_equal(self.nodes[0].getbalance(minconf=0), 0) # wallet txs not in the mempool are untrusted assert_equal(self.nodes[0].getbalance(minconf=0), 0) # wallet txs not in the mempool are untrusted
# Now confirm tx_orig # Now confirm tx_orig

View file

@ -60,15 +60,14 @@ class WalletTest(BitcoinTestFramework):
self.log.info("Mining blocks...") self.log.info("Mining blocks...")
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
walletinfo = self.nodes[0].getwalletinfo() walletinfo = self.nodes[0].getwalletinfo()
assert_equal(walletinfo['immature_balance'], 50) assert_equal(walletinfo['immature_balance'], 50)
assert_equal(walletinfo['balance'], 0) assert_equal(walletinfo['balance'], 0)
self.sync_all(self.nodes[0:3]) self.sync_all(self.nodes[0:3])
self.generate(self.nodes[1], COINBASE_MATURITY + 1) self.generate(self.nodes[1], COINBASE_MATURITY + 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
assert_equal(self.nodes[0].getbalance(), 50) assert_equal(self.nodes[0].getbalance(), 50)
assert_equal(self.nodes[1].getbalance(), 50) assert_equal(self.nodes[1].getbalance(), 50)
@ -116,8 +115,7 @@ class WalletTest(BitcoinTestFramework):
assert_equal(walletinfo['immature_balance'], 0) assert_equal(walletinfo['immature_balance'], 0)
# Have node0 mine a block, thus it will collect its own fee. # Have node0 mine a block, thus it will collect its own fee.
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
# Exercise locking of unspent outputs # Exercise locking of unspent outputs
unspent_0 = self.nodes[2].listunspent()[0] unspent_0 = self.nodes[2].listunspent()[0]
@ -196,8 +194,7 @@ class WalletTest(BitcoinTestFramework):
assert_equal(len(self.nodes[1].listlockunspent()), 0) assert_equal(len(self.nodes[1].listlockunspent()), 0)
# Have node1 generate 100 blocks (so node0 can recover the fee) # Have node1 generate 100 blocks (so node0 can recover the fee)
self.generate(self.nodes[1], COINBASE_MATURITY) self.generate(self.nodes[1], COINBASE_MATURITY, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
# node0 should end up with 100 btc in block rewards plus fees, but # node0 should end up with 100 btc in block rewards plus fees, but
# minus the 21 plus fees sent to node2 # minus the 21 plus fees sent to node2
@ -225,8 +222,7 @@ class WalletTest(BitcoinTestFramework):
self.nodes[1].sendrawtransaction(hexstring=txns_to_send[1]["hex"], maxfeerate=0) self.nodes[1].sendrawtransaction(hexstring=txns_to_send[1]["hex"], maxfeerate=0)
# Have node1 mine a block to confirm transactions: # Have node1 mine a block to confirm transactions:
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
assert_equal(self.nodes[0].getbalance(), 0) assert_equal(self.nodes[0].getbalance(), 0)
assert_equal(self.nodes[2].getbalance(), 94) assert_equal(self.nodes[2].getbalance(), 94)
@ -240,15 +236,13 @@ class WalletTest(BitcoinTestFramework):
fee_per_byte = Decimal('0.001') / 1000 fee_per_byte = Decimal('0.001') / 1000
self.nodes[2].settxfee(fee_per_byte * 1000) self.nodes[2].settxfee(fee_per_byte * 1000)
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False) txid = self.nodes[2].sendtoaddress(address, 10, "", "", False)
self.generate(self.nodes[2], 1) self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])) node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(self.nodes[0].getbalance(), Decimal('10')) assert_equal(self.nodes[0].getbalance(), Decimal('10'))
# Send 10 BTC with subtract fee from amount # Send 10 BTC with subtract fee from amount
txid = self.nodes[2].sendtoaddress(address, 10, "", "", True) txid = self.nodes[2].sendtoaddress(address, 10, "", "", True)
self.generate(self.nodes[2], 1) self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
node_2_bal -= Decimal('10') node_2_bal -= Decimal('10')
assert_equal(self.nodes[2].getbalance(), node_2_bal) assert_equal(self.nodes[2].getbalance(), node_2_bal)
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])) node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
@ -257,16 +251,14 @@ class WalletTest(BitcoinTestFramework):
# Sendmany 10 BTC # Sendmany 10 BTC
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", []) txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [])
self.generate(self.nodes[2], 1) self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
node_0_bal += Decimal('10') node_0_bal += Decimal('10')
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])) node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(self.nodes[0].getbalance(), node_0_bal) assert_equal(self.nodes[0].getbalance(), node_0_bal)
# Sendmany 10 BTC with subtract fee from amount # Sendmany 10 BTC with subtract fee from amount
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [address]) txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [address])
self.generate(self.nodes[2], 1) self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
node_2_bal -= Decimal('10') node_2_bal -= Decimal('10')
assert_equal(self.nodes[2].getbalance(), node_2_bal) assert_equal(self.nodes[2].getbalance(), node_2_bal)
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])) node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
@ -278,8 +270,7 @@ class WalletTest(BitcoinTestFramework):
# Test passing fee_rate as a string # Test passing fee_rate as a string
txid = self.nodes[2].sendmany(amounts={address: 10}, fee_rate=str(fee_rate_sat_vb)) txid = self.nodes[2].sendmany(amounts={address: 10}, fee_rate=str(fee_rate_sat_vb))
self.generate(self.nodes[2], 1) self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
balance = self.nodes[2].getbalance() balance = self.nodes[2].getbalance()
node_2_bal = self.check_fee_amount(balance, node_2_bal - Decimal('10'), explicit_fee_rate_btc_kvb, self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])) node_2_bal = self.check_fee_amount(balance, node_2_bal - Decimal('10'), explicit_fee_rate_btc_kvb, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(balance, node_2_bal) assert_equal(balance, node_2_bal)
@ -289,8 +280,7 @@ class WalletTest(BitcoinTestFramework):
# Test passing fee_rate as an integer # Test passing fee_rate as an integer
amount = Decimal("0.0001") amount = Decimal("0.0001")
txid = self.nodes[2].sendmany(amounts={address: amount}, fee_rate=fee_rate_sat_vb) txid = self.nodes[2].sendmany(amounts={address: amount}, fee_rate=fee_rate_sat_vb)
self.generate(self.nodes[2], 1) self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
balance = self.nodes[2].getbalance() balance = self.nodes[2].getbalance()
node_2_bal = self.check_fee_amount(balance, node_2_bal - amount, explicit_fee_rate_btc_kvb, self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])) node_2_bal = self.check_fee_amount(balance, node_2_bal - amount, explicit_fee_rate_btc_kvb, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(balance, node_2_bal) assert_equal(balance, node_2_bal)
@ -374,14 +364,12 @@ class WalletTest(BitcoinTestFramework):
txid_not_broadcast = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2) txid_not_broadcast = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2)
tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast) tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast)
self.generate(self.nodes[1], 1) # mine a block, tx should not be in there self.generate(self.nodes[1], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3])) # mine a block, tx should not be in there
self.sync_all(self.nodes[0:3])
assert_equal(self.nodes[2].getbalance(), node_2_bal) # should not be changed because tx was not broadcasted assert_equal(self.nodes[2].getbalance(), node_2_bal) # should not be changed because tx was not broadcasted
# now broadcast from another node, mine a block, sync, and check the balance # now broadcast from another node, mine a block, sync, and check the balance
self.nodes[1].sendrawtransaction(tx_obj_not_broadcast['hex']) self.nodes[1].sendrawtransaction(tx_obj_not_broadcast['hex'])
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
node_2_bal += 2 node_2_bal += 2
tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast) tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast)
assert_equal(self.nodes[2].getbalance(), node_2_bal) assert_equal(self.nodes[2].getbalance(), node_2_bal)
@ -399,8 +387,7 @@ class WalletTest(BitcoinTestFramework):
self.connect_nodes(0, 2) self.connect_nodes(0, 2)
self.sync_blocks(self.nodes[0:3]) self.sync_blocks(self.nodes[0:3])
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:3]))
self.sync_blocks(self.nodes[0:3])
node_2_bal += 2 node_2_bal += 2
# tx should be added to balance because after restarting the nodes tx should be broadcast # tx should be added to balance because after restarting the nodes tx should be broadcast
@ -467,8 +454,7 @@ class WalletTest(BitcoinTestFramework):
self.sync_mempools(self.nodes[0:3]) self.sync_mempools(self.nodes[0:3])
vout = find_vout_for_address(self.nodes[2], txid, address_to_import) vout = find_vout_for_address(self.nodes[2], txid, address_to_import)
self.nodes[2].lockunspent(False, [{"txid": txid, "vout": vout}]) self.nodes[2].lockunspent(False, [{"txid": txid, "vout": vout}])
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
self.log.info("Test sendtoaddress with fee_rate param (explicit fee rate in sat/vB)") self.log.info("Test sendtoaddress with fee_rate param (explicit fee rate in sat/vB)")
prebalance = self.nodes[2].getbalance() prebalance = self.nodes[2].getbalance()
@ -480,8 +466,7 @@ class WalletTest(BitcoinTestFramework):
# Test passing fee_rate as an integer # Test passing fee_rate as an integer
txid = self.nodes[2].sendtoaddress(address=address, amount=amount, fee_rate=fee_rate_sat_vb) txid = self.nodes[2].sendtoaddress(address=address, amount=amount, fee_rate=fee_rate_sat_vb)
tx_size = self.get_vsize(self.nodes[2].gettransaction(txid)['hex']) tx_size = self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
postbalance = self.nodes[2].getbalance() postbalance = self.nodes[2].getbalance()
fee = prebalance - postbalance - Decimal(amount) fee = prebalance - postbalance - Decimal(amount)
assert_fee_amount(fee, tx_size, Decimal(fee_rate_btc_kvb)) assert_fee_amount(fee, tx_size, Decimal(fee_rate_btc_kvb))
@ -493,8 +478,7 @@ class WalletTest(BitcoinTestFramework):
# Test passing fee_rate as a string # Test passing fee_rate as a string
txid = self.nodes[2].sendtoaddress(address=address, amount=amount, fee_rate=str(fee_rate_sat_vb)) txid = self.nodes[2].sendtoaddress(address=address, amount=amount, fee_rate=str(fee_rate_sat_vb))
tx_size = self.get_vsize(self.nodes[2].gettransaction(txid)['hex']) tx_size = self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
postbalance = self.nodes[2].getbalance() postbalance = self.nodes[2].getbalance()
fee = prebalance - postbalance - amount fee = prebalance - postbalance - amount
assert_fee_amount(fee, tx_size, Decimal(fee_rate_btc_kvb)) assert_fee_amount(fee, tx_size, Decimal(fee_rate_btc_kvb))
@ -555,17 +539,15 @@ class WalletTest(BitcoinTestFramework):
# Mine a block from node0 to an address from node1 # Mine a block from node0 to an address from node1
coinbase_addr = self.nodes[1].getnewaddress() coinbase_addr = self.nodes[1].getnewaddress()
block_hash = self.generatetoaddress(self.nodes[0], 1, coinbase_addr)[0] block_hash = self.generatetoaddress(self.nodes[0], 1, coinbase_addr, sync_fun=lambda: self.sync_all(self.nodes[0:3]))[0]
coinbase_txid = self.nodes[0].getblock(block_hash)['tx'][0] coinbase_txid = self.nodes[0].getblock(block_hash)['tx'][0]
self.sync_all(self.nodes[0:3])
# Check that the txid and balance is found by node1 # Check that the txid and balance is found by node1
self.nodes[1].gettransaction(coinbase_txid) self.nodes[1].gettransaction(coinbase_txid)
# check if wallet or blockchain maintenance changes the balance # check if wallet or blockchain maintenance changes the balance
self.sync_all(self.nodes[0:3]) self.sync_all(self.nodes[0:3])
blocks = self.generate(self.nodes[0], 2) blocks = self.generate(self.nodes[0], 2, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
self.sync_all(self.nodes[0:3])
balance_nodes = [self.nodes[i].getbalance() for i in range(3)] balance_nodes = [self.nodes[i].getbalance() for i in range(3)]
block_count = self.nodes[0].getblockcount() block_count = self.nodes[0].getblockcount()
@ -606,13 +588,13 @@ class WalletTest(BitcoinTestFramework):
# Get all non-zero utxos together # Get all non-zero utxos together
chain_addrs = [self.nodes[0].getnewaddress(), self.nodes[0].getnewaddress()] chain_addrs = [self.nodes[0].getnewaddress(), self.nodes[0].getnewaddress()]
singletxid = self.nodes[0].sendtoaddress(chain_addrs[0], self.nodes[0].getbalance(), "", "", True) singletxid = self.nodes[0].sendtoaddress(chain_addrs[0], self.nodes[0].getbalance(), "", "", True)
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
node0_balance = self.nodes[0].getbalance() node0_balance = self.nodes[0].getbalance()
# Split into two chains # Split into two chains
rawtx = self.nodes[0].createrawtransaction([{"txid": singletxid, "vout": 0}], {chain_addrs[0]: node0_balance / 2 - Decimal('0.01'), chain_addrs[1]: node0_balance / 2 - Decimal('0.01')}) rawtx = self.nodes[0].createrawtransaction([{"txid": singletxid, "vout": 0}], {chain_addrs[0]: node0_balance / 2 - Decimal('0.01'), chain_addrs[1]: node0_balance / 2 - Decimal('0.01')})
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx) signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
singletxid = self.nodes[0].sendrawtransaction(hexstring=signedtx["hex"], maxfeerate=0) singletxid = self.nodes[0].sendrawtransaction(hexstring=signedtx["hex"], maxfeerate=0)
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
# Make a long chain of unconfirmed payments without hitting mempool limit # Make a long chain of unconfirmed payments without hitting mempool limit
# Each tx we make leaves only one output of change on a chain 1 longer # Each tx we make leaves only one output of change on a chain 1 longer
@ -663,7 +645,7 @@ class WalletTest(BitcoinTestFramework):
assert not address_info["ischange"] assert not address_info["ischange"]
# Test getaddressinfo 'ischange' field on change address. # Test getaddressinfo 'ischange' field on change address.
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
destination = self.nodes[1].getnewaddress() destination = self.nodes[1].getnewaddress()
txid = self.nodes[0].sendtoaddress(destination, 0.123) txid = self.nodes[0].sendtoaddress(destination, 0.123)
tx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded'] tx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']

View file

@ -529,7 +529,7 @@ def test_unconfirmed_not_spendable(self, rbf_node, rbf_node_address):
assert_equal([t for t in rbf_node.listunspent(minconf=0, include_unsafe=False) if t["txid"] == rbfid], []) assert_equal([t for t in rbf_node.listunspent(minconf=0, include_unsafe=False) if t["txid"] == rbfid], [])
# check that the main output from the rbf tx is spendable after confirmed # check that the main output from the rbf tx is spendable after confirmed
self.generate(rbf_node, 1) self.generate(rbf_node, 1, sync_fun=self.no_op)
assert_equal( assert_equal(
sum(1 for t in rbf_node.listunspent(minconf=0, include_unsafe=False) sum(1 for t in rbf_node.listunspent(minconf=0, include_unsafe=False)
if t["txid"] == rbfid and t["address"] == rbf_node_address and t["spendable"]), 1) if t["txid"] == rbfid and t["address"] == rbf_node_address and t["spendable"]), 1)

View file

@ -181,7 +181,6 @@ class ImportRescanTest(BitcoinTestFramework):
self.generate(self.nodes[0], 1) # Generate one block for each send self.generate(self.nodes[0], 1) # Generate one block for each send
variant.confirmation_height = self.nodes[0].getblockcount() variant.confirmation_height = self.nodes[0].getblockcount()
variant.timestamp = self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())["time"] variant.timestamp = self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())["time"]
self.sync_all() # Conclude sync before calling setmocktime to avoid timeouts
# Generate a block further in the future (past the rescan window). # Generate a block further in the future (past the rescan window).
assert_equal(self.nodes[0].getrawmempool(), []) assert_equal(self.nodes[0].getrawmempool(), [])

View file

@ -62,8 +62,8 @@ class ImportMultiTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.log.info("Mining blocks...") self.log.info("Mining blocks...")
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=self.no_op)
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
self.nodes[1].syncwithvalidationinterfacequeue() # Sync the timestamp to the wallet, so that importmulti works self.nodes[1].syncwithvalidationinterfacequeue() # Sync the timestamp to the wallet, so that importmulti works
@ -256,9 +256,9 @@ class ImportMultiTest(BitcoinTestFramework):
# P2SH address # P2SH address
multisig = get_multisig(self.nodes[0]) multisig = get_multisig(self.nodes[0])
self.generate(self.nodes[1], COINBASE_MATURITY) self.generate(self.nodes[1], COINBASE_MATURITY, sync_fun=self.no_op)
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00) self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=self.no_op)
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
self.nodes[1].syncwithvalidationinterfacequeue() self.nodes[1].syncwithvalidationinterfacequeue()
@ -277,9 +277,9 @@ class ImportMultiTest(BitcoinTestFramework):
# P2SH + Redeem script # P2SH + Redeem script
multisig = get_multisig(self.nodes[0]) multisig = get_multisig(self.nodes[0])
self.generate(self.nodes[1], COINBASE_MATURITY) self.generate(self.nodes[1], COINBASE_MATURITY, sync_fun=self.no_op)
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00) self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=self.no_op)
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
self.nodes[1].syncwithvalidationinterfacequeue() self.nodes[1].syncwithvalidationinterfacequeue()
@ -298,9 +298,9 @@ class ImportMultiTest(BitcoinTestFramework):
# P2SH + Redeem script + Private Keys + !Watchonly # P2SH + Redeem script + Private Keys + !Watchonly
multisig = get_multisig(self.nodes[0]) multisig = get_multisig(self.nodes[0])
self.generate(self.nodes[1], COINBASE_MATURITY) self.generate(self.nodes[1], COINBASE_MATURITY, sync_fun=self.no_op)
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00) self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=self.no_op)
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
self.nodes[1].syncwithvalidationinterfacequeue() self.nodes[1].syncwithvalidationinterfacequeue()
@ -324,9 +324,9 @@ class ImportMultiTest(BitcoinTestFramework):
# P2SH + Redeem script + Private Keys + Watchonly # P2SH + Redeem script + Private Keys + Watchonly
multisig = get_multisig(self.nodes[0]) multisig = get_multisig(self.nodes[0])
self.generate(self.nodes[1], COINBASE_MATURITY) self.generate(self.nodes[1], COINBASE_MATURITY, sync_fun=self.no_op)
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00) self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=self.no_op)
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime'] timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
self.nodes[1].syncwithvalidationinterfacequeue() self.nodes[1].syncwithvalidationinterfacequeue()

View file

@ -54,7 +54,6 @@ class ListSinceBlockTest(BitcoinTestFramework):
blockhash, = self.generate(self.nodes[2], 1) blockhash, = self.generate(self.nodes[2], 1)
blockheight = self.nodes[2].getblockheader(blockhash)['height'] blockheight = self.nodes[2].getblockheader(blockhash)['height']
self.sync_all()
txs = self.nodes[0].listtransactions() txs = self.nodes[0].listtransactions()
assert_array_result(txs, {"txid": txid}, { assert_array_result(txs, {"txid": txid}, {
@ -99,7 +98,6 @@ class ListSinceBlockTest(BitcoinTestFramework):
self.log.info("Test target_confirmations") self.log.info("Test target_confirmations")
blockhash, = self.generate(self.nodes[2], 1) blockhash, = self.generate(self.nodes[2], 1)
blockheight = self.nodes[2].getblockheader(blockhash)['height'] blockheight = self.nodes[2].getblockheader(blockhash)['height']
self.sync_all()
assert_equal( assert_equal(
self.nodes[0].getblockhash(0), self.nodes[0].getblockhash(0),
@ -147,14 +145,11 @@ class ListSinceBlockTest(BitcoinTestFramework):
senttx = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 1) senttx = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 1)
# generate on both sides # generate on both sides
nodes1_last_blockhash = self.generate(self.nodes[1], 6)[-1] nodes1_last_blockhash = self.generate(self.nodes[1], 6, sync_fun=lambda: self.sync_all(self.nodes[:2]))[-1]
nodes2_first_blockhash = self.generate(self.nodes[2], 7)[0] nodes2_first_blockhash = self.generate(self.nodes[2], 7, sync_fun=lambda: self.sync_all(self.nodes[2:]))[0]
self.log.debug("nodes[1] last blockhash = {}".format(nodes1_last_blockhash)) self.log.debug("nodes[1] last blockhash = {}".format(nodes1_last_blockhash))
self.log.debug("nodes[2] first blockhash = {}".format(nodes2_first_blockhash)) self.log.debug("nodes[2] first blockhash = {}".format(nodes2_first_blockhash))
self.sync_all(self.nodes[:2])
self.sync_all(self.nodes[2:])
self.join_network() self.join_network()
# listsinceblock(nodes1_last_blockhash) should now include tx as seen from nodes[0] # listsinceblock(nodes1_last_blockhash) should now include tx as seen from nodes[0]
@ -236,8 +231,8 @@ class ListSinceBlockTest(BitcoinTestFramework):
self.nodes[2].createrawtransaction(utxo_dicts, recipient_dict2))['hex']) self.nodes[2].createrawtransaction(utxo_dicts, recipient_dict2))['hex'])
# generate on both sides # generate on both sides
lastblockhash = self.generate(self.nodes[1], 3)[2] lastblockhash = self.generate(self.nodes[1], 3, sync_fun=self.no_op)[2]
self.generate(self.nodes[2], 4) self.generate(self.nodes[2], 4, sync_fun=self.no_op)
self.join_network() self.join_network()
@ -308,7 +303,7 @@ class ListSinceBlockTest(BitcoinTestFramework):
txid1 = self.nodes[1].sendrawtransaction(signedtx) txid1 = self.nodes[1].sendrawtransaction(signedtx)
# generate bb1-bb2 on right side # generate bb1-bb2 on right side
self.generate(self.nodes[2], 2) self.generate(self.nodes[2], 2, sync_fun=self.no_op)
# send from nodes[2]; this will end up in bb3 # send from nodes[2]; this will end up in bb3
txid2 = self.nodes[2].sendrawtransaction(signedtx) txid2 = self.nodes[2].sendrawtransaction(signedtx)
@ -316,8 +311,8 @@ class ListSinceBlockTest(BitcoinTestFramework):
assert_equal(txid1, txid2) assert_equal(txid1, txid2)
# generate on both sides # generate on both sides
lastblockhash = self.generate(self.nodes[1], 3)[2] lastblockhash = self.generate(self.nodes[1], 3, sync_fun=self.no_op)[2]
self.generate(self.nodes[2], 2) self.generate(self.nodes[2], 2, sync_fun=self.no_op)
self.join_network() self.join_network()

View file

@ -38,7 +38,6 @@ class ListTransactionsTest(BitcoinTestFramework):
self.log.info("Test confirmations change after mining a block") self.log.info("Test confirmations change after mining a block")
blockhash = self.generate(self.nodes[0], 1)[0] blockhash = self.generate(self.nodes[0], 1)[0]
blockheight = self.nodes[0].getblockheader(blockhash)['height'] blockheight = self.nodes[0].getblockheader(blockhash)['height']
self.sync_all()
assert_array_result(self.nodes[0].listtransactions(), assert_array_result(self.nodes[0].listtransactions(),
{"txid": txid}, {"txid": txid},
{"category": "send", "amount": Decimal("-0.1"), "confirmations": 1, "blockhash": blockhash, "blockheight": blockheight}) {"category": "send", "amount": Decimal("-0.1"), "confirmations": 1, "blockhash": blockhash, "blockheight": blockheight})

View file

@ -185,7 +185,7 @@ class MultiWalletTest(BitcoinTestFramework):
self.nodes[0].createwallet("w5") self.nodes[0].createwallet("w5")
assert_equal(set(node.listwallets()), {"w4", "w5"}) assert_equal(set(node.listwallets()), {"w4", "w5"})
w5 = wallet("w5") w5 = wallet("w5")
self.generatetoaddress(node, nblocks=1, address=w5.getnewaddress()) self.generatetoaddress(node, nblocks=1, address=w5.getnewaddress(), sync_fun=self.no_op)
# now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded # now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded
os.rename(wallet_dir2, wallet_dir()) os.rename(wallet_dir2, wallet_dir())
@ -217,7 +217,7 @@ class MultiWalletTest(BitcoinTestFramework):
wallet_bad = wallet("bad") wallet_bad = wallet("bad")
# check wallet names and balances # check wallet names and balances
self.generatetoaddress(node, nblocks=1, address=wallets[0].getnewaddress()) self.generatetoaddress(node, nblocks=1, address=wallets[0].getnewaddress(), sync_fun=self.no_op)
for wallet_name, wallet in zip(wallet_names, wallets): for wallet_name, wallet in zip(wallet_names, wallets):
info = wallet.getwalletinfo() info = wallet.getwalletinfo()
assert_equal(info['immature_balance'], 50 if wallet is wallets[0] else 0) assert_equal(info['immature_balance'], 50 if wallet is wallets[0] else 0)
@ -230,7 +230,7 @@ class MultiWalletTest(BitcoinTestFramework):
assert_raises_rpc_error(-19, "Wallet file not specified", node.getwalletinfo) assert_raises_rpc_error(-19, "Wallet file not specified", node.getwalletinfo)
w1, w2, w3, w4, *_ = wallets w1, w2, w3, w4, *_ = wallets
self.generatetoaddress(node, nblocks=COINBASE_MATURITY + 1, address=w1.getnewaddress()) self.generatetoaddress(node, nblocks=COINBASE_MATURITY + 1, address=w1.getnewaddress(), sync_fun=self.no_op)
assert_equal(w1.getbalance(), 100) assert_equal(w1.getbalance(), 100)
assert_equal(w2.getbalance(), 0) assert_equal(w2.getbalance(), 0)
assert_equal(w3.getbalance(), 0) assert_equal(w3.getbalance(), 0)
@ -239,7 +239,7 @@ class MultiWalletTest(BitcoinTestFramework):
w1.sendtoaddress(w2.getnewaddress(), 1) w1.sendtoaddress(w2.getnewaddress(), 1)
w1.sendtoaddress(w3.getnewaddress(), 2) w1.sendtoaddress(w3.getnewaddress(), 2)
w1.sendtoaddress(w4.getnewaddress(), 3) w1.sendtoaddress(w4.getnewaddress(), 3)
self.generatetoaddress(node, nblocks=1, address=w1.getnewaddress()) self.generatetoaddress(node, nblocks=1, address=w1.getnewaddress(), sync_fun=self.no_op)
assert_equal(w2.getbalance(), 1) assert_equal(w2.getbalance(), 1)
assert_equal(w3.getbalance(), 2) assert_equal(w3.getbalance(), 2)
assert_equal(w4.getbalance(), 3) assert_equal(w4.getbalance(), 3)

View file

@ -43,7 +43,7 @@ class ReorgsRestoreTest(BitcoinTestFramework):
# Send a tx to be unconfirmed later # Send a tx to be unconfirmed later
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10")) txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10"))
tx = self.nodes[0].gettransaction(txid) tx = self.nodes[0].gettransaction(txid)
self.generate(self.nodes[0], 4) self.generate(self.nodes[0], 4, sync_fun=self.no_op)
tx_before_reorg = self.nodes[0].gettransaction(txid) tx_before_reorg = self.nodes[0].gettransaction(txid)
assert_equal(tx_before_reorg["confirmations"], 4) assert_equal(tx_before_reorg["confirmations"], 4)
@ -62,9 +62,9 @@ class ReorgsRestoreTest(BitcoinTestFramework):
conflicting = self.nodes[0].signrawtransactionwithwallet(self.nodes[0].createrawtransaction(inputs, outputs_2)) conflicting = self.nodes[0].signrawtransactionwithwallet(self.nodes[0].createrawtransaction(inputs, outputs_2))
conflicted_txid = self.nodes[0].sendrawtransaction(conflicted["hex"]) conflicted_txid = self.nodes[0].sendrawtransaction(conflicted["hex"])
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=self.no_op)
conflicting_txid = self.nodes[2].sendrawtransaction(conflicting["hex"]) conflicting_txid = self.nodes[2].sendrawtransaction(conflicting["hex"])
self.generate(self.nodes[2], 9) self.generate(self.nodes[2], 9, sync_fun=self.no_op)
# Reconnect node0 and node2 and check that conflicted_txid is effectively conflicted # Reconnect node0 and node2 and check that conflicted_txid is effectively conflicted
self.connect_nodes(0, 2) self.connect_nodes(0, 2)
@ -78,11 +78,11 @@ class ReorgsRestoreTest(BitcoinTestFramework):
self.restart_node(0) self.restart_node(0)
# The block chain re-orgs and the tx is included in a different block # The block chain re-orgs and the tx is included in a different block
self.generate(self.nodes[1], 9) self.generate(self.nodes[1], 9, sync_fun=self.no_op)
self.nodes[1].sendrawtransaction(tx["hex"]) self.nodes[1].sendrawtransaction(tx["hex"])
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=self.no_op)
self.nodes[1].sendrawtransaction(conflicted["hex"]) self.nodes[1].sendrawtransaction(conflicted["hex"])
self.generate(self.nodes[1], 1) self.generate(self.nodes[1], 1, sync_fun=self.no_op)
# Node0 wallet file is loaded on longest sync'ed node1 # Node0 wallet file is loaded on longest sync'ed node1
self.stop_node(1) self.stop_node(1)

View file

@ -448,7 +448,6 @@ class WalletSendTest(BitcoinTestFramework):
res = self.nodes[0].sendrawtransaction(hex) res = self.nodes[0].sendrawtransaction(hex)
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1)
assert_equal(self.nodes[0].gettransaction(txid)["confirmations"], 1) assert_equal(self.nodes[0].gettransaction(txid)["confirmations"], 1)
self.sync_all()
self.log.info("Lock unspents...") self.log.info("Lock unspents...")
utxo1 = w0.listunspent()[0] utxo1 = w0.listunspent()[0]

View file

@ -272,11 +272,11 @@ class WalletTaprootTest(BitcoinTestFramework):
boring_balance = int(self.boring.getbalance() * 100000000) boring_balance = int(self.boring.getbalance() * 100000000)
to_amnt = random.randrange(1000000, boring_balance) to_amnt = random.randrange(1000000, boring_balance)
self.boring.sendtoaddress(address=addr_g, amount=Decimal(to_amnt) / 100000000, subtractfeefromamount=True) self.boring.sendtoaddress(address=addr_g, amount=Decimal(to_amnt) / 100000000, subtractfeefromamount=True)
self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress()) self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress(), sync_fun=self.no_op)
test_balance = int(self.rpc_online.getbalance() * 100000000) test_balance = int(self.rpc_online.getbalance() * 100000000)
ret_amnt = random.randrange(100000, test_balance) ret_amnt = random.randrange(100000, test_balance)
res = self.rpc_online.sendtoaddress(address=self.boring.getnewaddress(), amount=Decimal(ret_amnt) / 100000000, subtractfeefromamount=True) res = self.rpc_online.sendtoaddress(address=self.boring.getnewaddress(), amount=Decimal(ret_amnt) / 100000000, subtractfeefromamount=True)
self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress()) self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress(), sync_fun=self.no_op)
assert(self.rpc_online.gettransaction(res)["confirmations"] > 0) assert(self.rpc_online.gettransaction(res)["confirmations"] > 0)
def do_test_psbt(self, comment, pattern, privmap, treefn, keys_pay, keys_change): def do_test_psbt(self, comment, pattern, privmap, treefn, keys_pay, keys_change):
@ -303,7 +303,7 @@ class WalletTaprootTest(BitcoinTestFramework):
boring_balance = int(self.boring.getbalance() * 100000000) boring_balance = int(self.boring.getbalance() * 100000000)
to_amnt = random.randrange(1000000, boring_balance) to_amnt = random.randrange(1000000, boring_balance)
self.boring.sendtoaddress(address=addr_g, amount=Decimal(to_amnt) / 100000000, subtractfeefromamount=True) self.boring.sendtoaddress(address=addr_g, amount=Decimal(to_amnt) / 100000000, subtractfeefromamount=True)
self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress()) self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress(), sync_fun=self.no_op)
test_balance = int(self.psbt_online.getbalance() * 100000000) test_balance = int(self.psbt_online.getbalance() * 100000000)
ret_amnt = random.randrange(100000, test_balance) ret_amnt = random.randrange(100000, test_balance)
psbt = self.psbt_online.walletcreatefundedpsbt([], [{self.boring.getnewaddress(): Decimal(ret_amnt) / 100000000}], None, {"subtractFeeFromOutputs":[0]})['psbt'] psbt = self.psbt_online.walletcreatefundedpsbt([], [{self.boring.getnewaddress(): Decimal(ret_amnt) / 100000000}], None, {"subtractFeeFromOutputs":[0]})['psbt']
@ -311,7 +311,7 @@ class WalletTaprootTest(BitcoinTestFramework):
assert(res['complete']) assert(res['complete'])
rawtx = self.nodes[0].finalizepsbt(res['psbt'])['hex'] rawtx = self.nodes[0].finalizepsbt(res['psbt'])['hex']
txid = self.nodes[0].sendrawtransaction(rawtx) txid = self.nodes[0].sendrawtransaction(rawtx)
self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress()) self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress(), sync_fun=self.no_op)
assert(self.psbt_online.gettransaction(txid)['confirmations'] > 0) assert(self.psbt_online.gettransaction(txid)['confirmations'] > 0)
def do_test(self, comment, pattern, privmap, treefn, nkeys): def do_test(self, comment, pattern, privmap, treefn, nkeys):
@ -343,7 +343,7 @@ class WalletTaprootTest(BitcoinTestFramework):
self.log.info("Mining blocks...") self.log.info("Mining blocks...")
gen_addr = self.boring.getnewaddress() gen_addr = self.boring.getnewaddress()
self.generatetoaddress(self.nodes[0], 101, gen_addr) self.generatetoaddress(self.nodes[0], 101, gen_addr, sync_fun=self.no_op)
self.do_test( self.do_test(
"tr(XPRV)", "tr(XPRV)",
@ -412,7 +412,7 @@ class WalletTaprootTest(BitcoinTestFramework):
self.log.info("Sending everything back...") self.log.info("Sending everything back...")
txid = self.rpc_online.sendtoaddress(address=self.boring.getnewaddress(), amount=self.rpc_online.getbalance(), subtractfeefromamount=True) txid = self.rpc_online.sendtoaddress(address=self.boring.getnewaddress(), amount=self.rpc_online.getbalance(), subtractfeefromamount=True)
self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress()) self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress(), sync_fun=self.no_op)
assert(self.rpc_online.gettransaction(txid)["confirmations"] > 0) assert(self.rpc_online.gettransaction(txid)["confirmations"] > 0)
psbt = self.psbt_online.walletcreatefundedpsbt([], [{self.boring.getnewaddress(): self.psbt_online.getbalance()}], None, {"subtractFeeFromOutputs": [0]})['psbt'] psbt = self.psbt_online.walletcreatefundedpsbt([], [{self.boring.getnewaddress(): self.psbt_online.getbalance()}], None, {"subtractFeeFromOutputs": [0]})['psbt']
@ -420,7 +420,7 @@ class WalletTaprootTest(BitcoinTestFramework):
assert(res['complete']) assert(res['complete'])
rawtx = self.nodes[0].finalizepsbt(res['psbt'])['hex'] rawtx = self.nodes[0].finalizepsbt(res['psbt'])['hex']
txid = self.nodes[0].sendrawtransaction(rawtx) txid = self.nodes[0].sendrawtransaction(rawtx)
self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress()) self.generatetoaddress(self.nodes[0], 1, self.boring.getnewaddress(), sync_fun=self.no_op)
assert(self.psbt_online.gettransaction(txid)['confirmations'] > 0) assert(self.psbt_online.gettransaction(txid)['confirmations'] > 0)
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -93,8 +93,7 @@ class TxnMallTest(BitcoinTestFramework):
# Have node0 mine a block, if requested: # Have node0 mine a block, if requested:
if (self.options.mine_block): if (self.options.mine_block):
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:2]))
self.sync_blocks(self.nodes[0:2])
tx1 = self.nodes[0].gettransaction(txid1) tx1 = self.nodes[0].gettransaction(txid1)
tx2 = self.nodes[0].gettransaction(txid2) tx2 = self.nodes[0].gettransaction(txid2)
@ -123,7 +122,7 @@ class TxnMallTest(BitcoinTestFramework):
return return
# ... mine a block... # ... mine a block...
self.generate(self.nodes[2], 1) self.generate(self.nodes[2], 1, sync_fun=self.no_op)
# Reconnect the split network, and sync chain: # Reconnect the split network, and sync chain:
self.connect_nodes(1, 2) self.connect_nodes(1, 2)

View file

@ -91,8 +91,7 @@ class TxnMallTest(BitcoinTestFramework):
# Have node0 mine a block: # Have node0 mine a block:
if (self.options.mine_block): if (self.options.mine_block):
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:2]))
self.sync_blocks(self.nodes[0:2])
tx1 = self.nodes[0].gettransaction(txid1) tx1 = self.nodes[0].gettransaction(txid1)
tx2 = self.nodes[0].gettransaction(txid2) tx2 = self.nodes[0].gettransaction(txid2)
@ -120,7 +119,7 @@ class TxnMallTest(BitcoinTestFramework):
self.nodes[2].sendrawtransaction(fund_bar_tx["hex"]) self.nodes[2].sendrawtransaction(fund_bar_tx["hex"])
doublespend_txid = self.nodes[2].sendrawtransaction(doublespend["hex"]) doublespend_txid = self.nodes[2].sendrawtransaction(doublespend["hex"])
# ... mine a block... # ... mine a block...
self.generate(self.nodes[2], 1) self.generate(self.nodes[2], 1, sync_fun=self.no_op)
# Reconnect the split network, and sync chain: # Reconnect the split network, and sync chain:
self.connect_nodes(1, 2) self.connect_nodes(1, 2)

View file

@ -119,8 +119,7 @@ class UpgradeWalletTest(BitcoinTestFramework):
assert_equal(wallet.getwalletinfo()["walletversion"], previous_version) assert_equal(wallet.getwalletinfo()["walletversion"], previous_version)
def run_test(self): def run_test(self):
self.generatetoaddress(self.nodes[0], COINBASE_MATURITY + 1, self.nodes[0].getnewaddress()) self.generatetoaddress(self.nodes[0], COINBASE_MATURITY + 1, self.nodes[0].getnewaddress(), sync_fun=lambda: self.dumb_sync_blocks())
self.dumb_sync_blocks()
# # Sanity check the test framework: # # Sanity check the test framework:
res = self.nodes[0].getblockchaininfo() res = self.nodes[0].getblockchaininfo()
assert_equal(res['blocks'], COINBASE_MATURITY + 1) assert_equal(res['blocks'], COINBASE_MATURITY + 1)
@ -131,8 +130,7 @@ class UpgradeWalletTest(BitcoinTestFramework):
# Send coins to old wallets for later conversion checks. # Send coins to old wallets for later conversion checks.
v16_3_wallet = v16_3_node.get_wallet_rpc('wallet.dat') v16_3_wallet = v16_3_node.get_wallet_rpc('wallet.dat')
v16_3_address = v16_3_wallet.getnewaddress() v16_3_address = v16_3_wallet.getnewaddress()
self.generatetoaddress(node_master, COINBASE_MATURITY + 1, v16_3_address) self.generatetoaddress(node_master, COINBASE_MATURITY + 1, v16_3_address, sync_fun=lambda: self.dumb_sync_blocks())
self.dumb_sync_blocks()
v16_3_balance = v16_3_wallet.getbalance() v16_3_balance = v16_3_wallet.getbalance()
self.log.info("Test upgradewallet RPC...") self.log.info("Test upgradewallet RPC...")