diff options
author | Greg Sanders <gsanders87@gmail.com> | 2024-06-27 14:45:01 -0400 |
---|---|---|
committer | Greg Sanders <gsanders87@gmail.com> | 2024-07-30 14:06:58 -0400 |
commit | 1349e9ec1558484f2912a2444c410170fcec8745 (patch) | |
tree | 888471c451e464bab2e03a81847ab6b99f868312 /test | |
parent | 9d892099378b2ad5f52220403bdeae43c61d6955 (diff) |
test: Add anchor mempool acceptance test
Diffstat (limited to 'test')
-rwxr-xr-x | test/functional/mempool_accept.py | 51 | ||||
-rwxr-xr-x | test/functional/test_framework/script_util.py | 3 |
2 files changed, 54 insertions, 0 deletions
diff --git a/test/functional/mempool_accept.py b/test/functional/mempool_accept.py index 2b841f3791..4b9ff3d138 100755 --- a/test/functional/mempool_accept.py +++ b/test/functional/mempool_accept.py @@ -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) diff --git a/test/functional/test_framework/script_util.py b/test/functional/test_framework/script_util.py index 855f3b8cf5..938183ece4 100755 --- a/test/functional/test_framework/script_util.py +++ b/test/functional/test_framework/script_util.py @@ -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]) |