Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-p2p-fullblocktest-sigops.py
Show All 20 Lines | from test_framework.blocktools import ( | ||||
create_tx_with_script, | create_tx_with_script, | ||||
make_conform_to_ctor, | make_conform_to_ctor, | ||||
) | ) | ||||
from test_framework.cdefs import ( | from test_framework.cdefs import ( | ||||
MAX_BLOCK_SIGOPS_PER_MB, | MAX_BLOCK_SIGOPS_PER_MB, | ||||
MAX_TX_SIGOPS_COUNT, | MAX_TX_SIGOPS_COUNT, | ||||
ONE_MEGABYTE, | ONE_MEGABYTE, | ||||
) | ) | ||||
from test_framework.key import CECKey | from test_framework.key import ECKey | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
COutPoint, | COutPoint, | ||||
CTransaction, | CTransaction, | ||||
CTxIn, | CTxIn, | ||||
CTxOut, | CTxOut, | ||||
ser_compact_size, | ser_compact_size, | ||||
) | ) | ||||
from test_framework.mininode import P2PDataStore | from test_framework.mininode import P2PDataStore | ||||
▲ Show 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
29, spend=out[6], script=too_many_tx_checksigs, block_size=ONE_MEGABYTE + 1) | 29, spend=out[6], script=too_many_tx_checksigs, block_size=ONE_MEGABYTE + 1) | ||||
node.p2p.send_blocks_and_test( | node.p2p.send_blocks_and_test( | ||||
[self.tip], node, success=False, reject_reason='bad-txn-sigops') | [self.tip], node, success=False, reject_reason='bad-txn-sigops') | ||||
# Rewind bad block | # Rewind bad block | ||||
tip(26) | tip(26) | ||||
# Generate a key pair to test P2SH sigops count | # Generate a key pair to test P2SH sigops count | ||||
private_key = CECKey() | private_key = ECKey() | ||||
private_key.set_secretbytes(b"fatstacks") | private_key.generate() | ||||
public_key = private_key.get_pubkey() | public_key = private_key.get_pubkey().get_bytes() | ||||
# 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( | redeem_script = CScript( | ||||
[public_key] + [OP_2DUP, OP_CHECKSIGVERIFY] * 5 + [OP_CHECKSIG]) | [public_key] + [OP_2DUP, OP_CHECKSIGVERIFY] * 5 + [OP_CHECKSIG]) | ||||
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]) | ||||
Show All 10 Lines | def run_test(self): | ||||
def spend_p2sh_tx(output_script=CScript([OP_TRUE])): | def spend_p2sh_tx(output_script=CScript([OP_TRUE])): | ||||
# Create the transaction | # Create the transaction | ||||
spent_p2sh_tx = CTransaction() | spent_p2sh_tx = CTransaction() | ||||
spent_p2sh_tx.vin.append(CTxIn(COutPoint(p2sh_tx.sha256, 0), b'')) | spent_p2sh_tx.vin.append(CTxIn(COutPoint(p2sh_tx.sha256, 0), b'')) | ||||
spent_p2sh_tx.vout.append(CTxOut(1, output_script)) | spent_p2sh_tx.vout.append(CTxOut(1, 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.vout[0].nValue) | redeem_script, spent_p2sh_tx, 0, SIGHASH_ALL | SIGHASH_FORKID, p2sh_tx.vout[0].nValue) | ||||
sig = private_key.sign(sighash) + \ | sig = private_key.sign_ecdsa(sighash) + \ | ||||
bytes(bytearray([SIGHASH_ALL | SIGHASH_FORKID])) | 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 | ||||
# Sigops p2sh limit | # Sigops p2sh limit | ||||
p2sh_sigops_limit = MAX_BLOCK_SIGOPS_PER_MB - \ | p2sh_sigops_limit = MAX_BLOCK_SIGOPS_PER_MB - \ | ||||
redeem_script.GetSigOpCount(True) | redeem_script.GetSigOpCount(True) | ||||
Show All 33 Lines |