Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-mempool-accept-txn.py
Show All 10 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, | ||||
) | ) | ||||
from test_framework.cdefs import MAX_STANDARD_TX_SIGOPS | from test_framework.cdefs import MAX_STANDARD_TX_SIGOPS | ||||
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, | ||||
ToHex, | ToHex, | ||||
) | ) | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
Show All 32 Lines | |||||
class FullBlockTest(BitcoinTestFramework): | class FullBlockTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.block_heights = {} | self.block_heights = {} | ||||
self.coinbase_key = CECKey() | self.coinbase_key = ECKey() | ||||
self.coinbase_key.set_secretbytes(b"horsebattery") | # The test expects uncompressed keys | ||||
self.coinbase_pubkey = self.coinbase_key.get_pubkey() | self.coinbase_key.generate(compressed=False) | ||||
self.coinbase_pubkey = self.coinbase_key.get_pubkey().get_bytes() | |||||
self.tip = None | self.tip = None | ||||
self.blocks = {} | self.blocks = {} | ||||
self.extra_args = [ | self.extra_args = [ | ||||
['-phononactivationtime={}'.format(SIGOPS_DEACTIVATION_TIME), | ['-phononactivationtime={}'.format(SIGOPS_DEACTIVATION_TIME), | ||||
'-acceptnonstdtxn=1']] | '-acceptnonstdtxn=1']] | ||||
def add_options(self, parser): | def add_options(self, parser): | ||||
super().add_options(parser) | super().add_options(parser) | ||||
Show All 17 Lines | class FullBlockTest(BitcoinTestFramework): | ||||
def sign_tx(self, tx, spend_tx, n): | def sign_tx(self, tx, spend_tx, n): | ||||
scriptPubKey = bytearray(spend_tx.vout[n].scriptPubKey) | scriptPubKey = bytearray(spend_tx.vout[n].scriptPubKey) | ||||
if (scriptPubKey[0] == OP_TRUE): # an anyone-can-spend | if (scriptPubKey[0] == OP_TRUE): # an anyone-can-spend | ||||
tx.vin[0].scriptSig = CScript() | tx.vin[0].scriptSig = CScript() | ||||
return | return | ||||
sighash = SignatureHashForkId( | sighash = SignatureHashForkId( | ||||
spend_tx.vout[n].scriptPubKey, tx, 0, SIGHASH_ALL | SIGHASH_FORKID, spend_tx.vout[n].nValue) | spend_tx.vout[n].scriptPubKey, tx, 0, SIGHASH_ALL | SIGHASH_FORKID, spend_tx.vout[n].nValue) | ||||
tx.vin[0].scriptSig = CScript( | tx.vin[0].scriptSig = CScript( | ||||
[self.coinbase_key.sign(sighash) + bytes(bytearray([SIGHASH_ALL | SIGHASH_FORKID]))]) | [self.coinbase_key.sign_ecdsa(sighash) + bytes(bytearray([SIGHASH_ALL | SIGHASH_FORKID]))]) | ||||
def create_and_sign_transaction( | def create_and_sign_transaction( | ||||
self, spend_tx, n, value, script=CScript([OP_TRUE])): | self, spend_tx, n, value, script=CScript([OP_TRUE])): | ||||
tx = self.create_tx(spend_tx, n, value, script) | tx = self.create_tx(spend_tx, n, value, script) | ||||
self.sign_tx(tx, spend_tx, n) | self.sign_tx(tx, spend_tx, n) | ||||
tx.rehash() | tx.rehash() | ||||
return tx | return tx | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# 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_ecdsa( | ||||
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( | assert len( | ||||
spent_p2sh_tx.vin[0].scriptSig) >= 198, "needs to pass input sigchecks limit" | 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 | ||||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |