diff --git a/test/functional/abc-invalid-chains.py b/test/functional/abc-invalid-chains.py --- a/test/functional/abc-invalid-chains.py +++ b/test/functional/abc-invalid-chains.py @@ -40,6 +40,12 @@ self.blocks[number] = block return block + def set_tip(self, number: int): + """ + Move the tip back to a previous block. + """ + self.tip = self.blocks[number] + def run_test(self): node = self.nodes[0] node.add_p2p_connection(P2PDataStore()) @@ -47,10 +53,6 @@ self.genesis_hash = int(node.getbestblockhash(), 16) self.block_heights[self.genesis_hash] = 0 - # move the tip back to a previous block - def tip(number): - self.tip = self.blocks[number] - # shorthand for functions block = self.next_block @@ -75,11 +77,11 @@ assert_equal(self.blocks[0].hash, node.getbestblockhash()) # Mining on top of blocks 1 or 2 is rejected - tip(1) + self.set_tip(1) node.p2p.send_blocks_and_test( [block(11)], node, success=False, force_send=True, reject_reason='bad-prevblk') - tip(2) + self.set_tip(2) node.p2p.send_blocks_and_test( [block(21)], node, success=False, force_send=True, reject_reason='bad-prevblk') @@ -91,16 +93,16 @@ # Mining on the block 1 chain should be accepted # (needs to mine two blocks because less-work chains are not processed) - tip(1) + self.set_tip(1) node.p2p.send_blocks_and_test([block(12), block(13)], node) # Mining on the block 2 chain should still be accepted # (needs to mine two blocks because less-work chains are not processed) - tip(2) + self.set_tip(2) node.p2p.send_blocks_and_test([block(22), block(221)], node) # Mine more blocks from block 22 to be longest chain - tip(22) + self.set_tip(22) node.p2p.send_blocks_and_test([block(23), block(24)], node) # Sanity checks @@ -113,17 +115,17 @@ assert_equal(self.blocks[13].hash, node.getbestblockhash()) # Mining on the block 2 chain should be rejected - tip(24) + self.set_tip(24) node.p2p.send_blocks_and_test( [block(25)], node, success=False, force_send=True, reject_reason='bad-prevblk') # Continued mining on the block 1 chain is still ok - tip(13) + self.set_tip(13) node.p2p.send_blocks_and_test([block(14)], node) # Mining on a once-valid chain forking from block 2's longest chain, # which is now invalid, should also be rejected. - tip(221) + self.set_tip(221) node.p2p.send_blocks_and_test( [block(222)], node, success=False, force_send=True, reject_reason='bad-prevblk') @@ -131,7 +133,7 @@ "Make sure that reconsidering a block behaves correctly when cousin chains (neither ancestors nor descendants) become available as a result") # Reorg out 14 with four blocks. - tip(13) + self.set_tip(13) node.p2p.send_blocks_and_test( [block(15), block(16), block(17), block(18)], node) diff --git a/test/functional/abc-mempool-coherence-on-activations.py b/test/functional/abc-mempool-coherence-on-activations.py --- a/test/functional/abc-mempool-coherence-on-activations.py +++ b/test/functional/abc-mempool-coherence-on-activations.py @@ -171,10 +171,6 @@ def get_spendable_output(): return PreviousSpendableOutput(spendable_outputs.pop(0).vtx[0], 0) - # move the tip back to a previous block - def tip(number): - self.tip = self.blocks[number] - # adds transactions to the block and updates state def update_block(block_number, new_transactions): block = self.blocks[block_number] @@ -353,7 +349,7 @@ # Set up a longer competing chain that doesn't confirm any of our txns. # This starts after 5204, so it contains neither the forkblockid nor # the postforkblockid from above. - tip(5204) + self.tip = self.blocks[5204] reorg_blocks = [] for i in range(3): reorg_blocks.append(block(5900 + i)) diff --git a/test/functional/abc-replay-protection.py b/test/functional/abc-replay-protection.py --- a/test/functional/abc-replay-protection.py +++ b/test/functional/abc-replay-protection.py @@ -86,6 +86,12 @@ self.blocks[number] = block return block + def set_tip(self, number: int): + """ + Move the tip back to a previous block. + """ + self.tip = self.blocks[number] + def run_test(self): node = self.nodes[0] node.add_p2p_connection(P2PDataStore()) @@ -103,10 +109,6 @@ def get_spendable_output(): return PreviousSpendableOutput(spendable_outputs.pop(0).vtx[0], 0) - # move the tip back to a previous block - def tip(number): - self.tip = self.blocks[number] - # adds transactions to the block and updates state def update_block(block_number, new_transactions): block = self.blocks[block_number] @@ -202,7 +204,7 @@ [self.tip], node, success=False, reject_reason='blk-bad-inputs') # Rewind bad block - tip(1) + self.set_tip(1) # Create a block that would activate the replay protection. bfork = block(5555) @@ -231,7 +233,7 @@ [self.tip], node, success=False, reject_reason='blk-bad-inputs') # Rewind bad block - tip(5104) + self.set_tip(5104) # Send some non replay protected txns in the mempool to check # they get cleaned at activation. @@ -264,7 +266,7 @@ [self.tip], node, success=False, reject_reason='blk-bad-inputs') # Rewind bad block - tip(5556) + self.set_tip(5556) # The replay protected transaction is now valid replay_tx0_id = send_transaction_to_mempool(replay_txns[0]) diff --git a/test/functional/abc-segwit-recovery.py b/test/functional/abc-segwit-recovery.py --- a/test/functional/abc-segwit-recovery.py +++ b/test/functional/abc-segwit-recovery.py @@ -138,10 +138,6 @@ def accepted(node): node.p2p.send_blocks_and_test([self.tip], node) - # move the tip back to a previous block - def tip(number): - self.tip = self.blocks[number] - # adds transactions to the block and updates state def update_block(block_number, new_transactions): block = self.blocks[block_number] diff --git a/test/functional/abc-transaction-ordering.py b/test/functional/abc-transaction-ordering.py --- a/test/functional/abc-transaction-ordering.py +++ b/test/functional/abc-transaction-ordering.py @@ -115,6 +115,12 @@ self.blocks[number] = block return block + def set_tip(self, number: int): + """ + Move the tip back to a previous block. + """ + self.tip = self.blocks[number] + def run_test(self): node = self.nodes[0] node.add_p2p_connection(P2PDataStore()) @@ -131,10 +137,6 @@ def get_spendable_output(): return PreviousSpendableOutput(spendable_outputs.pop(0).vtx[0], 0) - # move the tip back to a previous block - def tip(number): - self.tip = self.blocks[number] - # update block state def update_block(block_number): block = self.blocks[block_number] @@ -182,7 +184,7 @@ 5557, out[17], tx_count=16)], node, success=False, reject_reason='tx-ordering') # Rewind bad block. - tip(5556) + self.set_tip(5556) # After we activate the Nov 15, 2018 HF, transaction order is enforced. def ordered_block(block_number, spend): @@ -205,7 +207,7 @@ [self.tip], node, success=False, reject_reason='bad-txns-duplicate') # Rewind bad block. - tip(4446) + self.set_tip(4446) # Check over two blocks. proper_block = ordered_block(4448, out[20]) diff --git a/test/functional/abc_p2p_compactblocks.py b/test/functional/abc_p2p_compactblocks.py --- a/test/functional/abc_p2p_compactblocks.py +++ b/test/functional/abc_p2p_compactblocks.py @@ -235,10 +235,6 @@ def get_spendable_output(): return PreviousSpendableOutput(spendable_outputs.pop(0).vtx[0], 0) - # move the tip back to a previous block - def tip(number): - self.tip = self.blocks[number] - # shorthand for functions block = self.next_block diff --git a/test/functional/abc_p2p_fullblocktest.py b/test/functional/abc_p2p_fullblocktest.py --- a/test/functional/abc_p2p_fullblocktest.py +++ b/test/functional/abc_p2p_fullblocktest.py @@ -190,10 +190,6 @@ def get_spendable_output(): return PreviousSpendableOutput(spendable_outputs.pop(0).vtx[0], 0) - # move the tip back to a previous block - def tip(number): - self.tip = self.blocks[number] - # adds transactions to the block and updates state def update_block(block_number, new_transactions): block = self.blocks[block_number] @@ -248,7 +244,7 @@ [self.tip], node, success=False, reject_reason='bad-blk-length') # Rewind bad block. - tip(17) + self.tip = self.blocks[17] # Submit a very large block via RPC large_block = block(