From ab2cadd2b541b3ca9ea854350caec8c3301cdb00 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 26 Jul 2018 19:12:04 +0000 Subject: [PATCH 1/3] Fix cli_tests WS port binding #1178; coding style --- tests/cli/main.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 672a8b8600..19553a8733 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -97,7 +97,7 @@ std::shared_ptr start_application(fc::temp_directory app1->startup(); fc::usleep(fc::milliseconds(500)); - return app1; + return app1; } /////////// @@ -108,13 +108,12 @@ std::shared_ptr start_application(fc::temp_directory bool generate_block(std::shared_ptr app) { try { fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan"))); - auto db = app->chain_database(); - auto block_1 = db->generate_block( - db->get_slot_time(1), - db->get_scheduled_witness(1), - committee_key, - database::skip_nothing); - return true; + auto db = app->chain_database(); + auto block_1 = db->generate_block( db->get_slot_time(1), + db->get_scheduled_witness(1), + committee_key, + database::skip_nothing ); + return true; } catch (exception &e) { return false; } @@ -208,11 +207,11 @@ BOOST_AUTO_TEST_CASE( cli_connect ) try { fc::temp_directory app_dir ( graphene::utilities::temp_directory_path() ); - int server_port_number = 0; - app1 = start_application(app_dir, server_port_number); + int server_port_number = 0; + app1 = start_application(app_dir, server_port_number); // connect to the server - client_connection con(app1, app_dir, server_port_number); + client_connection con(app1, app_dir, server_port_number); } catch( fc::exception& e ) { edump((e.to_detail_string())); @@ -268,7 +267,7 @@ BOOST_AUTO_TEST_CASE( cli_vote_for_2_witnesses ) BOOST_CHECK(!bki.brain_priv_key.empty()); signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, "jmjatlanta", "nathan", "nathan", true); // save the private key for this new account in the wallet file - BOOST_CHECK(con.wallet_api_ptr->import_key("jmjatlanta", bki.wif_priv_key)); + BOOST_CHECK(con.wallet_api_ptr->import_key("jmjatlanta", bki.wif_priv_key)); con.wallet_api_ptr->save_wallet_file(con.wallet_filename); // attempt to give jmjatlanta some bitsahres @@ -330,7 +329,7 @@ BOOST_AUTO_TEST_CASE( cli_set_voting_proxy ) fc::temp_directory app_dir( graphene::utilities::temp_directory_path() ); - int server_port_number; + int server_port_number = 0; app1 = start_application(app_dir, server_port_number); // connect to the server @@ -364,7 +363,7 @@ BOOST_AUTO_TEST_CASE( cli_set_voting_proxy ) BOOST_CHECK(!bki.brain_priv_key.empty()); signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, "jmjatlanta", "nathan", "nathan", true); // save the private key for this new account in the wallet file - BOOST_CHECK(con.wallet_api_ptr->import_key("jmjatlanta", bki.wif_priv_key)); + BOOST_CHECK(con.wallet_api_ptr->import_key("jmjatlanta", bki.wif_priv_key)); con.wallet_api_ptr->save_wallet_file(con.wallet_filename); // attempt to give jmjatlanta some bitsahres @@ -402,7 +401,7 @@ BOOST_AUTO_TEST_CASE( cli_confidential_tx_test ) // ** Start a Graphene chain and API server: fc::temp_directory app_dir( graphene::utilities::temp_directory_path() ); - int server_port_number; + int server_port_number = 0; app1 = start_application(app_dir, server_port_number); unsigned int head_block = 0; From 367c564dd455839255e20b658293ded969c2bb5f Mon Sep 17 00:00:00 2001 From: Abit Date: Fri, 27 Jul 2018 20:14:56 +0200 Subject: [PATCH 2/3] cli_test: return available port in host byte order sin_port is the the assigned port number, in network byte order. --- tests/cli/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 19553a8733..88643ac13b 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -71,7 +71,7 @@ int get_available_port() socklen_t len = sizeof(sin); if (getsockname(socket_fd, (struct sockaddr *)&sin, &len) == -1) return -1; - return sin.sin_port; + return ntohs(sin.sin_port); } /////////// From 5c615ae0a422d5efe78757dafbae3ae520595a26 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 27 Jul 2018 21:50:11 +0000 Subject: [PATCH 3/3] Close socket before returning, so port is usable --- tests/cli/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 88643ac13b..1ce1ff6f5c 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -71,6 +71,7 @@ int get_available_port() socklen_t len = sizeof(sin); if (getsockname(socket_fd, (struct sockaddr *)&sin, &len) == -1) return -1; + close(socket_fd); return ntohs(sin.sin_port); }