mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 10:19:26 +02:00
Merge bitcoin/bitcoin#22818: test: Activate all regtest softforks at height 1, unless overridden
fa4db8671b
test: Activate all regtest softforks at height 1, unless overridden (MarcoFalke)faad1e5ffd
Introduce -testactivationheight=name@height setting (MarcoFalke)fadb2ef2fa
test: Add extra_args argument to TestChain100Setup constructor (MarcoFalke)faa46986aa
test: Remove version argument from build_next_block in p2p_segwit test (MarcoFalke)fa086ef539
test: Remove unused ~TestChain100Setup (MarcoFalke) Pull request description: All softforks that are active at the tip of mainnet, should also be active from genesis in regtest. Otherwise their rules might not be enforced in user testing, thus making their testing less useful. To still allow tests to check pre-softfork rules, a runtime argument can change the activation height. ACKs for top commit: laanwj: Code review ACKfa4db8671b
theStack: re-ACKfa4db8671b
Tree-SHA512: 6397d46ff56ebc48c007a4cda633904d6ac085bc76b4ecf83097c546c7eec93ac0c44b88083b2611b9091c8d1fb8ee1e314065de078ef15e922c015de7ade8bf
This commit is contained in:
@ -84,10 +84,6 @@ from test_framework.util import (
|
||||
assert_raises_rpc_error,
|
||||
)
|
||||
|
||||
# The versionbit bit used to signal activation of SegWit
|
||||
VB_WITNESS_BIT = 1
|
||||
VB_TOP_BITS = 0x20000000
|
||||
|
||||
MAX_SIGOP_COST = 80000
|
||||
|
||||
SEGWIT_HEIGHT = 120
|
||||
@ -197,8 +193,8 @@ class SegWitTest(BitcoinTestFramework):
|
||||
self.num_nodes = 2
|
||||
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
|
||||
self.extra_args = [
|
||||
["-acceptnonstdtxn=1", "-segwitheight={}".format(SEGWIT_HEIGHT), "-whitelist=noban@127.0.0.1"],
|
||||
["-acceptnonstdtxn=0", "-segwitheight={}".format(SEGWIT_HEIGHT)],
|
||||
["-acceptnonstdtxn=1", f"-testactivationheight=segwit@{SEGWIT_HEIGHT}", "-whitelist=noban@127.0.0.1"],
|
||||
["-acceptnonstdtxn=0", f"-testactivationheight=segwit@{SEGWIT_HEIGHT}"],
|
||||
]
|
||||
self.supports_cli = False
|
||||
|
||||
@ -207,13 +203,13 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Helper functions
|
||||
|
||||
def build_next_block(self, version=4):
|
||||
def build_next_block(self):
|
||||
"""Build a block on top of node0's tip."""
|
||||
tip = self.nodes[0].getbestblockhash()
|
||||
height = self.nodes[0].getblockcount() + 1
|
||||
block_time = self.nodes[0].getblockheader(tip)["mediantime"] + 1
|
||||
block = create_block(int(tip, 16), create_coinbase(height), block_time)
|
||||
block.nVersion = version
|
||||
block.nVersion = 4
|
||||
block.rehash()
|
||||
return block
|
||||
|
||||
@ -299,7 +295,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# Mine a block with an anyone-can-spend coinbase,
|
||||
# let it mature, then try to spend it.
|
||||
|
||||
block = self.build_next_block(version=1)
|
||||
block = self.build_next_block()
|
||||
block.solve()
|
||||
self.test_node.send_and_ping(msg_no_witness_block(block)) # make sure the block was processed
|
||||
txid = block.vtx[0].sha256
|
||||
@ -337,8 +333,8 @@ class SegWitTest(BitcoinTestFramework):
|
||||
tx.rehash()
|
||||
assert tx.sha256 != tx.calc_sha256(with_witness=True)
|
||||
|
||||
# Construct a segwit-signaling block that includes the transaction.
|
||||
block = self.build_next_block(version=(VB_TOP_BITS | (1 << VB_WITNESS_BIT)))
|
||||
# Construct a block that includes the transaction.
|
||||
block = self.build_next_block()
|
||||
self.update_witness_block_with_transactions(block, [tx])
|
||||
# Sending witness data before activation is not allowed (anti-spam
|
||||
# rule).
|
||||
@ -365,7 +361,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# test_node has set NODE_WITNESS, so all getdata requests should be for
|
||||
# witness blocks.
|
||||
# Test announcing a block via inv results in a getdata, and that
|
||||
# announcing a version 4 or random VB block with a header results in a getdata
|
||||
# announcing a block with a header results in a getdata
|
||||
block1 = self.build_next_block()
|
||||
block1.solve()
|
||||
|
||||
@ -373,19 +369,13 @@ class SegWitTest(BitcoinTestFramework):
|
||||
assert self.test_node.last_message["getdata"].inv[0].type == blocktype
|
||||
test_witness_block(self.nodes[0], self.test_node, block1, True)
|
||||
|
||||
block2 = self.build_next_block(version=4)
|
||||
block2 = self.build_next_block()
|
||||
block2.solve()
|
||||
|
||||
self.test_node.announce_block_and_wait_for_getdata(block2, use_header=True)
|
||||
assert self.test_node.last_message["getdata"].inv[0].type == blocktype
|
||||
test_witness_block(self.nodes[0], self.test_node, block2, True)
|
||||
|
||||
block3 = self.build_next_block(version=(VB_TOP_BITS | (1 << 15)))
|
||||
block3.solve()
|
||||
self.test_node.announce_block_and_wait_for_getdata(block3, use_header=True)
|
||||
assert self.test_node.last_message["getdata"].inv[0].type == blocktype
|
||||
test_witness_block(self.nodes[0], self.test_node, block3, True)
|
||||
|
||||
# Check that we can getdata for witness blocks or regular blocks,
|
||||
# and the right thing happens.
|
||||
if not self.segwit_active:
|
||||
@ -430,7 +420,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
assert_equal(rpc_details["weight"], block.get_weight())
|
||||
|
||||
# Upgraded node should not ask for blocks from unupgraded
|
||||
block4 = self.build_next_block(version=4)
|
||||
block4 = self.build_next_block()
|
||||
block4.solve()
|
||||
self.old_node.getdataset = set()
|
||||
|
||||
|
Reference in New Issue
Block a user