Merge bitcoin/bitcoin#26884: test: wallet: add coverage for -spendzeroconfchange setting

603d295199 test: wallet: add coverage for `-spendzeroconfchange` setting (Sebastian Falbesoner)
50112034bc 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 dddca3899c.

ACKs for top commit:
  brunoerg:
    crACK 603d295199

Tree-SHA512: 15d9c8bd5eb37c6b228bf887eb27debee0a391c82356662785da4553ee2558e611834c3936ef7136812b46f877bab7aa5f3088bbd278b81f296bdda96cc8e1c3
This commit is contained in:
MarcoFalke
2023-01-17 11:12:14 +01:00
2 changed files with 39 additions and 1 deletions

View File

@@ -25,7 +25,6 @@ class MempoolLimitTest(BitcoinTestFramework):
self.extra_args = [[
"-datacarriersize=100000",
"-maxmempool=5",
"-spendzeroconfchange=0",
]]
self.supports_cli = False

View File

@@ -731,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()