Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-mempool-accept-txn.py
Show All 27 Lines | from test_framework.mininode import ( | ||||
P2PDataStore, | P2PDataStore, | ||||
) | ) | ||||
from test_framework.script import ( | from test_framework.script import ( | ||||
CScript, | CScript, | ||||
hash160, | hash160, | ||||
OP_2DUP, | OP_2DUP, | ||||
OP_CHECKSIG, | OP_CHECKSIG, | ||||
OP_CHECKSIGVERIFY, | OP_CHECKSIGVERIFY, | ||||
OP_DROP, | |||||
OP_EQUAL, | OP_EQUAL, | ||||
OP_HASH160, | OP_HASH160, | ||||
OP_TRUE, | OP_TRUE, | ||||
SIGHASH_ALL, | SIGHASH_ALL, | ||||
SIGHASH_FORKID, | SIGHASH_FORKID, | ||||
SignatureHashForkId, | SignatureHashForkId, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Collect spendable outputs now to avoid cluttering the code later on | # Collect spendable outputs now to avoid cluttering the code later on | ||||
out = [] | out = [] | ||||
for i in range(33): | for i in range(33): | ||||
out.append(get_spendable_output()) | out.append(get_spendable_output()) | ||||
# P2SH | # P2SH | ||||
# Build the redeem script, hash it, use hash to create the p2sh script | # Build the redeem script, hash it, use hash to create the p2sh script | ||||
redeem_script = CScript([self.coinbase_pubkey] + [ | # Pad with extra bytes to make sure that the scriptsig length will be | ||||
# >= 198 after signature is added, even if it's a schnorr sig; this | |||||
# ensures a not-too-high density of sigchecks. | |||||
redeem_script = CScript([b'X' * 51, OP_DROP, self.coinbase_pubkey] + [ | |||||
OP_2DUP, OP_CHECKSIGVERIFY] * 5 + [OP_CHECKSIG]) | OP_2DUP, OP_CHECKSIGVERIFY] * 5 + [OP_CHECKSIG]) | ||||
# should be this length since coinbase_pubkey is uncompressed. | |||||
assert_equal(len(redeem_script), 130) | |||||
redeem_script_hash = hash160(redeem_script) | redeem_script_hash = hash160(redeem_script) | ||||
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(1000, 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]) | ||||
assert len( | |||||
spent_p2sh_tx.vin[0].scriptSig) >= 198, "needs to pass input sigchecks limit" | |||||
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, 10000, p2sh_script) | out[0].tx, out[0].n, 10000, p2sh_script) | ||||
Show All 40 Lines |