mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-26 08:56:24 +01:00
test: Add anchor mempool acceptance test
This commit is contained in:
parent
9d89209937
commit
1349e9ec15
2 changed files with 54 additions and 0 deletions
|
@ -37,6 +37,7 @@ from test_framework.script_util import (
|
|||
keys_to_multisig_script,
|
||||
MIN_PADDING,
|
||||
MIN_STANDARD_TX_NONWITNESS_SIZE,
|
||||
PAY_TO_ANCHOR,
|
||||
script_to_p2sh_script,
|
||||
script_to_p2wsh_script,
|
||||
)
|
||||
|
@ -389,6 +390,56 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
|
|||
maxfeerate=0,
|
||||
)
|
||||
|
||||
self.log.info('OP_1 <0x4e73> is able to be created and spent')
|
||||
anchor_value = 10000
|
||||
create_anchor_tx = self.wallet.send_to(from_node=node, scriptPubKey=PAY_TO_ANCHOR, amount=anchor_value)
|
||||
self.generate(node, 1)
|
||||
|
||||
# First spend has non-empty witness, will be rejected to prevent third party wtxid malleability
|
||||
anchor_nonempty_wit_spend = CTransaction()
|
||||
anchor_nonempty_wit_spend.vin.append(CTxIn(COutPoint(int(create_anchor_tx["txid"], 16), create_anchor_tx["sent_vout"]), b""))
|
||||
anchor_nonempty_wit_spend.vout.append(CTxOut(anchor_value - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE]))))
|
||||
anchor_nonempty_wit_spend.wit.vtxinwit.append(CTxInWitness())
|
||||
anchor_nonempty_wit_spend.wit.vtxinwit[0].scriptWitness.stack.append(b"f")
|
||||
anchor_nonempty_wit_spend.rehash()
|
||||
|
||||
self.check_mempool_result(
|
||||
result_expected=[{'txid': anchor_nonempty_wit_spend.rehash(), 'allowed': False, 'reject-reason': 'bad-witness-nonstandard'}],
|
||||
rawtxs=[anchor_nonempty_wit_spend.serialize().hex()],
|
||||
maxfeerate=0,
|
||||
)
|
||||
|
||||
# Clear witness stuffing
|
||||
anchor_spend = anchor_nonempty_wit_spend
|
||||
anchor_spend.wit.vtxinwit[0].scriptWitness.stack = []
|
||||
anchor_spend.rehash()
|
||||
|
||||
self.check_mempool_result(
|
||||
result_expected=[{'txid': anchor_spend.rehash(), 'allowed': True, 'vsize': anchor_spend.get_vsize(), 'fees': { 'base': Decimal('0.00000700')}}],
|
||||
rawtxs=[anchor_spend.serialize().hex()],
|
||||
maxfeerate=0,
|
||||
)
|
||||
|
||||
self.log.info('But cannot be spent if nested sh()')
|
||||
nested_anchor_tx = self.wallet.create_self_transfer(sequence=SEQUENCE_FINAL)['tx']
|
||||
nested_anchor_tx.vout[0].scriptPubKey = script_to_p2sh_script(PAY_TO_ANCHOR)
|
||||
nested_anchor_tx.rehash()
|
||||
self.generateblock(node, self.wallet.get_address(), [nested_anchor_tx.serialize().hex()])
|
||||
|
||||
nested_anchor_spend = CTransaction()
|
||||
nested_anchor_spend.vin.append(CTxIn(COutPoint(nested_anchor_tx.sha256, 0), b""))
|
||||
nested_anchor_spend.vin[0].scriptSig = CScript([bytes(PAY_TO_ANCHOR)])
|
||||
nested_anchor_spend.vout.append(CTxOut(nested_anchor_tx.vout[0].nValue - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE]))))
|
||||
nested_anchor_spend.rehash()
|
||||
|
||||
self.check_mempool_result(
|
||||
result_expected=[{'txid': nested_anchor_spend.rehash(), 'allowed': False, 'reject-reason': 'non-mandatory-script-verify-flag (Witness version reserved for soft-fork upgrades)'}],
|
||||
rawtxs=[nested_anchor_spend.serialize().hex()],
|
||||
maxfeerate=0,
|
||||
)
|
||||
# but is consensus-legal
|
||||
self.generateblock(node, self.wallet.get_address(), [nested_anchor_spend.serialize().hex()])
|
||||
|
||||
self.log.info('Spending a confirmed bare multisig is okay')
|
||||
address = self.wallet.get_address()
|
||||
tx = tx_from_hex(raw_tx_reference)
|
||||
|
|
|
@ -8,6 +8,7 @@ import unittest
|
|||
from test_framework.script import (
|
||||
CScript,
|
||||
OP_0,
|
||||
OP_1,
|
||||
OP_15,
|
||||
OP_16,
|
||||
OP_CHECKMULTISIG,
|
||||
|
@ -42,6 +43,8 @@ assert MIN_PADDING == 5
|
|||
DUMMY_MIN_OP_RETURN_SCRIPT = CScript([OP_RETURN] + ([OP_0] * (MIN_PADDING - 1)))
|
||||
assert len(DUMMY_MIN_OP_RETURN_SCRIPT) == MIN_PADDING
|
||||
|
||||
PAY_TO_ANCHOR = CScript([OP_1, bytes.fromhex("4e73")])
|
||||
|
||||
def key_to_p2pk_script(key):
|
||||
key = check_key(key)
|
||||
return CScript([key, OP_CHECKSIG])
|
||||
|
|
Loading…
Add table
Reference in a new issue