-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Tests: Add test for getdifficulty #10229
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
Conversation
@@ -57,7 +64,8 @@ def _test_gettxoutsetinfo(self): | |||
def _test_getblockheader(self): | |||
node = self.nodes[0] | |||
|
|||
assert_raises_jsonrpc(-5, "Block not found", node.getblockheader, "nonsense") | |||
assert_raises_jsonrpc(-5, "Block not found", |
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.
Why this change?
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.
flake8 warning: E501 line too long (85 > 79 characters)
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.
My personal preference is to ignore the 'line too long' warning. Nothing wrong with going over 79 character lines in my opinion (but we don't have a style guide for functional tests, so entirely up to you)
test/functional/blockchain.py
Outdated
self.nodes[0].verifychain(4, 0) | ||
|
||
def _test_getdifficulty(self): | ||
res = self.nodes[0].getdifficulty() |
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.
Mention the getdifficulty
RPC test in the top level comment or remove the list of tested methods there.
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.
adding to the comment, thanks!
test/functional/blockchain.py
Outdated
self.nodes[0].verifychain(4, 0) | ||
|
||
def _test_getdifficulty(self): |
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.
Can you move the def after the _test_getblockheader
so it is ordered the same as it is called?
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.
Yep, will do.
test/functional/blockchain.py
Outdated
res = self.nodes[0].getdifficulty() | ||
# 1 hash in 2 should be valid, so difficulty should be 1/2**31 | ||
# binary => decimal => binary math is why we round | ||
assert_equal(round(res * 2**31, 4), 1.0) |
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.
Ugh.
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.
Is there a cleverer way to do this?
bfd615c
to
a75c80e
Compare
Fixed issues, rebased to master. |
8fd75de
to
ba2b295
Compare
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.
ACK 821dd5e
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.
Looks good. Tested ACK ba2b295093d5f5cad4701f9ca86b2c83e60c3ef9.
A few nits which you can take or leave.
test/functional/blockchain.py
Outdated
@@ -6,6 +6,7 @@ | |||
|
|||
Test the following RPCs: | |||
- gettxoutsetinfo | |||
- getdifficulty | |||
- verifychain |
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.
Might as well fix this docstring while you're at it. The following RPCs are also tested:
- getbestblockhash
- getblockhash
- getblockheader
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.
good idea.
@@ -57,7 +64,8 @@ def _test_gettxoutsetinfo(self): | |||
def _test_getblockheader(self): | |||
node = self.nodes[0] | |||
|
|||
assert_raises_jsonrpc(-5, "Block not found", node.getblockheader, "nonsense") | |||
assert_raises_jsonrpc(-5, "Block not found", |
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.
My personal preference is to ignore the 'line too long' warning. Nothing wrong with going over 79 character lines in my opinion (but we don't have a style guide for functional tests, so entirely up to you)
test/functional/blockchain.py
Outdated
@@ -79,5 +82,11 @@ def _test_getblockheader(self): | |||
assert isinstance(int(header['versionHex'], 16), int) | |||
assert isinstance(header['difficulty'], Decimal) | |||
|
|||
def _test_getdifficulty(self): | |||
res = self.nodes[0].getdifficulty() |
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'd prefer a more descriptive name than res
, perhaps difficulty
? (or even combine with the line below)
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.
Makes sense.
Test added to blockchain.py as adding a new test to reduce test run time.
ba2b295
to
821dd5e
Compare
Fixed nits and squashed. |
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
821dd5e Tests: Add test for getdifficulty (Jimmy Song) Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
Test added to blockchain.py as adding a new test to reduce test run time.