this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add proper mst diffing test

+51 -1
+7 -1
README.md
··· 1 1 # atmst 2 2 3 - ![Static Badge](https://img.shields.io/badge/license-MIT-blue) ![Static Badge](https://img.shields.io/badge/works%20on%20my%20machine-green) ![Static Badge](https://img.shields.io/badge/test%20coverage-0%25-red) ![Static Badge](https://img.shields.io/badge/docs-maybe%20one%20day-red) ![Static Badge](https://img.shields.io/badge/cryptography-certified%20hand--rolled-yellow) 3 + ![Static Badge](https://img.shields.io/badge/license-MIT-blue) ![Static Badge](https://img.shields.io/badge/works%20on%20my%20machine-forestgreen) ![Static Badge](https://img.shields.io/badge/test%20coverage-0%25-red) ![Static Badge](https://img.shields.io/badge/docs-maybe%20one%20day-red) ![Static Badge](https://img.shields.io/badge/cryptography-certified%20hand--rolled-yellow) 4 4 5 5 A Python library for wrangling atproto-flavoured Merkle Search Trees 6 6 ··· 18 18 19 19 ``` 20 20 python3 -m pip install -e . 21 + ``` 22 + 23 + Running the tests: 24 + 25 + ``` 26 + python3 -m unittest discover -v 21 27 ``` 22 28 23 29 build the docs:
tests/__init__.py

This is a binary file and will not be displayed.

+44
tests/test_mst_diff.py
··· 1 + import unittest 2 + 3 + from atmst import MemoryBlockStore, NodeStore, NodeWrangler, mst_diff, very_slow_mst_diff 4 + from atmst.mst.node import MSTNode 5 + from atmst.util import hash_to_cid 6 + 7 + class MSTDiffTestCase(unittest.TestCase): 8 + def setUp(self): 9 + keys = [] 10 + dummy_value = hash_to_cid(b"value") 11 + i = 0 12 + for height in [0, 1, 0, 2, 0, 1, 0]: # if all these keys are added to a MST, it'll form a perfect binary tree. 13 + while True: 14 + key = f"{i:04d}" 15 + i += 1 16 + if MSTNode.key_height(key) == height: 17 + keys.append(key) 18 + break 19 + 20 + bs = MemoryBlockStore() 21 + self.ns = NodeStore(bs) 22 + wrangler = NodeWrangler(self.ns) 23 + 24 + # create all possible permutations of the full binary tree 25 + # the idea is that this'll cover most "interesting" trees up to a height of 3 26 + 27 + self.trees = [] 28 + for i in range(2**len(keys)): 29 + root = self.ns.get_node(None).cid 30 + for j, k in enumerate(keys): 31 + if (i>>j)&1: 32 + root = wrangler.put_record(root, k, dummy_value) 33 + self.trees.append(root) 34 + 35 + def test_diff_all_pairs(self): 36 + for a in self.trees: 37 + for b in self.trees: 38 + reference_created, reference_deleted = very_slow_mst_diff(self.ns, a, b) 39 + created, deleted = mst_diff(self.ns, a, b) 40 + self.assertEqual(created, reference_created) 41 + self.assertEqual(deleted, reference_deleted) 42 + 43 + if __name__ == '__main__': 44 + unittest.main()