From 32a75a3500e1b455d41847c0a86982c6e40e5516 Mon Sep 17 00:00:00 2001 From: Novo Date: Sun, 4 Aug 2024 16:39:48 +0100 Subject: [PATCH] wip --- .../wallet_silentpayments_receiving.py | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/test/functional/wallet_silentpayments_receiving.py b/test/functional/wallet_silentpayments_receiving.py index a8b223ddf3233..f254280dac970 100755 --- a/test/functional/wallet_silentpayments_receiving.py +++ b/test/functional/wallet_silentpayments_receiving.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +from test_framework.descriptors import descsum_create from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_approx, @@ -11,6 +12,7 @@ class SilentPaymentsReceivingTest(BitcoinTestFramework): def add_options(self, parser): self.add_wallet_options(parser, legacy=False) + parser.add_argument("-maxtxfee", dest="maxtxfee", default=10000) def set_test_params(self): self.setup_clean_chain = True @@ -135,15 +137,63 @@ def test_import_rescan(self): assert_approx(alice_wo.getbalance(), 10, 0.0001) + def test_rbf(self): + self.log.info("Check Silent Payments RBF") + + self.nodes[0].createwallet(wallet_name="craig", silent_payment=True) + wallet = self.nodes[0].get_wallet_rpc("craig") + address = wallet.getnewaddress(address_type="silent-payment") + + txid = self.def_wallet.sendtoaddress(address, 49.99, replaceable=True) + assert_equal(self.nodes[0].getrawmempool(), [txid]) + raw_tx = self.nodes[0].getrawtransaction(txid) + tx = self.nodes[0].decoderawtransaction(raw_tx) + assert_equal(len(tx["vin"]), 1) + + psbt = self.def_wallet.psbtbumpfee(txid, fee_rate=10000)["psbt"] + decoded = self.nodes[0].decodepsbt(psbt) + assert_equal(len(decoded["tx"]["vin"]), 2) + + res = self.def_wallet.walletprocesspsbt(psbt) + assert_equal(res["complete"], True) + txid = self.def_wallet.sendrawtransaction(res["hex"]) + assert_equal(self.nodes[0].getrawmempool(), [txid]) + + assert_equal(wallet.getbalance(), 0) + self.generate(self.nodes[0], 1) + assert_approx(wallet.getbalance(), 49.99, 0.0001) + + def test_import_link_keys(self): + self.log.info("Check wallet with key recognizes imported sppub") + + self.nodes[0].createwallet(wallet_name="base", silent_payment=True) + base_wallet = self.nodes[0].get_wallet_rpc("base") + hd_info = base_wallet.gethdkeys(private=True) + xprv = hd_info[0]["xprv"] + sppub_desc = [d["desc"] for d in base_wallet.listdescriptors()["descriptors"] if d["desc"].startswith("sp(")][0] + spprv_desc = [d["desc"] for d in base_wallet.listdescriptors(private=True)["descriptors"] if d["desc"].startswith("sp(")][0] + + self.nodes[0].createwallet(wallet_name="blank", blank=True) + wallet = self.nodes[0].get_wallet_rpc("blank") + # Import this descriptor adds the xprv to the wallet + assert_equal(wallet.importdescriptors([{"desc": descsum_create(f"pkh({xprv}/44h/2h/0h/0/0/*)"), "timestamp": "now", "active": True}])[0]["success"], True) + # Fails here because we can't import a desc wuithout private keys to a wallet with private keys enabled + assert_equal(wallet.importdescriptors([{"desc": sppub_desc, "timestamp": "now", "active": True}])[0]["success"], True) + + wallet_spprv_dec = [d["desc"] for d in base_wallet.listdescriptors(private=True)["descriptors"] if d["desc"].startswith("sp(")][0] + assert_equal(wallet_spprv_dec, spprv_desc) + def run_test(self): self.def_wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name) - self.generate(self.nodes[0], 101) + self.generate(self.nodes[0], 102) + self.test_rbf() self.test_createwallet() self.test_encrypt_and_decrypt() self.test_encrypting_unencrypted() self.test_basic() self.test_import_rescan() + self.test_import_link_keys() if __name__ == '__main__':