From aac0b6dd79b0db1e9d42a6f466709a61cfd1f69f Mon Sep 17 00:00:00 2001 From: ishaanam Date: Sun, 26 Nov 2023 13:43:17 -0500 Subject: [PATCH] test: test sendall and send do anti-fee-sniping --- test/functional/wallet_send.py | 5 +++++ test/functional/wallet_sendall.py | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/test/functional/wallet_send.py b/test/functional/wallet_send.py index 067df43e50a..4c6accc7534 100755 --- a/test/functional/wallet_send.py +++ b/test/functional/wallet_send.py @@ -140,7 +140,12 @@ class WalletSendTest(BitcoinTestFramework): return if locktime: + assert_equal(from_wallet.gettransaction(txid=res["txid"], verbose=True)["decoded"]["locktime"], locktime) return res + else: + if add_to_wallet: + decoded_tx = from_wallet.gettransaction(txid=res["txid"], verbose=True)["decoded"] + assert_greater_than(decoded_tx["locktime"], from_wallet.getblockcount() - 100) if from_wallet.getwalletinfo()["private_keys_enabled"] and not include_watching: assert_equal(res["complete"], True) diff --git a/test/functional/wallet_sendall.py b/test/functional/wallet_sendall.py index 29906263236..ef748157876 100755 --- a/test/functional/wallet_sendall.py +++ b/test/functional/wallet_sendall.py @@ -6,6 +6,7 @@ from decimal import Decimal, getcontext +from test_framework.messages import SEQUENCE_FINAL from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -430,6 +431,26 @@ class SendallTest(BitcoinTestFramework): assert_greater_than(higher_parent_feerate_amount, lower_parent_feerate_amount) + @cleanup + def sendall_anti_fee_sniping(self): + self.log.info("Testing sendall does anti-fee-sniping when locktime is not specified") + self.add_utxos([10,11]) + tx_from_wallet = self.test_sendall_success(sendall_args = [self.remainder_target]) + + assert_greater_than(tx_from_wallet["decoded"]["locktime"], tx_from_wallet["blockheight"] - 100) + + self.log.info("Testing sendall does not do anti-fee-sniping when locktime is specified") + self.add_utxos([10,11]) + txid = self.wallet.sendall(recipients=[self.remainder_target], options={"locktime":0})["txid"] + assert_equal(self.wallet.gettransaction(txid=txid, verbose=True)["decoded"]["locktime"], 0) + + self.log.info("Testing sendall does not do anti-fee-sniping when even one of the sequences is final") + self.add_utxos([10, 11]) + utxos = self.wallet.listunspent() + utxos[0]["sequence"] = SEQUENCE_FINAL + txid = self.wallet.sendall(recipients=[self.remainder_target], inputs=utxos)["txid"] + assert_equal(self.wallet.gettransaction(txid=txid, verbose=True)["decoded"]["locktime"], 0) + # This tests needs to be the last one otherwise @cleanup will fail with "Transaction too large" error def sendall_fails_with_transaction_too_large(self): self.log.info("Test that sendall fails if resulting transaction is too large") @@ -511,6 +532,9 @@ class SendallTest(BitcoinTestFramework): # Sendall only uses outputs with less than a given number of confirmation when using minconf self.sendall_with_maxconf() + # Sendall discourages fee-sniping when a locktime is not specified + self.sendall_anti_fee_sniping() + # Sendall spends unconfirmed change self.sendall_spends_unconfirmed_change()