mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
b07a7b810c
* Merge #11796: [tests] Functional test naming convention5fecd84
[tests] Remove redundant import in blocktools.py test (Anthony Towns)9b20bb4
[tests] Check tests conform to naming convention (Anthony Towns)7250b4e
[tests] README.md nit fixes (Anthony Towns)82b2712
[tests] move witness util functions to blocktools.py (John Newbery)1e10854
[tests] [docs] update README for new test naming scheme (John Newbery) Pull request description: Splitting #11774 into two parts -- this part updates the README with the proposed naming convention, and adds some checks to test_runner.py that the number of tests violating the naming convention doesn't increase too much. Idea is this part of the change should not introduce merge conflicts or require much rebasing, so reviews of the complicated bits won't become invalidated too often; while the second part will just be file renames, which will require regular rebasing and will introduce merge conflicts with pending PRs, but can be merged later, and should also be much easier to review, since it will only include relatively trivial changes. Tree-SHA512: b96557d41714addbbfe2aed62fb5a48639eaeb1eb3aba30ac1b3a86bb3cb8d796c6247f9c414c4695c4bf54c0ec9968ac88e2f88fb62483bc1a2f89368f7fc80 * update violation count Signed-off-by: pasta <pasta@dashboost.org> * Merge #11774: [tests] Rename functional tests6f881cc880
[tests] Remove EXPECTED_VIOLATION_COUNT (Anthony Towns)3150b3fea7
[tests] Rename misc functional tests. (Anthony Towns)81b79f2c39
[tests] Rename rpc_* functional tests. (Anthony Towns)61b8f7f273
[tests] Rename p2p_* functional tests. (Anthony Towns)90600bc7db
[tests] Rename wallet_* functional tests. (Anthony Towns)ca6523d0c8
[tests] Rename feature_* functional tests. (Anthony Towns) Pull request description: This PR changes the functional tests to have a consistent naming scheme: tests for individual RPC methods are named rpc_... tests for interfaces (REST, ZMQ, RPC features) are named interface_... tests that explicitly test the p2p interface are named p2p_... tests for wallet features are named wallet_... tests for mining features are named mining_... tests for mempool behaviour are named mempool_... tests for full features that aren't wallet/mining/mempool are named feature_... Rationale: it's sometimes difficult for new contributors to know what's already covered by existing tests and where new tests should be added. Naming in a consistent fashion makes it easier to see what's already covered at a glance. Tree-SHA512: 4246790552d42bbd95f6d5bdf67702b81b3b2c583ce7eaf1fe6d8e254721279b47315973c6e9ae82dad6e4c747f12188160764bf2624c0f8f3b4d39330ec8b16 * rename tests and edit associated strings to align test-suite with test name standards Signed-off-by: pasta <pasta@dashboost.org> * fix grammar in test/functional/test_runner.py Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com> * ci: Fix excluded test names * rename feature_privatesend.py to rpc_privatesend.py Signed-off-by: pasta <pasta@dashboost.org> Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com> Co-authored-by: MarcoFalke <falke.marco@gmail.com> Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com> Co-authored-by: xdustinface <xdustinfacex@gmail.com>
219 lines
9.1 KiB
Python
Executable File
219 lines
9.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2014-2016 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test logic for skipping signature validation on old blocks.
|
|
|
|
Test logic for skipping signature validation on blocks which we've assumed
|
|
valid (https://github.com/bitcoin/bitcoin/pull/9484)
|
|
|
|
We build a chain that includes and invalid signature for one of the
|
|
transactions:
|
|
|
|
0: genesis block
|
|
1: block 1 with coinbase transaction output.
|
|
2-101: bury that block with 100 blocks so the coinbase transaction
|
|
output can be spent
|
|
102: a block containing a transaction spending the coinbase
|
|
transaction output. The transaction has an invalid signature.
|
|
103-2202: bury the bad block with just over two weeks' worth of blocks
|
|
(2100 blocks)
|
|
|
|
Start three nodes:
|
|
|
|
- node0 has no -assumevalid parameter. Try to sync to block 2202. It will
|
|
reject block 102 and only sync as far as block 101
|
|
- node1 has -assumevalid set to the hash of block 102. Try to sync to
|
|
block 2202. node1 will sync all the way to block 2202.
|
|
- node2 has -assumevalid set to the hash of block 102. Try to sync to
|
|
block 200. node2 will reject block 102 since it's assumed valid, but it
|
|
isn't buried by at least two weeks' work.
|
|
"""
|
|
import time
|
|
|
|
from test_framework.blocktools import (create_block, create_coinbase)
|
|
from test_framework.key import CECKey
|
|
from test_framework.mininode import (CBlockHeader,
|
|
COutPoint,
|
|
CTransaction,
|
|
CTxIn,
|
|
CTxOut,
|
|
network_thread_join,
|
|
network_thread_start,
|
|
P2PInterface,
|
|
msg_block,
|
|
msg_headers)
|
|
from test_framework.script import (CScript, OP_TRUE)
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import (assert_equal, set_node_times)
|
|
|
|
class BaseNode(P2PInterface):
|
|
def send_header_for_blocks(self, new_blocks):
|
|
headers_message = msg_headers()
|
|
headers_message.headers = [CBlockHeader(b) for b in new_blocks]
|
|
self.send_message(headers_message)
|
|
|
|
class AssumeValidTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.setup_clean_chain = True
|
|
self.num_nodes = 3
|
|
self.extra_args = ["-dip3params=9000:9000", "-checkblockindex=0"]
|
|
|
|
def setup_network(self):
|
|
self.add_nodes(3)
|
|
# Start node0. We don't start the other nodes yet since
|
|
# we need to pre-mine a block with an invalid transaction
|
|
# signature so we can pass in the block hash as assumevalid.
|
|
self.start_node(0, extra_args=self.extra_args)
|
|
|
|
def send_blocks_until_disconnected(self, p2p_conn):
|
|
"""Keep sending blocks to the node until we're disconnected."""
|
|
for i in range(len(self.blocks)):
|
|
if p2p_conn.state != "connected":
|
|
break
|
|
try:
|
|
p2p_conn.send_message(msg_block(self.blocks[i]))
|
|
# TODO There is a race condition between send_message and on_close which causes an AttributError on Travis
|
|
# We can reenable the correct exception handling and the assert when Bitcoin 0.16 mininode.py changes have been
|
|
# backported
|
|
#except IOError as e:
|
|
except:
|
|
#assert str(e) == 'Not connected, no pushbuf'
|
|
break
|
|
|
|
def assert_blockchain_height(self, node, height):
|
|
"""Wait until the blockchain is no longer advancing and verify it's reached the expected height."""
|
|
last_height = node.getblock(node.getbestblockhash())['height']
|
|
timeout = 10
|
|
while True:
|
|
time.sleep(0.25)
|
|
current_height = node.getblock(node.getbestblockhash())['height']
|
|
if current_height != last_height:
|
|
last_height = current_height
|
|
if timeout < 0:
|
|
assert False, "blockchain too short after timeout: %d" % current_height
|
|
timeout - 0.25
|
|
continue
|
|
elif current_height > height:
|
|
assert False, "blockchain too long: %d" % current_height
|
|
elif current_height == height:
|
|
break
|
|
|
|
def run_test(self):
|
|
|
|
# Connect to node0
|
|
p2p0 = self.nodes[0].add_p2p_connection(BaseNode())
|
|
|
|
network_thread_start()
|
|
self.nodes[0].p2p.wait_for_verack()
|
|
|
|
# Build the blockchain
|
|
self.tip = int(self.nodes[0].getbestblockhash(), 16)
|
|
self.block_time = self.nodes[0].getblock(self.nodes[0].getbestblockhash())['time'] + 1
|
|
|
|
self.blocks = []
|
|
|
|
# Get a pubkey for the coinbase TXO
|
|
coinbase_key = CECKey()
|
|
coinbase_key.set_secretbytes(b"horsebattery")
|
|
coinbase_pubkey = coinbase_key.get_pubkey()
|
|
|
|
# Create the first block with a coinbase output to our key
|
|
height = 1
|
|
block = create_block(self.tip, create_coinbase(height, coinbase_pubkey), self.block_time)
|
|
self.blocks.append(block)
|
|
self.block_time += 1
|
|
block.solve()
|
|
# Save the coinbase for later
|
|
self.block1 = block
|
|
self.tip = block.sha256
|
|
height += 1
|
|
|
|
# Bury the block 100 deep so the coinbase output is spendable
|
|
for i in range(100):
|
|
block = create_block(self.tip, create_coinbase(height), self.block_time)
|
|
block.solve()
|
|
self.blocks.append(block)
|
|
self.tip = block.sha256
|
|
self.block_time += 1
|
|
height += 1
|
|
|
|
# Create a transaction spending the coinbase output with an invalid (null) signature
|
|
tx = CTransaction()
|
|
tx.vin.append(CTxIn(COutPoint(self.block1.vtx[0].sha256, 0), scriptSig=b""))
|
|
tx.vout.append(CTxOut(49 * 100000000, CScript([OP_TRUE])))
|
|
tx.calc_sha256()
|
|
|
|
block102 = create_block(self.tip, create_coinbase(height), self.block_time)
|
|
self.block_time += 1
|
|
block102.vtx.extend([tx])
|
|
block102.hashMerkleRoot = block102.calc_merkle_root()
|
|
block102.rehash()
|
|
block102.solve()
|
|
self.blocks.append(block102)
|
|
self.tip = block102.sha256
|
|
self.block_time += 1
|
|
height += 1
|
|
|
|
# Bury the assumed valid block 8400 deep (Dash needs 4x as much blocks to allow -assumevalid to work)
|
|
for i in range(8400):
|
|
block = create_block(self.tip, create_coinbase(height), self.block_time)
|
|
block.nVersion = 4
|
|
block.solve()
|
|
self.blocks.append(block)
|
|
self.tip = block.sha256
|
|
self.block_time += 1
|
|
height += 1
|
|
|
|
# We're adding new connections so terminate the network thread
|
|
self.nodes[0].disconnect_p2ps()
|
|
network_thread_join()
|
|
|
|
# Start node1 and node2 with assumevalid so they accept a block with a bad signature.
|
|
self.start_node(1, extra_args=self.extra_args + ["-assumevalid=" + hex(block102.sha256)])
|
|
self.start_node(2, extra_args=self.extra_args + ["-assumevalid=" + hex(block102.sha256)])
|
|
|
|
p2p0 = self.nodes[0].add_p2p_connection(BaseNode())
|
|
p2p1 = self.nodes[1].add_p2p_connection(BaseNode())
|
|
p2p2 = self.nodes[2].add_p2p_connection(BaseNode())
|
|
|
|
network_thread_start()
|
|
|
|
p2p0.wait_for_verack()
|
|
p2p1.wait_for_verack()
|
|
p2p2.wait_for_verack()
|
|
|
|
# Make sure nodes actually accept the many headers
|
|
self.mocktime = self.block_time
|
|
set_node_times(self.nodes, self.mocktime)
|
|
|
|
# send header lists to all three nodes.
|
|
# node0 does not need to receive all headers
|
|
# node1 must receive all headers as otherwise assumevalid is ignored in ConnectBlock
|
|
# node2 should NOT receive all headers to force skipping of the assumevalid check in ConnectBlock
|
|
p2p0.send_header_for_blocks(self.blocks[0:2000])
|
|
p2p1.send_header_for_blocks(self.blocks[0:2000])
|
|
p2p1.send_header_for_blocks(self.blocks[2000:4000])
|
|
p2p1.send_header_for_blocks(self.blocks[4000:6000])
|
|
p2p1.send_header_for_blocks(self.blocks[6000:8000])
|
|
p2p1.send_header_for_blocks(self.blocks[8000:])
|
|
p2p2.send_header_for_blocks(self.blocks[0:200])
|
|
|
|
# Send blocks to node0. Block 102 will be rejected.
|
|
self.send_blocks_until_disconnected(p2p0)
|
|
self.assert_blockchain_height(self.nodes[0], 101)
|
|
|
|
# Send 200 blocks to node1. All blocks, including block 102, will be accepted.
|
|
for i in range(200):
|
|
p2p1.send_message(msg_block(self.blocks[i]))
|
|
# Syncing so many blocks can take a while on slow systems. Give it plenty of time to sync.
|
|
p2p1.sync_with_ping(300)
|
|
assert_equal(self.nodes[1].getblock(self.nodes[1].getbestblockhash())['height'], 200)
|
|
|
|
# Send blocks to node2. Block 102 will be rejected.
|
|
self.send_blocks_until_disconnected(p2p2)
|
|
self.assert_blockchain_height(self.nodes[2], 101)
|
|
|
|
if __name__ == '__main__':
|
|
AssumeValidTest().main()
|