Return bytes instead of str
Closes https://github.com/datpy/merkle-tree-stream/issues/2.
This commit is contained in:
parent
1c4fe9533f
commit
dd1c0776b2
@ -1,3 +1,12 @@
|
|||||||
|
Merkle_Tree_Stream 0.0.1a2 (2019-10-06)
|
||||||
|
=======================================
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
- MerkleTreeIterator leaf and parent functions now return bytes.
|
||||||
|
|
||||||
|
|
||||||
Merkle_Tree_Stream 0.0.1a1 (2019-08-07)
|
Merkle_Tree_Stream 0.0.1a1 (2019-08-07)
|
||||||
=======================================
|
=======================================
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class MerkleTreeNode:
|
|||||||
parent: int
|
parent: int
|
||||||
size: int
|
size: int
|
||||||
data: bytes
|
data: bytes
|
||||||
hash: Optional[str] = attr.Factory(str)
|
hash: Optional[bytes] = attr.Factory(bytes)
|
||||||
|
|
||||||
def __attrs_post_init__(self) -> Any:
|
def __attrs_post_init__(self) -> Any:
|
||||||
"""Initialise the parent index."""
|
"""Initialise the parent index."""
|
||||||
|
@ -7,8 +7,6 @@ from flat_tree import FlatTreeAccessor
|
|||||||
|
|
||||||
from merkle_tree_stream.node import MerkleTreeNode
|
from merkle_tree_stream.node import MerkleTreeNode
|
||||||
|
|
||||||
Hash = str
|
|
||||||
|
|
||||||
EMPTY_DATA = b''
|
EMPTY_DATA = b''
|
||||||
EMPTY_HASH = None
|
EMPTY_HASH = None
|
||||||
|
|
||||||
@ -26,8 +24,8 @@ class MerkleTreeIterator:
|
|||||||
:param roots: The tree roots
|
:param roots: The tree roots
|
||||||
"""
|
"""
|
||||||
|
|
||||||
leaf: Callable[[MerkleTreeNode], Hash]
|
leaf: Callable[[MerkleTreeNode], bytes]
|
||||||
parent: Callable[[MerkleTreeNode, MerkleTreeNode], Hash]
|
parent: Callable[[MerkleTreeNode, MerkleTreeNode], bytes]
|
||||||
roots: List[MerkleTreeNode] = attr.Factory(list)
|
roots: List[MerkleTreeNode] = attr.Factory(list)
|
||||||
|
|
||||||
_position: int = 0
|
_position: int = 0
|
||||||
|
@ -6,7 +6,7 @@ import pytest
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def leaf():
|
def leaf():
|
||||||
def _leaf(node, roots=None):
|
def _leaf(node, roots=None):
|
||||||
return hashlib.sha256(node.data).hexdigest()
|
return hashlib.sha256(node.data).digest()
|
||||||
|
|
||||||
return _leaf
|
return _leaf
|
||||||
|
|
||||||
@ -17,6 +17,6 @@ def parent():
|
|||||||
sha256 = hashlib.sha256()
|
sha256 = hashlib.sha256()
|
||||||
sha256.update(first.data)
|
sha256.update(first.data)
|
||||||
sha256.update(second.data)
|
sha256.update(second.data)
|
||||||
return sha256.hexdigest()
|
return sha256.digest()
|
||||||
|
|
||||||
return _parent
|
return _parent
|
||||||
|
@ -17,26 +17,18 @@ def test_hashes(leaf, parent):
|
|||||||
assert len(merkle_iter) == expected_count
|
assert len(merkle_iter) == expected_count
|
||||||
|
|
||||||
assert next(merkle_iter) == MerkleTreeNode(
|
assert next(merkle_iter) == MerkleTreeNode(
|
||||||
index=0,
|
index=0, parent=1, hash=hashlib.sha256(b'a').digest(), size=1, data=b'a'
|
||||||
parent=1,
|
|
||||||
hash=hashlib.sha256(b'a').hexdigest(),
|
|
||||||
size=1,
|
|
||||||
data=b'a',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert next(merkle_iter) == MerkleTreeNode(
|
assert next(merkle_iter) == MerkleTreeNode(
|
||||||
index=2,
|
index=2, parent=1, hash=hashlib.sha256(b'b').digest(), size=1, data=b'b'
|
||||||
parent=1,
|
|
||||||
hash=hashlib.sha256(b'b').hexdigest(),
|
|
||||||
size=1,
|
|
||||||
data=b'b',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
hashed = hashlib.sha256(b'a')
|
hashed = hashlib.sha256(b'a')
|
||||||
hashed.update(b'b')
|
hashed.update(b'b')
|
||||||
|
|
||||||
assert next(merkle_iter) == MerkleTreeNode(
|
assert next(merkle_iter) == MerkleTreeNode(
|
||||||
index=1, parent=3, hash=hashed.hexdigest(), size=2, data=b''
|
index=1, parent=3, hash=hashed.digest(), size=2, data=b''
|
||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(StopIteration):
|
with pytest.raises(StopIteration):
|
||||||
|
Loading…
Reference in New Issue
Block a user