-
Notifications
You must be signed in to change notification settings - Fork 647
Expand file tree
/
Copy pathtest_rpc.py
More file actions
65 lines (55 loc) · 2.08 KB
/
test_rpc.py
File metadata and controls
65 lines (55 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (C) The python-bitcoinlib developers
#
# This file is part of python-bitcoinlib.
#
# It is subject to the license terms in the LICENSE file found in the top-level
# directory of this distribution.
#
# No part of python-bitcoinlib, including this file, may be copied, modified,
# propagated, or distributed except according to the terms contained in the
# LICENSE file.
import unittest
import tempfile
from bitcoin.rpc import Proxy, parse_conf_file, get_authpair
class TestConfigFileparser(unittest.TestCase):
def test_parse(self):
with tempfile.TemporaryFile("w+") as fd:
fd.write("""
datadir = /home/user/.bitcoin
# Comment
dbcache = 300 # in MB # Inline comment
""")
fd.seek(0)
self.assertEqual(parse_conf_file(fd), {
"datadir": "/home/user/.bitcoin",
"dbcache": "300"
})
def test_authpair_from_conf(self):
self.assertEqual(
"user:insecure_youll_be_robed",
get_authpair(
{
"rpcuser": "user",
"rpcpassword": "insecure_youll_be_robed"
}, "mainnet", "dummy.file"))
def test_authpair_fail(self):
with self.assertRaises(ValueError):
get_authpair({}, "testnet", "ou/conf")
class Test_RPC(unittest.TestCase):
# Tests disabled, see discussion below.
# "Looks like your unit tests won't work if Bitcoin Core isn't running;
# maybe they in turn need to check that and disable the test if core isn't available?"
# https://github.com/petertodd/python-bitcoinlib/pull/10
pass
# def test_can_validate(self):
# working_address = '1CB2fxLGAZEzgaY4pjr4ndeDWJiz3D3AT7'
# p = Proxy()
# r = p.validateAddress(working_address)
# self.assertEqual(r['address'], working_address)
# self.assertEqual(r['isvalid'], True)
#
# def test_cannot_validate(self):
# non_working_address = 'LTatMHrYyHcxhxrY27AqFN53bT4TauR86h'
# p = Proxy()
# r = p.validateAddress(non_working_address)
# self.assertEqual(r['isvalid'], False)