6
6
# Exercise the wallet keypool, and interaction with wallet encryption/locking
7
7
8
8
# Add python-bitcoinrpc to module search path:
9
- import os
10
- import sys
11
-
12
- import json
13
- import shutil
14
- import subprocess
15
- import tempfile
16
- import traceback
17
9
10
+ from test_framework .test_framework import BitcoinTestFramework
18
11
from test_framework .util import *
19
12
20
13
@@ -39,12 +32,15 @@ def check_array_result(object_array, to_match, expected):
39
32
if num_matched == 0 :
40
33
raise AssertionError ("No objects matched %s" % (str (to_match )))
41
34
42
- def run_test (nodes , tmpdir ):
35
+ class KeyPoolTest (BitcoinTestFramework ):
36
+
37
+ def run_test (self ):
38
+ nodes = self .nodes
43
39
# Encrypt wallet and wait to terminate
44
40
nodes [0 ].encryptwallet ('test' )
45
41
bitcoind_processes [0 ].wait ()
46
42
# Restart node 0
47
- nodes [0 ] = start_node (0 , tmpdir )
43
+ nodes [0 ] = start_node (0 , self . options . tmpdir )
48
44
# Keep creating keys
49
45
addr = nodes [0 ].getnewaddress ()
50
46
try :
@@ -89,57 +85,12 @@ def run_test(nodes, tmpdir):
89
85
except JSONRPCException ,e :
90
86
assert (e .error ['code' ]== - 12 )
91
87
92
- def main ():
93
- import optparse
94
-
95
- parser = optparse .OptionParser (usage = "%prog [options]" )
96
- parser .add_option ("--nocleanup" , dest = "nocleanup" , default = False , action = "store_true" ,
97
- help = "Leave bitcoinds and test.* datadir on exit or error" )
98
- parser .add_option ("--srcdir" , dest = "srcdir" , default = "../../src" ,
99
- help = "Source directory containing bitcoind/bitcoin-cli (default: %default%)" )
100
- parser .add_option ("--tmpdir" , dest = "tmpdir" , default = tempfile .mkdtemp (prefix = "test" ),
101
- help = "Root directory for datadirs" )
102
- (options , args ) = parser .parse_args ()
103
-
104
- os .environ ['PATH' ] = options .srcdir + ":" + os .environ ['PATH' ]
105
-
106
- check_json_precision ()
107
-
108
- success = False
109
- nodes = []
110
- try :
111
- print ("Initializing test directory " + options .tmpdir )
112
- if not os .path .isdir (options .tmpdir ):
113
- os .makedirs (options .tmpdir )
114
- initialize_chain (options .tmpdir )
115
-
116
- nodes = start_nodes (1 , options .tmpdir )
117
-
118
- run_test (nodes , options .tmpdir )
119
-
120
- success = True
121
-
122
- except AssertionError as e :
123
- print ("Assertion failed: " + e .message )
124
- except JSONRPCException as e :
125
- print ("JSONRPC error: " + e .error ['message' ])
126
- traceback .print_tb (sys .exc_info ()[2 ])
127
- except Exception as e :
128
- print ("Unexpected exception caught during testing: " + str (sys .exc_info ()[0 ]))
129
- traceback .print_tb (sys .exc_info ()[2 ])
130
-
131
- if not options .nocleanup :
132
- print ("Cleaning up" )
133
- stop_nodes (nodes )
134
- wait_bitcoinds ()
135
- shutil .rmtree (options .tmpdir )
88
+ def setup_chain (self ):
89
+ print ("Initializing test directory " + self .options .tmpdir )
90
+ initialize_chain (self .options .tmpdir )
136
91
137
- if success :
138
- print ("Tests successful" )
139
- sys .exit (0 )
140
- else :
141
- print ("Failed" )
142
- sys .exit (1 )
92
+ def setup_network (self ):
93
+ self .nodes = start_nodes (1 , self .options .tmpdir )
143
94
144
95
if __name__ == '__main__' :
145
- main ()
96
+ KeyPoolTest (). main ()
0 commit comments