Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
transfers.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 "gtest/gtest.h"
33
#include <sstream>
34
#include "wallet/wallet.h"
35
#include "
rpc/core_rpc_server.h
"
36
#include "
cryptonote_basic/account.h
"
37
#include "net/http_client_abstract_invoke.h"
38
using namespace
std
;
39
using namespace
epee::misc_utils
;
40
using namespace
cryptonote
;
41
42
string
daemon_address
=
"http://localhost:23400"
;
43
44
#define ACCS 5
45
46
TEST
(Transfers, Transfers)
47
{
48
log_space::get_set_log_detalisation_level(
true
, LOG_LEVEL_3);
49
log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
50
51
cout <<
"TESTING: transfers"
<< endl;
52
53
net_utils::http::http_simple_client
http_client;
54
wallet
miner
, accs[100], receiver;
55
miner
.generate();
56
ASSERT_TRUE
(
miner
.
init
());
57
ASSERT_TRUE
(
miner
.store(
"miner.b2wallet"
));
58
cout <<
"miner: "
<<
miner
.get_account().get_public_address_str(
false
) << endl;
59
60
for
(
int
i = 0; i <
ACCS
; i++) {
61
ostringstream s;
62
s <<
"acc"
<< setw(2) << setfill(
'0'
) << i <<
".b2wallet"
;
63
accs[i].generate();
64
assert(accs[i].init());
65
assert(accs[i].store(s.str()));
66
}
67
receiver.generate();
68
assert(receiver.init());
69
receiver.store(
"receiver.b2wallet"
);
70
71
{
72
COMMAND_RPC_START_MINE::request req;
73
req.miner_address =
miner
.get_account().get_public_address_str(
false
);
74
req.threads_count = 1;
75
COMMAND_RPC_START_MINE::response
res
;
76
bool
r = net_utils::http::invoke_http_json_remote_command(
daemon_address
+
"/start_mine"
, req,
res
, http_client);
77
ASSERT_TRUE
(r);
78
}
79
80
string
s;
81
//getline(cin, s);
82
sleep_no_w
(1000);
83
ASSERT_TRUE
(
miner
.refresh());
84
cout <<
"miner balance: "
<<
miner
.balance() << endl;
85
86
vector<pair<account_public_address, uint64_t>> d_accs;
87
for
(
int
i = 0; i <
ACCS
; i++)
88
d_accs.push_back(make_pair(accs[i].get_account().get_keys().m_account_address, 1));
89
ASSERT_TRUE
(
miner
.transfer(d_accs));
90
91
//getline(cin, s);
92
sleep_no_w
(1000);
93
for
(
int
i = 0; i <
ACCS
; i++) {
94
ASSERT_TRUE
(accs[i].refresh());
95
ASSERT_TRUE
(accs[i].transfer(receiver.get_account().get_keys().m_account_address, 1));
96
}
97
98
//getline(cin, s);
99
cout <<
"wait for block"
<< endl;
100
sleep_no_w
(10000);
101
receiver.refresh();
102
ASSERT_TRUE
(receiver.balance() ==
ACCS
);
103
cout <<
"OK"
<< endl;
104
}
account.h
cryptonote::miner
Definition
miner.h:60
cryptonote::miner::init
bool init(const boost::program_options::variables_map &vm, network_type nettype, bool fallback_to_pow=false)
Definition
miner.cpp:292
core_rpc_server.h
TEST
#define TEST(test_case_name, test_name)
Definition
gtest.h:2187
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition
gtest.h:1865
res
const char * res
Definition
hmac_keccak.cpp:41
cryptonote
Holds cryptonote related classes and helpers.
Definition
ban.cpp:40
epee::misc_utils
Definition
misc_language.h:56
epee::misc_utils::sleep_no_w
bool sleep_no_w(long ms)
Definition
misc_language.h:100
epee::net_utils::http::http_simple_client
http_simple_client_template< blocked_mode_client > http_simple_client
Definition
http_client.h:1018
std
STL namespace.
daemon_address
string daemon_address
Definition
transfers.cpp:42
ACCS
#define ACCS
Definition
transfers.cpp:44
tests
daemon_tests
transfers.cpp
Generated on
for Electroneum by
1.17.0