aboutsummaryrefslogtreecommitdiff
path: root/test/functional/wallet_listsinceblock.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/wallet_listsinceblock.py')
-rwxr-xr-xtest/functional/wallet_listsinceblock.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/functional/wallet_listsinceblock.py b/test/functional/wallet_listsinceblock.py
index 1f3a276d9c..f259449bef 100755
--- a/test/functional/wallet_listsinceblock.py
+++ b/test/functional/wallet_listsinceblock.py
@@ -6,6 +6,7 @@
from test_framework.address import key_to_p2wpkh
from test_framework.blocktools import COINBASE_MATURITY
+from test_framework.descriptors import descsum_create
from test_framework.key import ECKey
from test_framework.test_framework import BitcoinTestFramework
from test_framework.messages import MAX_BIP125_RBF_SEQUENCE
@@ -22,6 +23,8 @@ class ListSinceBlockTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 4
self.setup_clean_chain = True
+ # whitelist peers to speed up tx relay / mempool sync
+ self.extra_args = [["-whitelist=noban@127.0.0.1"]] * self.num_nodes
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
@@ -39,6 +42,9 @@ class ListSinceBlockTest(BitcoinTestFramework):
self.test_double_send()
self.double_spends_filtered()
self.test_targetconfirmations()
+ if self.options.descriptors:
+ self.test_desc()
+ self.test_send_to_self()
def test_no_blockhash(self):
self.log.info("Test no blockhash")
@@ -383,5 +389,65 @@ class ListSinceBlockTest(BitcoinTestFramework):
assert_equal(original_found, False)
assert_equal(double_found, False)
+ def test_desc(self):
+ """Make sure we can track coins by descriptor."""
+ self.log.info("Test descriptor lookup by scriptPubKey.")
+
+ # Create a watchonly wallet tracking two multisig descriptors.
+ multi_a = descsum_create("wsh(multi(1,tpubD6NzVbkrYhZ4YBNjUo96Jxd1u4XKWgnoc7LsA1jz3Yc2NiDbhtfBhaBtemB73n9V5vtJHwU6FVXwggTbeoJWQ1rzdz8ysDuQkpnaHyvnvzR/*,tpubD6NzVbkrYhZ4YHdDGMAYGaWxMSC1B6tPRTHuU5t3BcfcS3nrF523iFm5waFd1pP3ZvJt4Jr8XmCmsTBNx5suhcSgtzpGjGMASR3tau1hJz4/*))")
+ multi_b = descsum_create("wsh(multi(1,tpubD6NzVbkrYhZ4YHdDGMAYGaWxMSC1B6tPRTHuU5t3BcfcS3nrF523iFm5waFd1pP3ZvJt4Jr8XmCmsTBNx5suhcSgtzpGjGMASR3tau1hJz4/*,tpubD6NzVbkrYhZ4Y2RLiuEzNQkntjmsLpPYDm3LTRBYynUQtDtpzeUKAcb9sYthSFL3YR74cdFgF5mW8yKxv2W2CWuZDFR2dUpE5PF9kbrVXNZ/*))")
+ self.nodes[0].createwallet(wallet_name="wo", descriptors=True, disable_private_keys=True)
+ wo_wallet = self.nodes[0].get_wallet_rpc("wo")
+ wo_wallet.importdescriptors([
+ {
+ "desc": multi_a,
+ "active": False,
+ "timestamp": "now",
+ },
+ {
+ "desc": multi_b,
+ "active": False,
+ "timestamp": "now",
+ },
+ ])
+
+ # Send a coin to each descriptor.
+ assert_equal(len(wo_wallet.listsinceblock()["transactions"]), 0)
+ addr_a = self.nodes[0].deriveaddresses(multi_a, 0)[0]
+ addr_b = self.nodes[0].deriveaddresses(multi_b, 0)[0]
+ self.nodes[2].sendtoaddress(addr_a, 1)
+ self.nodes[2].sendtoaddress(addr_b, 2)
+ self.generate(self.nodes[2], 1)
+
+ # We can identify on which descriptor each coin was received.
+ coins = wo_wallet.listsinceblock()["transactions"]
+ assert_equal(len(coins), 2)
+ coin_a = next(c for c in coins if c["amount"] == 1)
+ assert_equal(coin_a["parent_descs"][0], multi_a)
+ coin_b = next(c for c in coins if c["amount"] == 2)
+ assert_equal(coin_b["parent_descs"][0], multi_b)
+
+ def test_send_to_self(self):
+ """We can make listsinceblock output our change outputs."""
+ self.log.info("Test the inclusion of change outputs in the output.")
+
+ # Create a UTxO paying to one of our change addresses.
+ block_hash = self.nodes[2].getbestblockhash()
+ addr = self.nodes[2].getrawchangeaddress()
+ self.nodes[2].sendtoaddress(addr, 1)
+
+ # If we don't list change, we won't have an entry for it.
+ coins = self.nodes[2].listsinceblock(blockhash=block_hash)["transactions"]
+ assert not any(c["address"] == addr for c in coins)
+
+ # Now if we list change, we'll get both the send (to a change address) and
+ # the actual change.
+ res = self.nodes[2].listsinceblock(blockhash=block_hash, include_change=True)
+ coins = [entry for entry in res["transactions"] if entry["category"] == "receive"]
+ assert_equal(len(coins), 2)
+ assert any(c["address"] == addr for c in coins)
+ assert all(self.nodes[2].getaddressinfo(c["address"])["ischange"] for c in coins)
+
+
if __name__ == '__main__':
ListSinceBlockTest().main()