Debian Codegraph @

tests/functional_tests/main.cpp

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