aboutsummaryrefslogtreecommitdiff
path: root/test/functional/wallet_basic.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/wallet_basic.py')
-rwxr-xr-xtest/functional/wallet_basic.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py
index 20c577ceb3..52022a2eee 100755
--- a/test/functional/wallet_basic.py
+++ b/test/functional/wallet_basic.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2014-2021 The Bitcoin Core developers
+# Copyright (c) 2014-2022 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the wallet."""
@@ -23,6 +23,9 @@ OUT_OF_RANGE = "Amount out of range"
class WalletTest(BitcoinTestFramework):
+ def add_options(self, parser):
+ self.add_wallet_options(parser)
+
def set_test_params(self):
self.num_nodes = 4
self.extra_args = [[
@@ -728,6 +731,45 @@ class WalletTest(BitcoinTestFramework):
assert_equal(coin_b["parent_descs"][0], multi_b)
self.nodes[0].unloadwallet("wo")
+ self.log.info("Test -spendzeroconfchange")
+ self.restart_node(0, ["-spendzeroconfchange=0"])
+
+ # create new wallet and fund it with a confirmed UTXO
+ self.nodes[0].createwallet(wallet_name="zeroconf", load_on_startup=True)
+ zeroconf_wallet = self.nodes[0].get_wallet_rpc("zeroconf")
+ default_wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
+ default_wallet.sendtoaddress(zeroconf_wallet.getnewaddress(), Decimal('1.0'))
+ self.generate(self.nodes[0], 1, sync_fun=self.no_op)
+ utxos = zeroconf_wallet.listunspent(minconf=0)
+ assert_equal(len(utxos), 1)
+ assert_equal(utxos[0]['confirmations'], 1)
+
+ # spend confirmed UTXO to ourselves
+ zeroconf_wallet.sendall(recipients=[zeroconf_wallet.getnewaddress()])
+ utxos = zeroconf_wallet.listunspent(minconf=0)
+ assert_equal(len(utxos), 1)
+ assert_equal(utxos[0]['confirmations'], 0)
+ # accounts for untrusted pending balance
+ bal = zeroconf_wallet.getbalances()
+ assert_equal(bal['mine']['trusted'], 0)
+ assert_equal(bal['mine']['untrusted_pending'], utxos[0]['amount'])
+
+ # spending an unconfirmed UTXO sent to ourselves should fail
+ assert_raises_rpc_error(-6, "Insufficient funds", zeroconf_wallet.sendtoaddress, zeroconf_wallet.getnewaddress(), Decimal('0.5'))
+
+ # check that it works again with -spendzeroconfchange set (=default)
+ self.restart_node(0, ["-spendzeroconfchange=1"])
+ zeroconf_wallet = self.nodes[0].get_wallet_rpc("zeroconf")
+ utxos = zeroconf_wallet.listunspent(minconf=0)
+ assert_equal(len(utxos), 1)
+ assert_equal(utxos[0]['confirmations'], 0)
+ # accounts for trusted balance
+ bal = zeroconf_wallet.getbalances()
+ assert_equal(bal['mine']['trusted'], utxos[0]['amount'])
+ assert_equal(bal['mine']['untrusted_pending'], 0)
+
+ zeroconf_wallet.sendtoaddress(zeroconf_wallet.getnewaddress(), Decimal('0.5'))
+
if __name__ == '__main__':
WalletTest().main()