Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunovo committed Aug 4, 2024
1 parent ac1181b commit 32a75a3
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion test/functional/wallet_silentpayments_receiving.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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__':
Expand Down

0 comments on commit 32a75a3

Please sign in to comment.