-
Notifications
You must be signed in to change notification settings - Fork 37.8k
[tests] Add getmininginfo test #11150
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
test/functional/rpc_getmininginfo.py
Outdated
from test_framework.util import assert_equal | ||
from decimal import Decimal | ||
|
||
|
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.
Remove newline.
test/functional/rpc_getmininginfo.py
Outdated
self.num_nodes = 1 | ||
self.setup_clean_chain = False | ||
|
||
|
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.
Remove newline.
test/functional/rpc_getmininginfo.py
Outdated
self._test_values() | ||
self._test_blocks_key_is_equal_to_getblockcount() | ||
|
||
|
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.
Remove newline.
test/functional/rpc_getmininginfo.py
Outdated
for key in required_keys: | ||
assert(key in self.mining_info) | ||
|
||
|
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.
Remove newline.
test/functional/rpc_getmininginfo.py
Outdated
assert_equal(self.mining_info['networkhashps'], networkhashps) | ||
assert_equal(self.mining_info['pooledtx'], 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.
Remove newline.
test/functional/rpc_getmininginfo.py
Outdated
assert_equal(self.nodes[0].getblockcount(), 200) | ||
assert_equal(self.mining_info['blocks'], self.nodes[0].getblockcount()) | ||
|
||
|
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.
Remove newline.
test/functional/rpc_getmininginfo.py
Outdated
|
||
|
||
def run_test(self): | ||
self.mining_info = self.nodes[0].getmininginfo() |
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.
Don't create self.mining_info
, pass to functions below?
test/functional/rpc_getmininginfo.py
Outdated
self._test_blocks_key_is_equal_to_getblockcount() | ||
|
||
|
||
def _test_returns_all_the_keys(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.
There are few with _
prefix, remove?
test/functional/rpc_getmininginfo.py
Outdated
|
||
|
||
def _test_values(self): | ||
difficulty = Decimal('4.656542373906925E-10') |
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.
Inline below?
test/functional/rpc_getmininginfo.py
Outdated
|
||
def _test_values(self): | ||
difficulty = Decimal('4.656542373906925E-10') | ||
networkhashps = Decimal('0.003333333333333334') |
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.
Same a above?
@promag thanks for taking a look. Obviously won't leave 2 new lines in the future 😄 |
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.
Thanks for this @mess110 . As an alternative to making this an individual test case (which adds a few seconds overhead to running the test suite), you could add this as a sub-test at the top of the mining.py
test script.
Whether or not to add a new test script or extend an old one is a judgement call. In this case, I think the getmininginfo
RPC can be run at the start of mining.py
without any side-effects so it's a good candidate for extending the existing test.
test/functional/rpc_getmininginfo.py
Outdated
|
||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.util import assert_equal | ||
from decimal import Decimal |
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.
supernit: place imports in PEP-8 ordering (std library first, then project imports)
test/functional/rpc_getmininginfo.py
Outdated
assert(key in mining_info) | ||
|
||
def test_values(self, mining_info): | ||
errors = 'This is a pre-release test build - use at your own risk -' \ |
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.
The This is a pre-release test build - use at your own risk
error is only presented on non-release branches, so this assert will fail on all release branches. Just omit it.
test/functional/rpc_getmininginfo.py
Outdated
] | ||
|
||
for key in required_keys: | ||
assert(key in mining_info) |
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.
No need to assert for keys in our tests. Python has you covered by throwing a KeyError in case you access a key that does not exist.
@jnewbery thanks. I initially started in @MarcoFalke thanks for the review and hint |
Looks good to me. We could test the actual values returned by Tested ACK 4f2905b |
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.
utACK 4f2905b.
import copy | ||
from binascii import b2a_hex | ||
from decimal import Decimal | ||
|
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.
Nit, remove empty lines?
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.
Ignore as per PEP-8.
4f2905b Add getmininginfo functional test (Cristian Mircea Messel) Pull request description: Add `getmininginfo` functional test in `mining.py` Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
Github-Pull: bitcoin#11150 Rebased-From: 4f2905b
4f2905b Add getmininginfo functional test (Cristian Mircea Messel) Pull request description: Add `getmininginfo` functional test in `mining.py` Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
4f2905b Add getmininginfo functional test (Cristian Mircea Messel) Pull request description: Add `getmininginfo` functional test in `mining.py` Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
4f2905b Add getmininginfo functional test (Cristian Mircea Messel) Pull request description: Add `getmininginfo` functional test in `mining.py` Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
4f2905b Add getmininginfo functional test (Cristian Mircea Messel) Pull request description: Add `getmininginfo` functional test in `mining.py` Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
4f2905b Add getmininginfo functional test (Cristian Mircea Messel) Pull request description: Add `getmininginfo` functional test in `mining.py` Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
Add
getmininginfo
functional test inmining.py