forked from syscoin/syscoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_llmqdkgerrors.py
executable file
·102 lines (83 loc) · 4.57 KB
/
feature_llmqdkgerrors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/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.
from test_framework.test_framework import DashTestFramework
from test_framework.util import force_finish_mnsync
'''
feature_llmqdkgerrors.py
Simulate and check DKG errors
'''
class LLMQDKGErrors(DashTestFramework):
def set_test_params(self):
self.set_dash_test_params(4, 3, [["[email protected]"]] * 4, fast_dip3_enforcement=True)
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self):
self.sync_blocks(self.nodes, timeout=60*5)
self.confirm_mns()
for i in range(len(self.nodes)):
force_finish_mnsync(self.nodes[i])
self.nodes[0].spork("SPORK_17_QUORUM_DKG_ENABLED", 0)
self.wait_for_sporks_same()
self.log.info("Mine one quorum without simulating any errors")
qh = self.mine_quorum()
self.assert_member_valid(qh, self.mninfo[0].proTxHash, True)
self.log.info("Lets omit the contribution")
self.mninfo[0].node.quorum_dkgsimerror('contribution-omit', 1)
qh = self.mine_quorum(expected_contributions=2)
self.assert_member_valid(qh, self.mninfo[0].proTxHash, False)
self.log.info("Lets lie in the contribution but provide a correct justification")
self.mninfo[0].node.quorum_dkgsimerror('contribution-omit', 0)
self.mninfo[0].node.quorum_dkgsimerror('contribution-lie', 1)
qh = self.mine_quorum(expected_contributions=3, expected_complaints=2, expected_justifications=1)
self.assert_member_valid(qh, self.mninfo[0].proTxHash, True)
self.log.info("Lets lie in the contribution and then omit the justification")
self.mninfo[0].node.quorum_dkgsimerror('justify-omit', 1)
qh = self.mine_quorum(expected_contributions=3, expected_complaints=2)
self.assert_member_valid(qh, self.mninfo[0].proTxHash, False)
self.log.info("Heal some damage (don't get PoSe banned)")
self.heal_masternodes(33)
self.log.info("Lets lie in the contribution and then also lie in the justification")
self.mninfo[0].node.quorum_dkgsimerror('justify-omit', 0)
self.mninfo[0].node.quorum_dkgsimerror('justify-lie', 1)
qh = self.mine_quorum(expected_contributions=3, expected_complaints=2, expected_justifications=1)
self.assert_member_valid(qh, self.mninfo[0].proTxHash, False)
self.log.info("Lets lie about another MN")
self.mninfo[0].node.quorum_dkgsimerror('contribution-lie', 0)
self.mninfo[0].node.quorum_dkgsimerror('justify-lie', 0)
self.mninfo[0].node.quorum_dkgsimerror('complain-lie', 1)
qh = self.mine_quorum(expected_contributions=3, expected_complaints=1, expected_justifications=2)
self.assert_member_valid(qh, self.mninfo[0].proTxHash, True)
self.log.info("Lets omit 1 premature commitments")
self.mninfo[0].node.quorum_dkgsimerror('complain-lie', 0)
self.mninfo[0].node.quorum_dkgsimerror('commit-omit', 1)
qh = self.mine_quorum(expected_contributions=3, expected_complaints=0, expected_justifications=0, expected_commitments=2)
self.assert_member_valid(qh, self.mninfo[0].proTxHash, True)
self.log.info("Lets lie in 1 premature commitments")
self.mninfo[0].node.quorum_dkgsimerror('commit-omit', 0)
self.mninfo[0].node.quorum_dkgsimerror('commit-lie', 1)
qh = self.mine_quorum(expected_contributions=3, expected_complaints=0, expected_justifications=0, expected_commitments=2)
self.assert_member_valid(qh, self.mninfo[0].proTxHash, True)
def assert_member_valid(self, quorumHash, proTxHash, expectedValid):
q = self.nodes[0].quorum_info(100, quorumHash, True)
for m in q['members']:
if m['proTxHash'] == proTxHash:
if expectedValid:
assert(m['valid'])
else:
assert(not m['valid'])
else:
assert(m['valid'])
def heal_masternodes(self, blockCount):
# We're not testing PoSe here, so lets heal the MNs :)
self.nodes[0].spork("SPORK_17_QUORUM_DKG_ENABLED", 4070908800)
self.wait_for_sporks_same()
for i in range(blockCount):
self.bump_mocktime(1)
self.generate(self.nodes[0], 1)
self.sync_all()
self.nodes[0].spork("SPORK_17_QUORUM_DKG_ENABLED", 0)
self.wait_for_sporks_same()
if __name__ == '__main__':
LLMQDKGErrors().main()