Skip to content

Commit

Permalink
fix: tests fixed. 2 more to go. error: Romve the forks is not working…
Browse files Browse the repository at this point in the history
… properly maybe
  • Loading branch information
Aviksaikat committed Jun 19, 2024
1 parent cccde68 commit b704a0e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
7 changes: 4 additions & 3 deletions src/mantaray_py/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
install()
console = Console()

PATH_SEPARATOR = "/"
PATH_SEPARATOR = b"/"
PATH_SEPARATOR_BYTE = 47
PADDING_BYTE = 0x0A
NODE_SIZE = 255
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
64 changes: 33 additions & 31 deletions tests/integration/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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())

Expand All @@ -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):
Expand Down

0 comments on commit b704a0e

Please sign in to comment.