Use defines from .hrl in the code

This commit is contained in:
Juraj Hlista 2019-03-12 10:28:36 +07:00
parent 82a7cb813a
commit 73b70519f1
3 changed files with 9 additions and 9 deletions

View File

@ -24,7 +24,7 @@
-include("aeminer.hrl").
-type nonce() :: 0..?MAX_NONCE.
-type nonce() :: ?MIN_NONCE..?MAX_NONCE.
-type int_target() :: integer().

View File

@ -464,7 +464,7 @@ parse_generation_result(["Solution" ++ NonceValuesStr | Rest],
[NonceStr | SolStrs] = string:tokens(NonceValuesStr, " "),
Soln = [list_to_integer(string:trim(V, both, [$\r]), 16) || V <- SolStrs],
case {length(Soln), test_target(Soln, Target, EdgeBits)} of
{42, true} ->
{?SOLUTION_SIZE, true} ->
stop_execution(OsPid),
case parse_nonce_str(NonceStr) of
{ok, Nonce} ->
@ -474,8 +474,8 @@ parse_generation_result(["Solution" ++ NonceValuesStr | Rest],
?debug("Bad nonce: ~p", [Err]),
Err
end;
{N, _} when N /= 42 ->
?debug("Solution has wrong length (~p) should be 42", [N]),
{N, _} when N /= ?SOLUTION_SIZE ->
?debug("Solution has wrong length (~p) should be ~p", [N, ?SOLUTION_SIZE]),
%% No nonce in solution, old miner exec?
stop_execution(OsPid),
{error, bad_miner};

View File

@ -26,7 +26,7 @@ pow_test_() ->
Config = fast_and_deterministic_cuckoo_pow(),
Res = spawn_worker(fun() -> ?TEST_MODULE:generate(?TEST_BIN, Target, Nonce, Config, undefined) end),
{ok, {Nonce, Soln}} = Res,
?assertMatch(L when length(L) == 42, Soln),
?assertMatch(L when length(L) == ?SOLUTION_SIZE, Soln),
%% verify the nonce and the solution
Res2 = ?TEST_MODULE:verify(?TEST_BIN, Nonce, Soln, Target, ?EDGE_BITS_15),
@ -53,7 +53,7 @@ pow_test_() ->
?TEST_MODULE:generate(?TEST_BIN, HighTarget, Nonce, Config, undefined)
end),
{ok, {Nonce, Soln2}} = Res2,
?assertMatch(L when length(L) == 42, Soln2),
?assertMatch(L when length(L) == ?SOLUTION_SIZE, Soln2),
%% ... then attempt to verify such solution (and
%% nonce) with the low target threshold (shall fail).
?assertNot(?TEST_MODULE:verify(?TEST_BIN, Nonce, Soln2, Target, ?EDGE_BITS_15))
@ -66,10 +66,10 @@ pow_test_() ->
Config = fast_and_deterministic_cuckoo_pow(),
Res = spawn_worker(fun() -> ?TEST_MODULE:generate(?TEST_BIN, Target, Nonce, Config, undefined) end),
{ok, {Nonce, Soln}} = Res,
?assertMatch(L when length(L) == 42, Soln),
?assertMatch(L when length(L) == ?SOLUTION_SIZE, Soln),
WrongSoln = lists:seq(0, 41),
?assertMatch(L when length(L) == 42, WrongSoln),
?assertMatch(L when length(L) == ?SOLUTION_SIZE, WrongSoln),
?assertNotEqual(Soln, WrongSoln),
?assertNot(?TEST_MODULE:verify(?TEST_BIN, Nonce, WrongSoln, Target, ?EDGE_BITS_15))
end},
@ -82,7 +82,7 @@ pow_test_() ->
spawn_worker(fun() -> ?TEST_MODULE:generate(?TEST_BIN, Target, Nonce, Config, undefined) end)),
DummySoln = lists:seq(0, 41),
?assertMatch(L when length(L) == 42, DummySoln),
?assertMatch(L when length(L) == ?SOLUTION_SIZE, DummySoln),
?assertNot(?TEST_MODULE:verify(?TEST_BIN, Nonce, DummySoln, Target, ?EDGE_BITS_15))
end},
{"Attempt to verify nonce that is too big shall fail gracefully",