Electroneum
main.cpp
Go to the documentation of this file.
1 // Copyrights(c) 2017-2021, The Electroneum Project
2 // Copyrights(c) 2014-2019, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31 
32 #include <boost/program_options.hpp>
33 
34 #include "include_base_utils.h"
35 #include "string_tools.h"
36 using namespace epee;
37 
38 #include "common/command_line.h"
39 #include "common/util.h"
40 #include "transactions_flow_test.h"
41 
42 namespace po = boost::program_options;
43 
44 namespace
45 {
46  const command_line::arg_descriptor<bool> arg_test_transactions_flow = {"test_transactions_flow", ""};
47 
48  const command_line::arg_descriptor<std::string> arg_working_folder = {"working-folder", "", "."};
49  const command_line::arg_descriptor<std::string> arg_source_wallet = {"source-wallet", "", "", true};
50  const command_line::arg_descriptor<std::string> arg_dest_wallet = {"dest-wallet", "", "", true};
51  const command_line::arg_descriptor<std::string> arg_daemon_addr_a = {"daemon-addr-a", "", "127.0.0.1:8080"};
52  const command_line::arg_descriptor<std::string> arg_daemon_addr_b = {"daemon-addr-b", "", "127.0.0.1:8082"};
53 
54  const command_line::arg_descriptor<uint64_t> arg_transfer_amount = {"transfer_amount", "", 60000000000000};
55  const command_line::arg_descriptor<size_t> arg_mix_in_factor = {"mix-in-factor", "", 10};
56  const command_line::arg_descriptor<size_t> arg_tx_count = {"tx-count", "", 100};
57  const command_line::arg_descriptor<size_t> arg_tx_per_second = {"tx-per-second", "", 20};
58  const command_line::arg_descriptor<size_t> arg_test_repeat_count = {"test_repeat_count", "", 1};
59 }
60 
61 int main(int argc, char* argv[])
62 {
63  TRY_ENTRY();
66 
67  //set up logging options
68  mlog_configure(mlog_get_default_log_path("functional_tests.log"), true);
70 
71  po::options_description desc_options("Allowed options");
73 
74  command_line::add_arg(desc_options, arg_test_transactions_flow);
75 
76  command_line::add_arg(desc_options, arg_working_folder);
77  command_line::add_arg(desc_options, arg_source_wallet);
78  command_line::add_arg(desc_options, arg_dest_wallet);
79  command_line::add_arg(desc_options, arg_daemon_addr_a);
80  command_line::add_arg(desc_options, arg_daemon_addr_b);
81 
82  command_line::add_arg(desc_options, arg_transfer_amount);
83  command_line::add_arg(desc_options, arg_mix_in_factor);
84  command_line::add_arg(desc_options, arg_tx_count);
85  command_line::add_arg(desc_options, arg_tx_per_second);
86  command_line::add_arg(desc_options, arg_test_repeat_count);
87 
88  po::variables_map vm;
89  bool r = command_line::handle_error_helper(desc_options, [&]()
90  {
91  po::store(po::parse_command_line(argc, argv, desc_options), vm);
92  po::notify(vm);
93  return true;
94  });
95  if (!r)
96  return 1;
97 
99  {
100  std::cout << desc_options << std::endl;
101  return 0;
102  }
103 
104  if (command_line::get_arg(vm, arg_test_transactions_flow))
105  {
106  std::string working_folder = command_line::get_arg(vm, arg_working_folder);
107  std::string path_source_wallet, path_target_wallet;
108  if(command_line::has_arg(vm, arg_source_wallet))
109  path_source_wallet = command_line::get_arg(vm, arg_source_wallet);
110  if(command_line::has_arg(vm, arg_dest_wallet))
111  path_target_wallet = command_line::get_arg(vm, arg_dest_wallet);
112 
113  std::string daemon_addr_a = command_line::get_arg(vm, arg_daemon_addr_a);
114  std::string daemon_addr_b = command_line::get_arg(vm, arg_daemon_addr_b);
115  uint64_t amount_to_transfer = command_line::get_arg(vm, arg_transfer_amount);
116  size_t mix_in_factor = command_line::get_arg(vm, arg_mix_in_factor);
117  size_t transactions_count = command_line::get_arg(vm, arg_tx_count);
118  size_t transactions_per_second = command_line::get_arg(vm, arg_tx_per_second);
119  size_t repeat_count = command_line::get_arg(vm, arg_test_repeat_count);
120 
121  for(size_t i = 0; i != repeat_count; i++)
122  if(!transactions_flow_test(working_folder, path_source_wallet, path_target_wallet, daemon_addr_a, daemon_addr_b, amount_to_transfer, mix_in_factor, transactions_count, transactions_per_second))
123  break;
124 
125  std::string s;
126  std::cin >> s;
127 
128  return 1;
129  }
130  else
131  {
132  std::cout << desc_options << std::endl;
133  return 1;
134  }
135 
136  CATCH_ENTRY_L0("main", 1);
137 
138  return 0;
139 }
int main(int argc, char *argv[])
Definition: main.cpp:63
bool set_module_name_and_folder(const std::string &path_to_process_)
Definition: string_tools.h:249
::std::string string
Definition: gtest-port.h:1097
std::string mlog_get_default_log_path(const char *default_filename)
Definition: mlog.cpp:72
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
Definition: mlog.cpp:148
const arg_descriptor< bool > arg_help
bool on_startup()
Definition: util.cpp:778
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
Definition: command_line.h:237
std::enable_if<!std::is_same< T, bool >::value, bool >::type has_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
Definition: command_line.h:258
#define TRY_ENTRY()
Definition: misc_log_ex.h:151
unsigned __int64 uint64_t
Definition: stdint.h:136
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
Definition: command_line.h:188
bool transactions_flow_test(std::string &working_folder, std::string path_source_wallet, std::string path_target_wallet, std::string &daemon_addr_a, std::string &daemon_addr_b, uint64_t amount_to_transfer, size_t mix_in_factor, size_t transactions_count, size_t transactions_per_second)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
boost::program_options::basic_parsed_options< charT > parse_command_line(int argc, const charT *const argv[], const boost::program_options::options_description &desc, bool allow_unregistered=false)
Definition: command_line.h:224
#define CATCH_ENTRY_L0(lacation, return_val)
Definition: misc_log_ex.h:165
void mlog_set_log_level(int level)
Definition: mlog.cpp:282