Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-mempool-accept-txn.py
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.block_heights = {} | self.block_heights = {} | ||||
self.coinbase_key = CECKey() | self.coinbase_key = CECKey() | ||||
self.coinbase_key.set_secretbytes(b"horsebattery") | self.coinbase_key.set_secretbytes(b"horsebattery") | ||||
self.coinbase_pubkey = self.coinbase_key.get_pubkey() | self.coinbase_pubkey = self.coinbase_key.get_pubkey() | ||||
self.tip = None | self.tip = None | ||||
self.blocks = {} | self.blocks = {} | ||||
def setup_network(self): | |||||
self.extra_args = [['-norelaypriority']] | |||||
self.add_nodes(self.num_nodes, self.extra_args) | |||||
self.start_nodes() | |||||
def add_options(self, parser): | def add_options(self, parser): | ||||
super().add_options(parser) | super().add_options(parser) | ||||
parser.add_argument( | parser.add_argument( | ||||
"--runbarelyexpensive", dest="runbarelyexpensive", default=True) | "--runbarelyexpensive", dest="runbarelyexpensive", default=True) | ||||
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) | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
p2sh_script = CScript([OP_HASH160, redeem_script_hash, OP_EQUAL]) | p2sh_script = CScript([OP_HASH160, redeem_script_hash, OP_EQUAL]) | ||||
# Creates a new transaction using a p2sh transaction as input | # Creates a new transaction using a p2sh transaction as input | ||||
def spend_p2sh_tx(p2sh_tx_to_spend, output_script=CScript([OP_TRUE])): | def spend_p2sh_tx(p2sh_tx_to_spend, output_script=CScript([OP_TRUE])): | ||||
# Create the transaction | # Create the transaction | ||||
spent_p2sh_tx = CTransaction() | spent_p2sh_tx = CTransaction() | ||||
spent_p2sh_tx.vin.append( | spent_p2sh_tx.vin.append( | ||||
CTxIn(COutPoint(p2sh_tx_to_spend.sha256, 0), b'')) | CTxIn(COutPoint(p2sh_tx_to_spend.sha256, 0), b'')) | ||||
spent_p2sh_tx.vout.append(CTxOut(1, output_script)) | spent_p2sh_tx.vout.append(CTxOut(1000, output_script)) | ||||
# Sign the transaction using the redeem script | # Sign the transaction using the redeem script | ||||
sighash = SignatureHashForkId( | sighash = SignatureHashForkId( | ||||
redeem_script, spent_p2sh_tx, 0, SIGHASH_ALL | SIGHASH_FORKID, p2sh_tx_to_spend.vout[0].nValue) | redeem_script, spent_p2sh_tx, 0, SIGHASH_ALL | SIGHASH_FORKID, p2sh_tx_to_spend.vout[0].nValue) | ||||
sig = self.coinbase_key.sign( | sig = self.coinbase_key.sign( | ||||
sighash) + bytes(bytearray([SIGHASH_ALL | SIGHASH_FORKID])) | sighash) + bytes(bytearray([SIGHASH_ALL | SIGHASH_FORKID])) | ||||
spent_p2sh_tx.vin[0].scriptSig = CScript([sig, redeem_script]) | spent_p2sh_tx.vin[0].scriptSig = CScript([sig, redeem_script]) | ||||
spent_p2sh_tx.rehash() | spent_p2sh_tx.rehash() | ||||
return spent_p2sh_tx | return spent_p2sh_tx | ||||
# P2SH tests | # P2SH tests | ||||
# Create a p2sh transaction | # Create a p2sh transaction | ||||
p2sh_tx = self.create_and_sign_transaction( | p2sh_tx = self.create_and_sign_transaction( | ||||
out[0].tx, out[0].n, 1, p2sh_script) | out[0].tx, out[0].n, 10000, p2sh_script) | ||||
# Add the transaction to the block | # Add the transaction to the block | ||||
block(1) | block(1) | ||||
update_block(1, [p2sh_tx]) | update_block(1, [p2sh_tx]) | ||||
node.p2p.send_blocks_and_test([self.tip], node) | node.p2p.send_blocks_and_test([self.tip], node) | ||||
# Sigops p2sh limit for the mempool test | # Sigops p2sh limit for the mempool test | ||||
p2sh_sigops_limit_mempool = MAX_STANDARD_TX_SIGOPS - \ | p2sh_sigops_limit_mempool = MAX_STANDARD_TX_SIGOPS - \ | ||||
Show All 33 Lines |