Skip to content

Commit

Permalink
tests: add receiving functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
josibake authored and achow101 committed Sep 12, 2023
1 parent 1bbd54a commit 186caac
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,10 @@ def __getattr__(self, name):
def createwallet_passthrough(self, *args, **kwargs):
return self.__getattr__("createwallet")(*args, **kwargs)

def createwallet(self, wallet_name, disable_private_keys=None, blank=None, passphrase='', avoid_reuse=None, descriptors=None, load_on_startup=None, external_signer=None):
def createwallet(self, wallet_name, disable_private_keys=None, blank=None, passphrase='', avoid_reuse=None, descriptors=None, load_on_startup=None, external_signer=None, silent_payment=None):
if descriptors is None:
descriptors = self.descriptors
return self.__getattr__('createwallet')(wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors, load_on_startup, external_signer)
return self.__getattr__('createwallet')(wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors, load_on_startup, external_signer, silent_payment)

def importprivkey(self, privkey, label=None, rescan=None):
wallet_info = self.getwalletinfo()
Expand Down
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
'wallet_avoid_mixing_output_types.py --descriptors',
'mempool_reorg.py',
'p2p_block_sync.py',
'wallet_silentpayments_receiving.py --descriptors',
'wallet_createwallet.py --legacy-wallet',
'wallet_createwallet.py --usecli',
'wallet_createwallet.py --descriptors',
Expand Down
48 changes: 48 additions & 0 deletions test/functional/wallet_silentpayments_receiving.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
)


class SilentPaymentsReceivingTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser, legacy=False)

def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
self.skip_if_no_sqlite()

def test_createwallet(self):
self.log.info("Check createwallet silent payments option")

self.nodes[0].createwallet(wallet_name="sp", silent_payment=True)
wallet = self.nodes[0].get_wallet_rpc("sp")
addr = wallet.getnewaddress(address_type="silent-payment")
assert addr.startswith("sp")
addr_again = wallet.getnewaddress(address_type="silent-payment")
assert_equal(addr, addr_again)

self.nodes[0].createwallet(wallet_name="non_sp", silent_payment=False)
wallet = self.nodes[0].get_wallet_rpc("non_sp")
assert_raises_rpc_error(-12, "Error: No silent-payment addresses available", wallet.getnewaddress, address_type="silent-payment")

if self.is_bdb_compiled():
assert_raises_rpc_error(-4, "Wallet with silent payments must also be a descriptor wallet", self.nodes[0].createwallet, wallet_name="legacy_sp", descriptors=False, silent_payment=True)

self.nodes[0].createwallet(wallet_name="legacy_sp", descriptors=False)
wallet = self.nodes[0].get_wallet_rpc("legacy_sp")
assert_raises_rpc_error(-12, "Error: No silent-payment addresses available", wallet.getnewaddress, address_type="silent-payment")

def run_test(self):
self.test_createwallet()


if __name__ == '__main__':
SilentPaymentsReceivingTest().main()

0 comments on commit 186caac

Please sign in to comment.