From d441da2959732be6781afc241b7f1de99efd6fb2 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 19 Jun 2015 15:20:48 +0200 Subject: [PATCH 1/4] Describe coverage testing --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e15ad7fe..b2121b05 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,31 @@ A list of CLI wallet commands is available [here](https://bitshares.github.io/do Code coverage testing --------------------- -TODO: Write something here +Check how much code is covered by unit tests, using gcov/lcov (see http://ltp.sourceforge.net/coverage/lcov.php ). + + cmake -D ENABLE_COVERAGE_TESTING=true -D CMAKE_BUILD_TYPE=Debug . + make + lcov --capture --initial --directory . --output-file base.info --no-external + libraries/fc/bloom_test + libraries/fc/task_cancel_test + libraries/fc/api + libraries/fc/blind + libraries/fc/ecc_test test + libraries/fc/real128_test + libraries/fc/lzma_test README.md + libraries/fc/ntp_test + tests/intense_test + tests/app_test + tests/chain_bench + tests/chain_test + tests/performance_test + lcov --capture --directory . --output-file test.info --no-external + lcov --add-tracefile base.info --add-tracefile test.info --output-file total.info + lcov -o interesting.info -r total.info libraries/fc/vendor/\* libraries/fc/tests/\* tests/\* + mkdir -p lcov + genhtml interesting.info --output-directory lcov --prefix `pwd` + +Now open `lcov/index.html` in a browser. Unit testing ------------ From 6fc11bb5fd27150505283bd921836429973534c2 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Fri, 19 Jun 2015 10:23:32 -0400 Subject: [PATCH 2/4] Resolve #59: Add witnesses to default genesis in witness_node --- libraries/app/application.cpp | 12 ++++++++++++ libraries/plugins/witness/witness.cpp | 21 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 201a3eaa..6deec129 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -150,6 +150,18 @@ namespace detail { auto nathan_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan"))); genesis_state_type initial_state; + secret_hash_type::encoder enc; + fc::raw::pack(enc, nathan_key); + fc::raw::pack(enc, secret_hash_type()); + for( int i = 0; i < 10; ++i ) + { + initial_state.allocation_targets.emplace_back("init"+fc::to_string(i), nathan_key.get_public_key(), 0, true); + initial_state.initial_committee.push_back({"init"+fc::to_string(i)}); + } + initial_state.initial_witnesses = vector(10, {"committee-account", + nathan_key.get_public_key(), + secret_hash_type::hash(enc.result())}); + initial_state.allocation_targets.emplace_back("nathan", address(public_key_type(nathan_key.get_public_key())), 1); if( _options->count("genesis-json") ) initial_state = fc::json::from_file(_options->at("genesis-json").as()).as(); diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index 13ac821e..8ad64c1e 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -36,7 +37,7 @@ void witness_plugin::plugin_set_program_options( ("witness-id,w", bpo::value>()->composing()->multitoken(), "ID of witness controlled by this node (e.g. \"1.7.0\", quotes are required, may specify multiple times)") ("private-key", bpo::value>()->composing()->multitoken()-> - DEFAULT_VALUE_VECTOR(std::make_pair(chain::key_id_type(), fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("null_key"))))), + DEFAULT_VALUE_VECTOR(std::make_pair(chain::key_id_type(), fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("nathan"))))), "Tuple of [key ID, private key] (may specify multiple times)") ; config_file_options.add(command_line_options); @@ -63,9 +64,23 @@ void witness_plugin::plugin_startup() graphene::time::now(); for( auto wit : _witnesses ) { - auto key = wit(database()).signing_key; - if( !_private_keys.count(key) ) + auto signing_key = wit(database()).signing_key; + if( !_private_keys.count(signing_key) ) { + // Check if it's a duplicate key of one I do have + bool found_duplicate = false; + for( const auto& private_key : _private_keys ) + if( chain::public_key_type(private_key.second.get_public_key()) == signing_key(database()).key_address() ) + { + ilog("Found duplicate key: ${k1} matches ${k2}; using this key to sign for ${w}", + ("k1", private_key.first)("k2", signing_key)("w", wit)); + _private_keys[signing_key] = private_key.second; + found_duplicate = true; + break; + } + if( found_duplicate ) + continue; + elog("Unable to find key for witness ${w}. Removing it from my witnesses.", ("w", wit)); bad_wits.insert(wit); } From fc11f40937fe1ecea6b534f56176f848d4b85eb7 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Fri, 19 Jun 2015 10:55:07 -0400 Subject: [PATCH 3/4] Fix app_test Sometimes it fails to connect, but when it does, it works. --- tests/app/main.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 93480b06..de35c181 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -40,7 +40,6 @@ BOOST_AUTO_TEST_CASE( two_node_network ) fc::temp_directory app_dir; fc::temp_directory app2_dir; fc::temp_file genesis_json; - fc::json::save_to_file(genesis_state_type(), genesis_json.path()); fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP ); @@ -48,7 +47,6 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app1.register_plugin(); bpo::variables_map cfg; cfg.emplace("p2p-endpoint", bpo::variable_value(string("127.0.0.1:3939"), false)); - cfg.emplace("genesis-json", bpo::variable_value(boost::filesystem::path(genesis_json.path()), false)); app1.initialize(app_dir.path(), cfg); graphene::app::application app2; @@ -63,19 +61,20 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app2.startup(); fc::usleep(fc::milliseconds(500)); - BOOST_CHECK_EQUAL(app1.p2p_node()->get_connection_count(), 1); + BOOST_REQUIRE_EQUAL(app1.p2p_node()->get_connection_count(), 1); BOOST_CHECK_EQUAL(std::string(app1.p2p_node()->get_connected_peers().front().host.get_address()), "127.0.0.1"); ilog("Connected!"); fc::ecc::private_key nathan_key = fc::ecc::private_key::generate(); - fc::ecc::private_key genesis_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); + fc::ecc::private_key genesis_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan"))); graphene::chain::signed_transaction trx; trx.set_expiration(now + fc::seconds(30)); std::shared_ptr db2 = app2.chain_database(); - trx.operations.push_back(key_create_operation({asset(), account_id_type(1), public_key_type(nathan_key.get_public_key())})); + trx.operations.push_back(key_create_operation({asset(), + GRAPHENE_TEMP_ACCOUNT, + public_key_type(nathan_key.get_public_key())})); trx.validate(); - trx.sign(key_id_type(0), genesis_key); processed_transaction ptrx = app1.chain_database()->push_transaction(trx); app1.p2p_node()->broadcast(graphene::net::trx_message(trx)); key_id_type nathan_key_id = ptrx.operation_results.front().get(); @@ -85,8 +84,10 @@ BOOST_AUTO_TEST_CASE( two_node_network ) ilog("Pushed transaction"); now += GRAPHENE_DEFAULT_BLOCK_INTERVAL; - app2.p2p_node()->broadcast(graphene::net::block_message(db2->generate_block( - now, db2->get_scheduled_witness( 1 ).first, genesis_key, database::skip_nothing ))); + app2.p2p_node()->broadcast(graphene::net::block_message(db2->generate_block(now, + db2->get_scheduled_witness(1).first, + genesis_key, + database::skip_nothing))); fc::usleep(fc::milliseconds(500)); BOOST_CHECK_EQUAL(app1.p2p_node()->get_connection_count(), 1); From dac278511b0b87e03b55b1591536f28083a094c8 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Fri, 19 Jun 2015 11:24:35 -0400 Subject: [PATCH 4/4] Cleaning up Dan's mess: fix broken mia_feeds test --- tests/tests/operation_tests2.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 5e6e932a..4acf3425 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -300,8 +300,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_delete ) PUSH_TX( db, trx ); } FC_LOG_AND_RETHROW() } -BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( broken_mia_feeds, 1 ) -BOOST_AUTO_TEST_CASE( broken_mia_feeds ) +BOOST_AUTO_TEST_CASE( mia_feeds ) { try { ACTORS((nathan)(dan)(ben)(vikram)); asset_id_type bit_usd_id = create_bitasset("BITUSD").id; @@ -337,31 +336,32 @@ BOOST_AUTO_TEST_CASE( broken_mia_feeds ) const asset_object& bit_usd = bit_usd_id(db); asset_publish_feed_operation op({asset(), vikram_id}); op.asset_id = bit_usd_id; - op.feed.settlement_price = price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(30)); + op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(30)); // We'll expire margins after a month // Accept defaults for required collateral trx.operations.emplace_back(op); PUSH_TX( db, trx, ~0 ); const asset_bitasset_data_object& bitasset = bit_usd.bitasset_data(db); - BOOST_CHECK(bitasset.current_feed.settlement_price.to_real() == GRAPHENE_BLOCKCHAIN_PRECISION / 30.0); + BOOST_CHECK(bitasset.current_feed.settlement_price.to_real() == 30.0 / GRAPHENE_BLOCKCHAIN_PRECISION); BOOST_CHECK(bitasset.current_feed.maintenance_collateral_ratio == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = ben_id; - op.feed.settlement_price = price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(25)); + op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(25)); trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); - BOOST_CHECK_EQUAL(bitasset.current_feed.settlement_price.to_real(), GRAPHENE_BLOCKCHAIN_PRECISION / 25.0); + BOOST_CHECK_EQUAL(bitasset.current_feed.settlement_price.to_real(), 30.0 / GRAPHENE_BLOCKCHAIN_PRECISION); BOOST_CHECK(bitasset.current_feed.maintenance_collateral_ratio == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = dan_id; - op.feed.settlement_price = price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(40)); + op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(40)); + op.feed.maximum_short_squeeze_ratio = 1000; op.feed.maintenance_collateral_ratio = 1000; trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); - BOOST_CHECK_EQUAL(bitasset.current_feed.settlement_price.to_real(), GRAPHENE_BLOCKCHAIN_PRECISION / 30.0); + BOOST_CHECK_EQUAL(bitasset.current_feed.settlement_price.to_real(), 30.0 / GRAPHENE_BLOCKCHAIN_PRECISION); BOOST_CHECK(bitasset.current_feed.maintenance_collateral_ratio == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = nathan_id; @@ -479,7 +479,7 @@ BOOST_AUTO_TEST_CASE( unimp_global_settle_test ) BOOST_CHECK_EQUAL(get_balance(ben_id, asset_id_type()), 10091); BOOST_CHECK_EQUAL(get_balance(dan_id, bit_usd_id), 0); BOOST_CHECK_EQUAL(get_balance(dan_id, asset_id_type()), 9850); -} FC_LOG_AND_RETHROW() +} FC_LOG_AND_RETHROW() */ }