mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-12 17:12:37 +02:00
Add test for unspendable transactions and parameter 'maxburnamount' to sendrawtransaction.
'maxburnamount' sets a maximum value for outputs heuristically deemed unspendable including datacarrier scripts that begin with `OP_RETURN`.
This commit is contained in:
@ -18,9 +18,17 @@ from itertools import product
|
||||
|
||||
from test_framework.messages import (
|
||||
MAX_BIP125_RBF_SEQUENCE,
|
||||
COIN,
|
||||
CTransaction,
|
||||
CTxOut,
|
||||
tx_from_hex,
|
||||
)
|
||||
from test_framework.script import (
|
||||
CScript,
|
||||
OP_FALSE,
|
||||
OP_INVALIDOPCODE,
|
||||
OP_RETURN,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
@ -331,6 +339,57 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
|
||||
assert_raises_rpc_error(-25, "bad-txns-inputs-missingorspent", self.nodes[2].sendrawtransaction, rawtx)
|
||||
|
||||
self.log.info("Test sendrawtransaction exceeding, falling short of, and equaling maxburnamount")
|
||||
max_burn_exceeded = "Unspendable output exceeds maximum configured by user (maxburnamount)"
|
||||
|
||||
|
||||
# Test that spendable transaction with default maxburnamount (0) gets sent
|
||||
tx = self.wallet.create_self_transfer()['tx']
|
||||
tx_hex = tx.serialize().hex()
|
||||
self.nodes[2].sendrawtransaction(hexstring=tx_hex)
|
||||
|
||||
# Test that datacarrier transaction with default maxburnamount (0) does not get sent
|
||||
tx = self.wallet.create_self_transfer()['tx']
|
||||
tx_val = 0.001
|
||||
tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_RETURN] + [OP_FALSE] * 30))]
|
||||
tx_hex = tx.serialize().hex()
|
||||
assert_raises_rpc_error(-25, max_burn_exceeded, self.nodes[2].sendrawtransaction, tx_hex)
|
||||
|
||||
# Test that oversized script gets rejected by sendrawtransaction
|
||||
tx = self.wallet.create_self_transfer()['tx']
|
||||
tx_val = 0.001
|
||||
tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_FALSE] * 10001))]
|
||||
tx_hex = tx.serialize().hex()
|
||||
assert_raises_rpc_error(-25, max_burn_exceeded, self.nodes[2].sendrawtransaction, tx_hex)
|
||||
|
||||
# Test that script containing invalid opcode gets rejected by sendrawtransaction
|
||||
tx = self.wallet.create_self_transfer()['tx']
|
||||
tx_val = 0.01
|
||||
tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_INVALIDOPCODE]))]
|
||||
tx_hex = tx.serialize().hex()
|
||||
assert_raises_rpc_error(-25, max_burn_exceeded, self.nodes[2].sendrawtransaction, tx_hex)
|
||||
|
||||
# Test a transaction where our burn exceeds maxburnamount
|
||||
tx = self.wallet.create_self_transfer()['tx']
|
||||
tx_val = 0.001
|
||||
tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_RETURN] + [OP_FALSE] * 30))]
|
||||
tx_hex = tx.serialize().hex()
|
||||
assert_raises_rpc_error(-25, max_burn_exceeded, self.nodes[2].sendrawtransaction, tx_hex, 0, 0.0009)
|
||||
|
||||
# Test a transaction where our burn falls short of maxburnamount
|
||||
tx = self.wallet.create_self_transfer()['tx']
|
||||
tx_val = 0.001
|
||||
tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_RETURN] + [OP_FALSE] * 30))]
|
||||
tx_hex = tx.serialize().hex()
|
||||
self.nodes[2].sendrawtransaction(hexstring=tx_hex, maxfeerate='0', maxburnamount='0.0011')
|
||||
|
||||
# Test a transaction where our burn equals maxburnamount
|
||||
tx = self.wallet.create_self_transfer()['tx']
|
||||
tx_val = 0.001
|
||||
tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_RETURN] + [OP_FALSE] * 30))]
|
||||
tx_hex = tx.serialize().hex()
|
||||
self.nodes[2].sendrawtransaction(hexstring=tx_hex, maxfeerate='0', maxburnamount='0.001')
|
||||
|
||||
def sendrawtransaction_testmempoolaccept_tests(self):
|
||||
self.log.info("Test sendrawtransaction/testmempoolaccept with maxfeerate")
|
||||
fee_exceeds_max = "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)"
|
||||
|
Reference in New Issue
Block a user