-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_candidateset.py
51 lines (41 loc) · 2.13 KB
/
test_candidateset.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
import unittest
from candidateset import CandidateSet
from transaction import Transaction
class TestCandidateSet(unittest.TestCase):
def setUp(self):
self.testDict = {
"123": Transaction("123", 100, 100, [], ["abc"]),
"abc": Transaction("abc", 100, 100, ["123"], []),
"nop": Transaction("nop", 1000, 100, [], ["qrs"]), # medium feerate
"qrs": Transaction("qrs", 10000, 100, ["nop"], ["tuv"]), # high feerate
"tuv": Transaction("tuv", 100, 100, ["qrs"], []), # low feerate
"xyz": Transaction("xyz", 10, 10, [], [])
}
def test_valid_candidate_set(self):
CandidateSet({"123": self.testDict["123"], "abc": self.testDict["abc"]})
def test_missing_ancestor_candidate_set(self):
self.assertRaises(TypeError, CandidateSet, {"abc": self.testDict["abc"]})
def test_candidate_set_equivalence(self):
cs = CandidateSet({"123": self.testDict["123"]})
other = CandidateSet({"123": self.testDict["123"]})
self.assertTrue(cs == other)
def test_fail_candidate_set_equivalence(self):
cs = CandidateSet({"nop": self.testDict["nop"]})
other = CandidateSet({"123": self.testDict["123"]})
self.assertFalse(cs == other)
def test_candidate_set_get_weight(self):
cand = CandidateSet({"123": self.testDict["123"], "abc": self.testDict["abc"]})
self.assertEqual(cand.get_weight(), 200)
def test_candidate_set_get_fees(self):
cand = CandidateSet({"123": self.testDict["123"], "abc": self.testDict["abc"]})
self.assertEqual(cand.get_fees(), 200)
def test_candidate_set_get_effective_feerate(self):
cand = CandidateSet({"123": self.testDict["123"], "abc": self.testDict["abc"]})
self.assertEqual(cand.get_feerate(), 1)
def test_candidate_set_get_effective_feerate_can_be_float(self):
cand = CandidateSet({"123": self.testDict["123"], "abc": self.testDict["abc"]})
self.testDict['123'].fee = 25
print('cand for feeRate: ' + str(cand))
self.assertEqual(cand.get_feerate(), 0.625)
if __name__ == '__main__':
unittest.main()