From b704a0e9f1434560cf763687b64556e71f19c8ce Mon Sep 17 00:00:00 2001 From: SAIKAT KARMAKAR Date: Wed, 19 Jun 2024 13:10:07 +0530 Subject: [PATCH] fix: tests fixed. 2 more to go. error: Romve the forks is not working properly maybe --- src/mantaray_py/node.py | 7 ++-- tests/conftest.py | 3 +- tests/integration/test_int.py | 64 ++++++++++++++++++----------------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/mantaray_py/node.py b/src/mantaray_py/node.py index 90abd1c..43e585d 100644 --- a/src/mantaray_py/node.py +++ b/src/mantaray_py/node.py @@ -20,7 +20,7 @@ install() console = Console() -PATH_SEPARATOR = "/" +PATH_SEPARATOR = b"/" PATH_SEPARATOR_BYTE = 47 PADDING_BYTE = 0x0A NODE_SIZE = 255 @@ -49,7 +49,7 @@ def __eq__(self, other): @staticmethod def __create_metadata_padding(metadata_size_with_size: int) -> bytes: # can be done as bytes(0) as well - padding = b"" + padding: bytes = b"" node_headers_sizes: NodeHeaderSizes = NodeHeaderSizes() if metadata_size_with_size < node_headers_sizes.obfuscation_key: @@ -137,6 +137,7 @@ def deserialise( # ! FIXME: this condition should never happpen. Most likely some recursive fn. is breaking if node.forks is None: node.forks = {} + console.log(f"-->{node.forks=}") return cls(prefix=prefix, node=node) @@ -274,7 +275,7 @@ def __make_not_with_path_separator(self) -> None: self.__type = (NodeType.mask.value ^ NodeType.with_path_separator.value) & self.__type def __update_with_path_separator(self, path: bytes) -> None: - if b"/" in path[1:]: + if PATH_SEPARATOR in path[1:]: self.__make_with_path_separator() else: self.__make_not_with_path_separator() diff --git a/tests/conftest.py b/tests/conftest.py index 2041547..633f313 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,7 +18,8 @@ @pytest.fixture def get_sample_mantaray_node() -> dict[MantarayNode, bytes]: node = MantarayNode() - random_address = gen_32_bytes() + # random_address = gen_32_bytes() + random_address = bytes(bytearray([229, 5, 247, 157, 211, 167, 196, 164, 82, 13, 129, 139, 75, 95, 58, 43, 188, 41, 52, 27, 52, 221, 242, 140, 150, 81, 189, 90, 184, 120, 19, 31])) node.set_entry(random_address) path1 = "path1/valami/elso".encode() diff --git a/tests/integration/test_int.py b/tests/integration/test_int.py index 7bf4546..2378fec 100644 --- a/tests/integration/test_int.py +++ b/tests/integration/test_int.py @@ -28,7 +28,7 @@ def save_function(data: bytes) -> bytes: def create_load_function(bee_class: Bee) -> Callable: def load_function(address: bytes) -> bytes: - # console.print(f"{address.hex()=}") + console.print(f"{address.hex()=}") return bee_class.download_data(bytes_to_hex(address)).data return load_function @@ -104,7 +104,7 @@ async def test_should_generate_same_content_hash_as_bee(bee_class, get_debug_pos {"Content-Type": "image/png", "Filename": "icon.png"}, ) i_node.add_fork(b"/", bytes(32), {"website-index-document": "index.html"}) - + console.log(i_node.forks) save_function = create_save_function(bee_class, get_debug_postage) @@ -159,7 +159,7 @@ async def test_construct_manifests_of_testpage_folder(get_debug_postage, bee_cla ) i_node = MantarayNode() - console.log(i_node) + i_node.add_fork( b"index.html", hex_to_bytes(index_reference), @@ -193,8 +193,8 @@ async def test_construct_manifests_of_testpage_folder(get_debug_postage, bee_cla ) console.log(i_node.forks) - # save_function = create_save_function(bee_class, get_debug_postage) - # i_node_ref = i_node.save(save_function) + save_function = create_save_function(bee_class, get_debug_postage) + i_node_ref = i_node.save(save_function) assert list(i_node.forks.keys())[::-1] == list(node.forks.keys()) @@ -210,41 +210,43 @@ async def test_construct_manifests_of_testpage_folder(get_debug_postage, bee_cla assert i_node == node -# def test_remove_fork_then_upload(get_sample_mantaray_node, get_debug_postage, bee_class): -# sample_node = get_sample_mantaray_node -# node = sample_node['node'] -# path1 = sample_node['paths'][0] -# path2 = sample_node['paths'][1] +def test_remove_fork_then_upload( + get_sample_mantaray_node, get_debug_postage, bee_class +): + sample_node = get_sample_mantaray_node + node: MantarayNode = sample_node["node"] + path1 = sample_node["paths"][0] + path2 = sample_node["paths"][1] -# save_function = create_save_function(bee_class, get_debug_postage) -# # Save the sample node -# ref_original = node.save(save_function) + save_function = create_save_function(bee_class, get_debug_postage) + # Save the sample node + ref_original = node.save(save_function) -# check_node1 = node.get_fork_at_path(b'path1/valami/').node -# ref_check_node1 = check_node1.get_content_address() + check_node1 = node.get_fork_at_path(b"path1/valami/").node + ref_check_node1 = check_node1.get_content_address() -# # Current forks of the node -# assert list(check_node1.forks.keys()) == [path1[13], path2[13]] + # Current forks of the node + assert list(check_node1.forks.keys()) == [path1[13], path2[13]] -# # Remove the path and save the node -# node.remove_path(path2) + # Remove the path and save the node + node.remove_path(path2) -# ref_deleted = node.save(save_function) + ref_deleted = node.save(save_function) -# # Root reference should not remain the same -# assert ref_deleted != ref_original + # Root reference should not remain the same + assert ref_deleted != ref_original -# load_function = create_load_function(bee_class) -# # Load the node from the deleted reference -# node.load(load_function, ref_deleted) + load_function = create_load_function(bee_class) + # Load the node from the deleted reference + node.load(load_function, ref_deleted) -# # 'm' key of prefix table disappeared -# check_node2 = node.get_fork_at_path(b'path1/valami/').node -# assert list(check_node2.forks.keys()) == [path1[13]] + # 'm' key of prefix table disappeared + check_node2 = node.get_fork_at_path(b"path1/valami/").node + assert list(check_node2.forks.keys()) == [path1[13]] -# # Reference should differ because the fork set changed -# ref_check_node2 = check_node2.get_content_address() -# assert ref_check_node2 != ref_check_node1 + # Reference should differ because the fork set changed + ref_check_node2 = check_node2.get_content_address() + assert ref_check_node2 != ref_check_node1 def test_modify_tree_and_save_load(bee_class, get_debug_postage):