-
Notifications
You must be signed in to change notification settings - Fork 11
/
liskpool3_unittest.py
130 lines (106 loc) · 3.81 KB
/
liskpool3_unittest.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import unittest
import liskpool3
class TestAddressToBinary(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(TestAddressToBinary, self).__init__(*args, **kwargs)
def test_1(self):
self.assertEqual(liskpool3.addressToBinary("lsks4bdyynsyxxrxxgractch2v6jen8xxsrmc47b8"), "da4da8c4fb88432087f2c8e63ee04ae58ef08772")
class TestGetVotesPercentages(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(TestGetVotesPercentages, self).__init__(*args, **kwargs)
def test_blacklist(self):
def mockedReq(conf, ep):
return {
"data": {
"votes": [
{"address": "A",
"amount": "10000000"},
{"address": "B",
"amount": "10000000"},
]
},
"meta": {
"total": 2
}
}
liskpool3.injectRequestHandler(mockedReq)
conf = {
"blackList": ["A"],
"delegateName": "C",
"includeSelfStake": False
}
res = liskpool3.getVotesPercentages(conf)
self.assertEqual(
res, [{'address': 'B', 'amount': '10000000', 'percentage': 100.0}])
def test_blacklistEmpty(self):
def mockedReq(conf, ep):
return {
"data": {
"votes": [
{"address": "A",
"amount": "10000000"},
{"address": "B",
"amount": "10000000"},
]
},
"meta": {
"total": 2
}
}
liskpool3.injectRequestHandler(mockedReq)
conf = {
"blackList": [],
"delegateName": "C",
"includeSelfStake": False
}
res = liskpool3.getVotesPercentages(conf)
self.assertEqual(res, [{'address': 'A', 'amount': '10000000', 'percentage': 50.0}, {
'address': 'B', 'amount': '10000000', 'percentage': 50.0}])
def test_includeSelfStakeFalse(self):
def mockedReq(conf, ep):
return {
"data": {
"votes": [
{"address": "A", "username": "A",
"amount": "10000000"},
{"address": "B",
"amount": "10000000"},
]
},
"meta": {
"total": 2
}
}
liskpool3.injectRequestHandler(mockedReq)
conf = {
"blackList": [],
"delegateName": "A",
"includeSelfStake": True
}
res = liskpool3.getVotesPercentages(conf)
self.assertEqual(res, [{'address': 'A', 'username': 'A', 'amount': '10000000', 'percentage': 50.0}, {'address': 'B', 'amount': '10000000', 'percentage': 50.0}])
def test_includeSelfStakeFalse(self):
def mockedReq(conf, ep):
return {
"data": {
"votes": [
{"address": "A", "username": "A",
"amount": "10000000"},
{"address": "B",
"amount": "10000000"},
]
},
"meta": {
"total": 2
}
}
liskpool3.injectRequestHandler(mockedReq)
conf = {
"blackList": [],
"delegateName": "A",
"includeSelfStake": False
}
res = liskpool3.getVotesPercentages(conf)
self.assertEqual(res, [{'address': 'B', 'amount': '10000000', 'percentage': 100.0}])
if __name__ == '__main__':
unittest.main()