Skip to content

Commit e52763d

Browse files
UdjinM6codablock
authored andcommitted
Refactor and fix instantsend tests/utils (#2776)
* Unify autoIS/send_smth functions * Rename autoix-mempool.py -> autois-mempool.py * Make sure create_raw_trx produces expected results * Make sure sender has enough inputs and nodes are synced before starting the actual test * Mine one block to clean mempool up * 2 blocks is enough for IS on regtest This also unifies it across different IS tests * Allow wait_for_instantlock to be called on any node, not only on the one that has the tx in the wallet * No need to query for tx this often in wait_for_instantlock * Rename create_raw_trx -> create_raw_tx * Fund sender with a single TX instead of 30
1 parent 2575e92 commit e52763d

File tree

6 files changed

+251
-320
lines changed

6 files changed

+251
-320
lines changed

qa/pull-tester/rpc-tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'fundrawtransaction.py',
3737
'fundrawtransaction-hd.py',
3838
'p2p-autoinstantsend.py',
39-
'autoix-mempool.py',
39+
'autois-mempool.py',
4040
# vv Tests less than 2m vv
4141
'p2p-instantsend.py',
4242
'wallet.py',

qa/rpc-tests/autois-mempool.py

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018 The Dash Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
from test_framework.mininode import *
7+
from test_framework.test_framework import DashTestFramework
8+
from test_framework.util import *
9+
from time import *
10+
11+
'''
12+
autois-mempool.py
13+
14+
Checks if automatic InstantSend locks stop working when transaction mempool
15+
is full (more than 0.1 part from max value).
16+
17+
'''
18+
19+
MAX_MEMPOOL_SIZE = 1 # max node mempool in MBs
20+
MB_SIZE = 1000000 # C++ code use this coefficient to calc MB in mempool
21+
AUTO_IX_MEM_THRESHOLD = 0.1
22+
23+
24+
class AutoISMempoolTest(DashTestFramework):
25+
def __init__(self):
26+
super().__init__(8, 5, ["-maxmempool=%d" % MAX_MEMPOOL_SIZE, '-limitdescendantsize=10'], fast_dip3_enforcement=True)
27+
# set sender, receiver
28+
self.receiver_idx = 1
29+
self.sender_idx = 2
30+
31+
def get_mempool_usage(self, node):
32+
info = node.getmempoolinfo()
33+
return info['usage']
34+
35+
def fill_mempool(self):
36+
# send lots of txes to yourself just to fill the mempool
37+
counter = 0
38+
sync_period = 10
39+
dummy_address = self.nodes[0].getnewaddress()
40+
while self.get_mempool_usage(self.nodes[self.sender_idx]) < MAX_MEMPOOL_SIZE * MB_SIZE * AUTO_IX_MEM_THRESHOLD:
41+
self.nodes[0].sendtoaddress(dummy_address, 1.0)
42+
counter += 1
43+
if counter % sync_period == 0:
44+
# sync nodes
45+
self.sync_all()
46+
self.sync_all()
47+
48+
def run_test(self):
49+
# make sure masternodes are synced
50+
sync_masternodes(self.nodes)
51+
52+
self.nodes[0].spork("SPORK_17_QUORUM_DKG_ENABLED", 0)
53+
self.wait_for_sporks_same()
54+
self.mine_quorum()
55+
56+
self.log.info("Test old InstantSend")
57+
self.test_auto();
58+
59+
self.nodes[0].spork("SPORK_20_INSTANTSEND_LLMQ_BASED", 0)
60+
self.wait_for_sporks_same()
61+
62+
self.log.info("Test new InstantSend")
63+
self.test_auto(True);
64+
65+
def test_auto(self, new_is = False):
66+
self.activate_autois_bip9(self.nodes[0])
67+
self.set_autois_spork_state(self.nodes[0], True)
68+
69+
# check pre-conditions for autoIS
70+
assert(self.get_autois_bip9_status(self.nodes[0]) == 'active')
71+
assert(self.get_autois_spork_state(self.nodes[0]))
72+
73+
# create 3 inputs for txes on sender node and give them enough confirmations
74+
sender = self.nodes[self.sender_idx]
75+
receiver = self.nodes[self.receiver_idx]
76+
sender_address = sender.getnewaddress()
77+
for i in range(0, 4):
78+
self.nodes[0].sendtoaddress(sender_address, 2.0)
79+
for i in range(0, 2):
80+
set_mocktime(get_mocktime() + 1)
81+
set_node_times(self.nodes, get_mocktime())
82+
self.nodes[0].generate(1)
83+
self.sync_all()
84+
85+
# autoIS is working
86+
assert(self.send_simple_tx(sender, receiver))
87+
88+
# fill mempool with transactions
89+
self.set_autois_spork_state(self.nodes[0], False)
90+
self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 4070908800)
91+
self.wait_for_sporks_same()
92+
self.fill_mempool()
93+
self.set_autois_spork_state(self.nodes[0], True)
94+
self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 0)
95+
self.wait_for_sporks_same()
96+
97+
# autoIS is not working now
98+
assert(not self.send_simple_tx(sender, receiver))
99+
# regular IS is still working for old IS but not for new one
100+
assert(not self.send_regular_instantsend(sender, receiver, False) if new_is else self.send_regular_instantsend(sender, receiver))
101+
102+
# generate one block to clean up mempool and retry auto and regular IS
103+
# generate 2 more blocks to have enough confirmations for IS
104+
self.nodes[0].generate(3)
105+
self.sync_all()
106+
assert(self.send_simple_tx(sender, receiver))
107+
assert(self.send_regular_instantsend(sender, receiver, not new_is))
108+
109+
110+
if __name__ == '__main__':
111+
AutoISMempoolTest().main()

qa/rpc-tests/autoix-mempool.py

-185
This file was deleted.

0 commit comments

Comments
 (0)