Merge bitcoin/bitcoin#32725: test: round difficulty and networkhashps

578ea3eedb test: round difficulty and networkhashps (Sjors Provoost)

Pull request description:

  Both are rational numbers. Client software should only use them to display information to humans. Followup calculations should use the underlying values such as target.

  Therefore it's not necessary to test the handling of these floating point values. Round them down to avoid spurious test failures.

  Fixes #32515

ACKs for top commit:
  Prabhat1308:
    Code Review ACK [`578ea3e`](578ea3eedb)
  achow101:
    ACK 578ea3eedb
  w0xlt:
    Code review ACK 578ea3eedb
  janb84:
    ACK 578ea3eedb

Tree-SHA512: 5fc63c73ad236b7cd55c15da0f1d1e6b45e4289d252147a86717bf77d79f897f42c3e38aa514df6a4a8deca10c87a8710b61b454c533ad56b0daf738365f426c
This commit is contained in:
Ava Chow
2025-06-20 16:30:41 -07:00

View File

@@ -379,14 +379,13 @@ class MiningTest(BitcoinTestFramework):
assert 'currentblockweight' not in mining_info
assert_equal(mining_info['bits'], nbits_str(REGTEST_N_BITS))
assert_equal(mining_info['target'], target_str(REGTEST_TARGET))
assert_equal(mining_info['difficulty'], Decimal('4.656542373906925E-10'))
assert_equal(mining_info['next'], {
'height': 201,
'target': target_str(REGTEST_TARGET),
'bits': nbits_str(REGTEST_N_BITS),
'difficulty': Decimal('4.656542373906925E-10')
})
assert_equal(mining_info['networkhashps'], Decimal('0.003333333333333334'))
# We don't care about precision, round to avoid mismatch under Valgrind:
assert_equal(round(mining_info['difficulty'], 10), Decimal('0.0000000005'))
assert_equal(mining_info['next']['height'], 201)
assert_equal(mining_info['next']['target'], target_str(REGTEST_TARGET))
assert_equal(mining_info['next']['bits'], nbits_str(REGTEST_N_BITS))
assert_equal(round(mining_info['next']['difficulty'], 10), Decimal('0.0000000005'))
assert_equal(round(mining_info['networkhashps'], 5), Decimal('0.00333'))
assert_equal(mining_info['pooledtx'], 0)
self.log.info("getblocktemplate: Test default witness commitment")