Skip to content

Commit

Permalink
test: Add test case for spending bare multisig
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Towns <aj@erisian.com.au>
  • Loading branch information
BrandonOdiwuor and ajtowns committed Jan 8, 2024
1 parent 3a0f54d commit e2fa191
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/functional/mempool_accept.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
OP_HASH160,
OP_RETURN,
OP_TRUE,
SIGHASH_ALL,
sign_input_legacy,
)
from test_framework.script_util import (
DUMMY_MIN_OP_RETURN_SCRIPT,
Expand Down Expand Up @@ -372,5 +374,24 @@ def run_test(self):
maxfeerate=0,
)

self.log.info('Spending a confirmed bare multisig is okay')
address = self.wallet.get_address()
tx = tx_from_hex(raw_tx_reference)
privkey, pubkey = generate_keypair()
tx.vout[0].scriptPubKey = keys_to_multisig_script([pubkey] * 3, k=1) # Some bare multisig script (1-of-3)
tx.rehash()
self.generateblock(node, address, [tx.serialize().hex()])
tx_spend = CTransaction()
tx_spend.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
tx_spend.vout.append(CTxOut(tx.vout[0].nValue - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE]))))
tx_spend.rehash()
sign_input_legacy(tx_spend, 0, tx.vout[0].scriptPubKey, privkey, sighash_type=SIGHASH_ALL)
tx_spend.vin[0].scriptSig = bytes(CScript([OP_0])) + tx_spend.vin[0].scriptSig
self.check_mempool_result(
result_expected=[{'txid': tx_spend.rehash(), 'allowed': True, 'vsize': tx_spend.get_vsize(), 'fees': { 'base': Decimal('0.00000700')}}],
rawtxs=[tx_spend.serialize().hex()],
maxfeerate=0,
)

if __name__ == '__main__':
MempoolAcceptanceTest().main()

0 comments on commit e2fa191

Please sign in to comment.