Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-transaction-ordering.py
- This file was copied to test/functional/abc-magnetic-anomaly-activation.py.
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2016 The Bitcoin Core developers | # Copyright (c) 2018 The Bitcoin developers | ||||
# Copyright (c) 2017 The Bitcoin developers | |||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
""" | """ | ||||
This test checks that the nod esoftware accepts transactions in | This test checks that the node software accepts transactions in | ||||
non topological order once the feature is activated. | non topological order once the feature is activated. | ||||
""" | """ | ||||
from test_framework.test_framework import ComparisonTestFramework | from test_framework.test_framework import ComparisonTestFramework | ||||
from test_framework.util import assert_equal, assert_raises_rpc_error | from test_framework.util import assert_equal, assert_raises_rpc_error | ||||
from test_framework.comptool import TestManager, TestInstance, RejectResult | from test_framework.comptool import TestManager, TestInstance, RejectResult | ||||
from test_framework.blocktools import * | from test_framework.blocktools import * | ||||
import time | import time | ||||
Show All 36 Lines | def run_test(self): | ||||
# Set the blocksize to 2MB as initial condition | # Set the blocksize to 2MB as initial condition | ||||
self.nodes[0].setmocktime(MAGNETIC_ANOMALY_START_TIME) | self.nodes[0].setmocktime(MAGNETIC_ANOMALY_START_TIME) | ||||
self.test.run() | self.test.run() | ||||
def add_transactions_to_block(self, block, tx_list): | def add_transactions_to_block(self, block, tx_list): | ||||
[tx.rehash() for tx in tx_list] | [tx.rehash() for tx in tx_list] | ||||
block.vtx.extend(tx_list) | block.vtx.extend(tx_list) | ||||
# this is a little handier to use than the version in blocktools.py | |||||
def create_tx(self, spend, value, script=CScript([OP_TRUE])): | |||||
tx = create_transaction(spend.tx, spend.n, b"", value, script) | |||||
return tx | |||||
def next_block(self, number, spend=None, tx_count=0): | def next_block(self, number, spend=None, tx_count=0): | ||||
if self.tip == None: | if self.tip == 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 | ||||
else: | else: | ||||
base_block_hash = self.tip.sha256 | base_block_hash = self.tip.sha256 | ||||
block_time = self.tip.nTime + 1 | block_time = self.tip.nTime + 1 | ||||
# First create the coinbase | # First create the coinbase | ||||
Show All 17 Lines | def next_block(self, number, spend=None, tx_count=0): | ||||
tx = CTransaction() | tx = CTransaction() | ||||
# Spend from one of the spendable outputs | # Spend from one of the spendable outputs | ||||
spend = spendable_outputs.popleft() | spend = spendable_outputs.popleft() | ||||
tx.vin.append(CTxIn(COutPoint(spend.tx.sha256, spend.n))) | tx.vin.append(CTxIn(COutPoint(spend.tx.sha256, spend.n))) | ||||
# Add spendable outputs | # Add spendable outputs | ||||
for i in range(4): | for i in range(4): | ||||
tx.vout.append(CTxOut(0, CScript([OP_TRUE]))) | tx.vout.append(CTxOut(0, CScript([OP_TRUE]))) | ||||
spendable_outputs.append(PreviousSpendableOutput(tx, i)) | spendable_outputs.append(PreviousSpendableOutput(tx, i)) | ||||
# Put some random data into the transaction in order to randomize ids. | |||||
# This also ensures that transaction are larger than 100 bytes. | |||||
tx.vout.append( | |||||
CTxOut(0, CScript([random.getrandbits(256), OP_RETURN]))) | |||||
return tx | return tx | ||||
tx = get_base_transaction() | tx = get_base_transaction() | ||||
# Make it the same format as transaction added for padding and save the size. | # Make it the same format as transaction added for padding and save the size. | ||||
# It's missing the padding output, so we add a constant to account for it. | # It's missing the padding output, so we add a constant to account for it. | ||||
tx.rehash() | tx.rehash() | ||||
base_tx_size = len(tx.serialize()) + 18 | |||||
# Put some random data into the first transaction of the chain to randomize ids. | |||||
tx.vout.append( | |||||
CTxOut(0, CScript([random.randint(0, 256), OP_RETURN]))) | |||||
# Add the transaction to the block | # Add the transaction to the block | ||||
self.add_transactions_to_block(block, [tx]) | self.add_transactions_to_block(block, [tx]) | ||||
# If we have a transaction count requirement, just fill the block until we get there | # If we have a transaction count requirement, just fill the block until we get there | ||||
while len(block.vtx) < tx_count: | while len(block.vtx) < tx_count: | ||||
# Create the new transaction and add it. | # Create the new transaction and add it. | ||||
tx = get_base_transaction() | tx = get_base_transaction() | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
# Rewind bad block. | # Rewind bad block. | ||||
tip(5104) | tip(5104) | ||||
# Activate the Nov 15, 2018 HF | # Activate the Nov 15, 2018 HF | ||||
block(5556, out[16], tx_count=16) | block(5556, out[16], tx_count=16) | ||||
yield accepted() | yield accepted() | ||||
# Now MTP is exactly the fork time. Bigger blocks are now accepted. | # Now MTP is exactly the fork time. Transactions are expected to be ordered now. | ||||
assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | ||||
MAGNETIC_ANOMALY_START_TIME) | MAGNETIC_ANOMALY_START_TIME) | ||||
# Block with regular ordering are now rejected. | # Block with regular ordering are now rejected. | ||||
block(5557, out[17], tx_count=16) | block(5557, out[17], tx_count=16) | ||||
yield rejected(RejectResult(16, b'tx-ordering')) | yield rejected(RejectResult(16, b'tx-ordering')) | ||||
# Rewind bad block. | # Rewind bad block. | ||||
Show All 21 Lines |