[qa] keypool: Fix white space to prepare transition to test framework

pull/7027/head
MarcoFalke 9 years ago
parent 6876a78b86
commit c6973ca03b

@ -39,107 +39,107 @@ def check_array_result(object_array, to_match, expected):
if num_matched == 0: if num_matched == 0:
raise AssertionError("No objects matched %s"%(str(to_match))) raise AssertionError("No objects matched %s"%(str(to_match)))
def run_test(nodes, tmpdir): def run_test(nodes, tmpdir):
# Encrypt wallet and wait to terminate # Encrypt wallet and wait to terminate
nodes[0].encryptwallet('test') nodes[0].encryptwallet('test')
bitcoind_processes[0].wait() bitcoind_processes[0].wait()
# Restart node 0 # Restart node 0
nodes[0] = start_node(0, tmpdir) nodes[0] = start_node(0, tmpdir)
# Keep creating keys # Keep creating keys
addr = nodes[0].getnewaddress()
try:
addr = nodes[0].getnewaddress() addr = nodes[0].getnewaddress()
raise AssertionError('Keypool should be exhausted after one address') try:
except JSONRPCException,e: addr = nodes[0].getnewaddress()
assert(e.error['code']==-12) raise AssertionError('Keypool should be exhausted after one address')
except JSONRPCException,e:
# put three new keys in the keypool assert(e.error['code']==-12)
nodes[0].walletpassphrase('test', 12000)
nodes[0].keypoolrefill(3) # put three new keys in the keypool
nodes[0].walletlock() nodes[0].walletpassphrase('test', 12000)
nodes[0].keypoolrefill(3)
# drain the keys nodes[0].walletlock()
addr = set()
addr.add(nodes[0].getrawchangeaddress()) # drain the keys
addr.add(nodes[0].getrawchangeaddress()) addr = set()
addr.add(nodes[0].getrawchangeaddress()) addr.add(nodes[0].getrawchangeaddress())
addr.add(nodes[0].getrawchangeaddress()) addr.add(nodes[0].getrawchangeaddress())
# assert that four unique addresses were returned addr.add(nodes[0].getrawchangeaddress())
assert(len(addr) == 4) addr.add(nodes[0].getrawchangeaddress())
# the next one should fail # assert that four unique addresses were returned
try: assert(len(addr) == 4)
addr = nodes[0].getrawchangeaddress() # the next one should fail
raise AssertionError('Keypool should be exhausted after three addresses') try:
except JSONRPCException,e: addr = nodes[0].getrawchangeaddress()
assert(e.error['code']==-12) raise AssertionError('Keypool should be exhausted after three addresses')
except JSONRPCException,e:
# refill keypool with three new addresses assert(e.error['code']==-12)
nodes[0].walletpassphrase('test', 12000)
nodes[0].keypoolrefill(3) # refill keypool with three new addresses
nodes[0].walletlock() nodes[0].walletpassphrase('test', 12000)
nodes[0].keypoolrefill(3)
# drain them by mining nodes[0].walletlock()
nodes[0].generate(1)
nodes[0].generate(1) # drain them by mining
nodes[0].generate(1)
nodes[0].generate(1)
try:
nodes[0].generate(1) nodes[0].generate(1)
raise AssertionError('Keypool should be exhausted after three addesses') nodes[0].generate(1)
except JSONRPCException,e: nodes[0].generate(1)
assert(e.error['code']==-12) nodes[0].generate(1)
try:
def main(): nodes[0].generate(1)
import optparse raise AssertionError('Keypool should be exhausted after three addesses')
except JSONRPCException,e:
parser = optparse.OptionParser(usage="%prog [options]") assert(e.error['code']==-12)
parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
help="Leave bitcoinds and test.* datadir on exit or error") def main():
parser.add_option("--srcdir", dest="srcdir", default="../../src", import optparse
help="Source directory containing bitcoind/bitcoin-cli (default: %default%)")
parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"), parser = optparse.OptionParser(usage="%prog [options]")
help="Root directory for datadirs") parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
(options, args) = parser.parse_args() help="Leave bitcoinds and test.* datadir on exit or error")
parser.add_option("--srcdir", dest="srcdir", default="../../src",
os.environ['PATH'] = options.srcdir+":"+os.environ['PATH'] help="Source directory containing bitcoind/bitcoin-cli (default: %default%)")
parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"),
check_json_precision() help="Root directory for datadirs")
(options, args) = parser.parse_args()
success = False
nodes = [] os.environ['PATH'] = options.srcdir+":"+os.environ['PATH']
try:
print("Initializing test directory "+options.tmpdir) check_json_precision()
if not os.path.isdir(options.tmpdir):
os.makedirs(options.tmpdir) success = False
initialize_chain(options.tmpdir) nodes = []
try:
nodes = start_nodes(1, options.tmpdir) print("Initializing test directory "+options.tmpdir)
if not os.path.isdir(options.tmpdir):
run_test(nodes, options.tmpdir) os.makedirs(options.tmpdir)
initialize_chain(options.tmpdir)
success = True
nodes = start_nodes(1, options.tmpdir)
except AssertionError as e:
print("Assertion failed: "+e.message) run_test(nodes, options.tmpdir)
except JSONRPCException as e:
print("JSONRPC error: "+e.error['message']) success = True
traceback.print_tb(sys.exc_info()[2])
except Exception as e: except AssertionError as e:
print("Unexpected exception caught during testing: "+str(sys.exc_info()[0])) print("Assertion failed: "+e.message)
traceback.print_tb(sys.exc_info()[2]) except JSONRPCException as e:
print("JSONRPC error: "+e.error['message'])
if not options.nocleanup: traceback.print_tb(sys.exc_info()[2])
print("Cleaning up") except Exception as e:
stop_nodes(nodes) print("Unexpected exception caught during testing: "+str(sys.exc_info()[0]))
wait_bitcoinds() traceback.print_tb(sys.exc_info()[2])
shutil.rmtree(options.tmpdir)
if not options.nocleanup:
if success: print("Cleaning up")
print("Tests successful") stop_nodes(nodes)
sys.exit(0) wait_bitcoinds()
else: shutil.rmtree(options.tmpdir)
print("Failed")
sys.exit(1) if success:
print("Tests successful")
sys.exit(0)
else:
print("Failed")
sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

Loading…
Cancel
Save