Merge branch 'master' of github.com:cryptonomex/graphene
This commit is contained in:
commit
a60c506cc7
1 changed files with 66 additions and 21 deletions
|
|
@ -18,6 +18,8 @@
|
||||||
#include <graphene/app/application.hpp>
|
#include <graphene/app/application.hpp>
|
||||||
#include <graphene/app/plugin.hpp>
|
#include <graphene/app/plugin.hpp>
|
||||||
|
|
||||||
|
#include <graphene/chain/balance_object.hpp>
|
||||||
|
|
||||||
#include <graphene/time/time.hpp>
|
#include <graphene/time/time.hpp>
|
||||||
|
|
||||||
#include <graphene/utilities/tempdir.hpp>
|
#include <graphene/utilities/tempdir.hpp>
|
||||||
|
|
@ -38,12 +40,13 @@ BOOST_AUTO_TEST_CASE( two_node_network )
|
||||||
using namespace graphene::chain;
|
using namespace graphene::chain;
|
||||||
using namespace graphene::app;
|
using namespace graphene::app;
|
||||||
try {
|
try {
|
||||||
|
BOOST_TEST_MESSAGE( "Creating temporary files" );
|
||||||
|
|
||||||
fc::temp_directory app_dir( graphene::utilities::temp_directory_path() );
|
fc::temp_directory app_dir( graphene::utilities::temp_directory_path() );
|
||||||
fc::temp_directory app2_dir( graphene::utilities::temp_directory_path() );
|
fc::temp_directory app2_dir( graphene::utilities::temp_directory_path() );
|
||||||
fc::temp_file genesis_json;
|
fc::temp_file genesis_json;
|
||||||
|
|
||||||
// TODO: Time should be read from the blockchain
|
BOOST_TEST_MESSAGE( "Creating and initializing app1" );
|
||||||
fc::time_point_sec now( 1431700000 );
|
|
||||||
|
|
||||||
graphene::app::application app1;
|
graphene::app::application app1;
|
||||||
app1.register_plugin<graphene::account_history::account_history_plugin>();
|
app1.register_plugin<graphene::account_history::account_history_plugin>();
|
||||||
|
|
@ -51,6 +54,8 @@ BOOST_AUTO_TEST_CASE( two_node_network )
|
||||||
cfg.emplace("p2p-endpoint", boost::program_options::variable_value(string("127.0.0.1:3939"), false));
|
cfg.emplace("p2p-endpoint", boost::program_options::variable_value(string("127.0.0.1:3939"), false));
|
||||||
app1.initialize(app_dir.path(), cfg);
|
app1.initialize(app_dir.path(), cfg);
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE( "Creating and initializing app2" );
|
||||||
|
|
||||||
graphene::app::application app2;
|
graphene::app::application app2;
|
||||||
app2.register_plugin<account_history::account_history_plugin>();
|
app2.register_plugin<account_history::account_history_plugin>();
|
||||||
auto cfg2 = cfg;
|
auto cfg2 = cfg;
|
||||||
|
|
@ -59,42 +64,82 @@ BOOST_AUTO_TEST_CASE( two_node_network )
|
||||||
cfg2.emplace("seed-node", boost::program_options::variable_value(vector<string>{"127.0.0.1:3939"}, false));
|
cfg2.emplace("seed-node", boost::program_options::variable_value(vector<string>{"127.0.0.1:3939"}, false));
|
||||||
app2.initialize(app2_dir.path(), cfg2);
|
app2.initialize(app2_dir.path(), cfg2);
|
||||||
|
|
||||||
app1.startup();
|
BOOST_TEST_MESSAGE( "Starting app1 and waiting 500 ms" );
|
||||||
|
app1.startup();
|
||||||
|
fc::usleep(fc::milliseconds(500));
|
||||||
|
BOOST_TEST_MESSAGE( "Starting app2 and waiting 500 ms" );
|
||||||
app2.startup();
|
app2.startup();
|
||||||
fc::usleep(fc::milliseconds(500));
|
fc::usleep(fc::milliseconds(500));
|
||||||
|
|
||||||
BOOST_REQUIRE_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");
|
BOOST_CHECK_EQUAL(std::string(app1.p2p_node()->get_connected_peers().front().host.get_address()), "127.0.0.1");
|
||||||
ilog("Connected!");
|
BOOST_TEST_MESSAGE( "app1 and app2 successfully connected" );
|
||||||
|
|
||||||
fc::ecc::private_key nathan_key = fc::ecc::private_key::generate();
|
std::shared_ptr<chain::database> db1 = app1.chain_database();
|
||||||
fc::ecc::private_key committee_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();
|
std::shared_ptr<chain::database> db2 = app2.chain_database();
|
||||||
|
|
||||||
assert_operation op;
|
BOOST_CHECK_EQUAL( db1->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 0 );
|
||||||
op.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
|
BOOST_CHECK_EQUAL( db2->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 0 );
|
||||||
op.predicates.push_back( graphene::chain::asset_symbol_eq_lit_predicate{ asset_id_type(), "CORE" } );
|
|
||||||
|
|
||||||
trx.operations.push_back( std::move( op ) );
|
BOOST_TEST_MESSAGE( "Creating transfer tx" );
|
||||||
|
graphene::chain::signed_transaction trx;
|
||||||
|
{
|
||||||
|
account_id_type nathan_id = db2->get_index_type<account_index>().indices().get<by_name>().find( "nathan" )->id;
|
||||||
|
fc::ecc::private_key nathan_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
|
||||||
|
|
||||||
trx.validate();
|
balance_claim_operation claim_op;
|
||||||
processed_transaction ptrx = app1.chain_database()->push_transaction(trx);
|
balance_id_type bid = balance_id_type();
|
||||||
|
claim_op.deposit_to_account = nathan_id;
|
||||||
|
claim_op.balance_to_claim = bid;
|
||||||
|
claim_op.balance_owner_key = nathan_key.get_public_key();
|
||||||
|
claim_op.total_claimed = bid(*db1).balance;
|
||||||
|
trx.operations.push_back( claim_op );
|
||||||
|
db1->current_fee_schedule().set_fee( trx.operations.back() );
|
||||||
|
|
||||||
|
transfer_operation xfer_op;
|
||||||
|
xfer_op.from = nathan_id;
|
||||||
|
xfer_op.to = GRAPHENE_NULL_ACCOUNT;
|
||||||
|
xfer_op.amount = asset( 1000000 );
|
||||||
|
trx.operations.push_back( xfer_op );
|
||||||
|
db1->current_fee_schedule().set_fee( trx.operations.back() );
|
||||||
|
|
||||||
|
trx.set_expiration( db1->get_slot_time( 10 ) );
|
||||||
|
trx.sign( nathan_key );
|
||||||
|
trx.validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE( "Pushing tx locally on db1" );
|
||||||
|
processed_transaction ptrx = db1->push_transaction(trx);
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( db1->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 1000000 );
|
||||||
|
BOOST_CHECK_EQUAL( db2->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 0 );
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE( "Broadcasting tx" );
|
||||||
app1.p2p_node()->broadcast(graphene::net::trx_message(trx));
|
app1.p2p_node()->broadcast(graphene::net::trx_message(trx));
|
||||||
|
|
||||||
fc::usleep(fc::milliseconds(250));
|
fc::usleep(fc::milliseconds(500));
|
||||||
ilog("Pushed transaction");
|
|
||||||
|
|
||||||
now += GRAPHENE_DEFAULT_BLOCK_INTERVAL;
|
BOOST_CHECK_EQUAL( db1->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 1000000 );
|
||||||
app2.p2p_node()->broadcast(graphene::net::block_message(db2->generate_block(now,
|
BOOST_CHECK_EQUAL( db2->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 1000000 );
|
||||||
db2->get_scheduled_witness(1).first,
|
|
||||||
committee_key,
|
BOOST_TEST_MESSAGE( "Generating block on db2" );
|
||||||
database::skip_nothing)));
|
fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
|
||||||
|
|
||||||
|
auto block_1 = db2->generate_block(
|
||||||
|
db2->get_slot_time(1),
|
||||||
|
db2->get_scheduled_witness(1).first,
|
||||||
|
committee_key,
|
||||||
|
database::skip_nothing);
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE( "Broadcasting block" );
|
||||||
|
app2.p2p_node()->broadcast(graphene::net::block_message( block_1 ));
|
||||||
|
|
||||||
fc::usleep(fc::milliseconds(500));
|
fc::usleep(fc::milliseconds(500));
|
||||||
|
BOOST_TEST_MESSAGE( "Verifying nodes are still connected" );
|
||||||
BOOST_CHECK_EQUAL(app1.p2p_node()->get_connection_count(), 1);
|
BOOST_CHECK_EQUAL(app1.p2p_node()->get_connection_count(), 1);
|
||||||
BOOST_CHECK_EQUAL(app1.chain_database()->head_block_num(), 1);
|
BOOST_CHECK_EQUAL(app1.chain_database()->head_block_num(), 1);
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE( "Checking GRAPHENE_NULL_ACCOUNT has balance" );
|
||||||
} catch( fc::exception& e ) {
|
} catch( fc::exception& e ) {
|
||||||
edump((e.to_detail_string()));
|
edump((e.to_detail_string()));
|
||||||
throw;
|
throw;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue