Skip to content

Commit

Permalink
Merge pull request #58 from Sovenok-Hacker/rewrite
Browse files Browse the repository at this point in the history
Add a check_pow test
  • Loading branch information
YeahNotSewerSide authored Apr 28, 2024
2 parents 5a23fa2 + 1b973e6 commit bda1001
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 7 additions & 2 deletions gen_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def total_leading_zeros(hash):

return to_return

def to_hex_list(bt: bytes) -> list:
r = []
for b in bt:
r.append(f'0x{hex(b)[2:].upper()}')
return r

def gen(hash, difficulty):
difficulty = total_leading_zeros(difficulty)
Expand All @@ -37,9 +42,9 @@ def gen(hash, difficulty):
ghash_leadin_zeros = total_leading_zeros(generated_hash)

if ghash_leadin_zeros >= difficulty:
print(pow, True)
print(', '.join(to_hex_list(pow)), True)
else:
print(pow, False)
print(', '.join(to_hex_list(pow)), False)


gen(hashlib.sha256(b'text').digest(),
Expand Down
15 changes: 13 additions & 2 deletions tests/tools_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
use blockchaintree::tools;
use blockchaintree::tools::{self, check_pow};

#[test]
fn pow_test() {}
fn check_pow_test() {
let hash: [u8; 32] = [0x98, 0x2D, 0x9E, 0x3E, 0xB9, 0x96, 0xF5, 0x59, 0xE6, 0x33, 0xF4, 0xD1, 0x94, 0xDE, 0xF3, 0x76, 0x1D, 0x90, 0x9F, 0x5A, 0x3B, 0x64, 0x7D, 0x1A, 0x85, 0x1F, 0xEA, 0xD6, 0x7C, 0x32, 0xC9, 0xD1];

assert_eq!(
check_pow(&hash, &[0xF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], &[0x0, 0x7A, 0x9, 0xDE, 0x81, 0x32, 0x58, 0x4F, 0x6D, 0xE8]),
false
);
assert_eq!(
check_pow(&hash, &[0xF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], &[0x3A, 0x91, 0x24, 0x45, 0xC9, 0x65, 0x60, 0xD5, 0x1E, 0x69]),
true
);
}

0 comments on commit bda1001

Please sign in to comment.