text:
#include "simulation/generic-path-generator.h"

#include <Eigen/Dense>
#include <glog/logging.h>
#include <maplab-common/gravity-provider.h>
#include <ros/ros.h>
#include <visualization_msgs/MarkerArray.h>

#include <simulation/eigen-visualization.h>

// Basic usage examples:
// rosrun simulation simulation_generic // Generates circular trajectory with
// default parameters.
// rosrun simulation simulation_generic -mode 1 // Same as previous line.
// rosrun simulation simulation_generic -mode 2 // Generates elliptic trajectory
// with default parameters.
// rosrun simulation simulation_generic -mode 2 -kappa 0.1 -lambda 0.2
// rosrun simulation simulation_generic -mode 3 // Generate rotation-only path
// rosrun simulation simulation_generic -mode 4 // Generate translation-only
// path
// rosrun simulation simulation_generic -mode 5 -filename_waypoints
// "/tmp/waypoints_translation_only.txt"
// rosrun simulation simulation_generic -mode 5 -filename_waypoints
// "/tmp/waypoints_rotation_only.txt"

// gflags: DEFINE_type(name, default value, help)
// Prefix tg_* stands for "trajectory generator".
DEFINE_bool(tg_visualization, true, "Publish visualization topics for RVIZ.");
DEFINE_double(
    tg_acc_bias_sigma_meter_by_sqrt_second5, 0.1,
    "Accelerometer noise bias standard deviation");
DEFINE_double(
    tg_acc_sigma_meter_by_sqrt_second2, 0.1,
    "Accelerometer noise standard deviation");
DEFINE_double(tg_circle_radius_meter, 10.0, "Circle radius");
DEFINE_double(tg_distance_to_keypoints_meter, 5.0, "Distance to keypoints");
DEFINE_double(
    tg_gyro_bias_sigma_rad_by_sqrt_second3, 0.1,
    "Gyroscope bias noise standard deviation");
DEFINE_double(
    tg_gyro_sigma_rad_by_sqrt_second, 0.1,
    "Gyroscope noise standard deviation");
DEFINE_double(
    tg_kappa, 0.1,
    "Kappa defining the ellipse shape according to x = (1.0 / kappa) "
    "* cos(t).");
DEFINE_double(
    tg_lambda, 0.05,
    "Lambda defining the ellipse shape according to y = (1.0 / "
    "lambda) * sin(t).");
DEFINE_double(
    tg_landmark_offset_x_meter, 50.0, "Landmark volume offset in x direction");
DEFINE_double(
    tg_landmark_offset_y_meter, 0.0, "Landmark volume offset in y direction");
DEFINE_double(
    tg_landmark_offset_z_meter, 0.5, "Landmark volume offset in z direction");
DEFINE_double(tg_landmark_variance_meter, 3.0, "Landmark variance");
DEFINE_double(
    tg_landmark_volume_x_meter, 10.0,
    "Landmark volume in x direction, centered around offset");
DEFINE_double(
    tg_landmark_volume_y_meter, 10.0,
    "Landmark volume in y direction, centered around offset");
DEFINE_double(
    tg_landmark_volume_z_meter, 5.0,
    "Landmark volume in z direction, centered around offset");
DEFINE_double(tg_num_of_rounds, 1.0, "Number of rounds");
DEFINE_double(tg_sampling_time_second, 0.1, "Sampling time");
DEFINE_double(
    tg_start_offset_x_meter, 0.0, "Offset from the origin in x direction");
DEFINE_double(
    tg_start_offset_y_meter, 0.0, "Offset from the origin in y direction");
DEFINE_double(tg_start_offset_yaw_radians, 0.0, "Yaw start offset");
DEFINE_double(
    tg_start_offset_z_meter, 0.0,
    "Offset from the origin in z direction. This is the constant height.");
DEFINE_double(
    tg_vertical_to_radial_variance_factor, 2.0,
    "Ratio between radial and vertical standard deviation of the "
    "keypoint positions.");
DEFINE_int32(tg_imu_noise_bias_seed, 10, "IMU noise bias seed");
DEFINE_int32(tg_landmark_seed, 5, "Landmark seed");
DEFINE_int32(
    tg_mode, 1,
    "Trajectory mode: [1] circle, [2] ellipse, [3] rotation, [4] translation, "
    "[5] from file");
DEFINE_int32(tg_num_of_path_constraints, 8, "Number of path constraints");
DEFINE_int32(tg_sub_sampling_factor, 5, "Sub-sampling factor");
DEFINE_int32(tg_num_of_landmarks, 1000, "Number of landmarks");
DEFINE_string(
    tg_filename_waypoints, "waypoints_translation_only.txt",
    "List with waypoints: x y z yaw");
DEFINE_string(
    tg_visualization_frame_id, "/map",
    "Visualization frame id of the simulation");
DEFINE_string(
    tg_visualization_topic, "path", "Visualization topic of the simulation");

void insertMarkers(
    const visualization_msgs::MarkerArray& to_insert,
    visualization_msgs::MarkerArray* m) {
  CHECK_NOTNULL(m);
  m->markers.insert(
      m->markers.end(), to_insert.markers.begin(), to_insert.markers.end());
}

void setUp(test_trajectory_gen::PathAndLandmarkSettings* settings) {
  CHECK_NOTNULL(settings);
  // Retrieve Zurich's gravity.
  common::GravityProvider gravity_provider(
      common::locations::kAltitudeZurichMeters,
      common::locations::kLatitudeZurichDegrees);
  // Accelerometer noise bias standard deviation.
  settings->imu_sigmas.acc_bias_random_walk_noise_density =
      FLAGS_tg_acc_bias_sigma_meter_by_sqrt_second5;
  // Accelerometer noise standard deviation.
  settings->imu_sigmas.acc_noise_density =
      FLAGS_tg_acc_sigma_meter_by_sqrt_second2;
  // Circle radius.
  settings->circle_radius_meter = FLAGS_tg_circle_radius_meter;
  // Distance to keypoints.
  settings->distance_to_keypoints_meter = FLAGS_tg_distance_to_keypoints_meter;
  // Gravity magnitude.
  settings->gravity_meter_by_second2 = gravity_provider.getGravityMagnitude();
  // Gyroscope bias noise standard deviation.
  settings->imu_sigmas.gyro_bias_random_walk_noise_density =
      FLAGS_tg_gyro_bias_sigma_rad_by_sqrt_second3;
  // Gyroscope noise standard deviation.
  settings->imu_sigmas.gyro_noise_density =
      FLAGS_tg_gyro_sigma_rad_by_sqrt_second;
  // Kappa defining the ellipse shape according to
  // x = (1.0 / kappa) * cos(t).
  settings->kappa = FLAGS_tg_kappa;
  // Lambda defining the ellipse shape according to
  // y = (1.0 / lambda) * sin(t).
  settings->lambda = FLAGS_tg_lambda;
  // Landmark volume offset in x direction.
  settings->landmark_offset_x_meter = FLAGS_tg_landmark_offset_x_meter;
  // Landmark volume offset in y direction.
  settings->landmark_offset_y_meter = FLAGS_tg_landmark_offset_y_meter;
  // Landmark volume offset in z direction.
  settings->landmark_offset_z_meter = FLAGS_tg_landmark_offset_z_meter;
  // Landmark variance.
  settings->landmark_variance_meter = FLAGS_tg_landmark_variance_meter;
  // Landmark volume in x direction, centered around offset.
  settings->landmark_volume_x_meter = FLAGS_tg_landmark_volume_x_meter;
  // Landmark volume in y direction, centered around offset.
  settings->landmark_volume_y_meter = FLAGS_tg_landmark_volume_y_meter;
  // Landmark volume in z direction, centered around offset.
  settings->landmark_volume_z_meter = FLAGS_tg_landmark_volume_z_meter;
  // Number of rounds. Currently only applies for elliptical mode.
  settings->num_of_rounds = FLAGS_tg_num_of_rounds;
  // Sampling time in seconds.
  settings->sampling_time_second = FLAGS_tg_sampling_time_second;
  // Offset from the origin in x direction.
  settings->start_offset_x_meter = FLAGS_tg_start_offset_x_meter;
  // Offset from the origin in y direction.
  settings->start_offset_y_meter = FLAGS_tg_start_offset_y_meter;
  // Yaw start offset.
  settings->start_offset_yaw_radians = FLAGS_tg_start_offset_yaw_radians;
  // Offset from the origin in z direction. This is the constant height.
  settings->start_offset_z_meter = FLAGS_tg_start_offset_z_meter;
  // Ratio between radial and vertical standard deviation of the
  // keypoint positions.
  settings->vertical_to_radial_variance_factor =
      FLAGS_tg_vertical_to_radial_variance_factor;
  // IMU noise bias seed.
  settings->imu_noise_bias_seed =
      static_cast<size_t>(FLAGS_tg_imu_noise_bias_seed);
  // Landmark seed.
  settings->landmark_seed = static_cast<size_t>(FLAGS_tg_landmark_seed);
  // Trajectory mode.
  settings->mode = static_cast<test_trajectory_gen::Path>(FLAGS_tg_mode);
  // Number of path constraints.
  settings->num_of_path_constraints =
      static_cast<size_t>(FLAGS_tg_num_of_path_constraints);
  // Number of landmarks.
  settings->num_of_landmarks = static_cast<size_t>(FLAGS_tg_num_of_landmarks);
  // List with waypoints: x y z yaw.
  settings->filename_waypoints = FLAGS_tg_filename_waypoints;
}

int main(int argc, char** argv) {
  // Initialize google logging and flags.
  google::InitGoogleLogging(argv[0]);
  google::ParseCommandLineFlags(&argc, &argv, true);

  // Initialize ros node handle and visualization publisher.
  ros::init(argc, argv, "path_generator_demo");
  ros::NodeHandle nh;
  ros::Publisher pub = nh.advertise<visualization_msgs::MarkerArray>(
      FLAGS_tg_visualization_topic, 1, true);

  // Define settings based on gflags.
  test_trajectory_gen::PathAndLandmarkSettings settings;
  setUp(&settings);

  // **************************************************************************
  //  Generating path and incorporating sensor biases.
  // **************************************************************************
  test_trajectory_gen::GenericPathGenerator path_generator(settings);
  path_generator.generatePath();
  path_generator.generateLandmarks();

  const mav_planning_utils::Motion4D<5, 2>::Vector& data =
      path_generator.getPathData();
  const Eigen::Matrix3Xd& landmarks = path_generator.getLandmarks();

  ROS_INFO("Generated %lu points", data.size());

  // **************************************************************************
  //  Visualization of the generated path and landmarks.
  // **************************************************************************
  if (FLAGS_tg_visualization) {
    visualization_msgs::MarkerArray markers, markers_tmp;
    std_msgs::Header header;
    header.frame_id = FLAGS_tg_visualization_frame_id;
    header.stamp = ros::Time::now();
    header.seq = 0;

    mav_planning_utils::MavState s;
    for (size_t i = 0; i < data.size(); i += FLAGS_tg_sub_sampling_factor) {
      path_generator.motionVectorToMavState(data[i], &s);
      mav_viz::drawAxesArrows(markers_tmp, s.p, s.q, 0.3);
      insertMarkers(markers_tmp, &markers);

      visualization_msgs::Marker marker;
      mav_viz::drawArrow(
          marker, s.p, s.p + s.a, mav_viz::createColorRGBA(1, 1, 0, 1));
      markers.markers.push_back(marker);

      mav_viz::drawArrow(
          marker, s.p, s.p + s.v, mav_viz::createColorRGBA(0, 1, 1, 1));
      markers.markers.push_back(marker);
    }

    for (int i = 0; i < landmarks.cols(); ++i) {
      visualization_msgs::Marker marker;
      marker.type = visualization_msgs::Marker::POINTS;
      marker.action = visualization_msgs::Marker::ADD;
      marker.color = mav_viz::createColorRGBA(0.8, 0.5, 0.2, 1);

      geometry_msgs::Point point;
      point.x = landmarks(0, i);
      point.y = landmarks(1, i);
      point.z = landmarks(2, i);
      marker.points.push_back(point);

      marker.scale.x = 0.1;
      marker.scale.y = 0.1;
      marker.scale.z = 0.1;

      markers.markers.push_back(marker);
    }

    int cnt = 0;
    for (visualization_msgs::MarkerArray::_markers_type::iterator it =
             markers.markers.begin();
         it != markers.markers.end(); ++it) {
      it->action = visualization_msgs::Marker::ADD;
      it->header = header;
      it->id = cnt;
      it->ns = FLAGS_tg_visualization_topic;
      ++cnt;
    }
    pub.publish(markers);
  }

  while (ros::ok()) {
    usleep(1e5);
  }
}

ext: cc

max_stars_repo_name: AdronTech/maplab

max_issues_repo_name: AdronTech/maplab

max_forks_repo_name: AdronTech/maplab


text:
/******************************************************************
 *
 * Round for C++
 *
 * Copyright (C) Satoshi Konno 2015
 *
 * This is licensed under BSD-style license, see file COPYING.
 *
 ******************************************************************/

#include <boost/test/unit_test.hpp>

#include <stdio.h>

#include <round/common/StringTokenizer.h>

using namespace Round;

BOOST_AUTO_TEST_SUITE(common)

BOOST_AUTO_TEST_CASE(StringUtilTokenizerTest) {
  StringTokenizer *strToken;
  const char *token[] = { "abcde", "test", "skonno" };
  char tokenStr[128];
  int tokenCnt;

  sprintf(tokenStr, "%s", token[0]);
  strToken = new StringTokenizer(tokenStr, ",");
  tokenCnt = 0;
  while( strToken->hasMoreTokens() == true) {
    const char *tstr = strToken->nextToken();
    BOOST_CHECK(strcmp(tstr, token[tokenCnt]) == 0);
    tokenCnt++;
  }
  BOOST_CHECK(tokenCnt == 1);
  delete strToken;

  sprintf(tokenStr, "%s,%s,%s", token[0], token[1], token[2]);
  strToken = new StringTokenizer(tokenStr, ",");
  tokenCnt = 0;
  while( strToken->hasMoreTokens() == true) {
    const char *tstr = strToken->nextToken();
    BOOST_CHECK(strcmp(tstr, token[tokenCnt]) == 0);
    tokenCnt++;
  }
  BOOST_CHECK(tokenCnt == 3);
  delete strToken;

  sprintf(tokenStr, "%s,%s,%s,", token[0], token[1], token[2]);
  strToken = new StringTokenizer(tokenStr, ",");
  tokenCnt = 0;
  while( strToken->hasMoreTokens() == true) {
    const char *tstr = strToken->nextToken();
    BOOST_CHECK(strcmp(tstr, token[tokenCnt]) == 0);
    tokenCnt++;
  }
  BOOST_CHECK(tokenCnt == 3);
  delete strToken;

  sprintf(tokenStr, ",%s,%s,%s,", token[0], token[1], token[2]);
  strToken = new StringTokenizer(tokenStr, ",");
  tokenCnt = 0;
  while( strToken->hasMoreTokens() == true) {
    const char *tstr = strToken->nextToken();
    BOOST_CHECK(strcmp(tstr, token[tokenCnt]) == 0);
    tokenCnt++;
  }
  BOOST_CHECK(tokenCnt == 3);
  delete strToken;

  strToken = new StringTokenizer("*", ",");
  tokenCnt = 0;
  while( strToken->hasMoreTokens() == true) {
    const char *tstr = strToken->nextToken();
    BOOST_CHECK(strcmp(tstr, "*") == 0);
    tokenCnt++;
  }
  BOOST_CHECK(tokenCnt == 1);
  delete strToken;

  sprintf(tokenStr, "%s", token[0]);
  strToken = new StringTokenizer(tokenStr, ", \n\t");
  tokenCnt = 0;
  while( strToken->hasMoreTokens() == true) {
    const char *tstr = strToken->nextToken();
    BOOST_CHECK(strcmp(tstr, token[tokenCnt]) == 0);
    tokenCnt++;
  }
  BOOST_CHECK(tokenCnt == 1);
  delete strToken;

  sprintf(tokenStr, "%s,,%s,,%s", token[0], token[1], token[2]);
  strToken = new StringTokenizer(tokenStr, ", \n\t");
  tokenCnt = 0;
  while( strToken->hasMoreTokens() == true) {
    const char *tstr = strToken->nextToken();
    BOOST_CHECK(strcmp(tstr, token[tokenCnt]) == 0);
    tokenCnt++;
  }
  BOOST_CHECK(tokenCnt == 3);
  delete strToken;

  sprintf(tokenStr, "  %s,  %s,  %s,  ", token[0], token[1], token[2]);
  strToken = new StringTokenizer(tokenStr, ", \n\t");
  tokenCnt = 0;
  while( strToken->hasMoreTokens() == true) {
    const char *tstr = strToken->nextToken();
    BOOST_CHECK(strcmp(tstr, token[tokenCnt]) == 0);
    tokenCnt++;
  }
  BOOST_CHECK(tokenCnt == 3);
  delete strToken;

  strToken = new StringTokenizer("*", ", \n\t");
  tokenCnt = 0;
  while( strToken->hasMoreTokens() == true) {
    const char *tstr = strToken->nextToken();
    BOOST_CHECK(strcmp(tstr, "*") == 0);
    tokenCnt++;
  }
  BOOST_CHECK(tokenCnt == 1);
  delete strToken;
}

BOOST_AUTO_TEST_SUITE_END()

ext: cpp

max_stars_repo_name: cybergarage/round-cc

max_issues_repo_name: cybergarage/round-cc

max_forks_repo_name: cybergarage/round-cc


text:
// (C) Copyright 2013 Louis Dionne
//
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0 (See accompanying file
// LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)

#include "cycle_test.hpp"
#include <boost/graph/hawick_circuits.hpp>
#include <iostream>

struct call_hawick_circuits {
    template <typename Graph, typename Visitor>
    void operator()(Graph const& g, Visitor const& v) const {
        boost::hawick_circuits(g, v);
    }
};

struct call_hawick_unique_circuits {
    template <typename Graph, typename Visitor>
    void operator()(Graph const& g, Visitor const& v) const {
        boost::hawick_unique_circuits(g, v);
    }
};

int main() {
    std::cout << "---------hawick_circuits---------\n";
    cycle_test(call_hawick_circuits());

    std::cout << "\n\n---------hawick_unique_circuits---------\n";
    cycle_test(call_hawick_unique_circuits());
}


text: #include <boost/geometry/iterators/segment_iterator.hpp>

ext: hpp

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
/* LICENSE:
Copyright (c) Members of the EGEE Collaboration. 2010.
See http://www.eu-egee.org/partners/ for details on the copyright
holders.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions and
limitations under the License.

END LICENSE */

#include <string>
#include <iostream>
#include <fstream>
#include <sys/types.h>          // getpid(), getpwnam()
#include <unistd.h>             // getpid(), usleep
#include <pwd.h>                // getpwnam()
#include <cstdio>               // popen()
#include <cstdlib>              // atoi()
#include <csignal>
#include <getopt.h>
#include <cerrno>
#include <vector>

#include "common/src/configuration/ICEConfiguration.h"
#include "common/src/configuration/WMConfiguration.h"
#include "common/src/configuration/CommonConfiguration.h"

#include "utils/CreamJob.h"
#include "db/GetAllJobs.h"
#include "db/GetJobByGid.h"
#include "db/Transaction.h"
#include "utils/CreamProxyMethod.h"
#include "utils/IceConfManager.h"
#include "utils/IceUtils.h"

#include "glite/ce/cream-client-api-c/JobFilterWrapper.h"
#include "glite/ce/cream-client-api-c/ResultWrapper.h"
#include "glite/ce/cream-client-api-c/VOMSWrapper.h"

#include <boost/scoped_ptr.hpp>
#include <boost/program_options.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/lexical_cast.hpp>

#include <list>

/* workaround for gsoap 2.7.13 */
#include "glite/ce/cream-client-api-c/cream_client_soapH.h"
SOAP_NMAC struct Namespace namespaces[] = {};

using namespace std;
//using namespace glite::ce::cream_client_api;
using namespace glite::wms::ice;

//namespace iceUtil   = glite::wms::ice::util;
//namespace iceDb     = glite::wms::ice::db;
//namespace po        = boost::program_options;
//namespace fs        = boost::filesystem;
//namespace api_util  = glite::ce::cream_client_api::util;
//namespace cream_api = glite::ce::cream_client_api::soap_proxy;

bool get_job( const string& gid, util::CreamJob& );
void get_all_jobs( list< util::CreamJob >& jobs );

int main(int argc, char*argv[])
{

  for( int i=0; i<100000; ++i) {
    //string S = glite::wms::ice::util::IceUtils::to_string( 4723453.23F );
    string S = boost::lexical_cast<string>( 4723453.23424 );
  }
  return 0;
  char*   confile = "glite_wms.conf";
  bool    cancel_all = false;
  string  gridjobid;
  int     option_index = 0;
  bool    log_abort = false;
  string  abort_reason;
  char    c;
  bool    from_file = false;
  string  inputlist;

  while(1) {
    static struct option long_options[] = {
      {"conf", 1, 0, 'c'},
      {"all", 0, 0, 'a'},
      {"log-abort", 1, 0, 'l'},
      {"from-file", 1, 0, 'f'},
      {0, 0, 0, 0}
    };
    c = getopt_long(argc, argv, "c:al:f:", long_options, &option_index);
    if ( c == -1 )
      break;

    switch(c) {
    case 'c':
      confile = optarg;
      break;
    case 'a':
      cancel_all = true;
      break;
    case 'l':
      log_abort = true;
      abort_reason = optarg;
      break;
    case 'f':
      from_file = true;
      inputlist = optarg;
      break;
    default:
      cerr << "Type " << argv[0] << " -h for help" << endl;
      exit(1);
    }
  }

  if( ( argv[optind] && from_file ) ||
      ( argv[optind] && cancel_all) ||
      ( cancel_all   && from_file ) )
    {
      cerr << "Only one of --all, --from-file <pathfile>, <gridjobid> "
	   << "must be specified in the command line" << endl;
      return 1;
    }

  if (!argv[optind] && !from_file && !cancel_all )
    {
      cerr << "Must specify one of the options --all, --from-file <pathfile>, <gridjobid>" << endl;
      return 1;
    }

  if( argv[optind] )
    gridjobid = string(argv[optind]);

  util::IceConfManager::init( confile );
  try{
    util::IceConfManager::instance();
  }
  catch(util::ConfigurationManagerException& ex) {
    cerr << "glite-wms-ice-rm::main - ERROR: " << ex.what() << endl;
    exit(1);
  }

  std::list< util::CreamJob > jobList;
  //iceUtil::iceLBLogger *lb_logger( iceUtil::iceLBLogger::instance() );

  /**
     If specified by the user
     read gridjobids to cancel from file
  */
  if( from_file ) {

    FILE* in = fopen( inputlist.c_str(), "r" );
    if(!in) {
      cerr << "Error opening [" << inputlist << "]: "
	   << strerror( errno ) << endl;
      return 1;
    }
    fclose( in );
    ifstream is(inputlist.c_str(), ios_base::in );
    string linestring;

    while( is >> linestring ) {

      util::CreamJob aJob;
      if( get_job( linestring, aJob ) )
        jobList.push_back( aJob );
      else
        cerr << "GriJobID ["<< linestring
	     << "] is not found in the ICE database. Skipping cancel for it..."
	     << endl;
    }
  }

  if( cancel_all ) {
    get_all_jobs( jobList );
  }

  if( !gridjobid.empty() ) {
    util::CreamJob aJob;
    if( get_job( gridjobid, aJob ) )
      jobList.push_back( aJob );
    else {
      cerr << "GriJobid "<< gridjobid << " is not found in the ICE database." << endl;
      return 1;
    }
  }

  std::list< util::CreamJob >::iterator jit;
  jit = jobList.begin( );
  while( jit != jobList.end( ) ) {

    vector<glite::ce::cream_client_api::soap_proxy::JobIdWrapper> toCancel;

    toCancel.push_back( glite::ce::cream_client_api::soap_proxy::JobIdWrapper(jit->cream_jobid(),
									      jit->cream_address(),
									      std::vector<glite::ce::cream_client_api::soap_proxy::JobPropertyWrapper>())
			);

    glite::ce::cream_client_api::soap_proxy::JobFilterWrapper req( toCancel, vector<string>(), -1, -1, "", "");
    glite::ce::cream_client_api::soap_proxy::ResultWrapper res;

    cout << "Sending JobCancel to CREAM for job ["
	 << jit->grid_jobid() << "] -> [" << jit->complete_cream_jobid() << "]" << endl;

    glite::ce::cream_client_api::soap_proxy::VOMSWrapper V( jit->user_proxyfile(),  !::getenv("GLITE_WMS_ICE_DISABLE_ACVER") );

    if( !V.IsValid( ) ) {
      cerr <<"*** For job [" << jit->grid_jobid() << "] -> ["
	   << jit->complete_cream_jobid() << "]"
	   << " the proxyfile ["
	   << jit->user_proxyfile()
	   << "] is not valid: "
	   << V.getErrorMessage()
	   << ". Skipping cancellation of this job. "
	   << endl;
    } else {
      try {
        util::CreamProxy_Cancel( jit->cream_address(), jit->user_proxyfile(), &req, &res ).execute( 3 );
	cout << "CANCELLED JOB ["<< jit->grid_jobid() << "]" << endl;
      } catch(exception& ex) {
        cerr << "*** Error cancelling job [" << jit->grid_jobid() << "]: " << ex.what() << endl;
      }
    }

    ++jit;
  }
  return 0;
}

//_______________________________________________________________________________
bool get_job( const string& gid, util::CreamJob& target )
{
  //list<string> fields_to_get;
  //list<vector<string> > result;
  //list<pair<string, string> > clause;

  //  fields_to_get.push_back("creamjobid");	//0
  // fields_to_get.push_back("creamurl");          //1
  //fields_to_get.push_back("userproxy");		//2
  //fields_to_get.push_back("gridjobid");         //3

  //clause.push_back( make_pair("gridjobid", gid ) );

  //iceDb::GetFields getter( fields_to_get, clause, result, "glite-wms-ice-rm::get_job" );
  db::GetJobByGid getter( gid, "glite-wms-ice-rm::get_job" );
  db::Transaction tnx( false, false );
  tnx.execute( &getter );

  if( !getter.found() ) return false;

  //  if(result.begin() == result.end()) return false;

  target = getter.get_job();//*result.begin( );

  return true;
}

//_______________________________________________________________________________
void get_all_jobs( list< util::CreamJob >& jobs )
{
//   list<string> fields_to_get;
//   list<vector<string> > result;

//   fields_to_get.push_back("creamjobid");	//0
//   fields_to_get.push_back("creamurl");          //1
//   fields_to_get.push_back("userproxy");		//2
//   fields_to_get.push_back("gridjobid");		//3

  //iceDb::GetFields getter( fields_to_get, list<pair<string,string> >(), result, "glite-wms-ice-rm::get_all_jobs" );
  db::GetAllJobs getter( &jobs, 0, 0, "glite-wms-ice-rm::get_all_jobs", false );
  db::Transaction tnx( false, false );
  tnx.execute( &getter );

  //  if(result.begin() == result.end()) return;

  //  list<vector<string> >::iterator jit = result.begin( );
  //  while( jit != result.end( ) )
  //  {
  //    jobs.push_back( *jit );
  //
  //    ++jit;
  //  }
}

max_stars_repo_name: italiangrid/wms

max_issues_repo_name: italiangrid/wms

max_forks_repo_name: italiangrid/wms


text:
#define BOOST_TEST_MODULE MasterMind
#include <boost/test/included/unit_test.hpp>

#include <vector>

int return_number_good_position_in_sequence(const std::vector<int> & code_sequence,
                                            const std::vector<int> & proposed_sequence)
{
    if (code_sequence == proposed_sequence)
        {
            return 1;
        }
    return 0;
}

BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)

BOOST_AUTO_TEST_CASE(code_sequence_1_proposed_sequence_1_return_1)
{
    std::vector<int> code_sequence(1,1);
    std::vector<int> proposed_sequence(1,1);
    BOOST_CHECK_EQUAL(1, return_number_good_position_in_sequence(code_sequence, proposed_sequence));
}

BOOST_AUTO_TEST_CASE(code_sequence_1_proposed_sequence_2_return_0)
{
    std::vector<int> code_sequence(1,1);
    std::vector<int> proposed_sequence(1,2);
    BOOST_CHECK_EQUAL(0, return_number_good_position_in_sequence(code_sequence, proposed_sequence));
}

BOOST_AUTO_TEST_SUITE_END()
#undef BOOST_TEST_MODULE


text:
#include <iostream>
#include <string>
#include <vector>

#include <boost/variant/apply_visitor.hpp>

#include "imageWriter.h"
#include "normalizer.h"
#include "parser.h"

int main(int argc, char * argv[])
{
    std::string storage;
    std::cin >> std::noskipws;
    std::copy(
        std::istream_iterator<char>(std::cin),
        std::istream_iterator<char>(),
        std::back_inserter(storage)
    );

    auto matrix = imageit::parse(storage.begin(), storage.end());

    if(!matrix)
        throw std::runtime_error("no matix");

    std::string filename("file.png");
    boost::apply_visitor([filename](auto const& m){
        return imageit::write(/*std::cout*/filename, m, imageit::make_normalizer(imageit::computeLimits(m)));
    }, *matrix);

    std::cout << filename << std::endl;

    return 0;
}

max_stars_repo_name: ethiago/image-it

max_issues_repo_name: ethiago/image-it

max_forks_repo_name: ethiago/image-it


text:
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
// Copyright (c) 2009 Boris Schaeling
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
// Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
// Copyright (c) 2016 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

/**
 * \file boost/process/config.hpp
 *
 * Defines various macros.
 */

#ifndef BOOST_PROCESS_DETAIL_CONFIG_HPP
#define BOOST_PROCESS_DETAIL_CONFIG_HPP

#include <boost/config.hpp>
#include <system_error>
#include <boost/system/api_config.hpp>

#include <boost/process/exception.hpp>

#if defined(BOOST_POSIX_API)
#include <errno.h>
#if defined(__GLIBC__)
#include <features.h>
#else
extern char **environ;
#endif
#elif defined(BOOST_WINDOWS_API)
#include <boost/winapi/get_last_error.hpp>
#else
#error "System API not supported by boost.process"
#endif

namespace boost { namespace process { namespace detail
{

#if !defined(BOOST_PROCESS_PIPE_SIZE)
#define BOOST_PROCESS_PIPE_SIZE 1024
#endif

#if defined(BOOST_POSIX_API)
namespace posix {namespace extensions {}}
namespace api = posix;

inline std::error_code get_last_error() noexcept
{
    return std::error_code(errno, std::system_category());
}

//copied from linux spec.
#if (_XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
#define BOOST_POSIX_HAS_VFORK 1
#endif

#elif defined(BOOST_WINDOWS_API)
namespace windows {namespace extensions {}}
namespace api = windows;

inline std::error_code get_last_error() noexcept
{
    return std::error_code(::boost::winapi::GetLastError(), std::system_category());
}
#endif

inline void throw_last_error(const std::string & msg)
{
    throw process_error(get_last_error(), msg);
}

inline void throw_last_error(const char * msg)
{
    throw process_error(get_last_error(), msg);
}

inline void throw_last_error()
{
    throw process_error(get_last_error());
}

inline void throw_error(const std::error_code& ec)
{
    if (ec)
        throw process_error(ec);
}

inline void throw_error(const std::error_code& ec, const char* msg)
{
    if (ec)
        throw process_error(ec, msg);
}

template<typename Char> constexpr Char null_char();
template<> constexpr char     null_char<char>     (){return   '\0';}
template<> constexpr wchar_t  null_char<wchar_t>  (){return  L'\0';}

template<typename Char> constexpr Char equal_sign();
template<> constexpr char     equal_sign<char>    () {return  '='; }
template<> constexpr wchar_t  equal_sign<wchar_t> () {return L'='; }

template<typename Char> constexpr Char quote_sign();
template<> constexpr char     quote_sign<char>    () {return  '"'; }
template<> constexpr wchar_t  quote_sign<wchar_t> () {return L'"'; }

template<typename Char> constexpr Char space_sign();
template<> constexpr char     space_sign<char>    () {return  ' '; }
template<> constexpr wchar_t  space_sign<wchar_t> () {return L' '; }

}}}
#endif


text:
#include <boost/test/unit_test.hpp>
#include <boost/algorithm/string/predicate.hpp>

#include <enumivo/testing/tester.hpp>
#include <enumivo/chain/abi_serializer.hpp>
#include <enumivo/chain/wasm_enumivo_constraints.hpp>
#include <enumivo/chain/resource_limits.hpp>
#include <enumivo/chain/exceptions.hpp>
#include <enumivo/chain/wast_to_wasm.hpp>
#include <enumivo/chain_plugin/chain_plugin.hpp>

#include <asserter/asserter.wast.hpp>
#include <asserter/asserter.abi.hpp>

#include <stltest/stltest.wast.hpp>
#include <stltest/stltest.abi.hpp>

#include <enu.system/enu.system.wast.hpp>
#include <enu.system/enu.system.abi.hpp>

#include <enu.token/enu.token.wast.hpp>
#include <enu.token/enu.token.abi.hpp>

#include <fc/io/fstream.hpp>

#include <Runtime/Runtime.h>

#include <fc/variant_object.hpp>
#include <fc/io/json.hpp>

#include <array>
#include <utility>

#ifdef NON_VALIDATING_TEST
#define TESTER tester
#else
#define TESTER validating_tester
#endif

using namespace enumivo;
using namespace enumivo::chain;
using namespace enumivo::testing;
using namespace fc;

BOOST_AUTO_TEST_SUITE(get_table_tests)

BOOST_FIXTURE_TEST_CASE( get_scope_test, TESTER ) try {
   produce_blocks(2);

   create_accounts({ N(enu.token), N(enu.ram), N(enu.ramfee), N(enu.stake),
      N(enu.blockpay), N(enu.votepay), N(enu.savings), N(enu.names) });

   std::vector<account_name> accs{N(inita), N(initb), N(initc), N(initd)};
   create_accounts(accs);
   produce_block();

   set_code( N(enu.token), enu_token_wast );
   set_abi( N(enu.token), enu_token_abi );
   produce_blocks(1);

   // create currency
   auto act = mutable_variant_object()
         ("issuer",       "enumivo")
         ("maximum_supply", enumivo::chain::asset::from_string("1000000000.0000 SYS"));
   push_action(N(enu.token), N(create), N(enu.token), act );

   // issue
   for (account_name a: accs) {
      push_action( N(enu.token), N(issue), "enumivo", mutable_variant_object()
                  ("to",      name(a) )
                  ("quantity", enumivo::chain::asset::from_string("999.0000 SYS") )
                  ("memo", "")
                  );
   }
   produce_blocks(1);

   // iterate over scope
   enumivo::chain_apis::read_only plugin(*(this->control), fc::microseconds(INT_MAX));
   enumivo::chain_apis::read_only::get_table_by_scope_params param{N(enu.token), N(accounts), "inita", "", 10};
   enumivo::chain_apis::read_only::get_table_by_scope_result result = plugin.read_only::get_table_by_scope(param);

   BOOST_REQUIRE_EQUAL(4, result.rows.size());
   BOOST_REQUIRE_EQUAL("", result.more);
   if (result.rows.size() >= 4) {
      BOOST_REQUIRE_EQUAL(name(N(enu.token)), result.rows[0].code);
      BOOST_REQUIRE_EQUAL(name(N(inita)), result.rows[0].scope);
      BOOST_REQUIRE_EQUAL(name(N(accounts)), result.rows[0].table);
      BOOST_REQUIRE_EQUAL(name(N(enumivo)), result.rows[0].payer);
      BOOST_REQUIRE_EQUAL(1, result.rows[0].count);

      BOOST_REQUIRE_EQUAL(name(N(initb)), result.rows[1].scope);
      BOOST_REQUIRE_EQUAL(name(N(initc)), result.rows[2].scope);
      BOOST_REQUIRE_EQUAL(name(N(initd)), result.rows[3].scope);
   }

   param.lower_bound = "initb";
   param.upper_bound = "initd";
   result = plugin.read_only::get_table_by_scope(param);
   BOOST_REQUIRE_EQUAL(2, result.rows.size());
   BOOST_REQUIRE_EQUAL("", result.more);
   if (result.rows.size() >= 2) {
      BOOST_REQUIRE_EQUAL(name(N(initb)), result.rows[0].scope);
      BOOST_REQUIRE_EQUAL(name(N(initc)), result.rows[1].scope);
   }

   param.limit = 1;
   result = plugin.read_only::get_table_by_scope(param);
   BOOST_REQUIRE_EQUAL(1, result.rows.size());
   BOOST_REQUIRE_EQUAL("initc", result.more);

   param.table = name(0);
   result = plugin.read_only::get_table_by_scope(param);
   BOOST_REQUIRE_EQUAL(1, result.rows.size());
   BOOST_REQUIRE_EQUAL("initc", result.more);

   param.table = N(invalid);
   result = plugin.read_only::get_table_by_scope(param);
   BOOST_REQUIRE_EQUAL(0, result.rows.size());
   BOOST_REQUIRE_EQUAL("", result.more);

} FC_LOG_AND_RETHROW() /// get_scope_test

BOOST_AUTO_TEST_SUITE_END()

max_stars_repo_name: dvlaicu/enumivo

max_issues_repo_name: dvlaicu/enumivo

max_forks_repo_name: dvlaicu/enumivo


text:
#include <boost/python.hpp>

// First the raw SRUP C++ Library files...
#include "pySRUP.h"
#include "SRUP_Generic.h"
#include "SRUP_Data.h"
#include "SRUP_Activate.h"
#include "SRUP_Join.h"
#include "SRUP_Observed_Base.h"
#include "SRUP_Observed_Join.h"
#include "SRUP_Observation_Req.h"
#include "SRUP_Syndicated_End_Request.h"
#include "SRUP_Syndicated_Terminate.h"
#include "SRUP_Syndicated_Data.h"
#include "SRUP_Syndicated_Action.h"
#include "SRUP_Syndicated_ID_REQ.h"
#include "SRUP_Syndicated_Device_Count.h"
#include "SRUP_Syndicated_Device_List.h"
#include "SRUP_Syndicated_C2_Req.h"
#include "SRUP_Syndication_Request.h"
#include "SRUP_Syndication_Init.h"

// Now the pySRUPLib files...
#include "pySRUP_Action.h"
#include "pySRUP_Response.h"
#include "pySRUP_Initiate.h"
#include "pySRUP_Data.h"
#include "pySRUP_Join.h"
#include "pySRUP_Observed.h"
#include "pySRUP_Syndicated_Action.h"
#include "pySRUP_Syndicated_Data.h"
#include "pySRUP_Syndicated_ID_REQ.h"
#include "pySRUP_Syndicated_Device_Count.h"
#include "pySRUP_Syndicated_Device_List.h"
#include "pySRUP_Syndicated_C2_Request.h"
#include "pySRUP_Syndication_Init.h"

BOOST_PYTHON_MODULE (pySRUPLib)
{
    // A "private" library function to get the library version...
    boost::python::def("__version", &get_srup_library_version);

    // Note that these can't be properties – as they're not really associated with any one of the types...

    // A set of "private" library functions to get the message type IDs for different types of message
    boost::python::def("__generic_message_type", &get_srup_library_generic_message_type);
    boost::python::def("__initiate_message_type", &get_srup_library_initiate_message_type);
    boost::python::def("__response_message_type", &get_srup_library_response_message_type);
    boost::python::def("__activate_message_type", &get_srup_library_activate_message_type);
    boost::python::def("__action_message_type", &get_srup_library_action_message_type);
    boost::python::def("__data_message_type", &get_srup_library_data_message_type);
    boost::python::def("__join_request_message_type", &get_srup_library_join_request_message_type);
    boost::python::def("__join_command_message_type", &get_srup_library_join_command_message_type);
    boost::python::def("__id_request_message_type", &get_srup_library_id_request_message_type);
    boost::python::def("__resign_request_message_type", &get_srup_library_resign_request_message_type);
    boost::python::def("__terminate_command_message_type", &get_srup_library_terminate_command_message_type);
    boost::python::def("__deregister_request_message_type", &get_srup_library_deregister_request_message_type);
    boost::python::def("__deregister_command_message_type", &get_srup_library_deregister_command_message_type);
    boost::python::def("__human_join_request_message_type", &get_srup_library_human_join_reqeust_message_type);
    boost::python::def("__human_join_response_message_type", &get_srup_library_human_join_response_message_type);
    boost::python::def("__observed_join_response_message_type", &get_srup_library_observed_join_response_message_type);
    boost::python::def("__observation_request_message_type", &get_srup_library_observation_request_message_type);
    boost::python::def("__observed_join_request_message_type", &get_srup_library_observed_join_request_message_type);

    boost::python::def("__syndicated_end_request_message_type", &get_srup_library_syndicated_end_request_message_type);
    boost::python::def("__syndicated_terminate_message_type", &get_srup_library_syndicated_terminate_message_type);
    boost::python::def("__syndicated_action_message_type", &get_srup_library_syndicated_action_message_type);
    boost::python::def("__syndicated_data_message_type", &get_srup_library_syndicated_data_message_type);
    boost::python::def("__syndicated_id_request_message_type", &get_srup_library_syndicated_ID_req_message_type);
    boost::python::def("__syndicated_device_count_message_type", &get_srup_library_syndicated_device_count_message_type);
    boost::python::def("__syndicated_device_list_message_type", &get_srup_library_syndicated_device_list_message_type);
    boost::python::def("__syndicated_c2_request_message_type", &get_srup_library_syndicated_c2_request_message_type);
    boost::python::def("__syndication_request_message_type", &get_srup_library_syndication_request_message_type);
    boost::python::def("__syndication_init_message_type", &get_srup_library_syndication_init_message_type);

    // Note that we will first create the base-class - which will set to non-copyable - and no_init
    // (meaning it is forced to be an abstract class...)
    boost::python::class_<SRUP_MSG, boost::noncopyable>("SRUP_Message_Base", boost::python::no_init)
            .add_property("version", &get_version)
            .add_property("msg_type", &get_msgtype)
            .add_property("token", &get_token, &set_token)
            .add_property("sequence_id", &get_sequenceID, &set_sequenceID)
            .add_property("sender_id", &get_senderID, &set_senderID)
          //.add_property("signature", &get_signature)
            .def("sign", &SRUP_MSG::SignF)
            .def("verify", &SRUP_MSG::VerifyF)
            .def("sign_keystring", &SRUP_MSG::Sign)
            .def("verify_keystring", &SRUP_MSG::Verify)
            .def("serialize", &serializer)
            .def("deserialize", &deserializer);

    // Next we'll add a base class for all of the observed join messages with an encrypted data item...
    // These are the Human Join Response, Observation Request, and Observed Join Request messages.
    // Note that we can't use a property here – since we have multiple parameters we need to pass to the function
    // (the data, a flag denoting if we're using a key file or a key string, & the key) – so we'll implement this
    // as discrete encrypt & decrypt methods.
    boost::python::class_<SRUP_MSG_OBS_BASE, boost::noncopyable, boost::python::bases<SRUP_MSG>>("SRUP_Observed_Base", boost::python::no_init)
            .def("encrypt", &set_encrypted_data)
            .def("decrypt", &get_decrypted_data)
            .def("encrypt_keystring", &set_encrypted_data_keystring)
            .def("decrypt_keystring", &get_decrypted_data_keystring);

    // We then create the action message as a subclass of the base messages... meaning we only need to add the bits
    // that are new to the subclass
    boost::python::class_<SRUP_MSG_ACTION, boost::python::bases<SRUP_MSG>>("SRUP_Action")
            .add_property("action_id", &get_actionID, &set_actionID);

    // Generic is essentially an implementable version of the base-class...
    boost::python::class_<SRUP_MSG_GENERIC, boost::python::bases<SRUP_MSG>> generic ("SRUP_Generic");

    // Activate doesn't have any additional properties over the base either...
    boost::python::class_<SRUP_MSG_ACTIVATE, boost::python::bases<SRUP_MSG>> activate ("SRUP_Activate");

    // Join Request doesn't have any additional properties over the base...
    boost::python::class_<SRUP_MSG_JOIN_REQ, boost::python::bases<SRUP_MSG>> join_request ("SRUP_Join_Request");

    // Human Join Request doesn't have any additional properties over the base...
    boost::python::class_<SRUP_MSG_HUMAN_JOIN_REQ, boost::python::bases<SRUP_MSG>> h_join_request ("SRUP_Human_Join_Request");

    // ID Request doesn't have any additional properties over the base...
    boost::python::class_<SRUP_MSG_ID_REQ, boost::python::bases<SRUP_MSG>> id_request ("SRUP_ID_Request");

    // Resign Request doesn't have any additional properties over the base...
    boost::python::class_<SRUP_MSG_RESIGN_REQ, boost::python::bases<SRUP_MSG>> resign_request ("SRUP_Resign_Request");

    // Terminate Command doesn't have any additional properties over the base...
    boost::python::class_<SRUP_MSG_TERMINATE_CMD, boost::python::bases<SRUP_MSG>> terminate_cmd ("SRUP_Terminate_Command");

    // Deregister Request doesn't have any additional properties over the base...
    boost::python::class_<SRUP_MSG_DEREGISTER_REQ, boost::python::bases<SRUP_MSG>> deregister_req ("SRUP_Deregister_Request");

    // Deregister Command doesn't have any additional properties over the base...
    boost::python::class_<SRUP_MSG_DEREGISTER_CMD, boost::python::bases<SRUP_MSG>> deregister_cmd ("SRUP_Deregister_Command");

    // Response has only one property to add – status...
    // But we'll also add all of the possible status values as read-only (getter only) properties...
    // Note: this includes responses for message types not yet implemented...
    boost::python::class_<SRUP_MSG_RESPONSE, boost::python::bases<SRUP_MSG>>("SRUP_Response")
            .add_property("status", &get_status, &set_status)
            .def("srup_response_status_update_success", &srup_response_status_update_success)
            .def("srup_response_status_update_fail_server", &srup_response_status_update_fail_server)
            .def("srup_response_status_update_fail_file", &srup_response_status_update_fail_file)
            .def("srup_response_status_update_fail_digest", &srup_response_status_update_fail_digest)
            .def("srup_response_status_update_fail_http_error", &srup_response_status_update_fail_http_error)
            .def("srup_response_status_activate_success", &srup_response_status_activate_success)
            .def("srup_response_status_activate_fail", &srup_response_status_activate_fail)
            .def("srup_response_status_action_success", &srup_response_status_action_success)
            .def("srup_response_status_action_unknown", &srup_response_status_action_unknown)
            .def("srup_response_status_action_fail", &srup_response_status_action_fail)
            .def("srup_response_status_data_type_unknown", &srup_response_status_data_type_unknown)
            .def("srup_response_status_join_success", &srup_response_status_join_success)
            .def("srup_response_status_join_refused", &srup_response_status_join_refused)
            .def("srup_response_status_join_fail", &srup_response_status_join_fail)
            .def("srup_response_status_observed_join_valid", &srup_response_status_observed_join_valid)
            .def("srup_response_status_observed_join_invalid", &srup_response_status_observed_join_invalid)
            .def("srup_response_status_observed_join_fail", &srup_response_status_observed_join_fail)
            .def("srup_response_status_resign_success", &srup_response_status_resign_success)
            .def("srup_response_status_resign_fail", &srup_response_status_resign_fail)
            .def("srup_response_status_deregister_success", &srup_response_status_deregister_success)
            .def("srup_response_status_deregister_fail", &srup_response_status_deregister_fail);

    // Initiate (note the slight naming change for Python) has the most simple properties to add...
    // (target, URL, digest)...
    boost::python::class_<SRUP_MSG_INIT, boost::python::bases<SRUP_MSG>>("SRUP_Initiate")
            .add_property("url", &get_url, &set_url)
            .add_property("digest", &get_digest, &set_digest);

    // Join Command adds a device ID...
    boost::python::class_<SRUP_MSG_JOIN_CMD, boost::python::bases<SRUP_MSG>>("SRUP_Join_Command")
            .add_property("device_id", &get_device_id_join, &set_device_id_join);

    // Observed Join Request adds an observer (device) ID...
    boost::python::class_<SRUP_MSG_OBSERVED_JOIN_REQ, boost::python::bases<SRUP_MSG>>("SRUP_Observed_Join_Request")
            .add_property("observer_id", &get_observer_id_join, &set_observer_id_join);

    // Data is the hard one – given the number of overloaded implementations of the data type...
    boost::python::class_<SRUP_MSG_DATA, boost::python::bases<SRUP_MSG>>("SRUP_Data")
            .add_property("data_id", &get_dataID, &set_dataID)
            .add_property("bytes_data", &get_byte_data, &set_byte_data)
            .add_property("uint8_data", &get_uint8_data, &set_uint8_data)
            .add_property("int8_data", &get_int8_data, &set_int8_data)
            .add_property("uint16_data", &get_uint16_data, &set_uint16_data)
            .add_property("int16_data", &get_int16_data, &set_int16_data)
            .add_property("uint32_data", &get_uint32_data, &set_uint32_data)
            .add_property("int32_data", &get_int32_data, &set_int32_data)
            .add_property("uint64_data", &get_uint64_data, &set_uint64_data)
            .add_property("int64_data", &get_int64_data, &set_int64_data)
            .add_property("float_data", &get_float_data, &set_float_data)
            .add_property("double_data", &get_double_data, &set_double_data);

    // Next we have Human Join Response ... which adds nothing to the observed base message class...
    boost::python::class_<SRUP_MSG_HUMAN_JOIN_RESP, boost::python::bases<SRUP_MSG_OBS_BASE>> h_join_resp ("SRUP_Human_Join_Response");

    // ... and Observation Request (the observed base class + the joining device ID)
    boost::python::class_<SRUP_MSG_OBSERVE_REQ, boost::python::bases<SRUP_MSG_OBS_BASE>>("SRUP_Observation_Request")
        .add_property("joining_device_id", &get_joining_device_id, &set_joining_device_id);

    // ... and lastly the Observed Join Response – which adds nothing to the observed base message...
    boost::python::class_<SRUP_MSG_OBS_JOIN_RESP, boost::python::bases<SRUP_MSG_OBS_BASE>> observed_join_resp ("SRUP_Observed_Join_Response");

    // Now we'll list the syndicated / syndication classes.
    // Starting with the easy two...
    // End and Terminate don't have any additional properties over the base...
    boost::python::class_<SRUP_MSG_SYNDICATED_TERMINATE, boost::python::bases<SRUP_MSG>> syndicated_terminate ("SRUP_Syndicated_Terminate");
    boost::python::class_<SRUP_MSG_SYNDICATED_END_REQ, boost::python::bases<SRUP_MSG>> syndicated_end ("SRUP_Syndicated_End_Request");

    // Next we'll do action, data, and ID.
    // The Syndicated ID request is the base-class plus one additional property (the target ID)...
    boost::python::class_<SRUP_MSG_SYNDICATED_ID_REQ, boost::python::bases<SRUP_MSG>>("SRUP_Syndicated_ID_Request")
            .add_property("target_id", &get_target_id_id_req, &set_target_id_id_req);
    // The Syndicated Action is the "regular" Action class plus the target ID...
    boost::python::class_<SRUP_MSG_SYNDICATED_ACTION, boost::python::bases<SRUP_MSG_ACTION>>("SRUP_Syndicated_Action")
            .add_property("target_id", &get_target_id_action, &set_target_id_action);
    // And the Syndicated Data is the previous data class - plus a source ID.
    boost::python::class_<SRUP_MSG_SYNDICATED_DATA, boost::python::bases<SRUP_MSG_DATA>>("SRUP_Syndicated_Data")
            .add_property("source_id", &get_source_id_data, &set_source_id_data);

    // Next we'll add the device count & list message classes…
    // Device_Count adds only the count property (uint32_t)
    boost::python::class_<SRUP_MSG_SYNDICATED_DEV_COUNT, boost::python::bases<SRUP_MSG>>("SRUP_Syndicated_Device_Count")
            .add_property("count", &get_count_dev_count, &set_count_dev_count);
    // Device_List adds two properties – device_sequence and device_ID…
    boost::python::class_<SRUP_MSG_SYNDICATED_DEV_LIST, boost::python::bases<SRUP_MSG>>("SRUP_Syndicated_Device_List")
            .add_property("device_sequence", &get_sequence_dev_list, &set_sequence_dev_list)
            .add_property("device_id", &get_device_id_dev_list, &set_device_id_dev_list);
    // C2_Request is more or less the same as the data message – but it uses a request_id instead of a data id...
    // Retrospectively – we could have made design changes earlier in the process to better reuse the existing
    // data message class here... But we didn't. :-( And we can't even directly re-use the property implementations.
    // This would be quite a lot of work to refactor; but it should probably go onto the list for a future release?
    boost::python::class_<SRUP_MSG_SYNDICATED_C2_REQ, boost::python::bases<SRUP_MSG>>("SRUP_Syndicated_C2_Request")
            .add_property("req_id", &get_reqID_c2_req, &set_reqID_c2_req)
            .add_property("bytes_data", &get_byte_c2_req, &set_byte_c2_req)
            .add_property("uint8_data", &get_uint8_c2_req, &set_uint8_c2_req)
            .add_property("int8_data", &get_int8_c2_req, &set_int8_c2_req)
            .add_property("uint16_data", &get_uint16_c2_req, &set_uint16_c2_req)
            .add_property("int16_data", &get_int16_c2_req, &set_int16_c2_req)
            .add_property("uint32_data", &get_uint32_c2_req, &set_uint32_c2_req)
            .add_property("int32_data", &get_int32_c2_req, &set_int32_c2_req)
            .add_property("uint64_data", &get_uint64_c2_req, &set_uint64_c2_req)
            .add_property("int64_data", &get_int64_c2_req, &set_int64_c2_req)
            .add_property("float_data", &get_float_c2_req, &set_float_c2_req)
            .add_property("double_data", &get_double_c2_req, &set_double_c2_req);

    // Next up for the syndication messages we have the Syndication Request...
    // For this we're using the observed base class – to provide the encrypted nonce value.
    // Syndication Request doesn't add anything new to the observed base class...
    boost::python::class_<SRUP_MSG_SYNDICATION_REQUEST, boost::python::bases<SRUP_MSG_OBS_BASE>> syndication_req ("SRUP_Syndication_Request");
    // And finally, we add the Syndication Init message – which like the syndication request, uses the observed base
    // but also adds a new property – the URL of the key service for the syndication.
    boost::python::class_<SRUP_MSG_SYNDICATION_INIT, boost::python::bases<SRUP_MSG_OBS_BASE>> ("SRUP_Syndication_Init")
            .add_property("url", &get_url_syndication_init, &set_url_syndication_init);
}

max_stars_repo_name: AJPoulter-Soton/srup

max_issues_repo_name: AJPoulter-Soton/srup

max_forks_repo_name: AJPoulter-Soton/srup


text:
#include <boost/test/unit_test.hpp>
#include <boost/program_options.hpp>

#include <steem/utilities/tempdir.hpp>
#include <steem/utilities/database_configuration.hpp>

#include <steem/chain/history_object.hpp>
#include <steem/chain/steem_objects.hpp>
#include <steem/chain/sps_objects.hpp>

#include <steem/plugins/account_history/account_history_plugin.hpp>
#include <steem/plugins/chain/chain_plugin.hpp>
#include <steem/plugins/rc/rc_plugin.hpp>
#include <steem/plugins/webserver/webserver_plugin.hpp>
#include <steem/plugins/witness/witness_plugin.hpp>

#include <steem/plugins/condenser_api/condenser_api_plugin.hpp>

#include <steem/chain/smt_objects/nai_pool_object.hpp>

#include <fc/crypto/digest.hpp>
#include <fc/smart_ref_impl.hpp>

#include <iostream>
#include <iomanip>
#include <sstream>

#include "database_fixture.hpp"

//using namespace steem::chain::test;

uint32_t STEEM_TESTING_GENESIS_TIMESTAMP = 1431700000;

using namespace steem::plugins::webserver;
using namespace steem::plugins::database_api;
using namespace steem::plugins::block_api;
using steem::plugins::condenser_api::condenser_api_plugin;

namespace steem { namespace chain {

using std::cout;
using std::cerr;

clean_database_fixture::clean_database_fixture( uint16_t shared_file_size_in_mb )
{
   try {
   int argc = boost::unit_test::framework::master_test_suite().argc;
   char** argv = boost::unit_test::framework::master_test_suite().argv;
   for( int i=1; i<argc; i++ )
   {
      const std::string arg = argv[i];
      if( arg == "--record-assert-trip" )
         fc::enable_record_assert_trip = true;
      if( arg == "--show-test-names" )
         std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl;
   }

   appbase::app().register_plugin< steem::plugins::account_history::account_history_plugin >();
   db_plugin = &appbase::app().register_plugin< steem::plugins::debug_node::debug_node_plugin >();
   appbase::app().register_plugin< steem::plugins::rc::rc_plugin >();
   appbase::app().register_plugin< steem::plugins::witness::witness_plugin >();

   db_plugin->logging = false;
   appbase::app().initialize<
      steem::plugins::account_history::account_history_plugin,
      steem::plugins::debug_node::debug_node_plugin,
      steem::plugins::rc::rc_plugin,
      steem::plugins::witness::witness_plugin
      >( argc, argv );

   steem::plugins::rc::rc_plugin_skip_flags rc_skip;
   rc_skip.skip_reject_not_enough_rc = 1;
   rc_skip.skip_deduct_rc = 0;
   rc_skip.skip_negative_rc_balance = 1;
   rc_skip.skip_reject_unknown_delta_vests = 0;
   appbase::app().get_plugin< steem::plugins::rc::rc_plugin >().set_rc_plugin_skip_flags( rc_skip );

   db = &appbase::app().get_plugin< steem::plugins::chain::chain_plugin >().db();
   BOOST_REQUIRE( db );

   init_account_pub_key = init_account_priv_key.get_public_key();

   open_database( shared_file_size_in_mb );

   generate_block();
   db->set_hardfork( STEEM_BLOCKCHAIN_VERSION.minor_v() );
   generate_block();

   vest( "initminer", 10000 );

   // Fill up the rest of the required miners
   for( int i = STEEM_NUM_INIT_MINERS; i < STEEM_MAX_WITNESSES; i++ )
   {
      account_create( STEEM_INIT_MINER_NAME + fc::to_string( i ), init_account_pub_key );
      fund( STEEM_INIT_MINER_NAME + fc::to_string( i ), STEEM_MIN_PRODUCER_REWARD.amount.value );
      witness_create( STEEM_INIT_MINER_NAME + fc::to_string( i ), init_account_priv_key, "foo.bar", init_account_pub_key, STEEM_MIN_PRODUCER_REWARD.amount );
   }

   validate_database();
   } catch ( const fc::exception& e )
   {
      edump( (e.to_detail_string()) );
      throw;
   }

   return;
}

clean_database_fixture::~clean_database_fixture()
{ try {
   // If we're unwinding due to an exception, don't do any more checks.
   // This way, boost test's last checkpoint tells us approximately where the error was.
   if( !std::uncaught_exception() )
   {
      BOOST_CHECK( db->get_node_properties().skip_flags == database::skip_nothing );
   }

   if( data_dir )
      db->wipe( data_dir->path(), data_dir->path(), true );
   return;
} FC_CAPTURE_AND_LOG( () )
   exit(1);
}

void clean_database_fixture::validate_database()
{
   database_fixture::validate_database();
   appbase::app().get_plugin< steem::plugins::rc::rc_plugin >().validate_database();
}

void clean_database_fixture::resize_shared_mem( uint64_t size )
{
   db->wipe( data_dir->path(), data_dir->path(), true );
   int argc = boost::unit_test::framework::master_test_suite().argc;
   char** argv = boost::unit_test::framework::master_test_suite().argv;
   for( int i=1; i<argc; i++ )
   {
      const std::string arg = argv[i];
      if( arg == "--record-assert-trip" )
         fc::enable_record_assert_trip = true;
      if( arg == "--show-test-names" )
         std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl;
   }
   init_account_pub_key = init_account_priv_key.get_public_key();

   {
      database::open_args args;
      args.data_dir = data_dir->path();
      args.shared_mem_dir = args.data_dir;
      args.initial_supply = INITIAL_TEST_SUPPLY;
      args.sbd_initial_supply = SBD_INITIAL_TEST_SUPPLY;
      args.shared_file_size = size;
      args.database_cfg = steem::utilities::default_database_configuration();
      db->open( args );
   }

   boost::program_options::variables_map options;

   generate_block();
   db->set_hardfork( STEEM_BLOCKCHAIN_VERSION.minor_v() );
   generate_block();

   vest( "initminer", 10000 );

   // Fill up the rest of the required miners
   for( int i = STEEM_NUM_INIT_MINERS; i < STEEM_MAX_WITNESSES; i++ )
   {
      account_create( STEEM_INIT_MINER_NAME + fc::to_string( i ), init_account_pub_key );
      fund( STEEM_INIT_MINER_NAME + fc::to_string( i ), STEEM_MIN_PRODUCER_REWARD.amount.value );
      witness_create( STEEM_INIT_MINER_NAME + fc::to_string( i ), init_account_priv_key, "foo.bar", init_account_pub_key, STEEM_MIN_PRODUCER_REWARD.amount );
   }

   validate_database();
}

live_database_fixture::live_database_fixture()
{
   try
   {
      int argc = boost::unit_test::framework::master_test_suite().argc;
      char** argv = boost::unit_test::framework::master_test_suite().argv;

      ilog( "Loading saved chain" );
      _chain_dir = fc::current_path() / "test_blockchain";
      FC_ASSERT( fc::exists( _chain_dir ), "Requires blockchain to test on in ./test_blockchain" );

      appbase::app().register_plugin< steem::plugins::account_history::account_history_plugin >();
      appbase::app().initialize<
         steem::plugins::account_history::account_history_plugin
         >( argc, argv );

      db = &appbase::app().get_plugin< steem::plugins::chain::chain_plugin >().db();
      BOOST_REQUIRE( db );

      {
         database::open_args args;
         args.data_dir = _chain_dir;
         args.shared_mem_dir = args.data_dir;
         args.database_cfg = steem::utilities::default_database_configuration();
         db->open( args );
      }

      validate_database();
      generate_block();

      ilog( "Done loading saved chain" );
   }
   FC_LOG_AND_RETHROW()
}

live_database_fixture::~live_database_fixture()
{
   try
   {
      // If we're unwinding due to an exception, don't do any more checks.
      // This way, boost test's last checkpoint tells us approximately where the error was.
      if( !std::uncaught_exception() )
      {
         BOOST_CHECK( db->get_node_properties().skip_flags == database::skip_nothing );
      }

      db->pop_block();
      db->close();
      return;
   }
   FC_CAPTURE_AND_LOG( () )
   exit(1);
}

fc::ecc::private_key database_fixture::generate_private_key(string seed)
{
   static const fc::ecc::private_key committee = fc::ecc::private_key::regenerate( fc::sha256::hash( string( "init_key" ) ) );
   if( seed == "init_key" )
      return committee;
   return fc::ecc::private_key::regenerate( fc::sha256::hash( seed ) );
}

#ifdef STEEM_ENABLE_SMT
asset_symbol_type database_fixture::get_new_smt_symbol( uint8_t token_decimal_places, chain::database* db )
{
   // The list of available nais is not dependent on SMT desired precision (token_decimal_places).
   static std::vector< asset_symbol_type >::size_type next_nai = 0;
   auto available_nais = db->get< nai_pool_object >().pool();
   FC_ASSERT( available_nais.size() > 0, "No available nai returned by get_nai_pool." );
   const asset_symbol_type& new_nai = available_nais[ next_nai++ % available_nais.size() ];
   // Note that token's precision is needed now, when creating actual symbol.
   return asset_symbol_type::from_nai( new_nai.to_nai(), token_decimal_places );
}
#endif

void database_fixture::open_database( uint16_t shared_file_size_in_mb )
{
   if( !data_dir )
   {
      data_dir = fc::temp_directory( steem::utilities::temp_directory_path() );
      db->_log_hardforks = false;

      idump( (data_dir->path()) );

      database::open_args args;
      args.data_dir = data_dir->path();
      args.shared_mem_dir = args.data_dir;
      args.initial_supply = INITIAL_TEST_SUPPLY;
      args.sbd_initial_supply = SBD_INITIAL_TEST_SUPPLY;
      args.shared_file_size = 1024 * 1024 * shared_file_size_in_mb; // 8MB(default) or more:  file for testing
      args.database_cfg = steem::utilities::default_database_configuration();
      args.sps_remove_threshold = 20;
      db->open(args);
   }
   else
   {
      idump( (data_dir->path()) );
   }
}

void database_fixture::generate_block(uint32_t skip, const fc::ecc::private_key& key, int miss_blocks)
{
   skip |= default_skip;
   db_plugin->debug_generate_blocks( steem::utilities::key_to_wif( key ), 1, skip, miss_blocks );
}

void database_fixture::generate_blocks( uint32_t block_count )
{
   auto produced = db_plugin->debug_generate_blocks( debug_key, block_count, default_skip, 0 );
   BOOST_REQUIRE( produced == block_count );
}

void database_fixture::generate_blocks(fc::time_point_sec timestamp, bool miss_intermediate_blocks)
{
   db_plugin->debug_generate_blocks_until( debug_key, timestamp, miss_intermediate_blocks, default_skip );
   BOOST_REQUIRE( ( db->head_block_time() - timestamp ).to_seconds() < STEEM_BLOCK_INTERVAL );
}

const account_object& database_fixture::account_create(
   const string& name,
   const string& creator,
   const private_key_type& creator_key,
   const share_type& fee,
   const public_key_type& key,
   const public_key_type& post_key,
   const string& json_metadata
   )
{
   try
   {
      auto actual_fee = std::min( fee, db->get_witness_schedule_object().median_props.account_creation_fee.amount );
      auto fee_remainder = fee - actual_fee;

      account_create_operation op;
      op.new_account_name = name;
      op.creator = creator;
      op.fee = asset( actual_fee, STEEM_SYMBOL );
      op.owner = authority( 1, key, 1 );
      op.active = authority( 1, key, 1 );
      op.posting = authority( 1, post_key, 1 );
      op.memo_key = key;
      op.json_metadata = json_metadata;

      trx.operations.push_back( op );

      trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
      sign( trx, creator_key );
      trx.validate();
      db->push_transaction( trx, 0 );
      trx.clear();

      if( fee_remainder > 0 )
      {
         vest( STEEM_INIT_MINER_NAME, name, asset( fee_remainder, STEEM_SYMBOL ) );
      }

      const account_object& acct = db->get_account( name );

      return acct;
   }
   FC_CAPTURE_AND_RETHROW( (name)(creator) )
}

const account_object& database_fixture::account_create(
   const string& name,
   const public_key_type& key,
   const public_key_type& post_key
)
{
   try
   {
      return account_create(
         name,
         STEEM_INIT_MINER_NAME,
         init_account_priv_key,
         std::max( db->get_witness_schedule_object().median_props.account_creation_fee.amount * STEEM_CREATE_ACCOUNT_WITH_STEEM_MODIFIER, share_type( 100 ) ),
         key,
         post_key,
         "" );
   }
   FC_CAPTURE_AND_RETHROW( (name) );
}

const account_object& database_fixture::account_create(
   const string& name,
   const public_key_type& key
)
{
   return account_create( name, key, key );
}

const witness_object& database_fixture::witness_create(
   const string& owner,
   const private_key_type& owner_key,
   const string& url,
   const public_key_type& signing_key,
   const share_type& fee )
{
   try
   {
      witness_update_operation op;
      op.owner = owner;
      op.url = url;
      op.block_signing_key = signing_key;
      op.fee = asset( fee, STEEM_SYMBOL );

      trx.operations.push_back( op );
      trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
      sign( trx, owner_key );
      trx.validate();
      db->push_transaction( trx, 0 );
      trx.clear();

      return db->get_witness( owner );
   }
   FC_CAPTURE_AND_RETHROW( (owner)(url) )
}

void database_fixture::fund(
   const string& account_name,
   const share_type& amount
   )
{
   try
   {
      transfer( STEEM_INIT_MINER_NAME, account_name, asset( amount, STEEM_SYMBOL ) );

   } FC_CAPTURE_AND_RETHROW( (account_name)(amount) )
}

void database_fixture::fund(
   const string& account_name,
   const asset& amount
   )
{
   try
   {
      db_plugin->debug_update( [=]( database& db)
      {
         if( amount.symbol.space() == asset_symbol_type::smt_nai_space )
         {
            db.adjust_balance(account_name, amount);
            db.adjust_supply(amount);
            // Note that SMT have no equivalent of SBD, hence no virtual supply, hence no need to update it.
            return;
         }

         db.modify( db.get_account( account_name ), [&]( account_object& a )
         {
            if( amount.symbol == STEEM_SYMBOL )
               a.balance += amount;
            else if( amount.symbol == SBD_SYMBOL )
            {
               a.sbd_balance += amount;
               a.sbd_seconds_last_update = db.head_block_time();
            }
         });

         db.modify( db.get_dynamic_global_properties(), [&]( dynamic_global_property_object& gpo )
         {
            if( amount.symbol == STEEM_SYMBOL )
               gpo.current_supply += amount;
            else if( amount.symbol == SBD_SYMBOL )
               gpo.current_sbd_supply += amount;
         });

         if( amount.symbol == SBD_SYMBOL )
         {
            const auto& median_feed = db.get_feed_history();
            if( median_feed.current_median_history.is_null() )
               db.modify( median_feed, [&]( feed_history_object& f )
               {
                  f.current_median_history = price( asset( 1, SBD_SYMBOL ), asset( 1, STEEM_SYMBOL ) );
               });
         }

         db.update_virtual_supply();
      }, default_skip );
   }
   FC_CAPTURE_AND_RETHROW( (account_name)(amount) )
}

void database_fixture::convert(
   const string& account_name,
   const asset& amount )
{
   try
   {
      if ( amount.symbol == STEEM_SYMBOL )
      {
         db->adjust_balance( account_name, -amount );
         db->adjust_balance( account_name, db->to_sbd( amount ) );
         db->adjust_supply( -amount );
         db->adjust_supply( db->to_sbd( amount ) );
      }
      else if ( amount.symbol == SBD_SYMBOL )
      {
         db->adjust_balance( account_name, -amount );
         db->adjust_balance( account_name, db->to_steem( amount ) );
         db->adjust_supply( -amount );
         db->adjust_supply( db->to_steem( amount ) );
      }
   } FC_CAPTURE_AND_RETHROW( (account_name)(amount) )
}

void database_fixture::transfer(
   const string& from,
   const string& to,
   const asset& amount )
{
   try
   {
      transfer_operation op;
      op.from = from;
      op.to = to;
      op.amount = amount;

      trx.operations.push_back( op );
      trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
      trx.validate();

      if( from == STEEM_INIT_MINER_NAME )
      {
         sign( trx, init_account_priv_key );
      }

      db->push_transaction( trx, ~0 );
      trx.clear();
   } FC_CAPTURE_AND_RETHROW( (from)(to)(amount) )
}

void database_fixture::vest( const string& from, const string& to, const asset& amount )
{
   try
   {
      FC_ASSERT( amount.symbol == STEEM_SYMBOL, "Can only vest TESTS" );

      transfer_to_vesting_operation op;
      op.from = from;
      op.to = to;
      op.amount = amount;

      trx.operations.push_back( op );
      trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
      trx.validate();

      // This sign() call fixes some tests, like withdraw_vesting_apply, that use this method
      //   with debug_plugin such that trx may be re-applied with less generous skip flags.
      if( from == STEEM_INIT_MINER_NAME )
      {
         sign( trx, init_account_priv_key );
      }

      db->push_transaction( trx, ~0 );
      trx.clear();
   } FC_CAPTURE_AND_RETHROW( (from)(to)(amount) )
}

void database_fixture::vest( const string& from, const share_type& amount )
{
   try
   {
      transfer_to_vesting_operation op;
      op.from = from;
      op.to = "";
      op.amount = asset( amount, STEEM_SYMBOL );

      trx.operations.push_back( op );
      trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
      trx.validate();

      if( from == STEEM_INIT_MINER_NAME )
      {
         sign( trx, init_account_priv_key );
      }

      db->push_transaction( trx, ~0 );
      trx.clear();
   } FC_CAPTURE_AND_RETHROW( (from)(amount) )
}

void database_fixture::proxy( const string& account, const string& proxy )
{
   try
   {
      account_witness_proxy_operation op;
      op.account = account;
      op.proxy = proxy;
      trx.operations.push_back( op );
      db->push_transaction( trx, ~0 );
      trx.clear();
   } FC_CAPTURE_AND_RETHROW( (account)(proxy) )
}

void database_fixture::set_price_feed( const price& new_price )
{
   for( size_t i = 1; i < 8; i++ )
   {
      witness_set_properties_operation op;
      op.owner = STEEM_INIT_MINER_NAME + fc::to_string( i );
      op.props[ "sbd_exchange_rate" ] = fc::raw::pack_to_vector( new_price );
      op.props[ "key" ] = fc::raw::pack_to_vector( init_account_pub_key );

      trx.operations.push_back( op );
      trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
      db->push_transaction( trx, ~0 );
      trx.clear();
   }

   generate_blocks( STEEM_BLOCKS_PER_HOUR );

   BOOST_REQUIRE(
#ifdef IS_TEST_NET
      !db->skip_price_feed_limit_check ||
#endif
      db->get(feed_history_id_type()).current_median_history == new_price
   );
}

void database_fixture::set_witness_props( const flat_map< string, vector< char > >& props )
{
   trx.clear();
   for( size_t i=0; i<STEEM_MAX_WITNESSES; i++ )
   {
      witness_set_properties_operation op;
      op.owner = STEEM_INIT_MINER_NAME + (i == 0 ? "" : fc::to_string( i ));
      op.props = props;
      if( props.find( "key" ) == props.end() )
         op.props["key"] = fc::raw::pack_to_vector( init_account_pub_key );

      trx.operations.push_back( op );
      trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
      db->push_transaction( trx, ~0 );
      trx.clear();
   }

   const witness_schedule_object* wso = &(db->get_witness_schedule_object());
   uint32_t old_next_shuffle = wso->next_shuffle_block_num;

   for( size_t i=0; i<2*STEEM_MAX_WITNESSES+1; i++ )
   {
      generate_block();
      wso = &(db->get_witness_schedule_object());
      if( wso->next_shuffle_block_num != old_next_shuffle )
         return;
   }
   FC_ASSERT( false, "Couldn't apply properties in ${n} blocks", ("n", 2*STEEM_MAX_WITNESSES+1) );
}

const asset& database_fixture::get_balance( const string& account_name )const
{
  return db->get_account( account_name ).balance;
}

void database_fixture::sign(signed_transaction& trx, const fc::ecc::private_key& key)
{
   trx.sign( key, db->get_chain_id(), default_sig_canon );
}

vector< operation > database_fixture::get_last_operations( uint32_t num_ops )
{
   vector< operation > ops;
   const auto& acc_hist_idx = db->get_index< account_history_index >().indices().get< by_id >();
   auto itr = acc_hist_idx.end();

   while( itr != acc_hist_idx.begin() && ops.size() < num_ops )
   {
      itr--;
      const buffer_type& _serialized_op = db->get(itr->op).serialized_op;
      std::vector<char> serialized_op;
      serialized_op.reserve( _serialized_op.size() );
      std::copy( _serialized_op.begin(), _serialized_op.end(), std::back_inserter( serialized_op ) );
      ops.push_back( fc::raw::unpack_from_vector< steem::chain::operation >( serialized_op ) );
   }

   return ops;
}

void database_fixture::validate_database()
{
   try
   {
      db->validate_invariants();
#ifdef STEEM_ENABLE_SMT
      db->validate_smt_invariants();
#endif
   }
   FC_LOG_AND_RETHROW();
}

#ifdef STEEM_ENABLE_SMT

template< typename T >
asset_symbol_type t_smt_database_fixture< T >::create_smt_with_nai( const string& account_name, const fc::ecc::private_key& key,
   uint32_t nai, uint8_t token_decimal_places )
{
   smt_create_operation op;
   signed_transaction tx;
   try
   {
      fund( account_name, 10 * 1000 * 1000 );
      this->generate_block();

      set_price_feed( price( ASSET( "1.000 TBD" ), ASSET( "1.000 TESTS" ) ) );
      convert( account_name, ASSET( "5000.000 TESTS" ) );

      op.symbol = asset_symbol_type::from_nai( nai, token_decimal_places );
      op.precision = op.symbol.decimals();
      op.smt_creation_fee = this->db->get_dynamic_global_properties().smt_creation_fee;
      op.control_account = account_name;

      tx.operations.push_back( op );
      tx.set_expiration( this->db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
      tx.sign( key, this->db->get_chain_id(), fc::ecc::bip_0062 );

      this->db->push_transaction( tx, 0 );

      this->generate_block();
   }
   FC_LOG_AND_RETHROW();

   return op.symbol;
}

template< typename T >
asset_symbol_type t_smt_database_fixture< T >::create_smt( const string& account_name, const fc::ecc::private_key& key,
   uint8_t token_decimal_places )
{
   asset_symbol_type symbol;
   try
   {
      auto nai_symbol = this->get_new_smt_symbol( token_decimal_places, this->db );
      symbol = create_smt_with_nai( account_name, key, nai_symbol.to_nai(), token_decimal_places );
   }
   FC_LOG_AND_RETHROW();

   return symbol;
}

void sub_set_create_op( smt_create_operation* op, account_name_type control_acount, chain::database& db )
{
   op->precision = op->symbol.decimals();
   op->smt_creation_fee = db.get_dynamic_global_properties().smt_creation_fee;
   op->control_account = control_acount;
}

void set_create_op( smt_create_operation* op, account_name_type control_account, uint8_t token_decimal_places, chain::database& db )
{
   op->symbol = database_fixture::get_new_smt_symbol( token_decimal_places, &db );
   sub_set_create_op( op, control_account, db );
}

void set_create_op( smt_create_operation* op, account_name_type control_account, uint32_t token_nai, uint8_t token_decimal_places, chain::database& db )
{
   op->symbol.from_nai(token_nai, token_decimal_places);
   sub_set_create_op( op, control_account, db );
}

template< typename T >
std::array<asset_symbol_type, 3> t_smt_database_fixture< T >::create_smt_3(const char* control_account_name, const fc::ecc::private_key& key)
{
   smt_create_operation op0;
   smt_create_operation op1;
   smt_create_operation op2;

   try
   {
      fund( control_account_name, 10 * 1000 * 1000 );
      this->generate_block();

      set_price_feed( price( ASSET( "1.000 TBD" ), ASSET( "1.000 TESTS" ) ) );
      convert( control_account_name, ASSET( "5000.000 TESTS" ) );

      set_create_op( &op0, control_account_name, 0, *this->db );
      set_create_op( &op1, control_account_name, 1, *this->db );
      set_create_op( &op2, control_account_name, 1, *this->db );

      signed_transaction tx;
      tx.operations.push_back( op0 );
      tx.operations.push_back( op1 );
      tx.operations.push_back( op2 );
      tx.set_expiration( this->db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
      tx.sign( key, this->db->get_chain_id(), fc::ecc::bip_0062 );
      this->db->push_transaction( tx, 0 );

      this->generate_block();

      std::array<asset_symbol_type, 3> retVal;
      retVal[0] = op0.symbol;
      retVal[1] = op1.symbol;
      retVal[2] = op2.symbol;
      std::sort(retVal.begin(), retVal.end(),
           [](const asset_symbol_type & a, const asset_symbol_type & b) -> bool
      {
         return a.to_nai() < b.to_nai();
      });
      return retVal;
   }
   FC_LOG_AND_RETHROW();
}

void push_invalid_operation(const operation& invalid_op, const fc::ecc::private_key& key, database* db)
{
   signed_transaction tx;
   tx.operations.push_back( invalid_op );
   tx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
   tx.sign( key, db->get_chain_id(), fc::ecc::bip_0062 );
   STEEM_REQUIRE_THROW( db->push_transaction( tx, database::skip_transaction_dupe_check ), fc::assert_exception );
}

template< typename T >
void t_smt_database_fixture< T >::create_invalid_smt( const char* control_account_name, const fc::ecc::private_key& key )
{
   // Fail due to precision too big.
   smt_create_operation op_precision;
   STEEM_REQUIRE_THROW( set_create_op( &op_precision, control_account_name, STEEM_ASSET_MAX_DECIMALS + 1, *this->db ), fc::assert_exception );
}

template< typename T >
void t_smt_database_fixture< T >::create_conflicting_smt( const asset_symbol_type existing_smt, const char* control_account_name,
   const fc::ecc::private_key& key )
{
   // Fail due to the same nai & precision.
   smt_create_operation op_same;
   set_create_op( &op_same, control_account_name, existing_smt.to_nai(), existing_smt.decimals(), *this->db );
   push_invalid_operation( op_same, key, this->db );
   // Fail due to the same nai (though different precision).
   smt_create_operation op_same_nai;
   set_create_op( &op_same_nai, control_account_name, existing_smt.to_nai(), existing_smt.decimals() == 0 ? 1 : 0, *this->db );
   push_invalid_operation (op_same_nai, key, this->db );
}

template< typename T >
smt_generation_unit t_smt_database_fixture< T >::get_generation_unit( const units& steem_unit, const units& token_unit )
{
   smt_generation_unit ret;

   ret.steem_unit = steem_unit;
   ret.token_unit = token_unit;

   return ret;
}

template< typename T >
smt_capped_generation_policy t_smt_database_fixture< T >::get_capped_generation_policy
(
   const smt_generation_unit& pre_soft_cap_unit,
   const smt_generation_unit& post_soft_cap_unit,
   uint16_t soft_cap_percent,
   uint32_t min_unit_ratio,
   uint32_t max_unit_ratio
)
{
   smt_capped_generation_policy ret;

   ret.pre_soft_cap_unit = pre_soft_cap_unit;
   ret.post_soft_cap_unit = post_soft_cap_unit;

   ret.soft_cap_percent = soft_cap_percent;

   ret.min_unit_ratio = min_unit_ratio;
   ret.max_unit_ratio = max_unit_ratio;

   return ret;
}

template asset_symbol_type t_smt_database_fixture< clean_database_fixture >::create_smt( const string& account_name, const fc::ecc::private_key& key, uint8_t token_decimal_places );

template asset_symbol_type t_smt_database_fixture< database_fixture >::create_smt( const string& account_name, const fc::ecc::private_key& key, uint8_t token_decimal_places );

template void t_smt_database_fixture< clean_database_fixture >::create_invalid_smt( const char* control_account_name, const fc::ecc::private_key& key );
template void t_smt_database_fixture< clean_database_fixture >::create_conflicting_smt( const asset_symbol_type existing_smt, const char* control_account_name, const fc::ecc::private_key& key );
template std::array<asset_symbol_type, 3> t_smt_database_fixture< clean_database_fixture >::create_smt_3( const char* control_account_name, const fc::ecc::private_key& key );

template smt_generation_unit t_smt_database_fixture< clean_database_fixture >::get_generation_unit( const units& steem_unit, const units& token_unit );
template smt_capped_generation_policy t_smt_database_fixture< clean_database_fixture >::get_capped_generation_policy
(
   const smt_generation_unit& pre_soft_cap_unit,
   const smt_generation_unit& post_soft_cap_unit,
   uint16_t soft_cap_percent,
   uint32_t min_unit_ratio,
   uint32_t max_unit_ratio
);

#endif

void sps_proposal_database_fixture::plugin_prepare()
{
   int argc = boost::unit_test::framework::master_test_suite().argc;
   char** argv = boost::unit_test::framework::master_test_suite().argv;
   for( int i=1; i<argc; i++ )
   {
      const std::string arg = argv[i];
      if( arg == "--record-assert-trip" )
         fc::enable_record_assert_trip = true;
      if( arg == "--show-test-names" )
         std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl;
   }

   db_plugin = &appbase::app().register_plugin< steem::plugins::debug_node::debug_node_plugin >();
   init_account_pub_key = init_account_priv_key.get_public_key();

   db_plugin->logging = false;
   appbase::app().initialize<
      steem::plugins::debug_node::debug_node_plugin
   >( argc, argv );

   db = &appbase::app().get_plugin< steem::plugins::chain::chain_plugin >().db();
   BOOST_REQUIRE( db );

   open_database();

   generate_block();
   db->set_hardfork( STEEM_NUM_HARDFORKS );
   generate_block();

   validate_database();
}

int64_t sps_proposal_database_fixture::create_proposal( std::string creator, std::string receiver,
                           time_point_sec start_date, time_point_sec end_date,
                           asset daily_pay, const fc::ecc::private_key& key )
{
   signed_transaction tx;
   create_proposal_operation op;

   op.creator = creator;
   op.receiver = receiver;

   op.start_date = start_date;
   op.end_date = end_date;

   op.daily_pay = daily_pay;

   static uint32_t cnt = 0;
   op.subject = std::to_string( cnt );

   const std::string permlink = "permlink" + std::to_string( cnt );
   post_comment(creator, permlink, "title", "body", "test", key);

   op.permlink = permlink;

   tx.operations.push_back( op );
   tx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
   sign( tx, key );
   db->push_transaction( tx, 0 );
   tx.signatures.clear();
   tx.operations.clear();

   const auto& proposal_idx = db-> template get_index< proposal_index >().indices(). template get< by_proposal_id >();
   auto itr = proposal_idx.end();
   BOOST_REQUIRE( proposal_idx.begin() != itr );
   --itr;
   BOOST_REQUIRE( creator == itr->creator );

   //An unique subject is generated by cnt
   ++cnt;

   return itr->proposal_id;
}

void sps_proposal_database_fixture::vote_proposal( std::string voter, const std::vector< int64_t >& id_proposals, bool approve, const fc::ecc::private_key& key )
{
   update_proposal_votes_operation op;

   op.voter = voter;
   op.proposal_ids.insert(id_proposals.cbegin(), id_proposals.cend());
   op.approve = approve;

   signed_transaction tx;
   tx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
   tx.operations.push_back( op );
   sign( tx, key );
   db->push_transaction( tx, 0 );
}

bool sps_proposal_database_fixture::exist_proposal( int64_t id )
{
   const auto& proposal_idx = db->get_index< proposal_index >().indices(). template get< by_proposal_id >();
   return proposal_idx.find( id ) != proposal_idx.end();
}

const proposal_object* sps_proposal_database_fixture::find_proposal( int64_t id )
{
   const auto& proposal_idx = db->get_index< proposal_index >().indices(). template get< by_proposal_id >();
   auto found = proposal_idx.find( id );

   if( found != proposal_idx.end() )
      return &(*found);
   else
      return nullptr;
}

void sps_proposal_database_fixture::remove_proposal(account_name_type _deleter, flat_set<int64_t> _proposal_id, const fc::ecc::private_key& _key)
{
   remove_proposal_operation rp;
   rp.proposal_owner = _deleter;
   rp.proposal_ids   = _proposal_id;

   signed_transaction trx;
   trx.operations.push_back( rp );
   trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
   sign( trx, _key );
   db->push_transaction( trx, 0 );
   trx.signatures.clear();
   trx.operations.clear();
}

bool sps_proposal_database_fixture::find_vote_for_proposal(const std::string& _user, int64_t _proposal_id)
{
      const auto& proposal_vote_idx = db->get_index< proposal_vote_index >().indices(). template get< by_voter_proposal >();
      auto found_vote = proposal_vote_idx.find( boost::make_tuple(_user, _proposal_id) );
      return found_vote != proposal_vote_idx.end() ;
}

uint64_t sps_proposal_database_fixture::get_nr_blocks_until_maintenance_block()
{
   auto block_time = db->head_block_time();

   auto next_maintenance_time = db->get_dynamic_global_properties().next_maintenance_time;
   auto ret = ( next_maintenance_time - block_time ).to_seconds() / STEEM_BLOCK_INTERVAL;

   FC_ASSERT( next_maintenance_time >= block_time );

   return ret;
}

void sps_proposal_database_fixture::post_comment( std::string _authro, std::string _permlink, std::string _title, std::string _body, std::string _parent_permlink, const fc::ecc::private_key& _key)
{
   generate_blocks( db->head_block_time() + STEEM_MIN_ROOT_COMMENT_INTERVAL + fc::seconds( STEEM_BLOCK_INTERVAL ), true );
   comment_operation comment;

   comment.author = _authro;
   comment.permlink = _permlink;
   comment.title = _title;
   comment.body = _body;
   comment.parent_permlink = _parent_permlink;

   signed_transaction trx;
   trx.operations.push_back( comment );
   trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
   sign( trx, _key );
   db->push_transaction( trx, 0 );
   trx.signatures.clear();
   trx.operations.clear();
}

void hf23_database_fixture::push_transaction( const operation& op, const fc::ecc::private_key& key )
{
   signed_transaction tx;
   tx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
   tx.operations.push_back( op );
   sign( tx, key );
   db->push_transaction( tx, 0 );
}

void hf23_database_fixture::vest( const string& from, const string& to, const asset& amount, const fc::ecc::private_key& key )
{
   FC_ASSERT( amount.symbol == STEEM_SYMBOL, "Can only vest TESTS" );

   transfer_to_vesting_operation op;
   op.from = from;
   op.to = to;
   op.amount = amount;

   push_transaction( op, key );
}

void hf23_database_fixture::delegate_vest( const string& delegator, const string& delegatee, const asset& amount, const fc::ecc::private_key& key )
{
   delegate_vesting_shares_operation op;
   op.vesting_shares = amount;
   op.delegator = delegator;
   op.delegatee = delegatee;

   push_transaction( op, key );
}

json_rpc_database_fixture::json_rpc_database_fixture()
{
   try {
   int argc = boost::unit_test::framework::master_test_suite().argc;
   char** argv = boost::unit_test::framework::master_test_suite().argv;
   for( int i=1; i<argc; i++ )
   {
      const std::string arg = argv[i];
      if( arg == "--record-assert-trip" )
         fc::enable_record_assert_trip = true;
      if( arg == "--show-test-names" )
         std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl;
   }

   appbase::app().register_plugin< steem::plugins::account_history::account_history_plugin >();
   db_plugin = &appbase::app().register_plugin< steem::plugins::debug_node::debug_node_plugin >();
   appbase::app().register_plugin< steem::plugins::witness::witness_plugin >();
   rpc_plugin = &appbase::app().register_plugin< steem::plugins::json_rpc::json_rpc_plugin >();
   appbase::app().register_plugin< steem::plugins::block_api::block_api_plugin >();
   appbase::app().register_plugin< steem::plugins::database_api::database_api_plugin >();
   appbase::app().register_plugin< steem::plugins::condenser_api::condenser_api_plugin >();

   db_plugin->logging = false;
   appbase::app().initialize<
      steem::plugins::account_history::account_history_plugin,
      steem::plugins::debug_node::debug_node_plugin,
      steem::plugins::json_rpc::json_rpc_plugin,
      steem::plugins::block_api::block_api_plugin,
      steem::plugins::database_api::database_api_plugin,
      steem::plugins::condenser_api::condenser_api_plugin
      >( argc, argv );

   appbase::app().get_plugin< steem::plugins::condenser_api::condenser_api_plugin >().plugin_startup();

   db = &appbase::app().get_plugin< steem::plugins::chain::chain_plugin >().db();
   BOOST_REQUIRE( db );

   init_account_pub_key = init_account_priv_key.get_public_key();

   open_database();

   generate_block();
   db->set_hardfork( STEEM_BLOCKCHAIN_VERSION.minor_v() );
   generate_block();

   vest( "initminer", 10000 );

   // Fill up the rest of the required miners
   for( int i = STEEM_NUM_INIT_MINERS; i < STEEM_MAX_WITNESSES; i++ )
   {
      account_create( STEEM_INIT_MINER_NAME + fc::to_string( i ), init_account_pub_key );
      fund( STEEM_INIT_MINER_NAME + fc::to_string( i ), STEEM_MIN_PRODUCER_REWARD.amount.value );
      witness_create( STEEM_INIT_MINER_NAME + fc::to_string( i ), init_account_priv_key, "foo.bar", init_account_pub_key, STEEM_MIN_PRODUCER_REWARD.amount );
   }

   validate_database();
   } catch ( const fc::exception& e )
   {
      edump( (e.to_detail_string()) );
      throw;
   }

   return;
}

json_rpc_database_fixture::~json_rpc_database_fixture()
{
   // If we're unwinding due to an exception, don't do any more checks.
   // This way, boost test's last checkpoint tells us approximately where the error was.
   if( !std::uncaught_exception() )
   {
      BOOST_CHECK( db->get_node_properties().skip_flags == database::skip_nothing );
   }

   if( data_dir )
      db->wipe( data_dir->path(), data_dir->path(), true );
   return;
}

fc::variant json_rpc_database_fixture::get_answer( std::string& request )
{
   return fc::json::from_string( rpc_plugin->call( request ) );
}

void check_id_equal( const fc::variant& id_a, const fc::variant& id_b )
{
   BOOST_REQUIRE( id_a.get_type() == id_b.get_type() );

   switch( id_a.get_type() )
   {
      case fc::variant::int64_type:
         BOOST_REQUIRE( id_a.as_int64() == id_b.as_int64() );
         break;
      case fc::variant::uint64_type:
         BOOST_REQUIRE( id_a.as_uint64() == id_b.as_uint64() );
         break;
      case fc::variant::string_type:
         BOOST_REQUIRE( id_a.as_string() == id_b.as_string() );
         break;
      case fc::variant::null_type:
         break;
      default:
         BOOST_REQUIRE( false );
   }
}

void json_rpc_database_fixture::review_answer( fc::variant& answer, int64_t code, bool is_warning, bool is_fail, fc::optional< fc::variant > id )
{
   fc::variant_object error;
   int64_t answer_code;

   if( is_fail )
   {
      if( id.valid() && code != JSON_RPC_INVALID_REQUEST )
      {
         BOOST_REQUIRE( answer.get_object().contains( "id" ) );
         check_id_equal( answer[ "id" ], *id );
      }

      BOOST_REQUIRE( answer.get_object().contains( "error" ) );
      BOOST_REQUIRE( answer["error"].is_object() );
      error = answer["error"].get_object();
      BOOST_REQUIRE( error.contains( "code" ) );
      BOOST_REQUIRE( error["code"].is_int64() );
      answer_code = error["code"].as_int64();
      BOOST_REQUIRE( answer_code == code );
      if( is_warning )
         BOOST_TEST_MESSAGE( error["message"].as_string() );
   }
   else
   {
      BOOST_REQUIRE( answer.get_object().contains( "result" ) );
      BOOST_REQUIRE( answer.get_object().contains( "id" ) );
      if( id.valid() )
         check_id_equal( answer[ "id" ], *id );
   }
}

void json_rpc_database_fixture::make_array_request( std::string& request, int64_t code, bool is_warning, bool is_fail )
{
   fc::variant answer = get_answer( request );
   BOOST_REQUIRE( answer.is_array() );

   fc::variants request_array = fc::json::from_string( request ).get_array();
   fc::variants array = answer.get_array();

   BOOST_REQUIRE( array.size() == request_array.size() );
   for( size_t i = 0; i < array.size(); ++i )
   {
      fc::optional< fc::variant > id;

      try
      {
         id = request_array[i][ "id" ];
      }
      catch( ... ) {}

      review_answer( array[i], code, is_warning, is_fail, id );
   }
}

fc::variant json_rpc_database_fixture::make_request( std::string& request, int64_t code, bool is_warning, bool is_fail )
{
   fc::variant answer = get_answer( request );
   BOOST_REQUIRE( answer.is_object() );
   fc::optional< fc::variant > id;

   try
   {
      id = fc::json::from_string( request ).get_object()[ "id" ];
   }
   catch( ... ) {}

   review_answer( answer, code, is_warning, is_fail, id );

   return answer;
}

void json_rpc_database_fixture::make_positive_request( std::string& request )
{
   make_request( request, 0/*code*/, false/*is_warning*/, false/*is_fail*/);
}

namespace test {

bool _push_block( database& db, const signed_block& b, uint32_t skip_flags /* = 0 */ )
{
   return db.push_block( b, skip_flags);
}

void _push_transaction( database& db, const signed_transaction& tx, uint32_t skip_flags /* = 0 */ )
{ try {
   db.push_transaction( tx, skip_flags );
} FC_CAPTURE_AND_RETHROW((tx)) }

} // steem::chain::test

} } // steem::chain

max_stars_repo_name: andelf/hive

max_issues_repo_name: andelf/hive

max_forks_repo_name: andelf/hive