Skip to content

Commit 5f88622

Browse files
committed
Merge bitcoin/bitcoin#27852: test: add coverage to rpc_blockchain.py
376dc2c test: add coverage to rpc_blockchain.py (kevkevin) Pull request description: Included a test that checks the functionality of setting the first param of getnetworkhashps to negative value returns the average network hashes per second from the last difficulty change. ACKs for top commit: jlopp: tACK bitcoin/bitcoin@376dc2c achow101: ACK 376dc2c ismaelsadeeq: Tested ACK 376dc2c pablomartin4btc: tACK 376dc2c Tree-SHA512: 02d52f622e9cb7a1240c5d124510dd75d03f696f119b2625b0befd60b004ec50ff1a2d5515e0e227601adeecd837e0778ed131ee2a8c5f75f1b824be711213a7
2 parents 0857f29 + 376dc2c commit 5f88622

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/functional/rpc_blockchain.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
TIME_RANGE_MTP = TIME_GENESIS_BLOCK + (HEIGHT - 6) * TIME_RANGE_STEP
5959
TIME_RANGE_TIP = TIME_GENESIS_BLOCK + (HEIGHT - 1) * TIME_RANGE_STEP
6060
TIME_RANGE_END = TIME_GENESIS_BLOCK + HEIGHT * TIME_RANGE_STEP
61+
DIFFICULTY_ADJUSTMENT_INTERVAL = 2016
6162

6263

6364
class BlockchainTest(BitcoinTestFramework):
@@ -451,6 +452,15 @@ def _test_getnetworkhashps(self):
451452
# This should be 2 hashes every 10 minutes or 1/300
452453
assert abs(hashes_per_second * 300 - 1) < 0.0001
453454

455+
# Test setting the first param of getnetworkhashps to negative value returns the average network
456+
# hashes per second from the last difficulty change.
457+
current_block_height = self.nodes[0].getmininginfo()['blocks']
458+
blocks_since_last_diff_change = current_block_height % DIFFICULTY_ADJUSTMENT_INTERVAL + 1
459+
expected_hashes_per_second_since_diff_change = self.nodes[0].getnetworkhashps(blocks_since_last_diff_change)
460+
461+
assert_equal(self.nodes[0].getnetworkhashps(-1), expected_hashes_per_second_since_diff_change)
462+
assert_equal(self.nodes[0].getnetworkhashps(-2), expected_hashes_per_second_since_diff_change)
463+
454464
def _test_stopatheight(self):
455465
self.log.info("Test stopping at height")
456466
assert_equal(self.nodes[0].getblockcount(), HEIGHT)

0 commit comments

Comments
 (0)