-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Add difficulty to boundary conversion method #191
Conversation
Codecov Report
@@ Coverage Diff @@
## master #191 +/- ##
==========================================
+ Coverage 98.52% 98.58% +0.06%
==========================================
Files 22 24 +2
Lines 1765 1840 +75
==========================================
+ Hits 1739 1814 +75
Misses 26 26
Flags with carried forward coverage won't be shown. Click here to find out more.
|
cd8d9d2
to
bf1d64b
Compare
test/unittests/difficulty.cpp
Outdated
uint32_t d[8]; | ||
for (int i = 0; i < n; ++i) | ||
d[i] = ethash::be::uint32(difficulty->word32s[8 - 1 - i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit hard to read: not immediate to understand you're swapping also words positions.
uint32_t d[8]; | |
for (int i = 0; i < n; ++i) | |
d[i] = ethash::be::uint32(difficulty->word32s[8 - 1 - i]); | |
int src{7 /*8-1*/}; | |
for (int tgt = 0; tgt < n; ++tgt, --src) { | |
d[tgt] = ethash::be::uint32(difficulty->word32s[src]); | |
} |
test/unittests/difficulty.cpp
Outdated
// For difficulty of 0 (division by 0) or 1 (256-bit overflow) return max boundary value. | ||
if (n == 0 || (n == 1 && d[0] == 1)) | ||
return max_boundary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this check can be moved before the swapping loop ?
// For difficulty of 0 (division by 0) or 1 (256-bit overflow) return max boundary value. | |
if (n == 0 || (n == 1 && d[0] == 1)) | |
return max_boundary; | |
// For difficulty of 0 (division by 0) or 1 (256-bit overflow) return max boundary value. | |
static const be_one = ethash::be::(1u); | |
if (n == 0 || (n == 1 && difficulty->word32s[7] == be_one) | |
return max_boundary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that at first, but the check is simpler if we have the native order. And where the check is does not matter very much as these cases are only for completeness but do not happen in practice.
test/unittests/difficulty.cpp
Outdated
ethash_hash256 boundary{}; | ||
for (int i = 0; i < 8; ++i) | ||
boundary.word32s[i] = ethash::be::uint32(q[8 - 1 - i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a personal preference I'd use the suggestion above for better reading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved these to separate function
No description provided.