aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-03-17 10:23:53 -0400
committerMarcoFalke <falke.marco@gmail.com>2020-03-17 10:23:58 -0400
commit8fc5f2bdf01d09d2e6f5df3134e95cebc7f3519a (patch)
tree5559b6bc25cffcf36612c9bc66894ee095e090cd
parent7060d2d97a289097f41fcc79698312c0117a75c8 (diff)
parent612a931d1a3ac1678d02aed30c48fd25ccd113db (diff)
downloadbitcoin-8fc5f2bdf01d09d2e6f5df3134e95cebc7f3519a.tar.xz
Merge #18366: tests: simplify next_block() function in feature_block
612a931d1a3ac1678d02aed30c48fd25ccd113db 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 612a931d1a3ac1678d02aed30c48fd25ccd113db TheQuantumPhysicist: ACK 612a931 Looks good. Thanks for improving it :smile: practicalswift: ACK 612a931d1a3ac1678d02aed30c48fd25ccd113db -- simpler is better and patch looks correct :) Tree-SHA512: 25b4879842ea37a3f598be886f02ce4c2fb0b5a618d02b266dbd380f5cbfdd71a8bd35ddd9d6f2cf83920e37c02caf9955a841a02b17ba75ac63f88d32f8b60b
-rwxr-xr-xtest/functional/feature_block.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py
index 5751db5af6..9e8e11e64f 100755
--- a/test/functional/feature_block.py
+++ b/test/functional/feature_block.py
@@ -630,17 +630,19 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block with invalid work")
self.move_tip(44)
- b47 = self.next_block(47, solve=False)
+ b47 = self.next_block(47)
target = uint256_from_compact(b47.nBits)
while b47.sha256 <= target:
+ # Rehash nonces until an invalid too-high-hash block is found.
b47.nNonce += 1
b47.rehash()
self.send_blocks([b47], False, force_send=True, reject_reason='high-hash', reconnect=True)
self.log.info("Reject a block with a timestamp >2 hours in the future")
self.move_tip(44)
- b48 = self.next_block(48, solve=False)
+ b48 = self.next_block(48)
b48.nTime = int(time.time()) + 60 * 60 * 3
+ # Header timestamp has changed. Re-solve the block.
b48.solve()
self.send_blocks([b48], False, force_send=True, reject_reason='time-too-new')
@@ -1321,7 +1323,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.rehash()
return tx
- def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), solve=True, *, version=1):
+ def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), *, version=1):
if self.tip is None:
base_block_hash = self.genesis_hash
block_time = int(time.time()) + 1
@@ -1343,10 +1345,8 @@ class FullBlockTest(BitcoinTestFramework):
self.sign_tx(tx, spend)
self.add_transactions_to_block(block, [tx])
block.hashMerkleRoot = block.calc_merkle_root()
- if solve:
- block.solve()
- else:
- block.rehash()
+ # Block is created. Find a valid nonce.
+ block.solve()
self.tip = block
self.block_heights[block.sha256] = height
assert number not in self.blocks