|
6 | 6 |
|
7 | 7 | from decimal import Decimal, getcontext
|
8 | 8 |
|
| 9 | +from test_framework.messages import SEQUENCE_FINAL |
9 | 10 | from test_framework.test_framework import BitcoinTestFramework
|
10 | 11 | from test_framework.util import (
|
11 | 12 | assert_equal,
|
@@ -430,6 +431,26 @@ def sendall_does_ancestor_aware_funding(self):
|
430 | 431 |
|
431 | 432 | assert_greater_than(higher_parent_feerate_amount, lower_parent_feerate_amount)
|
432 | 433 |
|
| 434 | + @cleanup |
| 435 | + def sendall_anti_fee_sniping(self): |
| 436 | + self.log.info("Testing sendall does anti-fee-sniping when locktime is not specified") |
| 437 | + self.add_utxos([10,11]) |
| 438 | + tx_from_wallet = self.test_sendall_success(sendall_args = [self.remainder_target]) |
| 439 | + |
| 440 | + assert_greater_than(tx_from_wallet["decoded"]["locktime"], tx_from_wallet["blockheight"] - 100) |
| 441 | + |
| 442 | + self.log.info("Testing sendall does not do anti-fee-sniping when locktime is specified") |
| 443 | + self.add_utxos([10,11]) |
| 444 | + txid = self.wallet.sendall(recipients=[self.remainder_target], options={"locktime":0})["txid"] |
| 445 | + assert_equal(self.wallet.gettransaction(txid=txid, verbose=True)["decoded"]["locktime"], 0) |
| 446 | + |
| 447 | + self.log.info("Testing sendall does not do anti-fee-sniping when even one of the sequences is final") |
| 448 | + self.add_utxos([10, 11]) |
| 449 | + utxos = self.wallet.listunspent() |
| 450 | + utxos[0]["sequence"] = SEQUENCE_FINAL |
| 451 | + txid = self.wallet.sendall(recipients=[self.remainder_target], inputs=utxos)["txid"] |
| 452 | + assert_equal(self.wallet.gettransaction(txid=txid, verbose=True)["decoded"]["locktime"], 0) |
| 453 | + |
433 | 454 | # This tests needs to be the last one otherwise @cleanup will fail with "Transaction too large" error
|
434 | 455 | def sendall_fails_with_transaction_too_large(self):
|
435 | 456 | self.log.info("Test that sendall fails if resulting transaction is too large")
|
@@ -511,6 +532,9 @@ def run_test(self):
|
511 | 532 | # Sendall only uses outputs with less than a given number of confirmation when using minconf
|
512 | 533 | self.sendall_with_maxconf()
|
513 | 534 |
|
| 535 | + # Sendall discourages fee-sniping when a locktime is not specified |
| 536 | + self.sendall_anti_fee_sniping() |
| 537 | + |
514 | 538 | # Sendall spends unconfirmed change
|
515 | 539 | self.sendall_spends_unconfirmed_change()
|
516 | 540 |
|
|
0 commit comments