|
18 | 18 |
|
19 | 19 | from test_framework.messages import (
|
20 | 20 | MAX_BIP125_RBF_SEQUENCE,
|
| 21 | + COIN, |
21 | 22 | CTransaction,
|
| 23 | + CTxOut, |
22 | 24 | tx_from_hex,
|
23 | 25 | )
|
| 26 | +from test_framework.script import ( |
| 27 | + CScript, |
| 28 | + OP_FALSE, |
| 29 | + OP_INVALIDOPCODE, |
| 30 | + OP_RETURN, |
| 31 | +) |
24 | 32 | from test_framework.test_framework import BitcoinTestFramework
|
25 | 33 | from test_framework.util import (
|
26 | 34 | assert_equal,
|
@@ -331,6 +339,57 @@ def sendrawtransaction_tests(self):
|
331 | 339 | rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
|
332 | 340 | assert_raises_rpc_error(-25, "bad-txns-inputs-missingorspent", self.nodes[2].sendrawtransaction, rawtx)
|
333 | 341 |
|
| 342 | + self.log.info("Test sendrawtransaction exceeding, falling short of, and equaling maxburnamount") |
| 343 | + max_burn_exceeded = "Unspendable output exceeds maximum configured by user (maxburnamount)" |
| 344 | + |
| 345 | + |
| 346 | + # Test that spendable transaction with default maxburnamount (0) gets sent |
| 347 | + tx = self.wallet.create_self_transfer()['tx'] |
| 348 | + tx_hex = tx.serialize().hex() |
| 349 | + self.nodes[2].sendrawtransaction(hexstring=tx_hex) |
| 350 | + |
| 351 | + # Test that datacarrier transaction with default maxburnamount (0) does not get sent |
| 352 | + tx = self.wallet.create_self_transfer()['tx'] |
| 353 | + tx_val = 0.001 |
| 354 | + tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_RETURN] + [OP_FALSE] * 30))] |
| 355 | + tx_hex = tx.serialize().hex() |
| 356 | + assert_raises_rpc_error(-25, max_burn_exceeded, self.nodes[2].sendrawtransaction, tx_hex) |
| 357 | + |
| 358 | + # Test that oversized script gets rejected by sendrawtransaction |
| 359 | + tx = self.wallet.create_self_transfer()['tx'] |
| 360 | + tx_val = 0.001 |
| 361 | + tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_FALSE] * 10001))] |
| 362 | + tx_hex = tx.serialize().hex() |
| 363 | + assert_raises_rpc_error(-25, max_burn_exceeded, self.nodes[2].sendrawtransaction, tx_hex) |
| 364 | + |
| 365 | + # Test that script containing invalid opcode gets rejected by sendrawtransaction |
| 366 | + tx = self.wallet.create_self_transfer()['tx'] |
| 367 | + tx_val = 0.01 |
| 368 | + tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_INVALIDOPCODE]))] |
| 369 | + tx_hex = tx.serialize().hex() |
| 370 | + assert_raises_rpc_error(-25, max_burn_exceeded, self.nodes[2].sendrawtransaction, tx_hex) |
| 371 | + |
| 372 | + # Test a transaction where our burn exceeds maxburnamount |
| 373 | + tx = self.wallet.create_self_transfer()['tx'] |
| 374 | + tx_val = 0.001 |
| 375 | + tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_RETURN] + [OP_FALSE] * 30))] |
| 376 | + tx_hex = tx.serialize().hex() |
| 377 | + assert_raises_rpc_error(-25, max_burn_exceeded, self.nodes[2].sendrawtransaction, tx_hex, 0, 0.0009) |
| 378 | + |
| 379 | + # Test a transaction where our burn falls short of maxburnamount |
| 380 | + tx = self.wallet.create_self_transfer()['tx'] |
| 381 | + tx_val = 0.001 |
| 382 | + tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_RETURN] + [OP_FALSE] * 30))] |
| 383 | + tx_hex = tx.serialize().hex() |
| 384 | + self.nodes[2].sendrawtransaction(hexstring=tx_hex, maxfeerate='0', maxburnamount='0.0011') |
| 385 | + |
| 386 | + # Test a transaction where our burn equals maxburnamount |
| 387 | + tx = self.wallet.create_self_transfer()['tx'] |
| 388 | + tx_val = 0.001 |
| 389 | + tx.vout = [CTxOut(int(Decimal(tx_val) * COIN), CScript([OP_RETURN] + [OP_FALSE] * 30))] |
| 390 | + tx_hex = tx.serialize().hex() |
| 391 | + self.nodes[2].sendrawtransaction(hexstring=tx_hex, maxfeerate='0', maxburnamount='0.001') |
| 392 | + |
334 | 393 | def sendrawtransaction_testmempoolaccept_tests(self):
|
335 | 394 | self.log.info("Test sendrawtransaction/testmempoolaccept with maxfeerate")
|
336 | 395 | fee_exceeds_max = "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)"
|
|
0 commit comments