Skip to content

Conversation

mess110
Copy link
Contributor

@mess110 mess110 commented Aug 25, 2017

Add getmininginfo functional test in mining.py

from test_framework.util import assert_equal
from decimal import Decimal


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline.

self.num_nodes = 1
self.setup_clean_chain = False


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline.

self._test_values()
self._test_blocks_key_is_equal_to_getblockcount()


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline.

for key in required_keys:
assert(key in self.mining_info)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline.

assert_equal(self.mining_info['networkhashps'], networkhashps)
assert_equal(self.mining_info['pooledtx'], 0)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline.

assert_equal(self.nodes[0].getblockcount(), 200)
assert_equal(self.mining_info['blocks'], self.nodes[0].getblockcount())


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline.



def run_test(self):
self.mining_info = self.nodes[0].getmininginfo()
Copy link
Contributor

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?

self._test_blocks_key_is_equal_to_getblockcount()


def _test_returns_all_the_keys(self):
Copy link
Contributor

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?



def _test_values(self):
difficulty = Decimal('4.656542373906925E-10')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline below?


def _test_values(self):
difficulty = Decimal('4.656542373906925E-10')
networkhashps = Decimal('0.003333333333333334')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same a above?

@fanquake fanquake added the Tests label Aug 25, 2017
@mess110
Copy link
Contributor Author

mess110 commented Aug 25, 2017

@promag thanks for taking a look. Obviously won't leave 2 new lines in the future 😄

Copy link
Contributor

@jnewbery jnewbery left a 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.


from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
from decimal import Decimal
Copy link
Contributor

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)

assert(key in mining_info)

def test_values(self, mining_info):
errors = 'This is a pre-release test build - use at your own risk -' \
Copy link
Contributor

@jnewbery jnewbery Aug 28, 2017

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.

]

for key in required_keys:
assert(key in mining_info)
Copy link
Member

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.

@mess110 mess110 changed the title [tests] Add getmininginfo functional tests [tests] Add getmininginfo test Aug 28, 2017
@mess110
Copy link
Contributor Author

mess110 commented Aug 28, 2017

@jnewbery thanks. I initially started in mining.py but I decided not to put it there because it would be "cleaner" to have its own test. In this particular case, I agree, the extra time to setup the test is not worth it

@MarcoFalke thanks for the review and hint

@jnewbery
Copy link
Contributor

Looks good to me. We could test the actual values returned by getmininginfo more thoroughly (ie are the values for size, weight, hashps, etc correct under different circumstances) in a different PR. Testing the interface correctness in this PR is better than no testing at all.

Tested ACK 4f2905b

Copy link
Contributor

@promag promag left a 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, remove empty lines?

Copy link
Contributor

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.

@maflcko maflcko merged commit 4f2905b into bitcoin:master Aug 29, 2017
maflcko pushed a commit that referenced this pull request Aug 29, 2017
4f2905b Add getmininginfo functional test (Cristian Mircea Messel)

Pull request description:

  Add `getmininginfo` functional test in `mining.py`

Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
@mess110 mess110 deleted the test_rpc_getmininginfo branch August 29, 2017 08:44
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 19, 2019
4f2905b Add getmininginfo functional test (Cristian Mircea Messel)

Pull request description:

  Add `getmininginfo` functional test in `mining.py`

Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 23, 2019
4f2905b Add getmininginfo functional test (Cristian Mircea Messel)

Pull request description:

  Add `getmininginfo` functional test in `mining.py`

Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 24, 2019
4f2905b Add getmininginfo functional test (Cristian Mircea Messel)

Pull request description:

  Add `getmininginfo` functional test in `mining.py`

Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
codablock pushed a commit to codablock/dash that referenced this pull request Sep 24, 2019
4f2905b Add getmininginfo functional test (Cristian Mircea Messel)

Pull request description:

  Add `getmininginfo` functional test in `mining.py`

Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
barrystyle pushed a commit to PACGlobalOfficial/PAC that referenced this pull request Jan 22, 2020
4f2905b Add getmininginfo functional test (Cristian Mircea Messel)

Pull request description:

  Add `getmininginfo` functional test in `mining.py`

Tree-SHA512: 12be9cfb37e9ac4c6625fc06051704c8a8dfd7271c2654f994c7659c8810e4b7a4335105ae159315308bcd45b65589bab1829bd134d2f4cabf74d63f2e5d22fe
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants