Skip to content

Commit aac0b6d

Browse files
committed
test: test sendall and send do anti-fee-sniping
1 parent 20802c7 commit aac0b6d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

test/functional/wallet_send.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ def test_send(self, from_wallet, to_wallet=None, amount=None, data=None,
140140
return
141141

142142
if locktime:
143+
assert_equal(from_wallet.gettransaction(txid=res["txid"], verbose=True)["decoded"]["locktime"], locktime)
143144
return res
145+
else:
146+
if add_to_wallet:
147+
decoded_tx = from_wallet.gettransaction(txid=res["txid"], verbose=True)["decoded"]
148+
assert_greater_than(decoded_tx["locktime"], from_wallet.getblockcount() - 100)
144149

145150
if from_wallet.getwalletinfo()["private_keys_enabled"] and not include_watching:
146151
assert_equal(res["complete"], True)

test/functional/wallet_sendall.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from decimal import Decimal, getcontext
88

9+
from test_framework.messages import SEQUENCE_FINAL
910
from test_framework.test_framework import BitcoinTestFramework
1011
from test_framework.util import (
1112
assert_equal,
@@ -430,6 +431,26 @@ def sendall_does_ancestor_aware_funding(self):
430431

431432
assert_greater_than(higher_parent_feerate_amount, lower_parent_feerate_amount)
432433

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+
433454
# This tests needs to be the last one otherwise @cleanup will fail with "Transaction too large" error
434455
def sendall_fails_with_transaction_too_large(self):
435456
self.log.info("Test that sendall fails if resulting transaction is too large")
@@ -511,6 +532,9 @@ def run_test(self):
511532
# Sendall only uses outputs with less than a given number of confirmation when using minconf
512533
self.sendall_with_maxconf()
513534

535+
# Sendall discourages fee-sniping when a locktime is not specified
536+
self.sendall_anti_fee_sniping()
537+
514538
# Sendall spends unconfirmed change
515539
self.sendall_spends_unconfirmed_change()
516540

0 commit comments

Comments
 (0)