Skip to content

Commit 4ea1790

Browse files
author
MarcoFalke
committed
[qa] keypool: DRY: Use test framework
1 parent c6973ca commit 4ea1790

File tree

1 file changed

+12
-61
lines changed

1 file changed

+12
-61
lines changed

qa/rpc-tests/keypool.py

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@
66
# Exercise the wallet keypool, and interaction with wallet encryption/locking
77

88
# 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
179

10+
from test_framework.test_framework import BitcoinTestFramework
1811
from test_framework.util import *
1912

2013

@@ -39,12 +32,15 @@ def check_array_result(object_array, to_match, expected):
3932
if num_matched == 0:
4033
raise AssertionError("No objects matched %s"%(str(to_match)))
4134

42-
def run_test(nodes, tmpdir):
35+
class KeyPoolTest(BitcoinTestFramework):
36+
37+
def run_test(self):
38+
nodes = self.nodes
4339
# Encrypt wallet and wait to terminate
4440
nodes[0].encryptwallet('test')
4541
bitcoind_processes[0].wait()
4642
# Restart node 0
47-
nodes[0] = start_node(0, tmpdir)
43+
nodes[0] = start_node(0, self.options.tmpdir)
4844
# Keep creating keys
4945
addr = nodes[0].getnewaddress()
5046
try:
@@ -89,57 +85,12 @@ def run_test(nodes, tmpdir):
8985
except JSONRPCException,e:
9086
assert(e.error['code']==-12)
9187

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)
13691

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)
14394

14495
if __name__ == '__main__':
145-
main()
96+
KeyPoolTest().main()

0 commit comments

Comments
 (0)