Skip to content

Commit

Permalink
scripted-diff: use self.sync_* methods
Browse files Browse the repository at this point in the history
-BEGIN VERIFY SCRIPT-
sed -i -e 's/sync_blocks(self.nodes)/self.sync_blocks()/g'     $(git grep -l 'sync_blocks(self.nodes)'   ./test/functional/*.py)
sed -i -e 's/sync_mempools(self.nodes)/self.sync_mempools()/g' $(git grep -l 'sync_mempools(self.nodes)' ./test/functional/*.py)

sed -i -e 's/  sync_blocks(/  self.sync_blocks(/g'     $(git grep -l sync_blocks   ./test/functional/*.py)
sed -i -e 's/  sync_mempools(/  self.sync_mempools(/g' $(git grep -l sync_mempools ./test/functional/*.py)
-END VERIFY SCRIPT-
  • Loading branch information
MarcoFalke committed Apr 9, 2019
1 parent faf77f9 commit fa16a09
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 86 deletions.
2 changes: 1 addition & 1 deletion test/functional/feature_bip68_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def activateCSV(self):
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], "locked_in")
self.nodes[0].generate(1)
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], "active")
sync_blocks(self.nodes)
self.sync_blocks()

# Use self.nodes[1] to test that version 2 transactions are standard.
def test_version2_relay(self):
Expand Down
6 changes: 3 additions & 3 deletions test/functional/feature_fee_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ def transact_and_mine(self, numblocks, mining_node):
self.memutxo, Decimal("0.005"), min_fee, min_fee)
tx_kbytes = (len(txhex) // 2) / 1000.0
self.fees_per_kb.append(float(fee) / tx_kbytes)
sync_mempools(self.nodes[0:3], wait=.1)
self.sync_mempools(self.nodes[0:3], wait=.1)
mined = mining_node.getblock(mining_node.generate(1)[0], True)["tx"]
sync_blocks(self.nodes[0:3], wait=.1)
self.sync_blocks(self.nodes[0:3], wait=.1)
# update which txouts are confirmed
newmem = []
for utx in self.memutxo:
Expand Down Expand Up @@ -237,7 +237,7 @@ def run_test(self):
while len(self.nodes[1].getrawmempool()) > 0:
self.nodes[1].generate(1)

sync_blocks(self.nodes[0:3], wait=.1)
self.sync_blocks(self.nodes[0:3], wait=.1)
self.log.info("Final estimates after emptying mempools")
check_estimates(self.nodes[1], self.fees_per_kb)

Expand Down
12 changes: 6 additions & 6 deletions test/functional/feature_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def setup_network(self):
connect_nodes(self.nodes[0], 2)
connect_nodes(self.nodes[0], 3)
connect_nodes(self.nodes[0], 4)
sync_blocks(self.nodes[0:5])
self.sync_blocks(self.nodes[0:5])

def setup_nodes(self):
self.add_nodes(self.num_nodes, self.extra_args)
Expand All @@ -111,13 +111,13 @@ def setup_nodes(self):
def create_big_chain(self):
# Start by creating some coinbases we can spend later
self.nodes[1].generate(200)
sync_blocks(self.nodes[0:2])
self.sync_blocks(self.nodes[0:2])
self.nodes[0].generate(150)

# Then mine enough full blocks to create more than 550MiB of data
mine_large_blocks(self.nodes[0], 645)

sync_blocks(self.nodes[0:5])
self.sync_blocks(self.nodes[0:5])

def test_height_min(self):
assert os.path.isfile(os.path.join(self.prunedir, "blk00000.dat")), "blk00000.dat is missing, pruning too early"
Expand Down Expand Up @@ -153,7 +153,7 @@ def create_chain_with_staleblocks(self):
# Create connections in the order so both nodes can see the reorg at the same time
connect_nodes(self.nodes[0], 1)
connect_nodes(self.nodes[0], 2)
sync_blocks(self.nodes[0:3])
self.sync_blocks(self.nodes[0:3])

self.log.info("Usage can be over target because of high stale rate: %d" % calc_usage(self.prunedir))

Expand Down Expand Up @@ -190,7 +190,7 @@ def reorg_test(self):
self.log.info("Reconnect nodes")
connect_nodes(self.nodes[0], 1)
connect_nodes(self.nodes[1], 2)
sync_blocks(self.nodes[0:3], timeout=120)
self.sync_blocks(self.nodes[0:3], timeout=120)

self.log.info("Verify height on node 2: %d" % self.nodes[2].getblockcount())
self.log.info("Usage possibly still high because of stale blocks in block files: %d" % calc_usage(self.prunedir))
Expand Down Expand Up @@ -345,7 +345,7 @@ def wallet_test(self):
self.log.info("Syncing node 5 to test wallet")
connect_nodes(self.nodes[0], 5)
nds = [self.nodes[0], self.nodes[5]]
sync_blocks(nds, wait=5, timeout=300)
self.sync_blocks(nds, wait=5, timeout=300)
self.stop_node(5) # stop and start to trigger rescan
self.start_node(5, extra_args=["-prune=550"])
self.log.info("Success")
Expand Down
14 changes: 7 additions & 7 deletions test/functional/feature_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def success_mine(self, node, txid, sign, redeem_script=""):
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script)
block = node.generate(1)
assert_equal(len(node.getblock(block[0])["tx"]), 2)
sync_blocks(self.nodes)
self.sync_blocks()

def skip_mine(self, node, txid, sign, redeem_script=""):
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script)
block = node.generate(1)
assert_equal(len(node.getblock(block[0])["tx"]), 1)
sync_blocks(self.nodes)
self.sync_blocks()

def fail_accept(self, node, error_msg, txid, sign, redeem_script=""):
assert_raises_rpc_error(-26, error_msg, send_to_witness, use_p2wsh=1, node=node, utxo=getutxo(txid), pubkey=self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=sign, insert_redeem_script=redeem_script)
Expand Down Expand Up @@ -131,15 +131,15 @@ def run_test(self):
p2sh_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[n], True, Decimal("49.999")))

self.nodes[0].generate(1) # block 163
sync_blocks(self.nodes)
self.sync_blocks()

# Make sure all nodes recognize the transactions as theirs
assert_equal(self.nodes[0].getbalance(), balance_presetup - 60 * 50 + 20 * Decimal("49.999") + 50)
assert_equal(self.nodes[1].getbalance(), 20 * Decimal("49.999"))
assert_equal(self.nodes[2].getbalance(), 20 * Decimal("49.999"))

self.nodes[0].generate(260) # block 423
sync_blocks(self.nodes)
self.sync_blocks()

self.log.info("Verify witness txs are skipped for mining before the fork")
self.skip_mine(self.nodes[2], wit_ids[NODE_2][WIT_V0][0], True) # block 424
Expand All @@ -156,7 +156,7 @@ def run_test(self):
self.log.info("Verify previous witness txs skipped for mining can now be mined")
assert_equal(len(self.nodes[2].getrawmempool()), 4)
blockhash = self.nodes[2].generate(1)[0] # block 432 (first block with new rules; 432 = 144 * 3)
sync_blocks(self.nodes)
self.sync_blocks()
assert_equal(len(self.nodes[2].getrawmempool()), 0)
segwit_tx_list = self.nodes[2].getblock(blockhash)["tx"]
assert_equal(len(segwit_tx_list), 5)
Expand Down Expand Up @@ -538,7 +538,7 @@ def mine_and_test_listunspent(self, script_list, ismine):
signresults = self.nodes[0].signrawtransactionwithwallet(tx.serialize_without_witness().hex())['hex']
txid = self.nodes[0].sendrawtransaction(signresults, 0)
txs_mined[txid] = self.nodes[0].generate(1)[0]
sync_blocks(self.nodes)
self.sync_blocks()
watchcount = 0
spendcount = 0
for i in self.nodes[0].listunspent():
Expand Down Expand Up @@ -590,7 +590,7 @@ def create_and_mine_tx_from_txids(self, txids, success=True):
signresults = self.nodes[0].signrawtransactionwithwallet(tx.serialize_without_witness().hex())['hex']
self.nodes[0].sendrawtransaction(signresults, 0)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
self.sync_blocks()


if __name__ == '__main__':
Expand Down
8 changes: 4 additions & 4 deletions test/functional/mempool_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def run_test(self):
# Check that prioritising a tx before it's added to the mempool works
# First clear the mempool by mining a block.
self.nodes[0].generate(1)
sync_blocks(self.nodes)
self.sync_blocks()
assert_equal(len(self.nodes[0].getrawmempool()), 0)
# Prioritise a transaction that has been mined, then add it back to the
# mempool by using invalidateblock.
Expand Down Expand Up @@ -228,7 +228,7 @@ def run_test(self):
# Test reorg handling
# First, the basics:
self.nodes[0].generate(1)
sync_blocks(self.nodes)
self.sync_blocks()
self.nodes[1].invalidateblock(self.nodes[0].getbestblockhash())
self.nodes[1].reconsiderblock(self.nodes[0].getbestblockhash())

Expand Down Expand Up @@ -283,12 +283,12 @@ def run_test(self):
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
txid = self.nodes[0].sendrawtransaction(signedtx['hex'])
sync_mempools(self.nodes)
self.sync_mempools()

# Now try to disconnect the tip on each node...
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
sync_blocks(self.nodes)
self.sync_blocks()

if __name__ == '__main__':
MempoolPackagesTest().main()
4 changes: 2 additions & 2 deletions test/functional/p2p_feefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run_test(self):
node0 = self.nodes[0]
# Get out of IBD
node1.generate(1)
sync_blocks(self.nodes)
self.sync_blocks()

self.nodes[0].add_p2p_connection(TestP2PConn())

Expand All @@ -71,7 +71,7 @@ def run_test(self):
# Change tx fee rate to 10 sat/byte and test they are no longer received
node1.settxfee(Decimal("0.00010000"))
[node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)]
sync_mempools(self.nodes) # must be sure node 0 has received all txs
self.sync_mempools() # must be sure node 0 has received all txs

# Send one transaction from node0 that should be received, so that we
# we can sync the test on receipt (if node1's txs were relayed, they'd
Expand Down
8 changes: 4 additions & 4 deletions test/functional/p2p_node_network_limited.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def run_test(self):
self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
connect_nodes_bi(self.nodes, 0, 1)
blocks = self.nodes[1].generatetoaddress(292, self.nodes[1].get_deterministic_priv_key().address)
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.")
node.send_getdata_for_block(blocks[1]) # last block in valid range
Expand All @@ -86,7 +86,7 @@ def run_test(self):
# because node 2 is in IBD and node 0 is a NODE_NETWORK_LIMITED peer, sync must not be possible
connect_nodes_bi(self.nodes, 0, 2)
try:
sync_blocks([self.nodes[0], self.nodes[2]], timeout=5)
self.sync_blocks([self.nodes[0], self.nodes[2]], timeout=5)
except:
pass
# node2 must remain at height 0
Expand All @@ -96,7 +96,7 @@ def run_test(self):
connect_nodes_bi(self.nodes, 1, 2)

# sync must be possible
sync_blocks(self.nodes)
self.sync_blocks()

# disconnect all peers
self.disconnect_all()
Expand All @@ -108,7 +108,7 @@ def run_test(self):
connect_nodes_bi(self.nodes, 0, 1)

# sync must be possible, node 1 is no longer in IBD and should therefore connect to node 0 (NODE_NETWORK_LIMITED)
sync_blocks([self.nodes[0], self.nodes[1]])
self.sync_blocks([self.nodes[0], self.nodes[1]])

if __name__ == '__main__':
NodeNetworkLimitedTest().main()
34 changes: 17 additions & 17 deletions test/functional/p2p_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def func_wrapper(self, *args, **kwargs):
func(self, *args, **kwargs)
# Each subtest should leave some utxos for the next subtest
assert self.utxo
sync_blocks(self.nodes)
self.sync_blocks()
# Assert segwit status is as expected at end of subtest
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], self.segwit_status)

Expand Down Expand Up @@ -644,7 +644,7 @@ def test_standardness_v0(self):
# Mine it on test_node to create the confirmed output.
test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_tx, with_witness=True, accepted=True)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
self.sync_blocks()

# Now test standardness of v0 P2WSH outputs.
# Start by creating a transaction with two outputs.
Expand Down Expand Up @@ -675,7 +675,7 @@ def test_standardness_v0(self):
tx3 = CTransaction()
# tx and tx2 were both accepted. Don't bother trying to reclaim the
# P2PKH output; just send tx's first output back to an anyone-can-spend.
sync_mempools([self.nodes[0], self.nodes[1]])
self.sync_mempools([self.nodes[0], self.nodes[1]])
tx3.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")]
tx3.vout = [CTxOut(tx.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))]
tx3.wit.vtxinwit.append(CTxInWitness())
Expand All @@ -694,7 +694,7 @@ def test_standardness_v0(self):
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=True)

self.nodes[0].generate(1)
sync_blocks(self.nodes)
self.sync_blocks()
self.utxo.pop(0)
self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue))
assert_equal(len(self.nodes[1].getrawmempool()), 0)
Expand Down Expand Up @@ -732,7 +732,7 @@ def test_p2sh_witness(self):
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx])
test_witness_block(self.nodes[0], self.test_node, block, accepted=True, with_witness=True)
sync_blocks(self.nodes)
self.sync_blocks()

# Now test attempts to spend the output.
spend_tx = CTransaction()
Expand Down Expand Up @@ -1377,7 +1377,7 @@ def test_segwit_versions(self):
for i in range(NUM_SEGWIT_VERSIONS):
self.utxo.append(UTXO(tx.sha256, i, split_value))

sync_blocks(self.nodes)
self.sync_blocks()
temp_utxo = []
tx = CTransaction()
witness_program = CScript([OP_TRUE])
Expand All @@ -1395,7 +1395,7 @@ def test_segwit_versions(self):
temp_utxo.append(UTXO(tx.sha256, 0, tx.vout[0].nValue))

self.nodes[0].generate(1) # Mine all the transactions
sync_blocks(self.nodes)
self.sync_blocks()
assert len(self.nodes[0].getrawmempool()) == 0

# Finally, verify that version 0 -> version 1 transactions
Expand Down Expand Up @@ -1432,7 +1432,7 @@ def test_segwit_versions(self):
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx2, tx3])
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
sync_blocks(self.nodes)
self.sync_blocks()

# Add utxo to our list
self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue))
Expand Down Expand Up @@ -1460,7 +1460,7 @@ def test_premature_coinbase_witness_spend(self):

# Now test a premature spend.
self.nodes[0].generate(98)
sync_blocks(self.nodes)
self.sync_blocks()
block2 = self.build_next_block()
self.update_witness_block_with_transactions(block2, [spend_tx])
test_witness_block(self.nodes[0], self.test_node, block2, accepted=False)
Expand All @@ -1470,7 +1470,7 @@ def test_premature_coinbase_witness_spend(self):
block2 = self.build_next_block()
self.update_witness_block_with_transactions(block2, [spend_tx])
test_witness_block(self.nodes[0], self.test_node, block2, accepted=True)
sync_blocks(self.nodes)
self.sync_blocks()

@subtest
def test_uncompressed_pubkey(self):
Expand Down Expand Up @@ -1600,7 +1600,7 @@ def test_signature_version_1(self):
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx])
test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
sync_blocks(self.nodes)
self.sync_blocks()
self.utxo.pop(0)

# Test each hashtype
Expand Down Expand Up @@ -1779,7 +1779,7 @@ def test_non_standard_witness_blinding(self):
tx.rehash()
test_transaction_acceptance(self.nodes[0], self.test_node, tx, False, True)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
self.sync_blocks()

# We'll add an unnecessary witness to this transaction that would cause
# it to be non-standard, to test that violating policy with a witness
Expand Down Expand Up @@ -1808,7 +1808,7 @@ def test_non_standard_witness_blinding(self):
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, False, True)

self.nodes[0].generate(1)
sync_blocks(self.nodes)
self.sync_blocks()

# Update our utxo list; we spent the first entry.
self.utxo.pop(0)
Expand Down Expand Up @@ -1844,7 +1844,7 @@ def test_non_standard_witness(self):
test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)

self.nodes[0].generate(1)
sync_blocks(self.nodes)
self.sync_blocks()

# Creating transactions for tests
p2wsh_txs = []
Expand Down Expand Up @@ -1908,7 +1908,7 @@ def test_non_standard_witness(self):

self.nodes[0].generate(1) # Mine and clean up the mempool of non-standard node
# Valid but non-standard transactions in a block should be accepted by standard node
sync_blocks(self.nodes)
self.sync_blocks()
assert_equal(len(self.nodes[0].getrawmempool()), 0)
assert_equal(len(self.nodes[1].getrawmempool()), 0)

Expand All @@ -1923,7 +1923,7 @@ def test_upgrade_after_activation(self):
self.start_node(2, extra_args=["-vbparams=segwit:0:999999999999"])
connect_nodes(self.nodes[0], 2)

sync_blocks(self.nodes)
self.sync_blocks()

# Make sure that this peer thinks segwit has activated.
assert get_bip9_status(self.nodes[2], 'segwit')['status'] == "active"
Expand Down Expand Up @@ -2020,7 +2020,7 @@ def test_witness_sigops(self):
test_witness_block(self.nodes[0], self.test_node, block_4, accepted=True)

# Reset the tip back down for the next test
sync_blocks(self.nodes)
self.sync_blocks()
for x in self.nodes:
x.invalidateblock(block_4.hash)

Expand Down
Loading

0 comments on commit fa16a09

Please sign in to comment.