diff options
author | Antoine Poinsot <darosior@protonmail.com> | 2022-07-07 14:06:27 +0200 |
---|---|---|
committer | Antoine Poinsot <darosior@protonmail.com> | 2022-08-16 18:33:05 +0200 |
commit | 0fd2d144540b720626fc065a3cef5188831b5ee2 (patch) | |
tree | 59dd67fd3cf748fbd829cad0421f0192cce12b29 /test/functional/wallet_listsinceblock.py | |
parent | 55f98d087efd2609d808c082d5770306cc489409 (diff) | |
download | bitcoin-0fd2d144540b720626fc065a3cef5188831b5ee2.tar.xz |
rpc: add an include_change parameter to listsinceblock
It's useful for an external application tracking coins to not be limited
by our change detection. For instance, for a watchonly wallet with two
descriptors a transaction from one to the other would be considered a
change output and not be included in the result (if the address was not
generated by this wallet).
Diffstat (limited to 'test/functional/wallet_listsinceblock.py')
-rwxr-xr-x | test/functional/wallet_listsinceblock.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/functional/wallet_listsinceblock.py b/test/functional/wallet_listsinceblock.py index ecce6652aa..36dbec467b 100755 --- a/test/functional/wallet_listsinceblock.py +++ b/test/functional/wallet_listsinceblock.py @@ -41,6 +41,7 @@ class ListSinceBlockTest(BitcoinTestFramework): self.double_spends_filtered() self.test_targetconfirmations() self.test_desc() + self.test_send_to_self() def test_no_blockhash(self): self.log.info("Test no blockhash") @@ -423,6 +424,27 @@ class ListSinceBlockTest(BitcoinTestFramework): 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() |