-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_cluster.py
55 lines (44 loc) · 1.9 KB
/
test_cluster.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
import unittest
from cluster import Cluster
from transaction import Transaction
class TestCluster(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 build_nop_cluster(self):
cluster = Cluster(self.testDict["nop"], 4000000)
cluster.addTx(self.testDict["qrs"])
cluster.addTx(self.testDict["tuv"])
return cluster
def test_get_best_candidate_set_with_limit(self):
cluster = self.build_nop_cluster()
best = cluster.getBestCandidateSet(100)
self.assertEqual(list(best.txs.keys()), ["nop"])
def test_assemble_ancestry(self):
cluster = self.build_nop_cluster()
nopAS = cluster.assembleAncestry('nop')
self.assertTrue('nop' in nopAS.txs.keys())
qrsAS = cluster.assembleAncestry('qrs')
self.assertTrue('nop' in qrsAS.txs.keys())
self.assertTrue('qrs' in qrsAS.txs.keys())
def test_get_best_candidate_set(self):
cluster = self.build_nop_cluster()
best = cluster.getBestCandidateSet(4000000)
self.assertEqual(sorted(list(best.txs.keys())), ["nop", "qrs"])
def test_remove_candidate_set_links(self):
cluster = self.build_nop_cluster()
best = cluster.getBestCandidateSet(4000000)
cluster.removeCandidateSetLinks(best)
for txid, tx in cluster.txs.items():
print(tx)
def test_export(self):
cluster = self.build_nop_cluster()
cluster.export()
if __name__ == '__main__':
unittest.main()