Electroneum
transaction_tests.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 "include_base_utils.h"
36 #include "misc_language.h"
37 
38 using namespace cryptonote;
39 
40 
41 
43 {
44 
45  account_base miner_acc1;
46  miner_acc1.generate();
47  account_base miner_acc2;
48  miner_acc2.generate();
49  account_base miner_acc3;
50  miner_acc3.generate();
51  account_base miner_acc4;
52  miner_acc4.generate();
53  account_base miner_acc5;
54  miner_acc5.generate();
55  account_base miner_acc6;
56  miner_acc6.generate();
57 
58  account_base rv_acc;
59  rv_acc.generate();
60  account_base rv_acc2;
61  rv_acc2.generate();
62  transaction tx_mine_1;
63  construct_miner_tx(0, 0, 0, 10, 0, miner_acc1.get_keys().m_account_address, tx_mine_1);
64  transaction tx_mine_2;
65  construct_miner_tx(0, 0, 0, 0, 0, miner_acc2.get_keys().m_account_address, tx_mine_2);
66  transaction tx_mine_3;
67  construct_miner_tx(0, 0, 0, 0, 0, miner_acc3.get_keys().m_account_address, tx_mine_3);
68  transaction tx_mine_4;
69  construct_miner_tx(0, 0, 0, 0, 0, miner_acc4.get_keys().m_account_address, tx_mine_4);
70  transaction tx_mine_5;
71  construct_miner_tx(0, 0, 0, 0, 0, miner_acc5.get_keys().m_account_address, tx_mine_5);
72  transaction tx_mine_6;
73  construct_miner_tx(0, 0, 0, 0, 0, miner_acc6.get_keys().m_account_address, tx_mine_6);
74 
75  //fill inputs entry
76  typedef tx_source_entry::output_entry tx_output_entry;
77  std::vector<tx_source_entry> sources;
78  sources.resize(sources.size()+1);
79  tx_source_entry& src = sources.back();
80  src.amount = 70368744177663;
81  {
82  tx_output_entry oe;
83 
84  src.push_output(0, boost::get<txout_to_key>(tx_mine_1.vout[0].target).key, src.amount);
85 
86  src.push_output(1, boost::get<txout_to_key>(tx_mine_2.vout[0].target).key, src.amount);
87 
88  src.push_output(2, boost::get<txout_to_key>(tx_mine_3.vout[0].target).key, src.amount);
89 
90  src.push_output(3, boost::get<txout_to_key>(tx_mine_4.vout[0].target).key, src.amount);
91 
92  src.push_output(4, boost::get<txout_to_key>(tx_mine_5.vout[0].target).key, src.amount);
93 
94  src.push_output(5, boost::get<txout_to_key>(tx_mine_6.vout[0].target).key, src.amount);
95 
97  src.real_output = 1;
98  src.rct = false;
100  }
101  //fill outputs entry
103  td.addr = rv_acc.get_keys().m_account_address;
104  td.amount = 69368744177663;
105  std::vector<tx_destination_entry> destinations;
106  destinations.push_back(td);
107 
108  transaction tx_rc1;
109  bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_rc1, 0);
110  CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
111 
112  crypto::hash pref_hash = get_transaction_prefix_hash(tx_rc1);
113  std::vector<const crypto::public_key *> output_keys;
114  output_keys.push_back(&boost::get<txout_to_key>(tx_mine_1.vout[0].target).key);
115  output_keys.push_back(&boost::get<txout_to_key>(tx_mine_2.vout[0].target).key);
116  output_keys.push_back(&boost::get<txout_to_key>(tx_mine_3.vout[0].target).key);
117  output_keys.push_back(&boost::get<txout_to_key>(tx_mine_4.vout[0].target).key);
118  output_keys.push_back(&boost::get<txout_to_key>(tx_mine_5.vout[0].target).key);
119  output_keys.push_back(&boost::get<txout_to_key>(tx_mine_6.vout[0].target).key);
120  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]);
121  CHECK_AND_ASSERT_MES(r, false, "failed to check ring signature");
122 
123  std::vector<size_t> outs;
124  uint64_t etn = 0;
125 
126  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, etn);
127  CHECK_AND_ASSERT_MES(r, false, "failed to lookup_acc_outs");
128  CHECK_AND_ASSERT_MES(td.amount == etn, false, "wrong ETN amount in new transaction");
129  etn = 0;
130  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, etn);
131  CHECK_AND_ASSERT_MES(r, false, "failed to lookup_acc_outs");
132  CHECK_AND_ASSERT_MES(0 == etn, false, "wrong ETN amount in new transaction");
133  return true;
134 }
135 
137 {
138  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};
139  std::vector<uint64_t> szs(&vszs[0], &vszs[90]);
141  bool r = get_account_address_from_str(info, MAINNET, "0099be99c70ef10fd534c43c88e9d13d1c8853213df7e362afbec0e4ee6fec4948d0c190b58f4b356cd7feaf8d9d0a76e7c7e5a9a0a497a6b1faf7a765882dd08ac2");
142  CHECK_AND_ASSERT_MES(r, false, "failed to import");
143  block b;
144  r = construct_miner_tx(90, epee::misc_utils::median(szs), 3553616528562147, 33094, 10000000, info.address, b.miner_tx, blobdata(), 11);
145  return r;
146 }
147 
149 {
151  return false;
152  if(!test_block_creation())
153  return false;
154 
155 
156  return true;
157 }
crypto::public_key real_out_tx_key
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
bool check_ring_signature(const hash &prefix_hash, const key_image &image, const public_key *const *pubs, std::size_t pubs_count, const signature *sig)
Definition: crypto.h:333
bool construct_tx(const account_keys &sender_account_keys, std::vector< tx_source_entry > &sources, const std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, const std::vector< uint8_t > &extra, transaction &tx, uint64_t unlock_time)
bool rct
bool test_transactions()
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
Definition: account.cpp:158
uint64_t amount
size_t real_output
const account_keys & get_keys() const
Definition: account.cpp:264
Holds cryptonote related classes and helpers.
Definition: ban.cpp:40
unsigned __int64 uint64_t
Definition: stdint.h:136
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
uint64_t amount
bool test_transaction_generation_and_ring_signature()
void push_output(uint64_t idx, const crypto::public_key &k, uint64_t amount)
std::vector< std::vector< crypto::signature > > signatures
account_public_address addr
std::string blobdata
Definition: blobdatatype.h:39
type_vec_type median(std::vector< type_vec_type > &v)
CXA_THROW_INFO_T * info
Definition: stack_trace.cpp:91
bool test_block_creation()
account_public_address m_account_address
Definition: account.h:43
void get_transaction_prefix_hash(const transaction_prefix &tx, crypto::hash &h)
size_t real_output_in_tx_index
bool get_account_address_from_str(address_parse_info &info, network_type nettype, std::string const &str)
POD_CLASS hash
Definition: hash.h:50
bool construct_miner_tx(size_t height, size_t median_weight, uint64_t already_generated_coins, size_t current_block_weight, uint64_t fee, const account_public_address &miner_address, transaction &tx, const blobdata &extra_nonce, size_t max_outs, uint8_t hard_fork_version, network_type nettype)
std::pair< uint64_t, rct::ctkey > output_entry
std::vector< crypto::public_key > get_additional_tx_pub_keys_from_extra(const std::vector< uint8_t > &tx_extra)
bool lookup_acc_outs(const account_keys &acc, const transaction &tx, std::vector< size_t > &outs, uint64_t &etn_transfered)