1#!/usr/bin/env python3
2# Copyright (c) 2015-2016 The Bitcoin Core developers
3# Distributed under the MIT software license, see the accompanying
4# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#
7# Exercise API with -disablewallet.
8#
9
10from test_framework.test_framework import BitcoinTestFramework
11from test_framework.util import *
12
13
14class DisableWalletTest (BitcoinTestFramework):
15
16    def __init__(self):
17        super().__init__()
18        self.setup_clean_chain = True
19        self.num_nodes = 1
20
21    def setup_network(self, split=False):
22        self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [['-disablewallet']])
23        self.is_network_split = False
24        self.sync_all()
25
26    def run_test (self):
27        # Check regression: https://github.com/bitcoin/bitcoin/issues/6963#issuecomment-154548880
28        x = self.nodes[0].validateaddress('3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
29        assert(x['isvalid'] == False)
30        x = self.nodes[0].validateaddress('mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ')
31        assert(x['isvalid'] == True)
32
33        # Checking mining to an address without a wallet
34        try:
35            self.nodes[0].generatetoaddress(1, 'mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ')
36        except JSONRPCException as e:
37            assert("Invalid address" not in e.error['message'])
38            assert("ProcessNewBlock, block not accepted" not in e.error['message'])
39            assert("Couldn't create new block" not in e.error['message'])
40
41        try:
42            self.nodes[0].generatetoaddress(1, '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
43            raise AssertionError("Must not mine to invalid address!")
44        except JSONRPCException as e:
45            assert("Invalid address" in e.error['message'])
46
47if __name__ == '__main__':
48    DisableWalletTest ().main ()
49