getmininginfo
functional test in mining.py
getmininginfo
functional test in mining.py
6+
7+from test_framework.test_framework import BitcoinTestFramework
8+from test_framework.util import assert_equal
9+from decimal import Decimal
10+
11+
13+ def __init__(self):
14+ super().__init__()
15+ self.num_nodes = 1
16+ self.setup_clean_chain = False
17+
18+
21+
22+ self._test_returns_all_the_keys()
23+ self._test_values()
24+ self._test_blocks_key_is_equal_to_getblockcount()
25+
26+
38+ ]
39+
40+ for key in required_keys:
41+ assert(key in self.mining_info)
42+
43+
55+ assert_equal(self.mining_info['difficulty'], difficulty)
56+ assert_equal(self.mining_info['errors'], errors)
57+ assert_equal(self.mining_info['networkhashps'], networkhashps)
58+ assert_equal(self.mining_info['pooledtx'], 0)
59+
60+
60+
61+ def _test_blocks_key_is_equal_to_getblockcount(self):
62+ assert_equal(self.nodes[0].getblockcount(), 200)
63+ assert_equal(self.mining_info['blocks'], self.nodes[0].getblockcount())
64+
65+
15+ self.num_nodes = 1
16+ self.setup_clean_chain = False
17+
18+
19+ def run_test(self):
20+ self.mining_info = self.nodes[0].getmininginfo()
self.mining_info
, pass to functions below?
22+ self._test_returns_all_the_keys()
23+ self._test_values()
24+ self._test_blocks_key_is_equal_to_getblockcount()
25+
26+
27+ def _test_returns_all_the_keys(self):
_
prefix, remove?
40+ for key in required_keys:
41+ assert(key in self.mining_info)
42+
43+
44+ def _test_values(self):
45+ difficulty = Decimal('4.656542373906925E-10')
41+ assert(key in self.mining_info)
42+
43+
44+ def _test_values(self):
45+ difficulty = Decimal('4.656542373906925E-10')
46+ networkhashps = Decimal('0.003333333333333334')
0@@ -0,0 +1,59 @@
1+#!/usr/bin/env python3
2+# Copyright (c) 2014-2017 The Bitcoin Core developers
3+# Distributed under the MIT software license, see the accompanying
4+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+"""Test the getmininginfo API."""
6+
7+from test_framework.test_framework import BitcoinTestFramework
8+from test_framework.util import assert_equal
9+from decimal import Decimal
36+
37+ for key in required_keys:
38+ assert(key in mining_info)
39+
40+ def test_values(self, mining_info):
41+ errors = 'This is a pre-release test build - use at your own risk -' \
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.
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.
33+ 'networkhashps',
34+ 'pooledtx',
35+ ]
36+
37+ for key in required_keys:
38+ assert(key in mining_info)
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
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 4f2905b76b502a9de235dbe739e5fe504ef5bc22
10
11-from binascii import b2a_hex
12 import copy
13+from binascii import b2a_hex
14+from decimal import Decimal
15
mess110
promag
jnewbery
MarcoFalke
Labels
Tests