Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-replay-protection.py
Show All 11 Lines | |||||
import time | import time | ||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_block, | create_block, | ||||
create_coinbase, | create_coinbase, | ||||
create_tx_with_script, | create_tx_with_script, | ||||
make_conform_to_ctor, | make_conform_to_ctor, | ||||
) | ) | ||||
from test_framework.key import CECKey | from test_framework.key import ECKey | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
COIN, | COIN, | ||||
COutPoint, | COutPoint, | ||||
CTransaction, | CTransaction, | ||||
CTxIn, | CTxIn, | ||||
CTxOut, | CTxOut, | ||||
ToHex, | ToHex, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
node.p2p.send_blocks_and_test(maturity_blocks, node) | node.p2p.send_blocks_and_test(maturity_blocks, node) | ||||
# 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(100): | for i in range(100): | ||||
out.append(get_spendable_output()) | out.append(get_spendable_output()) | ||||
# 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"replayprotection") | private_key.generate() | ||||
public_key = private_key.get_pubkey() | public_key = private_key.get_pubkey().get_bytes() | ||||
# This is a little handier to use than the version in blocktools.py | # This is a little handier to use than the version in blocktools.py | ||||
def create_fund_and_spend_tx(spend, forkvalue=0): | def create_fund_and_spend_tx(spend, forkvalue=0): | ||||
# Fund transaction | # Fund transaction | ||||
script = CScript([public_key, OP_CHECKSIG]) | script = CScript([public_key, OP_CHECKSIG]) | ||||
txfund = create_tx_with_script( | txfund = create_tx_with_script( | ||||
spend.tx, spend.n, b'', 50 * COIN - 1000, script) | spend.tx, spend.n, b'', 50 * COIN - 1000, script) | ||||
txfund.rehash() | txfund.rehash() | ||||
# Spend transaction | # Spend transaction | ||||
txspend = CTransaction() | txspend = CTransaction() | ||||
txspend.vout.append(CTxOut(50 * COIN - 2000, CScript([OP_TRUE]))) | txspend.vout.append(CTxOut(50 * COIN - 2000, CScript([OP_TRUE]))) | ||||
txspend.vin.append(CTxIn(COutPoint(txfund.sha256, 0), b'')) | txspend.vin.append(CTxIn(COutPoint(txfund.sha256, 0), b'')) | ||||
# Sign the transaction | # Sign the transaction | ||||
sighashtype = (forkvalue << 8) | SIGHASH_ALL | SIGHASH_FORKID | sighashtype = (forkvalue << 8) | SIGHASH_ALL | SIGHASH_FORKID | ||||
sighash = SignatureHashForkId( | sighash = SignatureHashForkId( | ||||
script, txspend, 0, sighashtype, 50 * COIN - 1000) | script, txspend, 0, sighashtype, 50 * COIN - 1000) | ||||
sig = private_key.sign(sighash) + \ | sig = private_key.sign_ecdsa(sighash) + \ | ||||
bytes(bytearray([SIGHASH_ALL | SIGHASH_FORKID])) | bytes(bytearray([SIGHASH_ALL | SIGHASH_FORKID])) | ||||
txspend.vin[0].scriptSig = CScript([sig]) | txspend.vin[0].scriptSig = CScript([sig]) | ||||
txspend.rehash() | txspend.rehash() | ||||
return [txfund, txspend] | return [txfund, txspend] | ||||
def send_transaction_to_mempool(tx): | def send_transaction_to_mempool(tx): | ||||
tx_id = node.sendrawtransaction(ToHex(tx)) | tx_id = node.sendrawtransaction(ToHex(tx)) | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |