Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Fix keosd auto-launching after CLI11 upgrade - 2.0 #9028

Merged
merged 2 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,7 @@ int main( int argc, char** argv ) {
app.add_option( "-r,--header", header_opt_callback, localized("pass specific HTTP header; repeat this option to pass multiple headers"));
app.add_flag( "-n,--no-verify", no_verify, localized("don't verify peer certificate when using HTTPS"));
app.add_flag( "--no-auto-" + string(key_store_executable_name), no_auto_keosd, localized("don't automatically launch a ${k} if one is not currently running", ("k", key_store_executable_name)));
app.callback([&app]{ ensure_keosd_running(&app);});
app.parse_complete_callback([&app]{ ensure_keosd_running(&app);});

app.add_flag( "-v,--verbose", verbose, localized("output verbose errors and action console output"));
app.add_flag("--print-request", print_request, localized("print HTTP request to STDERR"));
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nodeos_multiple_version_protocol_feat
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/consensus-validation-malicious-producers.py ${CMAKE_CURRENT_BINARY_DIR}/consensus-validation-malicious-producers.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/validate-dirty-db.py ${CMAKE_CURRENT_BINARY_DIR}/validate-dirty-db.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/launcher_test.py ${CMAKE_CURRENT_BINARY_DIR}/launcher_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/keosd_auto_launch_test.py ${CMAKE_CURRENT_BINARY_DIR}/keosd_auto_launch_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/db_modes_test.sh ${CMAKE_CURRENT_BINARY_DIR}/db_modes_test.sh COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/prod_preactivation_test.py ${CMAKE_CURRENT_BINARY_DIR}/prod_preactivation_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/release-build.sh ${CMAKE_CURRENT_BINARY_DIR}/release-build.sh COPYONLY)
Expand Down Expand Up @@ -87,6 +88,8 @@ add_test(NAME validate_dirty_db_test COMMAND tests/validate-dirty-db.py -v --cle
set_property(TEST validate_dirty_db_test PROPERTY LABELS nonparallelizable_tests)
add_test(NAME launcher_test COMMAND tests/launcher_test.py -v --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST launcher_test PROPERTY LABELS nonparallelizable_tests)
add_test(NAME keosd_auto_launch_test COMMAND tests/keosd_auto_launch_test.py WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST keosd_auto_launch_test PROPERTY LABELS nonparallelizable_tests)
add_test(NAME db_modes_test COMMAND tests/db_modes_test.sh WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(db_modes_test PROPERTIES COST 6000)
add_test(NAME release-build-test COMMAND tests/release-build.sh WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Expand Down
48 changes: 48 additions & 0 deletions tests/keosd_auto_launch_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3

# This script tests that cleos launches keosd automatically when keosd is not
# running yet.

import subprocess


def run_cleos_wallet_command(command: str, no_auto_keosd: bool):
"""Run the given cleos command and return subprocess.CompletedProcess."""
args = ['./programs/cleos/cleos']

if no_auto_keosd:
args.append('--no-auto-keosd')

args += 'wallet', command

return subprocess.run(args,
check=False,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE)


def stop_keosd():
"""Stop the default keosd instance."""
run_cleos_wallet_command('stop', no_auto_keosd=True)


def keosd_auto_launch_test():
"""Test that keos auto-launching works but can be optionally inhibited."""
stop_keosd()

# Make sure that when '--no-auto-keosd' is given, keosd is not started by
# cleos.
completed_process = run_cleos_wallet_command('list', no_auto_keosd=True)
assert completed_process.returncode != 0
assert b'Failed to connect to keosd' in completed_process.stderr

# Verify that keosd auto-launching works.
completed_process = run_cleos_wallet_command('list', no_auto_keosd=False)
assert completed_process.returncode == 0
assert b'launched' in completed_process.stderr


try:
keosd_auto_launch_test()
finally:
stop_keosd()