Skip to content

Commit 635f190

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#26884: test: wallet: add coverage for -spendzeroconfchange setting
603d295 test: wallet: add coverage for `-spendzeroconfchange` setting (Sebastian Falbesoner) 5011203 test: remove `-spendzeroconfchange` setting from mempool_limit.py (Sebastian Falbesoner) Pull request description: This PR adds missing test coverage for the `-spendzeroconfchange` setting (in particular the non-default case `=0`). Note that in contrast to the name, the setting does not only apply to change outputs, but in fact to _all_ unconfirmed outputs that we sent to ourselves, i.e. we can trigger the testing path simply with a single recipient address. The first commit removes the setting from the functional test mempool_limit.py, where it doesn't have any effect, since the test was changed to use MiniWallet in commit dddca38. ACKs for top commit: brunoerg: crACK 603d295 Tree-SHA512: 15d9c8bd5eb37c6b228bf887eb27debee0a391c82356662785da4553ee2558e611834c3936ef7136812b46f877bab7aa5f3088bbd278b81f296bdda96cc8e1c3
2 parents b7f6a89 + 603d295 commit 635f190

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

test/functional/mempool_limit.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def set_test_params(self):
2525
self.extra_args = [[
2626
"-datacarriersize=100000",
2727
"-maxmempool=5",
28-
"-spendzeroconfchange=0",
2928
]]
3029
self.supports_cli = False
3130

test/functional/wallet_basic.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,45 @@ def run_test(self):
731731
assert_equal(coin_b["parent_descs"][0], multi_b)
732732
self.nodes[0].unloadwallet("wo")
733733

734+
self.log.info("Test -spendzeroconfchange")
735+
self.restart_node(0, ["-spendzeroconfchange=0"])
736+
737+
# create new wallet and fund it with a confirmed UTXO
738+
self.nodes[0].createwallet(wallet_name="zeroconf", load_on_startup=True)
739+
zeroconf_wallet = self.nodes[0].get_wallet_rpc("zeroconf")
740+
default_wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
741+
default_wallet.sendtoaddress(zeroconf_wallet.getnewaddress(), Decimal('1.0'))
742+
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
743+
utxos = zeroconf_wallet.listunspent(minconf=0)
744+
assert_equal(len(utxos), 1)
745+
assert_equal(utxos[0]['confirmations'], 1)
746+
747+
# spend confirmed UTXO to ourselves
748+
zeroconf_wallet.sendall(recipients=[zeroconf_wallet.getnewaddress()])
749+
utxos = zeroconf_wallet.listunspent(minconf=0)
750+
assert_equal(len(utxos), 1)
751+
assert_equal(utxos[0]['confirmations'], 0)
752+
# accounts for untrusted pending balance
753+
bal = zeroconf_wallet.getbalances()
754+
assert_equal(bal['mine']['trusted'], 0)
755+
assert_equal(bal['mine']['untrusted_pending'], utxos[0]['amount'])
756+
757+
# spending an unconfirmed UTXO sent to ourselves should fail
758+
assert_raises_rpc_error(-6, "Insufficient funds", zeroconf_wallet.sendtoaddress, zeroconf_wallet.getnewaddress(), Decimal('0.5'))
759+
760+
# check that it works again with -spendzeroconfchange set (=default)
761+
self.restart_node(0, ["-spendzeroconfchange=1"])
762+
zeroconf_wallet = self.nodes[0].get_wallet_rpc("zeroconf")
763+
utxos = zeroconf_wallet.listunspent(minconf=0)
764+
assert_equal(len(utxos), 1)
765+
assert_equal(utxos[0]['confirmations'], 0)
766+
# accounts for trusted balance
767+
bal = zeroconf_wallet.getbalances()
768+
assert_equal(bal['mine']['trusted'], utxos[0]['amount'])
769+
assert_equal(bal['mine']['untrusted_pending'], 0)
770+
771+
zeroconf_wallet.sendtoaddress(zeroconf_wallet.getnewaddress(), Decimal('0.5'))
772+
734773

735774
if __name__ == '__main__':
736775
WalletTest().main()

0 commit comments

Comments
 (0)