Skip to content

Commit 290117f

Browse files
gto90claude
andcommitted
test: Add regression test for getmininginfo difficulty algorithm (issue #346)
Add test_getmininginfo_difficulty_algorithm() to verify that the 'difficulty' field in getmininginfo matches the difficulty for the current mining algorithm (pow_algo), not a hardcoded algorithm. This prevents regression of issue #346 where the difficulty field always returned Groestl's difficulty regardless of the configured mining algorithm. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent eee9151 commit 290117f

1 file changed

Lines changed: 54 additions & 6 deletions

File tree

test/functional/feature_digibyte_multialgo_mining.py

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,57 @@ def test_generateblock_rpc(self):
370370
# Should use default algorithm (scrypt)
371371
assert_equal(block['pow_algo'], 'scrypt')
372372

373+
def test_getmininginfo_difficulty_algorithm(self):
374+
"""Test that getmininginfo difficulty matches current mining algorithm.
375+
376+
Regression test for issue #346: The 'difficulty' field was always
377+
returning Groestl's difficulty (algo=2) instead of the current
378+
mining algorithm's difficulty due to a missing parameter in the
379+
GetDifficulty() call.
380+
"""
381+
self.log.info("Testing getmininginfo difficulty matches current algorithm (issue #346)...")
382+
383+
node = self.nodes[0]
384+
385+
# Get mining info
386+
info = node.getmininginfo()
387+
388+
# Get the current mining algorithm name
389+
current_algo = info['pow_algo']
390+
391+
# The 'difficulty' field should match the difficulty for the current algorithm
392+
# Before the fix, this would return groestl's difficulty regardless of pow_algo
393+
expected_difficulty = info['difficulties'][current_algo]
394+
actual_difficulty = info['difficulty']
395+
396+
self.log.info(f"Current algorithm: {current_algo}")
397+
self.log.info(f"Expected difficulty (from difficulties.{current_algo}): {expected_difficulty}")
398+
self.log.info(f"Actual difficulty field: {actual_difficulty}")
399+
400+
assert_equal(actual_difficulty, expected_difficulty,
401+
f"getmininginfo 'difficulty' should match 'difficulties.{current_algo}'. "
402+
f"Got {actual_difficulty}, expected {expected_difficulty}. "
403+
f"This may indicate issue #346 regression.")
404+
405+
# Additional sanity check: if we have multiple algorithms with different
406+
# difficulties, verify we're not just getting lucky
407+
difficulties = info['difficulties']
408+
if len(set(difficulties.values())) > 1:
409+
# We have different difficulties for different algorithms
410+
# Verify we're returning the right one, not just any one
411+
for algo_name, algo_diff in difficulties.items():
412+
if algo_name != current_algo and algo_diff != expected_difficulty:
413+
self.log.info(f"Verified: difficulty differs from {algo_name} ({algo_diff})")
414+
break
415+
416+
self.log.info("getmininginfo difficulty algorithm test passed!")
417+
373418
def test_mining_info_comprehensive(self):
374419
"""Comprehensive test of getmininginfo output."""
375420
self.log.info("Testing comprehensive getmininginfo output...")
376-
421+
377422
node = self.nodes[0]
378-
423+
379424
# Get mining info
380425
info = node.getmininginfo()
381426

@@ -437,11 +482,14 @@ def run_test(self):
437482

438483
# Test 7: Comprehensive mining info
439484
self.test_mining_info_comprehensive()
440-
441-
# Test 8: Difficulty adjustment
485+
486+
# Test 8: getmininginfo difficulty matches algorithm (issue #346 regression test)
487+
self.test_getmininginfo_difficulty_algorithm()
488+
489+
# Test 9: Difficulty adjustment
442490
self.test_difficulty_adjustment()
443-
444-
# Test 9: Odocrypt activation (if height permits)
491+
492+
# Test 10: Odocrypt activation (if height permits)
445493
if ODOCRYPT_HEIGHT < 1000: # Only test if reasonable for regtest
446494
self.test_odocrypt_activation()
447495

0 commit comments

Comments
 (0)