mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +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>
163 lines
7.4 KiB
Python
Executable File
163 lines
7.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2015-2020 The Dash Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
import time
|
|
|
|
from test_framework.mininode import *
|
|
from test_framework.test_framework import DashTestFramework
|
|
from test_framework.util import *
|
|
|
|
'''
|
|
feature_llmq_chainlocks.py
|
|
|
|
Checks LLMQs based ChainLocks
|
|
|
|
'''
|
|
|
|
class LLMQChainLocksTest(DashTestFramework):
|
|
def set_test_params(self):
|
|
self.set_dash_test_params(4, 3, fast_dip3_enforcement=True)
|
|
self.set_dash_dip8_activation(10)
|
|
|
|
def run_test(self):
|
|
|
|
# Connect all nodes to node1 so that we always have the whole network connected
|
|
# Otherwise only masternode connections will be established between nodes, which won't propagate TXs/blocks
|
|
# Usually node0 is the one that does this, but in this test we isolate it multiple times
|
|
for i in range(len(self.nodes)):
|
|
if i != 1:
|
|
connect_nodes(self.nodes[i], 1)
|
|
|
|
self.log.info("Wait for dip0008 activation")
|
|
|
|
while self.nodes[0].getblockchaininfo()["bip9_softforks"]["dip0008"]["status"] != "active":
|
|
self.nodes[0].generate(10)
|
|
self.sync_blocks(self.nodes, timeout=60*5)
|
|
|
|
self.nodes[0].spork("SPORK_17_QUORUM_DKG_ENABLED", 0)
|
|
self.wait_for_sporks_same()
|
|
|
|
self.log.info("Mining 4 quorums")
|
|
for i in range(4):
|
|
self.mine_quorum()
|
|
|
|
self.nodes[0].spork("SPORK_19_CHAINLOCKS_ENABLED", 0)
|
|
self.wait_for_sporks_same()
|
|
|
|
self.log.info("Mine single block, wait for chainlock")
|
|
self.nodes[0].generate(1)
|
|
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
|
|
|
|
self.log.info("Mine many blocks, wait for chainlock")
|
|
self.nodes[0].generate(20)
|
|
# We need more time here due to 20 blocks being generated at once
|
|
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash(), timeout=30)
|
|
|
|
self.log.info("Assert that all blocks up until the tip are chainlocked")
|
|
for h in range(1, self.nodes[0].getblockcount()):
|
|
block = self.nodes[0].getblock(self.nodes[0].getblockhash(h))
|
|
assert(block['chainlock'])
|
|
|
|
self.log.info("Isolate node, mine on another, and reconnect")
|
|
isolate_node(self.nodes[0])
|
|
node0_mining_addr = self.nodes[0].getnewaddress()
|
|
node0_tip = self.nodes[0].getbestblockhash()
|
|
self.nodes[1].generatetoaddress(5, node0_mining_addr)
|
|
self.wait_for_chainlocked_block(self.nodes[1], self.nodes[1].getbestblockhash())
|
|
assert(self.nodes[0].getbestblockhash() == node0_tip)
|
|
reconnect_isolated_node(self.nodes[0], 1)
|
|
self.nodes[1].generatetoaddress(1, node0_mining_addr)
|
|
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[1].getbestblockhash())
|
|
|
|
self.log.info("Isolate node, mine on both parts of the network, and reconnect")
|
|
isolate_node(self.nodes[0])
|
|
self.nodes[0].generate(5)
|
|
self.nodes[1].generatetoaddress(1, node0_mining_addr)
|
|
good_tip = self.nodes[1].getbestblockhash()
|
|
self.wait_for_chainlocked_block(self.nodes[1], good_tip)
|
|
assert(not self.nodes[0].getblock(self.nodes[0].getbestblockhash())["chainlock"])
|
|
reconnect_isolated_node(self.nodes[0], 1)
|
|
self.nodes[1].generatetoaddress(1, node0_mining_addr)
|
|
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[1].getbestblockhash())
|
|
assert(self.nodes[0].getblock(self.nodes[0].getbestblockhash())["previousblockhash"] == good_tip)
|
|
assert(self.nodes[1].getblock(self.nodes[1].getbestblockhash())["previousblockhash"] == good_tip)
|
|
|
|
self.log.info("Keep node connected and let it try to reorg the chain")
|
|
good_tip = self.nodes[0].getbestblockhash()
|
|
self.log.info("Restart it so that it forgets all the chainlocks from the past")
|
|
self.stop_node(0)
|
|
self.start_node(0)
|
|
connect_nodes(self.nodes[0], 1)
|
|
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
|
|
self.log.info("Now try to reorg the chain")
|
|
self.nodes[0].generate(2)
|
|
time.sleep(6)
|
|
assert(self.nodes[1].getbestblockhash() == good_tip)
|
|
self.nodes[0].generate(2)
|
|
time.sleep(6)
|
|
assert(self.nodes[1].getbestblockhash() == good_tip)
|
|
|
|
self.log.info("Now let the node which is on the wrong chain reorg back to the locked chain")
|
|
self.nodes[0].reconsiderblock(good_tip)
|
|
assert(self.nodes[0].getbestblockhash() != good_tip)
|
|
self.nodes[1].generatetoaddress(1, node0_mining_addr)
|
|
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[1].getbestblockhash())
|
|
assert(self.nodes[0].getbestblockhash() == self.nodes[1].getbestblockhash())
|
|
|
|
self.log.info("Enable LLMQ bases InstantSend, which also enables checks for \"safe\" transactions")
|
|
self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 0)
|
|
self.nodes[0].spork("SPORK_3_INSTANTSEND_BLOCK_FILTERING", 0)
|
|
self.wait_for_sporks_same()
|
|
|
|
self.log.info("Isolate a node and let it create some transactions which won't get IS locked")
|
|
isolate_node(self.nodes[0])
|
|
txs = []
|
|
for i in range(3):
|
|
txs.append(self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1))
|
|
txs += self.create_chained_txs(self.nodes[0], 1)
|
|
self.log.info("Assert that after block generation these TXs are NOT included (as they are \"unsafe\")")
|
|
self.nodes[0].generate(1)
|
|
for txid in txs:
|
|
tx = self.nodes[0].getrawtransaction(txid, 1)
|
|
assert("confirmations" not in tx)
|
|
time.sleep(1)
|
|
assert(not self.nodes[0].getblock(self.nodes[0].getbestblockhash())["chainlock"])
|
|
self.log.info("Disable LLMQ based InstantSend for a very short time (this never gets propagated to other nodes)")
|
|
self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 4070908800)
|
|
self.log.info("Now the TXs should be included")
|
|
self.nodes[0].generate(1)
|
|
self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 0)
|
|
self.log.info("Assert that TXs got included now")
|
|
for txid in txs:
|
|
tx = self.nodes[0].getrawtransaction(txid, 1)
|
|
assert("confirmations" in tx and tx["confirmations"] > 0)
|
|
# Enable network on first node again, which will cause the blocks to propagate and IS locks to happen retroactively
|
|
# for the mined TXs, which will then allow the network to create a CLSIG
|
|
self.log.info("Reenable network on first node and wait for chainlock")
|
|
reconnect_isolated_node(self.nodes[0], 1)
|
|
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[0].getbestblockhash(), timeout=30)
|
|
|
|
def create_chained_txs(self, node, amount):
|
|
txid = node.sendtoaddress(node.getnewaddress(), amount)
|
|
tx = node.getrawtransaction(txid, 1)
|
|
inputs = []
|
|
valueIn = 0
|
|
for txout in tx["vout"]:
|
|
inputs.append({"txid": txid, "vout": txout["n"]})
|
|
valueIn += txout["value"]
|
|
outputs = {
|
|
node.getnewaddress(): round(float(valueIn) - 0.0001, 6)
|
|
}
|
|
|
|
rawtx = node.createrawtransaction(inputs, outputs)
|
|
rawtx = node.signrawtransaction(rawtx)
|
|
rawtxid = node.sendrawtransaction(rawtx["hex"])
|
|
|
|
return [txid, rawtxid]
|
|
|
|
|
|
if __name__ == '__main__':
|
|
LLMQChainLocksTest().main()
|