<commit_before>#include <bts/app/application.hpp>
#include <bts/app/plugin.hpp>

#include <bts/chain/key_object.hpp>
#include <bts/time/time.hpp>

#include <bts/account_history/account_history_plugin.hpp>

#include <fc/thread/thread.hpp>

#include <boost/filesystem/path.hpp>

#define BOOST_TEST_MODULE Test Application
#include <boost/test/included/unit_test.hpp>

using namespace bts;

BOOST_AUTO_TEST_CASE( two_node_network )
{
   using namespace bts::chain;
   using namespace bts::app;
   try {
      fc::temp_directory app_dir;
      fc::temp_directory app2_dir;
      fc::temp_file genesis_json;
      fc::json::save_to_file(genesis_allocation(), genesis_json.path());

      fc::time_point_sec now( BTS_GENESIS_TIMESTAMP );

      bts::app::application app1;
      app1.register_plugin<bts::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);

      bts::app::application app2;
      app2.register_plugin<account_history::account_history_plugin>();
      auto cfg2 = cfg;
      cfg2.erase("p2p-endpoint");
      cfg2.emplace("p2p-endpoint", bpo::variable_value(string("127.0.0.1:4040"), false));
      cfg2.emplace("seed-node", bpo::variable_value(vector<string>{"127.0.0.1:3939"}, false));
      app2.initialize(app2_dir.path(), cfg2);

      app1.startup();
      app2.startup();
      fc::usleep(fc::milliseconds(500));

      BOOST_CHECK_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("genesis")));
      bts::chain::signed_transaction trx;
      trx.operations.push_back(key_create_operation({asset(), account_id_type(1), public_key_type(nathan_key.get_public_key())}));
      trx.set_expiration(app2.chain_database()->head_block_id());
      trx.validate();
      trx.signatures[key_id_type(0)] =  genesis_key.sign_compact(trx.digest());
      processed_transaction ptrx = app1.chain_database()->push_transaction(trx);
      app1.p2p_node()->broadcast(bts::net::trx_message(trx));
      key_id_type nathan_key_id = ptrx.operation_results.front().get<object_id_type>();

      fc::usleep(fc::milliseconds(250));
      BOOST_CHECK(nathan_key_id(*app2.chain_database()).key_data.get<public_key_type>() == nathan_key.get_public_key());
      ilog("Pushed transaction");

      std::shared_ptr<chain::database> db2 = app2.chain_database();
      now += BTS_DEFAULT_BLOCK_INTERVAL;
      app2.p2p_node()->broadcast(bts::net::block_message(db2->generate_block(
         now, db2->get_scheduled_witness( now )->second, genesis_key )));

      fc::usleep(fc::milliseconds(500));<commit_msg>app_test:  Fix failure due to wrong digest() overload for relative expiration<commit_after>#include <bts/app/application.hpp>
#include <bts/app/plugin.hpp>

#include <bts/chain/key_object.hpp>
#include <bts/time/time.hpp>

#include <bts/account_history/account_history_plugin.hpp>

#include <fc/thread/thread.hpp>

#include <boost/filesystem/path.hpp>

#define BOOST_TEST_MODULE Test Application
#include <boost/test/included/unit_test.hpp>

using namespace bts;

BOOST_AUTO_TEST_CASE( two_node_network )
{
   using namespace bts::chain;
   using namespace bts::app;
   try {
      fc::temp_directory app_dir;
      fc::temp_directory app2_dir;
      fc::temp_file genesis_json;
      fc::json::save_to_file(genesis_allocation(), genesis_json.path());

      fc::time_point_sec now( BTS_GENESIS_TIMESTAMP );

      bts::app::application app1;
      app1.register_plugin<bts::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);

      bts::app::application app2;
      app2.register_plugin<account_history::account_history_plugin>();
      auto cfg2 = cfg;
      cfg2.erase("p2p-endpoint");
      cfg2.emplace("p2p-endpoint", bpo::variable_value(string("127.0.0.1:4040"), false));
      cfg2.emplace("seed-node", bpo::variable_value(vector<string>{"127.0.0.1:3939"}, false));
      app2.initialize(app2_dir.path(), cfg2);

      app1.startup();
      app2.startup();
      fc::usleep(fc::milliseconds(500));

      BOOST_CHECK_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("genesis")));
      bts::chain::signed_transaction trx;
      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.set_expiration(db2->head_block_id());   // relative expiration
      trx.validate();
      trx.signatures[key_id_type(0)] =  genesis_key.sign_compact(trx.digest( db2->head_block_id() ));
      processed_transaction ptrx = app1.chain_database()->push_transaction(trx);
      app1.p2p_node()->broadcast(bts::net::trx_message(trx));
      key_id_type nathan_key_id = ptrx.operation_results.front().get<object_id_type>();

      fc::usleep(fc::milliseconds(250));
      BOOST_CHECK(nathan_key_id(*app2.chain_database()).key_data.get<public_key_type>() == nathan_key.get_public_key());
      ilog("Pushed transaction");

      now += BTS_DEFAULT_BLOCK_INTERVAL;
      app2.p2p_node()->broadcast(bts::net::block_message(db2->generate_block(
         now, db2->get_scheduled_witness( now )->second, genesis_key )));

      fc::usleep(fc::milliseconds(500));
{'fraction_non_alphanumeric': 0.1618164374800128, 'fraction_numerical': 0.02702270546850016, 'mean_word_length': 5.084630350194552, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '613207', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2186, 'n_words': 248}