[tests] p2p_segwit: Make sure each subtest leaves utxos for the next.
This commit is contained in:
parent
bfe32734de
commit
6839863d53
1 changed files with 8 additions and 34 deletions
|
@ -228,16 +228,17 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
# self.std_node is for testing node1 (fRequireStandard=true)
|
# self.std_node is for testing node1 (fRequireStandard=true)
|
||||||
self.std_node = self.nodes[1].add_p2p_connection(TestP2PConn(), services=NODE_NETWORK | NODE_WITNESS)
|
self.std_node = self.nodes[1].add_p2p_connection(TestP2PConn(), services=NODE_NETWORK | NODE_WITNESS)
|
||||||
|
|
||||||
|
for conn in (self.test_node, self.old_node, self.std_node):
|
||||||
|
conn.wait_for_verack()
|
||||||
|
|
||||||
|
assert self.test_node.nServices & NODE_WITNESS != 0
|
||||||
|
|
||||||
# Keep a place to store utxo's that can be used in later tests
|
# Keep a place to store utxo's that can be used in later tests
|
||||||
self.utxo = []
|
self.utxo = []
|
||||||
|
|
||||||
# Test logic begins here
|
|
||||||
self.test_node.wait_for_verack()
|
|
||||||
|
|
||||||
self.log.info("Starting tests before segwit lock in:")
|
self.log.info("Starting tests before segwit lock in:")
|
||||||
|
|
||||||
self.test_witness_services() # Verifies NODE_WITNESS
|
self.test_non_witness_transaction()
|
||||||
self.test_non_witness_transaction() # non-witness tx's are accepted
|
|
||||||
self.test_unnecessary_witness_before_segwit_activation()
|
self.test_unnecessary_witness_before_segwit_activation()
|
||||||
self.test_v0_outputs_arent_spendable()
|
self.test_v0_outputs_arent_spendable()
|
||||||
self.test_block_relay(segwit_activated=False)
|
self.test_block_relay(segwit_activated=False)
|
||||||
|
@ -297,13 +298,11 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
def func_wrapper(self, *args, **kwargs):
|
def func_wrapper(self, *args, **kwargs):
|
||||||
self.log.info("Subtest: {}".format(func.__name__))
|
self.log.info("Subtest: {}".format(func.__name__))
|
||||||
func(self, *args, **kwargs)
|
func(self, *args, **kwargs)
|
||||||
|
# Each subtest should leave some utxos for the next subtest
|
||||||
|
assert self.utxo
|
||||||
|
|
||||||
return func_wrapper
|
return func_wrapper
|
||||||
|
|
||||||
def test_witness_services(self):
|
|
||||||
self.log.info("Verifying NODE_WITNESS service bit")
|
|
||||||
assert((self.test_node.nServices & NODE_WITNESS) != 0)
|
|
||||||
|
|
||||||
@subtest
|
@subtest
|
||||||
def test_non_witness_transaction(self):
|
def test_non_witness_transaction(self):
|
||||||
"""See if sending a regular transaction works, and create a utxo to use in later tests."""
|
"""See if sending a regular transaction works, and create a utxo to use in later tests."""
|
||||||
|
@ -339,9 +338,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
def test_unnecessary_witness_before_segwit_activation(self):
|
def test_unnecessary_witness_before_segwit_activation(self):
|
||||||
"""Verify that blocks with witnesses are rejected before activation."""
|
"""Verify that blocks with witnesses are rejected before activation."""
|
||||||
|
|
||||||
# For now, rely on earlier tests to have created at least one utxo for
|
|
||||||
# us to use
|
|
||||||
assert(len(self.utxo) > 0)
|
|
||||||
assert(get_bip9_status(self.nodes[0], 'segwit')['status'] != 'active')
|
assert(get_bip9_status(self.nodes[0], 'segwit')['status'] != 'active')
|
||||||
|
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
|
@ -486,8 +482,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
witness, and so can't be spent before segwit activation (the point at which
|
witness, and so can't be spent before segwit activation (the point at which
|
||||||
blocks are permitted to contain witnesses)."""
|
blocks are permitted to contain witnesses)."""
|
||||||
|
|
||||||
assert len(self.utxo), "self.utxo is empty"
|
|
||||||
|
|
||||||
# Create two outputs, a p2wsh and p2sh-p2wsh
|
# Create two outputs, a p2wsh and p2sh-p2wsh
|
||||||
witness_program = CScript([OP_TRUE])
|
witness_program = CScript([OP_TRUE])
|
||||||
witness_hash = sha256(witness_program)
|
witness_hash = sha256(witness_program)
|
||||||
|
@ -632,7 +626,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
# Generate a transaction that doesn't require a witness, but send it
|
# Generate a transaction that doesn't require a witness, but send it
|
||||||
# with a witness. Should be rejected for premature-witness, but should
|
# with a witness. Should be rejected for premature-witness, but should
|
||||||
# not be added to recently rejected list.
|
# not be added to recently rejected list.
|
||||||
assert(len(self.utxo))
|
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
||||||
|
@ -676,8 +669,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
V0 segwit outputs and inputs are always standard.
|
V0 segwit outputs and inputs are always standard.
|
||||||
V0 segwit inputs may only be mined after activation, but not before."""
|
V0 segwit inputs may only be mined after activation, but not before."""
|
||||||
|
|
||||||
assert(len(self.utxo))
|
|
||||||
|
|
||||||
witness_program = CScript([OP_TRUE])
|
witness_program = CScript([OP_TRUE])
|
||||||
witness_hash = sha256(witness_program)
|
witness_hash = sha256(witness_program)
|
||||||
script_pubkey = CScript([OP_0, witness_hash])
|
script_pubkey = CScript([OP_0, witness_hash])
|
||||||
|
@ -766,8 +757,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
def test_p2sh_witness(self, segwit_activated):
|
def test_p2sh_witness(self, segwit_activated):
|
||||||
"""Test P2SH wrapped witness programs."""
|
"""Test P2SH wrapped witness programs."""
|
||||||
|
|
||||||
assert(len(self.utxo))
|
|
||||||
|
|
||||||
# Prepare the p2sh-wrapped witness output
|
# Prepare the p2sh-wrapped witness output
|
||||||
witness_program = CScript([OP_DROP, OP_TRUE])
|
witness_program = CScript([OP_DROP, OP_TRUE])
|
||||||
witness_hash = sha256(witness_program)
|
witness_hash = sha256(witness_program)
|
||||||
|
@ -861,7 +850,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
test_witness_block(self.nodes[0].rpc, self.test_node, block_2, accepted=True)
|
test_witness_block(self.nodes[0].rpc, self.test_node, block_2, accepted=True)
|
||||||
|
|
||||||
# Now test commitments with actual transactions
|
# Now test commitments with actual transactions
|
||||||
assert (len(self.utxo) > 0)
|
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||||
|
|
||||||
|
@ -1081,8 +1069,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
def test_extra_witness_data(self):
|
def test_extra_witness_data(self):
|
||||||
"""Test extra witness data in a transaction."""
|
"""Test extra witness data in a transaction."""
|
||||||
|
|
||||||
assert(len(self.utxo) > 0)
|
|
||||||
|
|
||||||
block = self.build_next_block()
|
block = self.build_next_block()
|
||||||
|
|
||||||
witness_program = CScript([OP_DROP, OP_TRUE])
|
witness_program = CScript([OP_DROP, OP_TRUE])
|
||||||
|
@ -1157,7 +1143,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
"""Test that witness stack can only allow up to 520 byte pushes."""
|
"""Test that witness stack can only allow up to 520 byte pushes."""
|
||||||
|
|
||||||
MAX_SCRIPT_ELEMENT_SIZE = 520
|
MAX_SCRIPT_ELEMENT_SIZE = 520
|
||||||
assert(len(self.utxo))
|
|
||||||
|
|
||||||
block = self.build_next_block()
|
block = self.build_next_block()
|
||||||
|
|
||||||
|
@ -1196,7 +1181,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
def test_max_witness_program_length(self):
|
def test_max_witness_program_length(self):
|
||||||
"""Test that witness outputs greater than 10kB can't be spent."""
|
"""Test that witness outputs greater than 10kB can't be spent."""
|
||||||
|
|
||||||
assert(len(self.utxo))
|
|
||||||
MAX_PROGRAM_LENGTH = 10000
|
MAX_PROGRAM_LENGTH = 10000
|
||||||
|
|
||||||
# This program is 19 max pushes (9937 bytes), then 64 more opcode-bytes.
|
# This program is 19 max pushes (9937 bytes), then 64 more opcode-bytes.
|
||||||
|
@ -1245,8 +1229,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
def test_witness_input_length(self):
|
def test_witness_input_length(self):
|
||||||
"""Test that vin length must match vtxinwit length."""
|
"""Test that vin length must match vtxinwit length."""
|
||||||
|
|
||||||
assert(len(self.utxo))
|
|
||||||
|
|
||||||
witness_program = CScript([OP_DROP, OP_TRUE])
|
witness_program = CScript([OP_DROP, OP_TRUE])
|
||||||
witness_hash = sha256(witness_program)
|
witness_hash = sha256(witness_program)
|
||||||
script_pubkey = CScript([OP_0, witness_hash])
|
script_pubkey = CScript([OP_0, witness_hash])
|
||||||
|
@ -1337,7 +1319,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
# Generate a transaction that doesn't require a witness, but send it
|
# Generate a transaction that doesn't require a witness, but send it
|
||||||
# with a witness. Should be rejected because we can't use a witness
|
# with a witness. Should be rejected because we can't use a witness
|
||||||
# when spending a non-witness output.
|
# when spending a non-witness output.
|
||||||
assert(len(self.utxo))
|
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
||||||
|
@ -1426,7 +1407,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
Future segwit version transactions are non-standard, but valid in blocks.
|
Future segwit version transactions are non-standard, but valid in blocks.
|
||||||
Can run this before and after segwit activation."""
|
Can run this before and after segwit activation."""
|
||||||
|
|
||||||
assert(len(self.utxo))
|
|
||||||
num_tests = 17 # will test OP_0, OP1, ..., OP_16
|
num_tests = 17 # will test OP_0, OP1, ..., OP_16
|
||||||
if (len(self.utxo) < num_tests):
|
if (len(self.utxo) < num_tests):
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
|
@ -1557,7 +1537,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
pubkey = CPubKey(key.get_pubkey())
|
pubkey = CPubKey(key.get_pubkey())
|
||||||
assert_equal(len(pubkey), 65) # This should be an uncompressed pubkey
|
assert_equal(len(pubkey), 65) # This should be an uncompressed pubkey
|
||||||
|
|
||||||
assert(len(self.utxo) > 0)
|
|
||||||
utxo = self.utxo.pop(0)
|
utxo = self.utxo.pop(0)
|
||||||
|
|
||||||
# Test 1: P2WPKH
|
# Test 1: P2WPKH
|
||||||
|
@ -1661,7 +1640,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
script_pubkey = CScript([OP_0, witness_hash])
|
script_pubkey = CScript([OP_0, witness_hash])
|
||||||
|
|
||||||
# First create a witness output for use in the tests.
|
# First create a witness output for use in the tests.
|
||||||
assert(len(self.utxo))
|
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||||
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
|
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
|
||||||
|
@ -1835,7 +1813,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
@subtest
|
@subtest
|
||||||
def test_non_standard_witness_blinding(self):
|
def test_non_standard_witness_blinding(self):
|
||||||
"""Test behavior of unnecessary witnesses in transactions does not blind the node for the transaction"""
|
"""Test behavior of unnecessary witnesses in transactions does not blind the node for the transaction"""
|
||||||
assert (len(self.utxo) > 0)
|
|
||||||
|
|
||||||
# Create a p2sh output -- this is so we can pass the standardness
|
# Create a p2sh output -- this is so we can pass the standardness
|
||||||
# rules (an anyone-can-spend OP_TRUE would be rejected, if not wrapped
|
# rules (an anyone-can-spend OP_TRUE would be rejected, if not wrapped
|
||||||
|
@ -1901,7 +1878,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
|
|
||||||
p2wsh_scripts = []
|
p2wsh_scripts = []
|
||||||
|
|
||||||
assert(len(self.utxo))
|
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||||
|
|
||||||
|
@ -2019,8 +1995,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
def test_witness_sigops(self):
|
def test_witness_sigops(self):
|
||||||
"""Test sigop counting is correct inside witnesses."""
|
"""Test sigop counting is correct inside witnesses."""
|
||||||
|
|
||||||
assert(len(self.utxo))
|
|
||||||
|
|
||||||
# Keep this under MAX_OPS_PER_SCRIPT (201)
|
# Keep this under MAX_OPS_PER_SCRIPT (201)
|
||||||
witness_program = CScript([OP_TRUE, OP_IF, OP_TRUE, OP_ELSE] + [OP_CHECKMULTISIG] * 5 + [OP_CHECKSIG] * 193 + [OP_ENDIF])
|
witness_program = CScript([OP_TRUE, OP_IF, OP_TRUE, OP_ELSE] + [OP_CHECKMULTISIG] * 5 + [OP_CHECKSIG] * 193 + [OP_ENDIF])
|
||||||
witness_hash = sha256(witness_program)
|
witness_hash = sha256(witness_program)
|
||||||
|
|
Loading…
Reference in a new issue