mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +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>
134 lines
5.5 KiB
Python
Executable File
134 lines
5.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2018-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.
|
|
|
|
from test_framework.mininode import *
|
|
from test_framework.test_framework import DashTestFramework
|
|
from test_framework.util import isolate_node, reconnect_isolated_node, assert_equal, \
|
|
assert_raises_rpc_error
|
|
|
|
'''
|
|
p2p_instantsend.py
|
|
|
|
Tests InstantSend functionality (prevent doublespend for unconfirmed transactions)
|
|
'''
|
|
|
|
class InstantSendTest(DashTestFramework):
|
|
def set_test_params(self):
|
|
self.set_dash_test_params(7, 3, fast_dip3_enforcement=True)
|
|
# set sender, receiver, isolated nodes
|
|
self.isolated_idx = 1
|
|
self.receiver_idx = 2
|
|
self.sender_idx = 3
|
|
|
|
def run_test(self):
|
|
self.nodes[0].spork("SPORK_17_QUORUM_DKG_ENABLED", 0)
|
|
self.wait_for_sporks_same()
|
|
self.mine_quorum()
|
|
|
|
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.test_mempool_doublespend()
|
|
self.test_block_doublespend()
|
|
|
|
def test_block_doublespend(self):
|
|
sender = self.nodes[self.sender_idx]
|
|
receiver = self.nodes[self.receiver_idx]
|
|
isolated = self.nodes[self.isolated_idx]
|
|
|
|
# feed the sender with some balance
|
|
sender_addr = sender.getnewaddress()
|
|
self.nodes[0].sendtoaddress(sender_addr, 1)
|
|
self.bump_mocktime(1)
|
|
self.nodes[0].generate(2)
|
|
self.sync_all()
|
|
|
|
# create doublespending transaction, but don't relay it
|
|
dblspnd_tx = self.create_raw_tx(sender, isolated, 0.5, 1, 100)
|
|
# isolate one node from network
|
|
isolate_node(isolated)
|
|
# instantsend to receiver
|
|
receiver_addr = receiver.getnewaddress()
|
|
is_id = sender.sendtoaddress(receiver_addr, 0.9)
|
|
# wait for the transaction to propagate
|
|
connected_nodes = self.nodes.copy()
|
|
del connected_nodes[self.isolated_idx]
|
|
self.sync_mempools(connected_nodes)
|
|
for node in connected_nodes:
|
|
self.wait_for_instantlock(is_id, node)
|
|
# send doublespend transaction to isolated node
|
|
isolated.sendrawtransaction(dblspnd_tx['hex'])
|
|
# generate block on isolated node with doublespend transaction
|
|
self.bump_mocktime(1)
|
|
isolated.generate(1)
|
|
wrong_block = isolated.getbestblockhash()
|
|
# connect isolated block to network
|
|
reconnect_isolated_node(isolated, 0)
|
|
# check doublespend block is rejected by other nodes
|
|
timeout = 10
|
|
for i in range(0, self.num_nodes):
|
|
if i == self.isolated_idx:
|
|
continue
|
|
res = self.nodes[i].waitforblock(wrong_block, timeout)
|
|
assert (res['hash'] != wrong_block)
|
|
# wait for long time only for first node
|
|
timeout = 1
|
|
# send coins back to the controller node without waiting for confirmations
|
|
receiver.sendtoaddress(self.nodes[0].getnewaddress(), 0.9, "", "", True)
|
|
assert_equal(receiver.getwalletinfo()["balance"], 0)
|
|
# mine more blocks
|
|
# TODO: mine these blocks on an isolated node
|
|
self.bump_mocktime(1)
|
|
# make sure the above TX is on node0
|
|
self.sync_mempools([n for n in self.nodes if n is not isolated])
|
|
self.nodes[0].generate(2)
|
|
self.sync_all()
|
|
|
|
def test_mempool_doublespend(self):
|
|
sender = self.nodes[self.sender_idx]
|
|
receiver = self.nodes[self.receiver_idx]
|
|
isolated = self.nodes[self.isolated_idx]
|
|
|
|
# feed the sender with some balance
|
|
sender_addr = sender.getnewaddress()
|
|
self.nodes[0].sendtoaddress(sender_addr, 1)
|
|
self.bump_mocktime(1)
|
|
self.nodes[0].generate(2)
|
|
self.sync_all()
|
|
|
|
# create doublespending transaction, but don't relay it
|
|
dblspnd_tx = self.create_raw_tx(sender, isolated, 0.5, 1, 100)
|
|
dblspnd_txid = bytes_to_hex_str(hash256(hex_str_to_bytes(dblspnd_tx['hex']))[::-1])
|
|
# isolate one node from network
|
|
isolate_node(isolated)
|
|
# send doublespend transaction to isolated node
|
|
isolated.sendrawtransaction(dblspnd_tx['hex'])
|
|
# let isolated node rejoin the network
|
|
# The previously isolated node should NOT relay the doublespending TX
|
|
reconnect_isolated_node(isolated, 0)
|
|
for node in self.nodes:
|
|
if node is not isolated:
|
|
assert_raises_rpc_error(-5, "No such mempool or blockchain transaction", node.getrawtransaction, dblspnd_txid)
|
|
# instantsend to receiver. The previously isolated node should prune the doublespend TX and request the correct
|
|
# TX from other nodes.
|
|
receiver_addr = receiver.getnewaddress()
|
|
is_id = sender.sendtoaddress(receiver_addr, 0.9)
|
|
# wait for the transaction to propagate
|
|
self.sync_mempools()
|
|
for node in self.nodes:
|
|
self.wait_for_instantlock(is_id, node)
|
|
assert_raises_rpc_error(-5, "No such mempool or blockchain transaction", isolated.getrawtransaction, dblspnd_txid)
|
|
# send coins back to the controller node without waiting for confirmations
|
|
receiver.sendtoaddress(self.nodes[0].getnewaddress(), 0.9, "", "", True)
|
|
assert_equal(receiver.getwalletinfo()["balance"], 0)
|
|
# mine more blocks
|
|
self.bump_mocktime(1)
|
|
self.nodes[0].generate(2)
|
|
self.sync_all()
|
|
|
|
if __name__ == '__main__':
|
|
InstantSendTest().main()
|