test: test sendall and send do anti-fee-sniping

This commit is contained in:
ishaanam 2023-11-26 13:43:17 -05:00
parent 6825ae0c78
commit b11d00d54e
2 changed files with 29 additions and 0 deletions

View file

@ -142,7 +142,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)

View file

@ -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,
@ -437,6 +438,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")
@ -518,6 +539,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()