Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-mempool-coherence-on-activations.py
Show All 16 Lines | |||||
3) on a reorg to a chain that deactivates and reactivates the fork, | 3) on a reorg to a chain that deactivates and reactivates the fork, | ||||
post-fork-only and always-valid transactions (unconfirmed and/or once | post-fork-only and always-valid transactions (unconfirmed and/or once | ||||
confirmed on the shorter chain) are kept or reincluded in the mempool. | confirmed on the shorter chain) are kept or reincluded in the mempool. | ||||
""" | """ | ||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_block, | create_block, | ||||
create_coinbase, | create_coinbase, | ||||
create_transaction, | create_tx_with_script, | ||||
make_conform_to_ctor, | make_conform_to_ctor, | ||||
) | ) | ||||
from test_framework.key import CECKey | from test_framework.key import CECKey | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
COIN, | COIN, | ||||
COutPoint, | COutPoint, | ||||
CTransaction, | CTransaction, | ||||
CTxIn, | CTxIn, | ||||
Show All 39 Lines | def create_fund_and_activation_specific_spending_tx(spend, pre_fork_only): | ||||
# Generate a key pair to test | # Generate a key pair to test | ||||
private_key = CECKey() | private_key = CECKey() | ||||
private_key.set_secretbytes(b"replayprotection") | private_key.set_secretbytes(b"replayprotection") | ||||
public_key = private_key.get_pubkey() | public_key = private_key.get_pubkey() | ||||
# Fund transaction | # Fund transaction | ||||
script = CScript([public_key, OP_CHECKSIG]) | script = CScript([public_key, OP_CHECKSIG]) | ||||
txfund = create_transaction( | txfund = create_tx_with_script( | ||||
spend.tx, spend.n, b'', 50 * COIN, script) | spend.tx, spend.n, b'', 50 * COIN, script) | ||||
txfund.rehash() | txfund.rehash() | ||||
# Activation specific spending tx | # Activation specific spending tx | ||||
txspend = CTransaction() | txspend = CTransaction() | ||||
txspend.vout.append(CTxOut(50 * COIN - 1000, CScript([OP_TRUE]))) | txspend.vout.append(CTxOut(50 * COIN - 1000, CScript([OP_TRUE]))) | ||||
txspend.vin.append(CTxIn(COutPoint(txfund.sha256, 0), b'')) | txspend.vin.append(CTxIn(COutPoint(txfund.sha256, 0), b'')) | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# checks the mempool has exactly the same txns as in the provided list | # checks the mempool has exactly the same txns as in the provided list | ||||
def check_mempool_equal(txns): | def check_mempool_equal(txns): | ||||
assert set(node.getrawmempool()) == set(tx.hash for tx in txns) | assert set(node.getrawmempool()) == set(tx.hash for tx in txns) | ||||
# Create an always-valid chained transaction. It spends a | # Create an always-valid chained transaction. It spends a | ||||
# scriptPub=OP_TRUE coin into another. Returns the transaction and its | # scriptPub=OP_TRUE coin into another. Returns the transaction and its | ||||
# spendable output for further chaining. | # spendable output for further chaining. | ||||
def create_always_valid_chained_tx(spend): | def create_always_valid_chained_tx(spend): | ||||
tx = create_transaction( | tx = create_tx_with_script( | ||||
spend.tx, spend.n, b'', spend.tx.vout[0].nValue - 1000, CScript([OP_TRUE])) | spend.tx, spend.n, b'', spend.tx.vout[0].nValue - 1000, CScript([OP_TRUE])) | ||||
tx.rehash() | tx.rehash() | ||||
return tx, PreviousSpendableOutput(tx, 0) | return tx, PreviousSpendableOutput(tx, 0) | ||||
# shorthand | # shorthand | ||||
block = self.next_block | block = self.next_block | ||||
# Create a new block | # Create a new block | ||||
▲ Show 20 Lines • Show All 159 Lines • Show Last 20 Lines |