diff --git a/gen_test_data.py b/gen_test_data.py index 12f555e..2bdee5e 100644 --- a/gen_test_data.py +++ b/gen_test_data.py @@ -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) @@ -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(), diff --git a/tests/tools_test.rs b/tests/tools_test.rs index 70cf495..9c235f1 100644 --- a/tests/tools_test.rs +++ b/tests/tools_test.rs @@ -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 + ); +} \ No newline at end of file