Skip to content

Commit 8fc5f2b

Browse files
author
MarcoFalke
committed
Merge #18366: tests: simplify next_block() function in feature_block
612a931 tests: simplify next_block() function in feature_block (John Newbery) Pull request description: The solve parameter is unnecessary. Remove it and add comments. ACKs for top commit: MarcoFalke: ACK 612a931 TheQuantumPhysicist: ACK 612a931 Looks good. Thanks for improving it 😄 practicalswift: ACK 612a931 -- simpler is better and patch looks correct :) Tree-SHA512: 25b4879842ea37a3f598be886f02ce4c2fb0b5a618d02b266dbd380f5cbfdd71a8bd35ddd9d6f2cf83920e37c02caf9955a841a02b17ba75ac63f88d32f8b60b
2 parents 7060d2d + 612a931 commit 8fc5f2b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

test/functional/feature_block.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -630,17 +630,19 @@ def run_test(self):
630630

631631
self.log.info("Reject a block with invalid work")
632632
self.move_tip(44)
633-
b47 = self.next_block(47, solve=False)
633+
b47 = self.next_block(47)
634634
target = uint256_from_compact(b47.nBits)
635635
while b47.sha256 <= target:
636+
# Rehash nonces until an invalid too-high-hash block is found.
636637
b47.nNonce += 1
637638
b47.rehash()
638639
self.send_blocks([b47], False, force_send=True, reject_reason='high-hash', reconnect=True)
639640

640641
self.log.info("Reject a block with a timestamp >2 hours in the future")
641642
self.move_tip(44)
642-
b48 = self.next_block(48, solve=False)
643+
b48 = self.next_block(48)
643644
b48.nTime = int(time.time()) + 60 * 60 * 3
645+
# Header timestamp has changed. Re-solve the block.
644646
b48.solve()
645647
self.send_blocks([b48], False, force_send=True, reject_reason='time-too-new')
646648

@@ -1321,7 +1323,7 @@ def create_and_sign_transaction(self, spend_tx, value, script=CScript([OP_TRUE])
13211323
tx.rehash()
13221324
return tx
13231325

1324-
def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), solve=True, *, version=1):
1326+
def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), *, version=1):
13251327
if self.tip is None:
13261328
base_block_hash = self.genesis_hash
13271329
block_time = int(time.time()) + 1
@@ -1343,10 +1345,8 @@ def next_block(self, number, spend=None, additional_coinbase_value=0, script=CSc
13431345
self.sign_tx(tx, spend)
13441346
self.add_transactions_to_block(block, [tx])
13451347
block.hashMerkleRoot = block.calc_merkle_root()
1346-
if solve:
1347-
block.solve()
1348-
else:
1349-
block.rehash()
1348+
# Block is created. Find a valid nonce.
1349+
block.solve()
13501350
self.tip = block
13511351
self.block_heights[block.sha256] = height
13521352
assert number not in self.blocks

0 commit comments

Comments
 (0)