Debian Codegraph @

tests/core_tests/chaingen001.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 <vector>
32 #include <iostream>
33
34 #include "include_base_utils.h"
35
36 #include "console_handler.h"
37
38 #include "cryptonote_basic/cryptonote_basic.h"
39 #include "cryptonote_basic/cryptonote_format_utils.h"
40
41 #include "chaingen.h"
42 #include "chaingen_tests_list.h"
43
44 using namespace std;
45
46 using namespace epee;
47 using namespace cryptonote;
48
49 ////////
50 // class one_block;
51
52 one_block::one_block()
53 {
54 REGISTER_CALLBACK("verify_1", one_block::verify_1);
55 }
56
57 bool one_block::generate(std::vector<test_event_entry> &events)
58 {
59 uint64_t ts_start = 1338224400;
60
61 MAKE_GENESIS_BLOCK(events, blk_0, alice, ts_start);
62 MAKE_ACCOUNT(events, alice);
63 DO_CALLBACK(events, "verify_1");
64
65 return true;
66 }
67
68 bool one_block::verify_1(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events)
69 {
70 DEFINE_TESTS_ERROR_CONTEXT("one_block::verify_1");
71
72 alice = boost::get<cryptonote::account_base>(events[1]);
73
74 // check balances
75 //std::vector<const cryptonote::block*> chain;
76 //map_hash2tx_t mtx;
77 //CHECK_TEST_CONDITION(find_block_chain(events, chain, mtx, get_block_hash(boost::get<cryptonote::block>(events[1]))));
78 //CHECK_TEST_CONDITION(get_block_reward(0) == get_balance(alice, events, chain, mtx));
79
80 // check height
81 std::vector<cryptonote::block> blocks;
82 std::list<crypto::public_key> outs;
83 bool r = c.get_blocks(0, 100, blocks);
84 //c.get_outs(100, outs);
85 CHECK_TEST_CONDITION(r);
86 CHECK_TEST_CONDITION(blocks.size() == 1);
87 //CHECK_TEST_CONDITION(outs.size() == blocks.size());
88 CHECK_TEST_CONDITION(c.get_blockchain_total_transactions() == 1);
89 CHECK_TEST_CONDITION(blocks.back() == boost::get<cryptonote::block>(events[0]));
90
91 return true;
92 }
93
94
95 ////////
96 // class gen_simple_chain_001;
97
98 gen_simple_chain_001::gen_simple_chain_001()
99 {
100 REGISTER_CALLBACK("verify_callback_1", gen_simple_chain_001::verify_callback_1);
101 REGISTER_CALLBACK("verify_callback_2", gen_simple_chain_001::verify_callback_2);
102 }
103
104 bool gen_simple_chain_001::generate(std::vector<test_event_entry> &events)
105 {
106 uint64_t ts_start = 1338224400;
107
108 GENERATE_ACCOUNT(miner);
109 GENERATE_ACCOUNT(alice);
110
111 MAKE_GENESIS_BLOCK(events, blk_0, miner, ts_start);
112 MAKE_NEXT_BLOCK(events, blk_1, blk_0, miner);
113 MAKE_NEXT_BLOCK(events, blk_1_side, blk_0, miner);
114 MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner);
115 //MAKE_TX(events, tx_0, first_miner_account, alice, 151, blk_2);
116
117 std::vector<cryptonote::block> chain;
118 map_hash2tx_t mtx;
119 /*bool r = */find_block_chain(events, chain, mtx, get_block_hash(boost::get<cryptonote::block>(events[3])));
120 std::cout << "BALANCE = " << get_balance(miner, chain, mtx) << std::endl;
121
122 REWIND_BLOCKS(events, blk_2r, blk_2, miner);
123 MAKE_TX_LIST_START(events, txlist_0, miner, alice, MK_COINS(1), blk_2);
124 MAKE_TX_LIST(events, txlist_0, miner, alice, MK_COINS(2), blk_2);
125 MAKE_TX_LIST(events, txlist_0, miner, alice, MK_COINS(4), blk_2);
126 MAKE_NEXT_BLOCK_TX_LIST(events, blk_3, blk_2r, miner, txlist_0);
127 REWIND_BLOCKS(events, blk_3r, blk_3, miner);
128 MAKE_TX(events, tx_1, miner, alice, MK_COINS(50), blk_3);
129 MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3r, miner, tx_1);
130 REWIND_BLOCKS(events, blk_4r, blk_4, miner);
131 MAKE_TX(events, tx_2, miner, alice, MK_COINS(50), blk_4);
132 MAKE_NEXT_BLOCK_TX1(events, blk_5, blk_4r, miner, tx_2);
133 REWIND_BLOCKS(events, blk_5r, blk_5, miner);
134 MAKE_TX(events, tx_3, miner, alice, MK_COINS(50), blk_5);
135 MAKE_NEXT_BLOCK_TX1(events, blk_6, blk_5r, miner, tx_3);
136
137 DO_CALLBACK(events, "verify_callback_1");
138 //e.t.c.
139 //MAKE_BLOCK_TX1(events, blk_3, 3, get_block_hash(blk_0), get_test_target(), first_miner_account, ts_start + 10, tx_0);
140 //MAKE_BLOCK_TX1(events, blk_3, 3, get_block_hash(blk_0), get_test_target(), first_miner_account, ts_start + 10, tx_0);
141 //DO_CALLBACK(events, "verify_callback_2");
142
143 /* std::vector<const cryptonote::block*> chain;
144 map_hash2tx_t mtx;
145 if (!find_block_chain(events, chain, mtx, get_block_hash(blk_6)))
146 throw;
147 cout << "miner = " << get_balance(first_miner_account, events, chain, mtx) << endl;
148 cout << "alice = " << get_balance(alice, events, chain, mtx) << endl;*/
149
150 return true;
151 }
152
153 bool gen_simple_chain_001::verify_callback_1(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events)
154 {
155 return true;
156 }
157
158 bool gen_simple_chain_001::verify_callback_2(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events)
159 {
160 return true;
161 }