Merge branch 'master' of github.com:cryptonomex/graphene

This commit is contained in:
Daniel Larimer 2015-06-19 12:11:36 -04:00
commit b2962c530f
5 changed files with 73 additions and 21 deletions

View file

@ -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
------------

View file

@ -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<genesis_state_type::initial_witness_type>(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<boost::filesystem::path>()).as<genesis_state_type>();

View file

@ -19,6 +19,7 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/time/time.hpp>
#include <fc/thread/thread.hpp>
@ -36,7 +37,7 @@ void witness_plugin::plugin_set_program_options(
("witness-id,w", bpo::value<vector<string>>()->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<vector<string>>()->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);
}

View file

@ -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<graphene::account_history::account_history_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<chain::database> 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<object_id_type>();
@ -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);

View file

@ -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()
*/
}