| 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 "gtest/gtest.h" |
| 32 | #include <sstream> |
| 33 | #include "wallet/wallet.h" |
| 34 | #include "rpc/core_rpc_server.h" |
| 35 | #include "cryptonote_basic/account.h" |
| 36 | #include "net/http_client_abstract_invoke.h" |
| 37 | using namespace std; |
| 38 | using namespace epee::misc_utils; |
| 39 | using namespace cryptonote; |
| 40 | |
| 41 | string daemon_address = "http://localhost:23400"; |
| 42 | |
| 43 | #define ACCS 5 |
| 44 | |
| 45 | TEST(Transfers, Transfers) |
| 46 | { |
| 47 | log_space::get_set_log_detalisation_level(true, LOG_LEVEL_3); |
| 48 | log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); |
| 49 | |
| 50 | cout << "TESTING: transfers" << endl; |
| 51 | |
| 52 | net_utils::http::http_simple_client http_client; |
| 53 | wallet miner, accs[100], receiver; |
| 54 | miner.generate(); |
| 55 | ASSERT_TRUE(miner.init()); |
| 56 | ASSERT_TRUE(miner.store("miner.b2wallet")); |
| 57 | cout << "miner: " << miner.get_account().get_public_address_str(false) << endl; |
| 58 | |
| 59 | for (int i = 0; i < ACCS; i++) { |
| 60 | ostringstream s; |
| 61 | s << "acc" << setw(2) << setfill('0') << i << ".b2wallet"; |
| 62 | accs[i].generate(); |
| 63 | assert(accs[i].init()); |
| 64 | assert(accs[i].store(s.str())); |
| 65 | } |
| 66 | receiver.generate(); |
| 67 | assert(receiver.init()); |
| 68 | receiver.store("receiver.b2wallet"); |
| 69 | |
| 70 | { |
| 71 | COMMAND_RPC_START_MINE::request req; |
| 72 | req.miner_address = miner.get_account().get_public_address_str(false); |
| 73 | req.threads_count = 1; |
| 74 | COMMAND_RPC_START_MINE::response res; |
| 75 | bool r = net_utils::http::invoke_http_json_remote_command(daemon_address + "/start_mine", req, res, http_client); |
| 76 | ASSERT_TRUE(r); |
| 77 | } |
| 78 | |
| 79 | string s; |
| 80 | //getline(cin, s); |
| 81 | sleep_no_w(1000); |
| 82 | ASSERT_TRUE(miner.refresh()); |
| 83 | cout << "miner balance: " << miner.balance() << endl; |
| 84 | |
| 85 | vector<pair<account_public_address, uint64_t>> d_accs; |
| 86 | for (int i = 0; i < ACCS; i++) |
| 87 | d_accs.push_back(make_pair(accs[i].get_account().get_keys().m_account_address, 1)); |
| 88 | ASSERT_TRUE(miner.transfer(d_accs)); |
| 89 | |
| 90 | //getline(cin, s); |
| 91 | sleep_no_w(1000); |
| 92 | for (int i = 0; i < ACCS; i++) { |
| 93 | ASSERT_TRUE(accs[i].refresh()); |
| 94 | ASSERT_TRUE(accs[i].transfer(receiver.get_account().get_keys().m_account_address, 1)); |
| 95 | } |
| 96 | |
| 97 | //getline(cin, s); |
| 98 | cout << "wait for block" << endl; |
| 99 | sleep_no_w(10000); |
| 100 | receiver.refresh(); |
| 101 | ASSERT_TRUE(receiver.balance() == ACCS); |
| 102 | cout << "OK" << endl; |
| 103 | } |