@@ -39,107 +39,107 @@ def check_array_result(object_array, to_match, expected):
39
39
if num_matched == 0 :
40
40
raise AssertionError ("No objects matched %s" % (str (to_match )))
41
41
42
- def run_test (nodes , tmpdir ):
43
- # Encrypt wallet and wait to terminate
44
- nodes [0 ].encryptwallet ('test' )
45
- bitcoind_processes [0 ].wait ()
46
- # Restart node 0
47
- nodes [0 ] = start_node (0 , tmpdir )
48
- # Keep creating keys
49
- addr = nodes [0 ].getnewaddress ()
50
- try :
42
+ def run_test (nodes , tmpdir ):
43
+ # Encrypt wallet and wait to terminate
44
+ nodes [0 ].encryptwallet ('test' )
45
+ bitcoind_processes [0 ].wait ()
46
+ # Restart node 0
47
+ nodes [0 ] = start_node (0 , tmpdir )
48
+ # Keep creating keys
51
49
addr = nodes [0 ].getnewaddress ()
52
- raise AssertionError ('Keypool should be exhausted after one address' )
53
- except JSONRPCException ,e :
54
- assert (e .error ['code' ]== - 12 )
55
-
56
- # put three new keys in the keypool
57
- nodes [0 ].walletpassphrase ('test' , 12000 )
58
- nodes [0 ].keypoolrefill (3 )
59
- nodes [0 ].walletlock ()
60
-
61
- # drain the keys
62
- addr = set ()
63
- addr .add (nodes [0 ].getrawchangeaddress ())
64
- addr .add (nodes [0 ].getrawchangeaddress ())
65
- addr .add (nodes [0 ].getrawchangeaddress ())
66
- addr .add (nodes [0 ].getrawchangeaddress ())
67
- # assert that four unique addresses were returned
68
- assert (len (addr ) == 4 )
69
- # the next one should fail
70
- try :
71
- addr = nodes [0 ].getrawchangeaddress ()
72
- raise AssertionError ('Keypool should be exhausted after three addresses' )
73
- except JSONRPCException ,e :
74
- assert (e .error ['code' ]== - 12 )
75
-
76
- # refill keypool with three new addresses
77
- nodes [0 ].walletpassphrase ('test' , 12000 )
78
- nodes [0 ].keypoolrefill (3 )
79
- nodes [0 ].walletlock ()
80
-
81
- # drain them by mining
82
- nodes [0 ].generate (1 )
83
- nodes [0 ].generate (1 )
84
- nodes [0 ].generate (1 )
85
- nodes [0 ].generate (1 )
86
- try :
50
+ try :
51
+ addr = nodes [0 ].getnewaddress ()
52
+ raise AssertionError ('Keypool should be exhausted after one address' )
53
+ except JSONRPCException ,e :
54
+ assert (e .error ['code' ]== - 12 )
55
+
56
+ # put three new keys in the keypool
57
+ nodes [0 ].walletpassphrase ('test' , 12000 )
58
+ nodes [0 ].keypoolrefill (3 )
59
+ nodes [0 ].walletlock ()
60
+
61
+ # drain the keys
62
+ addr = set ()
63
+ addr .add (nodes [0 ].getrawchangeaddress ())
64
+ addr .add (nodes [0 ].getrawchangeaddress ())
65
+ addr .add (nodes [0 ].getrawchangeaddress ())
66
+ addr .add (nodes [0 ].getrawchangeaddress ())
67
+ # assert that four unique addresses were returned
68
+ assert (len (addr ) == 4 )
69
+ # the next one should fail
70
+ try :
71
+ addr = nodes [0 ].getrawchangeaddress ()
72
+ raise AssertionError ('Keypool should be exhausted after three addresses' )
73
+ except JSONRPCException ,e :
74
+ assert (e .error ['code' ]== - 12 )
75
+
76
+ # refill keypool with three new addresses
77
+ nodes [0 ].walletpassphrase ('test' , 12000 )
78
+ nodes [0 ].keypoolrefill (3 )
79
+ nodes [0 ].walletlock ()
80
+
81
+ # drain them by mining
87
82
nodes [0 ].generate (1 )
88
- raise AssertionError ('Keypool should be exhausted after three addesses' )
89
- except JSONRPCException ,e :
90
- assert (e .error ['code' ]== - 12 )
91
-
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 )
136
-
137
- if success :
138
- print ("Tests successful" )
139
- sys .exit (0 )
140
- else :
141
- print ("Failed" )
142
- sys .exit (1 )
83
+ nodes [0 ].generate (1 )
84
+ nodes [0 ].generate (1 )
85
+ nodes [0 ].generate (1 )
86
+ try :
87
+ nodes [0 ].generate (1 )
88
+ raise AssertionError ('Keypool should be exhausted after three addesses' )
89
+ except JSONRPCException ,e :
90
+ assert (e .error ['code' ]== - 12 )
91
+
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 )
136
+
137
+ if success :
138
+ print ("Tests successful" )
139
+ sys .exit (0 )
140
+ else :
141
+ print ("Failed" )
142
+ sys .exit (1 )
143
143
144
144
if __name__ == '__main__' :
145
145
main ()
0 commit comments