Debian Codegraph @

tests/core_tests/transaction_tests.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 "include_base_utils.h"
32 #include "cryptonote_basic/cryptonote_basic_impl.h"
33 #include "cryptonote_basic/account.h"
34 #include "cryptonote_core/cryptonote_tx_utils.h"
35 #include "misc_language.h"
36
37 using namespace cryptonote;
38
39
40
41 bool test_transaction_generation_and_ring_signature()
42 {
43
44 account_base miner_acc1;
45 miner_acc1.generate();
46 account_base miner_acc2;
47 miner_acc2.generate();
48 account_base miner_acc3;
49 miner_acc3.generate();
50 account_base miner_acc4;
51 miner_acc4.generate();
52 account_base miner_acc5;
53 miner_acc5.generate();
54 account_base miner_acc6;
55 miner_acc6.generate();
56
57 account_base rv_acc;
58 rv_acc.generate();
59 account_base rv_acc2;
60 rv_acc2.generate();
61 transaction tx_mine_1;
62 construct_miner_tx(0, 0, 0, 10, 0, miner_acc1.get_keys().m_account_address, tx_mine_1);
63 transaction tx_mine_2;
64 construct_miner_tx(0, 0, 0, 0, 0, miner_acc2.get_keys().m_account_address, tx_mine_2);
65 transaction tx_mine_3;
66 construct_miner_tx(0, 0, 0, 0, 0, miner_acc3.get_keys().m_account_address, tx_mine_3);
67 transaction tx_mine_4;
68 construct_miner_tx(0, 0, 0, 0, 0, miner_acc4.get_keys().m_account_address, tx_mine_4);
69 transaction tx_mine_5;
70 construct_miner_tx(0, 0, 0, 0, 0, miner_acc5.get_keys().m_account_address, tx_mine_5);
71 transaction tx_mine_6;
72 construct_miner_tx(0, 0, 0, 0, 0, miner_acc6.get_keys().m_account_address, tx_mine_6);
73
74 //fill inputs entry
75 std::vector<tx_source_entry> sources;
76 sources.resize(sources.size()+1);
77 tx_source_entry& src = sources.back();
78 src.amount = 70368744177663;
79 {
80 src.push_output(0, boost::get<txout_to_key>(tx_mine_1.vout[0].target).key, src.amount);
81
82 src.push_output(1, boost::get<txout_to_key>(tx_mine_2.vout[0].target).key, src.amount);
83
84 src.push_output(2, boost::get<txout_to_key>(tx_mine_3.vout[0].target).key, src.amount);
85
86 src.push_output(3, boost::get<txout_to_key>(tx_mine_4.vout[0].target).key, src.amount);
87
88 src.push_output(4, boost::get<txout_to_key>(tx_mine_5.vout[0].target).key, src.amount);
89
90 src.push_output(5, boost::get<txout_to_key>(tx_mine_6.vout[0].target).key, src.amount);
91
92 src.real_out_tx_key = cryptonote::get_tx_pub_key_from_extra(tx_mine_2);
93 src.real_output = 1;
94 src.rct = false;
95 src.real_output_in_tx_index = 0;
96 }
97 //fill outputs entry
98 tx_destination_entry td;
99 td.addr = rv_acc.get_keys().m_account_address;
100 td.amount = 69368744177663;
101 std::vector<tx_destination_entry> destinations;
102 destinations.push_back(td);
103
104 transaction tx_rc1;
105 bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_rc1);
106 CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
107
108 crypto::hash pref_hash = get_transaction_prefix_hash(tx_rc1);
109 std::vector<const crypto::public_key *> output_keys;
110 output_keys.push_back(&boost::get<txout_to_key>(tx_mine_1.vout[0].target).key);
111 output_keys.push_back(&boost::get<txout_to_key>(tx_mine_2.vout[0].target).key);
112 output_keys.push_back(&boost::get<txout_to_key>(tx_mine_3.vout[0].target).key);
113 output_keys.push_back(&boost::get<txout_to_key>(tx_mine_4.vout[0].target).key);
114 output_keys.push_back(&boost::get<txout_to_key>(tx_mine_5.vout[0].target).key);
115 output_keys.push_back(&boost::get<txout_to_key>(tx_mine_6.vout[0].target).key);
116 r = crypto::check_ring_signature(pref_hash, boost::get<txin_to_key>(tx_rc1.vin[0]).k_image, output_keys, &tx_rc1.signatures[0][0]);
117 CHECK_AND_ASSERT_MES(r, false, "failed to check ring signature");
118
119 std::vector<size_t> outs;
120 uint64_t money = 0;
121
122 r = lookup_acc_outs(rv_acc.get_keys(), tx_rc1, get_tx_pub_key_from_extra(tx_rc1), get_additional_tx_pub_keys_from_extra(tx_rc1), outs, money);
123 CHECK_AND_ASSERT_MES(r, false, "failed to lookup_acc_outs");
124 CHECK_AND_ASSERT_MES(td.amount == money, false, "wrong money amount in new transaction");
125 money = 0;
126 r = lookup_acc_outs(rv_acc2.get_keys(), tx_rc1, get_tx_pub_key_from_extra(tx_rc1), get_additional_tx_pub_keys_from_extra(tx_rc1), outs, money);
127 CHECK_AND_ASSERT_MES(r, false, "failed to lookup_acc_outs");
128 CHECK_AND_ASSERT_MES(0 == money, false, "wrong money amount in new transaction");
129 return true;
130 }
131
132 bool test_block_creation()
133 {
134 uint64_t vszs[] = {80,476,476,475,475,474,475,474,474,475,472,476,476,475,475,474,475,474,474,475,472,476,476,475,475,474,475,474,474,475,9391,476,476,475,475,474,475,8819,8301,475,472,4302,5316,14347,16620,19583,19403,19728,19442,19852,19015,19000,19016,19795,19749,18087,19787,19704,19750,19267,19006,19050,19445,19407,19522,19546,19788,19369,19486,19329,19370,18853,19600,19110,19320,19746,19474,19474,19743,19494,19755,19715,19769,19620,19368,19839,19532,23424,28287,30707};
135 std::vector<uint64_t> szs(&vszs[0], &vszs[90]);
136 address_parse_info info;
137 bool r = get_account_address_from_str(info, MAINNET, "0099be99c70ef10fd534c43c88e9d13d1c8853213df7e362afbec0e4ee6fec4948d0c190b58f4b356cd7feaf8d9d0a76e7c7e5a9a0a497a6b1faf7a765882dd08ac2");
138 CHECK_AND_ASSERT_MES(r, false, "failed to import");
139 block b;
140 r = construct_miner_tx(90, epee::misc_utils::median(szs), 3553616528562147, 33094, 10000000, info.address, b.miner_tx, blobdata(), 11);
141 return r;
142 }
143
144 bool test_transactions()
145 {
146 if(!test_transaction_generation_and_ring_signature())
147 return false;
148 if(!test_block_creation())
149 return false;
150
151
152 return true;
153 }