mirror of
https://github.com/dogecoin/dogecoin.git
synced 2026-02-14 09:18:37 +00:00
Tree-SHA512: 7bcdf6c42ac75fb24df8d6b60bddcac5f14363a3f7dd89a239f798bb14b5c911c2d7535a0372c2998719d33a561d0d28b0b6764aaf1f2ec330d4035ce965997b -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEz7FuIclQ9n+pXlWPLuufXMCVJsEFAmEp9EoACgkQLuufXMCV JsGvcQ//ZSQOCEFH3e+gBuXHthXG2UZsHagC715ruQquhRt4aOKiFLu/eJGwiKBt Frc1wLF21dgtl/2JUtVBpVb54whni1PKgDowtkk4Ge7gWM0awW2OnvdgA21E+syD 501duaW6ORvo5icmf7uPQ7u/g9Ks1s1chBr1bLnYqqqg2e3/aqC4+drTjd8wziy3 J+8Bzc+KLAklgv8cIpH1EDuFGrumlMYxW0KHqJeN7Vk8wGX8PINrkEGCyrBDQ7DY BEd6txwcivPxqMfj61OP60DU0oG6IVECGMPrANtyK+ba0FHl+GkNQuTaX8zv4Ik9 dKscJ1OiRX2ER/pEJTwg8PJfOET5D/WRc1xSmrYBOK7cFLtYVqH2yvnHiLlWvH1P 7TQOAjfzQwa+yUnGRf2dWW+Rngv876JjBUX5vbm4UC5Geo8Bdl3z9U9glaq03fVd 3Q8uAgljLnXWFiylK9oDYhsFfWSUYgjyhM11LCb5K3y3t7ageclu6RTl574jy5sb 8qBwQxpJt5UtwIK2SNqq1iDmMW3J65sb3CmTND9ppDA79GfZzwlvGVwO1bN2TC6m 0dGTPvOPWS9x/PSq8+8o1uCHDzHrW9B5lUikf8kx+zNI7Rd3QLJ0pbdqwrJ3CcOk ttV5QXAYD2trfkCKEi69eiIpH21rasqjyI11ZoH4u+0BCpw8hQg= =GXjC -----END PGP SIGNATURE----- Merge tag 'v0.21.2rc2' into 1.21-dev Bitcoin Core 0.21.2 release candidate 2 Tree-SHA512: 7bcdf6c42ac75fb24df8d6b60bddcac5f14363a3f7dd89a239f798bb14b5c911c2d7535a0372c2998719d33a561d0d28b0b6764aaf1f2ec330d4035ce965997b
112 lines
4.6 KiB
Python
Executable File
112 lines
4.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2018-2019 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test createwallet watchonly arguments.
|
|
"""
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import (
|
|
assert_equal,
|
|
assert_raises_rpc_error
|
|
)
|
|
|
|
|
|
class CreateWalletWatchonlyTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.setup_clean_chain = False
|
|
self.num_nodes = 1
|
|
|
|
def skip_test_if_missing_module(self):
|
|
self.skip_if_no_wallet()
|
|
|
|
def run_test(self):
|
|
node = self.nodes[0]
|
|
|
|
self.nodes[0].createwallet(wallet_name='default')
|
|
def_wallet = node.get_wallet_rpc('default')
|
|
|
|
a1 = def_wallet.getnewaddress()
|
|
wo_change = def_wallet.getnewaddress()
|
|
wo_addr = def_wallet.getnewaddress()
|
|
|
|
self.nodes[0].createwallet(wallet_name='wo', disable_private_keys=True)
|
|
wo_wallet = node.get_wallet_rpc('wo')
|
|
|
|
wo_wallet.importpubkey(pubkey=def_wallet.getaddressinfo(wo_addr)['pubkey'])
|
|
wo_wallet.importpubkey(pubkey=def_wallet.getaddressinfo(wo_change)['pubkey'])
|
|
|
|
# generate some btc for testing
|
|
node.generatetoaddress(241, a1)
|
|
|
|
# send 1 btc to our watch-only address
|
|
txid = def_wallet.sendtoaddress(wo_addr, 1)
|
|
self.nodes[0].generate(1)
|
|
|
|
# getbalance
|
|
self.log.info('include_watchonly should default to true for watch-only wallets')
|
|
self.log.info('Testing getbalance watch-only defaults')
|
|
assert_equal(wo_wallet.getbalance(), 1)
|
|
assert_equal(len(wo_wallet.listtransactions()), 1)
|
|
assert_equal(wo_wallet.getbalance(include_watchonly=False), 0)
|
|
|
|
self.log.info('Test sending from a watch-only wallet raises RPC error')
|
|
msg = "Error: Private keys are disabled for this wallet"
|
|
assert_raises_rpc_error(-4, msg, wo_wallet.sendtoaddress, a1, 0.1)
|
|
assert_raises_rpc_error(-4, msg, wo_wallet.sendmany, amounts={a1: 0.1})
|
|
|
|
self.log.info('Testing listreceivedbyaddress watch-only defaults')
|
|
result = wo_wallet.listreceivedbyaddress()
|
|
assert_equal(len(result), 1)
|
|
assert_equal(result[0]["involvesWatchonly"], True)
|
|
result = wo_wallet.listreceivedbyaddress(include_watchonly=False)
|
|
assert_equal(len(result), 0)
|
|
|
|
self.log.info('Testing listreceivedbylabel watch-only defaults')
|
|
result = wo_wallet.listreceivedbylabel()
|
|
assert_equal(len(result), 1)
|
|
assert_equal(result[0]["involvesWatchonly"], True)
|
|
result = wo_wallet.listreceivedbylabel(include_watchonly=False)
|
|
assert_equal(len(result), 0)
|
|
|
|
self.log.info('Testing listtransactions watch-only defaults')
|
|
result = wo_wallet.listtransactions()
|
|
assert_equal(len(result), 1)
|
|
assert_equal(result[0]["involvesWatchonly"], True)
|
|
result = wo_wallet.listtransactions(include_watchonly=False)
|
|
assert_equal(len(result), 0)
|
|
|
|
self.log.info('Testing listsinceblock watch-only defaults')
|
|
result = wo_wallet.listsinceblock()
|
|
assert_equal(len(result["transactions"]), 1)
|
|
assert_equal(result["transactions"][0]["involvesWatchonly"], True)
|
|
result = wo_wallet.listsinceblock(include_watchonly=False)
|
|
assert_equal(len(result["transactions"]), 0)
|
|
|
|
self.log.info('Testing gettransaction watch-only defaults')
|
|
result = wo_wallet.gettransaction(txid)
|
|
assert_equal(result["details"][0]["involvesWatchonly"], True)
|
|
result = wo_wallet.gettransaction(txid=txid, include_watchonly=False)
|
|
assert_equal(len(result["details"]), 0)
|
|
|
|
self.log.info('Testing walletcreatefundedpsbt watch-only defaults')
|
|
inputs = []
|
|
outputs = [{a1: 0.5}]
|
|
options = {'changeAddress': wo_change}
|
|
no_wo_options = {'changeAddress': wo_change, 'includeWatching': False}
|
|
|
|
result = wo_wallet.walletcreatefundedpsbt(inputs=inputs, outputs=outputs, options=options)
|
|
assert_equal("psbt" in result, True)
|
|
assert_raises_rpc_error(-4, "Insufficient funds", wo_wallet.walletcreatefundedpsbt, inputs, outputs, 0, no_wo_options)
|
|
|
|
self.log.info('Testing fundrawtransaction watch-only defaults')
|
|
rawtx = wo_wallet.createrawtransaction(inputs=inputs, outputs=outputs)
|
|
result = wo_wallet.fundrawtransaction(hexstring=rawtx, options=options)
|
|
assert_equal("hex" in result, True)
|
|
assert_raises_rpc_error(-4, "Insufficient funds", wo_wallet.fundrawtransaction, rawtx, no_wo_options)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
CreateWalletWatchonlyTest().main()
|