Skip to content

Commit 8f1106d

Browse files
author
MarcoFalke
committed
Merge #13626: qa: Fix some TODOs in p2p_segwit
eeeef80 qa: Fix some TODOs in p2p_segwit (MarcoFalke) Pull request description: * I believe we don't need to redundantly test versionbits logic in every functional tests that tests a softfork deployment that is being done with versionbits. Thus, remove two `TODO`s that ask for that. * Replace another `TODO` with `wait_until`. * Some style fixups after #13467 Tree-SHA512: c7120404d50579d6f3b9092f1e259959190eeafe520231e3479c8c256a50bf7260ccc93f8301ac0e100c54037053f6849433ebb1c55607e01d94b9812e525083
2 parents 619cd29 + eeeef80 commit 8f1106d

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

test/functional/p2p_segwit.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from test_framework.mininode import (
4242
P2PInterface,
4343
mininode_lock,
44+
wait_until,
4445
)
4546
from test_framework.script import (
4647
CScript,
@@ -221,7 +222,7 @@ def update_witness_block_with_transactions(self, block, tx_list, nonce=0):
221222
block.solve()
222223

223224
def run_test(self):
224-
# Setup the p2p connections and start up the network thread.
225+
# Setup the p2p connections
225226
# self.test_node sets NODE_WITNESS|NODE_NETWORK
226227
self.test_node = self.nodes[0].add_p2p_connection(TestP2PConn(), services=NODE_NETWORK | NODE_WITNESS)
227228
# self.old_node sets only NODE_NETWORK
@@ -351,10 +352,7 @@ def test_unnecessary_witness_before_segwit_activation(self):
351352
# Sending witness data before activation is not allowed (anti-spam
352353
# rule).
353354
test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
354-
# TODO: fix synchronization so we can test reject reason
355-
# Right now, bitcoind delays sending reject messages for blocks
356-
# until the future, making synchronization here difficult.
357-
# assert_equal(self.test_node.last_message["reject"].reason, "unexpected-witness")
355+
wait_until(lambda: 'reject' in self.test_node.last_message and self.test_node.last_message["reject"].reason == b"unexpected-witness")
358356

359357
# But it should not be permanently marked bad...
360358
# Resend without witness information.
@@ -605,9 +603,6 @@ def test_getblocktemplate_before_lockin(self):
605603
@subtest
606604
def advance_to_segwit_lockin(self):
607605
"""Mine enough blocks to lock in segwit, but don't activate."""
608-
# TODO: we could verify that lockin only happens at the right threshold of
609-
# signalling blocks, rather than just at the right period boundary.
610-
611606
height = self.nodes[0].getblockcount()
612607
# Advance to end of period, and verify lock-in happens at the end
613608
self.nodes[0].generate(VB_PERIOD - 1)
@@ -741,9 +736,6 @@ def test_standardness_v0(self):
741736
@subtest
742737
def advance_to_segwit_active(self):
743738
"""Mine enough blocks to activate segwit."""
744-
# TODO: we could verify that activation only happens at the right threshold
745-
# of signalling blocks, rather than just at the right period boundary.
746-
747739
height = self.nodes[0].getblockcount()
748740
self.nodes[0].generate(VB_PERIOD - (height % VB_PERIOD) - 2)
749741
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'locked_in')
@@ -1402,30 +1394,28 @@ def test_segwit_versions(self):
14021394
Future segwit version transactions are non-standard, but valid in blocks.
14031395
Can run this before and after segwit activation."""
14041396

1405-
num_tests = 17 # will test OP_0, OP1, ..., OP_16
1406-
if (len(self.utxo) < num_tests):
1397+
NUM_SEGWIT_VERSIONS = 17 # will test OP_0, OP1, ..., OP_16
1398+
if len(self.utxo) < NUM_SEGWIT_VERSIONS:
14071399
tx = CTransaction()
14081400
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
1409-
split_value = (self.utxo[0].nValue - 4000) // num_tests
1410-
for i in range(num_tests):
1401+
split_value = (self.utxo[0].nValue - 4000) // NUM_SEGWIT_VERSIONS
1402+
for i in range(NUM_SEGWIT_VERSIONS):
14111403
tx.vout.append(CTxOut(split_value, CScript([OP_TRUE])))
14121404
tx.rehash()
14131405
block = self.build_next_block()
14141406
self.update_witness_block_with_transactions(block, [tx])
14151407
test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
14161408
self.utxo.pop(0)
1417-
for i in range(num_tests):
1409+
for i in range(NUM_SEGWIT_VERSIONS):
14181410
self.utxo.append(UTXO(tx.sha256, i, split_value))
14191411

14201412
sync_blocks(self.nodes)
14211413
temp_utxo = []
14221414
tx = CTransaction()
1423-
count = 0
14241415
witness_program = CScript([OP_TRUE])
14251416
witness_hash = sha256(witness_program)
14261417
assert_equal(len(self.nodes[1].getrawmempool()), 0)
14271418
for version in list(range(OP_1, OP_16 + 1)) + [OP_0]:
1428-
count += 1
14291419
# First try to spend to a future version segwit script_pubkey.
14301420
script_pubkey = CScript([CScriptOp(version), witness_hash])
14311421
tx.vin = [CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")]
@@ -1680,19 +1670,19 @@ def test_signature_version_1(self):
16801670
# Test combinations of signature hashes.
16811671
# Split the utxo into a lot of outputs.
16821672
# Randomly choose up to 10 to spend, sign with different hashtypes, and
1683-
# output to a random number of outputs. Repeat num_tests times.
1673+
# output to a random number of outputs. Repeat NUM_SIGHASH_TESTS times.
16841674
# Ensure that we've tested a situation where we use SIGHASH_SINGLE with
16851675
# an input index > number of outputs.
1686-
num_tests = 500
1676+
NUM_SIGHASH_TESTS = 500
16871677
temp_utxos = []
16881678
tx = CTransaction()
16891679
tx.vin.append(CTxIn(COutPoint(prev_utxo.sha256, prev_utxo.n), b""))
1690-
split_value = prev_utxo.nValue // num_tests
1691-
for i in range(num_tests):
1680+
split_value = prev_utxo.nValue // NUM_SIGHASH_TESTS
1681+
for i in range(NUM_SIGHASH_TESTS):
16921682
tx.vout.append(CTxOut(split_value, script_pubkey))
16931683
tx.wit.vtxinwit.append(CTxInWitness())
16941684
sign_p2pk_witness_input(witness_program, tx, 0, SIGHASH_ALL, prev_utxo.nValue, key)
1695-
for i in range(num_tests):
1685+
for i in range(NUM_SIGHASH_TESTS):
16961686
temp_utxos.append(UTXO(tx.sha256, i, split_value))
16971687

16981688
block = self.build_next_block()
@@ -1701,7 +1691,7 @@ def test_signature_version_1(self):
17011691

17021692
block = self.build_next_block()
17031693
used_sighash_single_out_of_bounds = False
1704-
for i in range(num_tests):
1694+
for i in range(NUM_SIGHASH_TESTS):
17051695
# Ping regularly to keep the connection alive
17061696
if (not i % 100):
17071697
self.test_node.sync_with_ping()

0 commit comments

Comments
 (0)