Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
v2_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 "
chaingen.h
"
33
#include "
v2_tests.h
"
34
35
using namespace
epee
;
36
using namespace
crypto
;
37
using namespace
cryptonote
;
38
39
//----------------------------------------------------------------------------------------------------------------------
40
// Tests
41
42
bool
gen_v2_tx_validation_base::generate_with
(std::vector<test_event_entry>& events,
const
int
*out_idx,
int
mixin,
uint64_t
amount_paid,
bool
valid)
const
43
{
44
uint64_t
ts_start = 1338224400;
45
46
GENERATE_ACCOUNT
(miner_account);
47
MAKE_GENESIS_BLOCK
(events, blk_0, miner_account, ts_start);
48
49
// create 4 miner accounts, and have them mine the next 4 blocks
50
cryptonote::account_base
miner_accounts[4];
51
const
cryptonote::block
*prev_block = &blk_0;
52
cryptonote::block
blocks
[4];
53
for
(
size_t
n = 0; n < 4; ++n) {
54
miner_accounts[n].
generate
();
55
CHECK_AND_ASSERT_MES
(generator.construct_block_manually(
blocks
[n], *prev_block, miner_accounts[n],
56
test_generator::bf_major_ver
|
test_generator::bf_minor_ver
|
test_generator::bf_timestamp
,
57
2, 2, prev_block->
timestamp
+
DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN
* 2,
// v2 has blocks twice as long
58
crypto::hash
(), 0,
transaction
(), std::vector<crypto::hash>(), 0, 0),
59
false
,
"Failed to generate block"
);
60
events.push_back(
blocks
[n]);
61
prev_block =
blocks
+ n;
62
}
63
64
// rewind
65
cryptonote::block
blk_r;
66
{
67
cryptonote::block
blk_last =
blocks
[3];
68
for
(
size_t
i = 0; i <
CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
; ++i)
69
{
70
cryptonote::block
blk;
71
CHECK_AND_ASSERT_MES
(generator.construct_block_manually(blk, blk_last, miner_account,
72
test_generator::bf_major_ver
|
test_generator::bf_minor_ver
|
test_generator::bf_timestamp
,
73
2, 2, blk_last.
timestamp
+
DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN
* 2,
// v2 has blocks twice as long
74
crypto::hash
(), 0,
transaction
(), std::vector<crypto::hash>(), 0, 0),
75
false
,
"Failed to generate block"
);
76
events.push_back(blk);
77
blk_last = blk;
78
}
79
blk_r = blk_last;
80
}
81
82
// create a tx with the Nth outputs of miner's block reward
83
std::vector<tx_source_entry> sources;
84
for
(
size_t
out_idx_idx = 0; out_idx[out_idx_idx] >= 0; ++out_idx_idx) {
85
sources.resize(sources.size()+1);
86
tx_source_entry
& src = sources.back();
87
88
src.
amount
=
blocks
[0].miner_tx.vout[out_idx[out_idx_idx]].amount;
89
std::cout <<
"using "
<<
print_etn
(src.
amount
) <<
" output at index "
<< out_idx[out_idx_idx] << std::endl;
90
for
(
int
m = 0; m <= mixin; ++m) {
91
int
idx;
92
if
(
is_valid_decomposed_amount
(src.
amount
))
93
idx = m+1;
// one out of that size per miner tx, including genesis
94
else
95
idx = 0;
// dusty, no other output of that size
96
src.
push_output
(idx, boost::get<txout_to_key>(
blocks
[m].miner_tx.vout[out_idx[out_idx_idx]].target).key, src.
amount
);
97
}
98
src.
real_out_tx_key
=
cryptonote::get_tx_pub_key_from_extra
(
blocks
[0].miner_tx);
99
src.
real_output
= 0;
100
src.
rct
=
false
;
101
src.
real_output_in_tx_index
= out_idx[out_idx_idx];
102
}
103
104
//fill outputs entry
105
tx_destination_entry
td;
106
td.
addr
= miner_account.get_keys().m_account_address;
107
td.
amount
= amount_paid;
108
std::vector<tx_destination_entry> destinations;
109
destinations.push_back(td);
110
111
transaction
tx;
112
bool
r =
construct_tx
(miner_accounts[0].get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx, 0);
113
CHECK_AND_ASSERT_MES
(r,
false
,
"failed to construct transaction"
);
114
if
(!valid)
115
DO_CALLBACK
(events,
"mark_invalid_tx"
);
116
events.push_back(tx);
117
118
return
true
;
119
}
120
121
bool
gen_v2_tx_mixable_0_mixin::generate
(std::vector<test_event_entry>& events)
const
122
{
123
const
int
mixin = 0;
124
const
int
out_idx[] = {1, -1};
125
const
uint64_t
amount_paid = 10000;
126
return
generate_with
(events, out_idx, mixin, amount_paid,
false
);
127
}
128
129
bool
gen_v2_tx_mixable_low_mixin::generate
(std::vector<test_event_entry>& events)
const
130
{
131
const
int
mixin = 1;
132
const
int
out_idx[] = {1, -1};
133
const
uint64_t
amount_paid = 10000;
134
return
generate_with
(events, out_idx, mixin, amount_paid,
false
);
135
}
136
137
bool
gen_v2_tx_unmixable_only::generate
(std::vector<test_event_entry>& events)
const
138
{
139
const
int
mixin = 0;
140
const
int
out_idx[] = {0, -1};
141
const
uint64_t
amount_paid = 10000;
142
return
generate_with
(events, out_idx, mixin, amount_paid,
true
);
143
}
144
145
bool
gen_v2_tx_unmixable_one::generate
(std::vector<test_event_entry>& events)
const
146
{
147
const
int
mixin = 0;
148
const
int
out_idx[] = {0, 1, -1};
149
const
uint64_t
amount_paid = 10000;
150
return
generate_with
(events, out_idx, mixin, amount_paid,
true
);
151
}
152
153
bool
gen_v2_tx_unmixable_two::generate
(std::vector<test_event_entry>& events)
const
154
{
155
const
int
mixin = 0;
156
const
int
out_idx[] = {0, 1, 2, -1};
157
const
uint64_t
amount_paid = 10000;
158
return
generate_with
(events, out_idx, mixin, amount_paid,
false
);
159
}
160
161
bool
gen_v2_tx_dust::generate
(std::vector<test_event_entry>& events)
const
162
{
163
const
int
mixin = 2;
164
const
int
out_idx[] = {1, -1};
165
const
uint64_t
amount_paid = 10001;
166
return
generate_with
(events, out_idx, mixin, amount_paid,
false
);
167
}
chaingen.h
MAKE_GENESIS_BLOCK
#define MAKE_GENESIS_BLOCK(VEC_EVENTS, BLK_NAME, MINER_ACC, TS)
Definition
chaingen.h:833
DO_CALLBACK
#define DO_CALLBACK(VEC_EVENTS, CB_NAME)
Definition
chaingen.h:820
GENERATE_ACCOUNT
#define GENERATE_ACCOUNT(account)
Definition
chaingen.h:801
cryptonote::account_base
Definition
account.h:77
cryptonote::account_base::generate
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
Definition
account.cpp:158
cryptonote::transaction
Definition
cryptonote_basic.h:298
test_generator::bf_timestamp
@ bf_timestamp
Definition
chaingen.h:222
test_generator::bf_minor_ver
@ bf_minor_ver
Definition
chaingen.h:221
test_generator::bf_major_ver
@ bf_major_ver
Definition
chaingen.h:220
DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN
#define DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN
Definition
cryptonote_config.h:107
CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
Definition
cryptonote_config.h:45
CHECK_AND_ASSERT_MES
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition
misc_log_ex.h:181
blocks
Definition
blocks.cpp:13
crypto
crypto namespace.
Definition
crypto.cpp:58
crypto::hash
POD_CLASS hash
Definition
hash.h:50
cryptonote
Holds cryptonote related classes and helpers.
Definition
ban.cpp:40
cryptonote::is_valid_decomposed_amount
bool is_valid_decomposed_amount(uint64_t amount)
Definition
cryptonote_format_utils.cpp:1331
cryptonote::get_tx_pub_key_from_extra
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
Definition
cryptonote_format_utils.cpp:518
cryptonote::construct_tx
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)
Definition
cryptonote_tx_utils.cpp:694
cryptonote::print_etn
std::string print_etn(uint64_t amount, unsigned int decimal_point)
Definition
cryptonote_format_utils.cpp:984
epee
Definition
ado_db_helper.h:67
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
cryptonote::block_header::timestamp
uint64_t timestamp
Definition
cryptonote_basic.h:450
cryptonote::block
Definition
cryptonote_basic.h:464
cryptonote::tx_destination_entry
Definition
cryptonote_tx_utils.h:84
cryptonote::tx_destination_entry::amount
uint64_t amount
Definition
cryptonote_tx_utils.h:86
cryptonote::tx_destination_entry::addr
account_public_address addr
Definition
cryptonote_tx_utils.h:87
cryptonote::tx_source_entry
Definition
cryptonote_tx_utils.h:44
cryptonote::tx_source_entry::real_out_tx_key
crypto::public_key real_out_tx_key
Definition
cryptonote_tx_utils.h:51
cryptonote::tx_source_entry::amount
uint64_t amount
Definition
cryptonote_tx_utils.h:54
cryptonote::tx_source_entry::rct
bool rct
Definition
cryptonote_tx_utils.h:55
cryptonote::tx_source_entry::real_output
size_t real_output
Definition
cryptonote_tx_utils.h:50
cryptonote::tx_source_entry::push_output
void push_output(uint64_t idx, const crypto::public_key &k, uint64_t amount)
Definition
cryptonote_tx_utils.h:63
cryptonote::tx_source_entry::real_output_in_tx_index
size_t real_output_in_tx_index
Definition
cryptonote_tx_utils.h:53
gen_v2_tx_dust::generate
bool generate(std::vector< test_event_entry > &events) const
Definition
v2_tests.cpp:161
gen_v2_tx_mixable_0_mixin::generate
bool generate(std::vector< test_event_entry > &events) const
Definition
v2_tests.cpp:121
gen_v2_tx_mixable_low_mixin::generate
bool generate(std::vector< test_event_entry > &events) const
Definition
v2_tests.cpp:129
gen_v2_tx_unmixable_one::generate
bool generate(std::vector< test_event_entry > &events) const
Definition
v2_tests.cpp:145
gen_v2_tx_unmixable_only::generate
bool generate(std::vector< test_event_entry > &events) const
Definition
v2_tests.cpp:137
gen_v2_tx_unmixable_two::generate
bool generate(std::vector< test_event_entry > &events) const
Definition
v2_tests.cpp:153
gen_v2_tx_validation_base::generate_with
bool generate_with(std::vector< test_event_entry > &events, const int *out_idx, int mixin, uint64_t amount_paid, bool valid) const
Definition
v2_tests.cpp:42
v2_tests.h
tests
core_tests
v2_tests.cpp
Generated on
for Electroneum by
1.17.0