|
9 | 9 | import struct
|
10 | 10 | import time
|
11 | 11 |
|
12 |
| -from test_framework.blocktools import create_block, create_coinbase, add_witness_commitment, get_witness_script, WITNESS_COMMITMENT_HEADER |
| 12 | +from test_framework.blocktools import create_block, create_coinbase, add_witness_commitment, WITNESS_COMMITMENT_HEADER |
13 | 13 | from test_framework.key import ECKey
|
14 | 14 | from test_framework.messages import (
|
15 | 15 | BIP125_SEQUENCE_NUMBER,
|
16 |
| - CBlock, |
17 | 16 | CBlockHeader,
|
18 | 17 | CInv,
|
19 | 18 | COutPoint,
|
@@ -209,24 +208,17 @@ def request_block(self, blockhash, inv_type, timeout=60):
|
209 | 208 | class SegWitTest(BitcoinTestFramework):
|
210 | 209 | def set_test_params(self):
|
211 | 210 | self.setup_clean_chain = True
|
212 |
| - self.num_nodes = 3 |
| 211 | + self.num_nodes = 2 |
213 | 212 | # This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
|
214 | 213 | self.extra_args = [
|
215 | 214 | [ "-acceptnonstdtxn=1", "-segwitheight={}". format( SEGWIT_HEIGHT), "[email protected]"],
|
216 | 215 | ["-acceptnonstdtxn=0", "-segwitheight={}".format(SEGWIT_HEIGHT)],
|
217 |
| - ["-acceptnonstdtxn=1", "-segwitheight=-1"], |
218 | 216 | ]
|
219 | 217 | self.supports_cli = False
|
220 | 218 |
|
221 | 219 | def skip_test_if_missing_module(self):
|
222 | 220 | self.skip_if_no_wallet()
|
223 | 221 |
|
224 |
| - def setup_network(self): |
225 |
| - self.setup_nodes() |
226 |
| - self.connect_nodes(0, 1) |
227 |
| - self.connect_nodes(0, 2) |
228 |
| - self.sync_all() |
229 |
| - |
230 | 222 | # Helper functions
|
231 | 223 |
|
232 | 224 | def build_next_block(self, version=4):
|
@@ -267,7 +259,6 @@ def run_test(self):
|
267 | 259 | self.test_non_witness_transaction()
|
268 | 260 | self.test_v0_outputs_arent_spendable()
|
269 | 261 | self.test_block_relay()
|
270 |
| - self.test_getblocktemplate_before_lockin() |
271 | 262 | self.test_unnecessary_witness_before_segwit_activation()
|
272 | 263 | self.test_witness_tx_relay_before_segwit_activation()
|
273 | 264 | self.test_standardness_v0()
|
@@ -295,7 +286,6 @@ def run_test(self):
|
295 | 286 | self.test_signature_version_1()
|
296 | 287 | self.test_non_standard_witness_blinding()
|
297 | 288 | self.test_non_standard_witness()
|
298 |
| - self.test_upgrade_after_activation() |
299 | 289 | self.test_witness_sigops()
|
300 | 290 | self.test_superfluous_witness()
|
301 | 291 | self.test_wtxid_relay()
|
@@ -485,11 +475,6 @@ def test_v0_outputs_arent_spendable(self):
|
485 | 475 | witness, and so can't be spent before segwit activation (the point at which
|
486 | 476 | blocks are permitted to contain witnesses)."""
|
487 | 477 |
|
488 |
| - # node2 doesn't need to be connected for this test. |
489 |
| - # (If it's connected, node0 may propagate an invalid block to it over |
490 |
| - # compact blocks and the nodes would have inconsistent tips.) |
491 |
| - self.disconnect_nodes(0, 2) |
492 |
| - |
493 | 478 | # Create two outputs, a p2wsh and p2sh-p2wsh
|
494 | 479 | witness_program = CScript([OP_TRUE])
|
495 | 480 | witness_hash = sha256(witness_program)
|
@@ -550,37 +535,9 @@ def test_v0_outputs_arent_spendable(self):
|
550 | 535 | # TODO: support multiple acceptable reject reasons.
|
551 | 536 | test_witness_block(self.nodes[0], self.test_node, block, accepted=False, with_witness=False)
|
552 | 537 |
|
553 |
| - self.connect_nodes(0, 2) |
554 |
| - |
555 | 538 | self.utxo.pop(0)
|
556 | 539 | self.utxo.append(UTXO(txid, 2, value))
|
557 | 540 |
|
558 |
| - @subtest # type: ignore |
559 |
| - def test_getblocktemplate_before_lockin(self): |
560 |
| - txid = int(self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1), 16) |
561 |
| - |
562 |
| - for node in [self.nodes[0], self.nodes[2]]: |
563 |
| - gbt_results = node.getblocktemplate({"rules": ["segwit"]}) |
564 |
| - if node == self.nodes[2]: |
565 |
| - # If this is a non-segwit node, we should not get a witness |
566 |
| - # commitment. |
567 |
| - assert 'default_witness_commitment' not in gbt_results |
568 |
| - else: |
569 |
| - # For segwit-aware nodes, check the witness |
570 |
| - # commitment is correct. |
571 |
| - assert 'default_witness_commitment' in gbt_results |
572 |
| - witness_commitment = gbt_results['default_witness_commitment'] |
573 |
| - |
574 |
| - # Check that default_witness_commitment is present. |
575 |
| - witness_root = CBlock.get_merkle_root([ser_uint256(0), |
576 |
| - ser_uint256(txid)]) |
577 |
| - script = get_witness_script(witness_root, 0) |
578 |
| - assert_equal(witness_commitment, script.hex()) |
579 |
| - |
580 |
| - # Clear out the mempool |
581 |
| - self.nodes[0].generate(1) |
582 |
| - self.sync_blocks() |
583 |
| - |
584 | 541 | @subtest # type: ignore
|
585 | 542 | def test_witness_tx_relay_before_segwit_activation(self):
|
586 | 543 |
|
@@ -1952,39 +1909,6 @@ def test_non_standard_witness(self):
|
1952 | 1909 |
|
1953 | 1910 | self.utxo.pop(0)
|
1954 | 1911 |
|
1955 |
| - @subtest # type: ignore |
1956 |
| - def test_upgrade_after_activation(self): |
1957 |
| - """Test the behavior of starting up a segwit-aware node after the softfork has activated.""" |
1958 |
| - |
1959 |
| - # All nodes are caught up and node 2 is a pre-segwit node that will soon upgrade. |
1960 |
| - for n in range(2): |
1961 |
| - assert_equal(self.nodes[n].getblockcount(), self.nodes[2].getblockcount()) |
1962 |
| - assert softfork_active(self.nodes[n], "segwit") |
1963 |
| - assert SEGWIT_HEIGHT < self.nodes[2].getblockcount() |
1964 |
| - assert 'segwit' not in self.nodes[2].getblockchaininfo()['softforks'] |
1965 |
| - |
1966 |
| - # Restarting node 2 should result in a shutdown because the blockchain consists of |
1967 |
| - # insufficiently validated blocks per segwit consensus rules. |
1968 |
| - self.stop_node(2) |
1969 |
| - self.nodes[2].assert_start_raises_init_error( |
1970 |
| - extra_args=[f"-segwitheight={SEGWIT_HEIGHT}"], |
1971 |
| - expected_msg=f": Witness data for blocks after height {SEGWIT_HEIGHT} requires validation. Please restart with -reindex..\nPlease restart with -reindex or -reindex-chainstate to recover.", |
1972 |
| - ) |
1973 |
| - |
1974 |
| - # As directed, the user restarts the node with -reindex |
1975 |
| - self.start_node(2, extra_args=["-reindex", f"-segwitheight={SEGWIT_HEIGHT}"]) |
1976 |
| - |
1977 |
| - # With the segwit consensus rules, the node is able to validate only up to SEGWIT_HEIGHT - 1 |
1978 |
| - assert_equal(self.nodes[2].getblockcount(), SEGWIT_HEIGHT - 1) |
1979 |
| - self.connect_nodes(0, 2) |
1980 |
| - |
1981 |
| - # We reconnect more than 100 blocks, give it plenty of time |
1982 |
| - # sync_blocks() also verifies the best block hash is the same for all nodes |
1983 |
| - self.sync_blocks(timeout=240) |
1984 |
| - |
1985 |
| - # The upgraded node should now have segwit activated |
1986 |
| - assert softfork_active(self.nodes[2], "segwit") |
1987 |
| - |
1988 | 1912 | @subtest # type: ignore
|
1989 | 1913 | def test_witness_sigops(self):
|
1990 | 1914 | """Test sigop counting is correct inside witnesses."""
|
|
0 commit comments