Skip to content

Commit e5f21e6

Browse files
Added compute hash doctest
1 parent 9696d22 commit e5f21e6

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

blockchain/simple_blockchain.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,19 @@ def compute_hash(self, nonce: int) -> str:
4545
4646
Returns:
4747
str: Hexadecimal hash string.
48+
49+
>>> block = Block(0, "Genesis", "0", difficulty=2)
50+
>>> len(block.compute_hash(0)) == 64
51+
True
52+
>>> isinstance(block.compute_hash(0), str)
53+
True
4854
"""
4955
block_string = (
5056
f"{self.index}{self.timestamp}{self.data}{self.previous_hash}{nonce}"
5157
)
5258
return hashlib.sha256(block_string.encode()).hexdigest()
5359

60+
5461
def mine_block(self, difficulty: int) -> Tuple[int, str]:
5562
"""
5663
Simple Proof-of-Work mining algorithm.

0 commit comments

Comments
 (0)