tests: simplify next_block() function in feature_block

The solve parameter is unnecessary. Remove it and add
comments.
This commit is contained in:
John Newbery 2020-03-17 09:45:00 -04:00
parent 7060d2d97a
commit 612a931d1a

View File

@ -630,17 +630,19 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block with invalid work") self.log.info("Reject a block with invalid work")
self.move_tip(44) self.move_tip(44)
b47 = self.next_block(47, solve=False) b47 = self.next_block(47)
target = uint256_from_compact(b47.nBits) target = uint256_from_compact(b47.nBits)
while b47.sha256 <= target: while b47.sha256 <= target:
# Rehash nonces until an invalid too-high-hash block is found.
b47.nNonce += 1 b47.nNonce += 1
b47.rehash() b47.rehash()
self.send_blocks([b47], False, force_send=True, reject_reason='high-hash', reconnect=True) 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.log.info("Reject a block with a timestamp >2 hours in the future")
self.move_tip(44) self.move_tip(44)
b48 = self.next_block(48, solve=False) b48 = self.next_block(48)
b48.nTime = int(time.time()) + 60 * 60 * 3 b48.nTime = int(time.time()) + 60 * 60 * 3
# Header timestamp has changed. Re-solve the block.
b48.solve() b48.solve()
self.send_blocks([b48], False, force_send=True, reject_reason='time-too-new') self.send_blocks([b48], False, force_send=True, reject_reason='time-too-new')
@ -1321,7 +1323,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.rehash() tx.rehash()
return tx 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: if self.tip is None:
base_block_hash = self.genesis_hash base_block_hash = self.genesis_hash
block_time = int(time.time()) + 1 block_time = int(time.time()) + 1
@ -1343,10 +1345,8 @@ class FullBlockTest(BitcoinTestFramework):
self.sign_tx(tx, spend) self.sign_tx(tx, spend)
self.add_transactions_to_block(block, [tx]) self.add_transactions_to_block(block, [tx])
block.hashMerkleRoot = block.calc_merkle_root() block.hashMerkleRoot = block.calc_merkle_root()
if solve: # Block is created. Find a valid nonce.
block.solve() block.solve()
else:
block.rehash()
self.tip = block self.tip = block
self.block_heights[block.sha256] = height self.block_heights[block.sha256] = height
assert number not in self.blocks assert number not in self.blocks