mirror of
https://github.com/logos-co/nomos-specs.git
synced 2025-01-24 14:29:52 +00:00
f635996d10
* Start implementing TreeOverlay * Implement tree overlay * Add basic tests * Fixes * Fill leaves with extra nodes one by one * Handle missing optional value * Parenting fixes * Parenting tests * Remove unnecesary number of committes * Fill from root committee * Adapt tests to root filling * Root parent is None * Typo: committee_idx * Fix leader supermajority threshold * Fix type signature on building committee data * Use plain carnot tree for carnot tree tests * Add tree implementation explanation * Fmt * Use blake2b * Fix idx signature on membership committees * Check on committee child existence
58 lines
2.1 KiB
Python
58 lines
2.1 KiB
Python
from unittest import TestCase
|
|
|
|
from tree_overlay import CarnotOverlay, CarnotTree
|
|
|
|
|
|
class TestCarnotTree(TestCase):
|
|
def setUp(self) -> None:
|
|
self.nodes = [int.to_bytes(i, length=32, byteorder="little") for i in range(10)]
|
|
self.tree = CarnotTree(self.nodes, 3)
|
|
|
|
def test_parenting(self):
|
|
root = self.tree.inner_committees[0]
|
|
one = self.tree.inner_committees[1]
|
|
two = self.tree.inner_committees[2]
|
|
self.assertIs(self.tree.parent_committee(one), root)
|
|
self.assertIs(self.tree.parent_committee(two), root)
|
|
|
|
def test_root_parenting(self):
|
|
root = self.tree.inner_committees[0]
|
|
self.assertIsNone(self.tree.parent_committee(root))
|
|
|
|
def test_childs(self):
|
|
root = self.tree.inner_committees[0]
|
|
one = self.tree.inner_committees[1]
|
|
two = self.tree.inner_committees[2]
|
|
self.assertEqual(self.tree.child_committees(root), (one, two))
|
|
|
|
|
|
class TestTreeOverlay(TestCase):
|
|
def setUp(self) -> None:
|
|
self.nodes = [int.to_bytes(i, length=32, byteorder="little") for i in range(10)]
|
|
self.tree = CarnotOverlay(self.nodes, self.nodes[0], b"0"*32, 3)
|
|
|
|
def test_leader(self):
|
|
self.assertEqual(self.tree.leader(), self.nodes[0])
|
|
|
|
def test_next_leader_is_advance_current_leader(self):
|
|
leader = self.tree.next_leader()
|
|
self.tree = self.tree.advance(b"1"*32)
|
|
self.assertEqual(leader, self.tree.leader())
|
|
|
|
def test_root_committee(self):
|
|
self.assertEqual(self.tree.root_committee(), set([self.nodes[9], *self.nodes[:3]]))
|
|
|
|
def test_leaf_committees(self):
|
|
self.assertEqual(self.tree.leaf_committees(), {frozenset(self.nodes[3:6]), frozenset(self.nodes[6:9])})
|
|
|
|
def test_super_majority_threshold_for_leaf(self):
|
|
self.assertEqual(self.tree.super_majority_threshold(self.nodes[-2]), 0)
|
|
|
|
def test_super_majority_threshold_for_root_member(self):
|
|
self.assertEqual(self.tree.super_majority_threshold(self.nodes[0]), 3)
|
|
|
|
def test_leader_super_majority_threshold(self):
|
|
self.assertEqual(self.tree.leader_super_majority_threshold(self.nodes[0]), 7)
|
|
|
|
|