Electroneum
chaingen001.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 <vector>
33 #include <iostream>
34 
35 #include "include_base_utils.h"
36 
37 #include "console_handler.h"
38 
41 
42 #include "chaingen.h"
43 #include "chaingen_tests_list.h"
44 
45 using namespace std;
46 
47 using namespace epee;
48 using namespace cryptonote;
49 
51 // class one_block;
52 
54 {
56 }
57 
58 bool one_block::generate(std::vector<test_event_entry> &events)
59 {
60  uint64_t ts_start = 1338224400;
61 
62  MAKE_GENESIS_BLOCK(events, blk_0, alice, ts_start);
63  MAKE_ACCOUNT(events, alice);
64  DO_CALLBACK(events, "verify_1");
65 
66  return true;
67 }
68 
69 bool one_block::verify_1(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events)
70 {
71  DEFINE_TESTS_ERROR_CONTEXT("one_block::verify_1");
72 
73  alice = boost::get<cryptonote::account_base>(events[1]);
74 
75  // check balances
76  //std::vector<const cryptonote::block*> chain;
77  //map_hash2tx_t mtx;
78  //CHECK_TEST_CONDITION(find_block_chain(events, chain, mtx, get_block_hash(boost::get<cryptonote::block>(events[1]))));
79  //CHECK_TEST_CONDITION(get_block_reward(0) == get_balance(alice, events, chain, mtx));
80 
81  // check height
82  std::vector<cryptonote::block> blocks;
83  std::list<crypto::public_key> outs;
84  bool r = c.get_blocks(0, 100, blocks);
85  //c.get_outs(100, outs);
87  CHECK_TEST_CONDITION(blocks.size() == 1);
88  //CHECK_TEST_CONDITION(outs.size() == blocks.size());
90  CHECK_TEST_CONDITION(blocks.back() == boost::get<cryptonote::block>(events[0]));
91 
92  return true;
93 }
94 
95 
97 // class gen_simple_chain_001;
98 
100 {
103 }
104 
105 bool gen_simple_chain_001::generate(std::vector<test_event_entry> &events)
106 {
107  uint64_t ts_start = 1338224400;
108 
110  GENERATE_ACCOUNT(alice);
111 
112  MAKE_GENESIS_BLOCK(events, blk_0, miner, ts_start);
113  MAKE_NEXT_BLOCK(events, blk_1, blk_0, miner);
114  MAKE_NEXT_BLOCK(events, blk_1_side, blk_0, miner);
115  MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner);
116  //MAKE_TX(events, tx_0, first_miner_account, alice, 151, blk_2);
117 
118  std::vector<cryptonote::block> chain;
119  map_hash2tx_t mtx;
120  /*bool r = */find_block_chain(events, chain, mtx, get_block_hash(boost::get<cryptonote::block>(events[3])));
121  std::cout << "BALANCE = " << get_balance(miner, chain, mtx) << std::endl;
122 
123  REWIND_BLOCKS(events, blk_2r, blk_2, miner);
124  MAKE_TX_LIST_START(events, txlist_0, miner, alice, MK_COINS(1), blk_2);
125  MAKE_TX_LIST(events, txlist_0, miner, alice, MK_COINS(2), blk_2);
126  MAKE_TX_LIST(events, txlist_0, miner, alice, MK_COINS(4), blk_2);
127  MAKE_NEXT_BLOCK_TX_LIST(events, blk_3, blk_2r, miner, txlist_0);
128  REWIND_BLOCKS(events, blk_3r, blk_3, miner);
129  MAKE_TX(events, tx_1, miner, alice, MK_COINS(50), blk_3);
130  MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3r, miner, tx_1);
131  REWIND_BLOCKS(events, blk_4r, blk_4, miner);
132  MAKE_TX(events, tx_2, miner, alice, MK_COINS(50), blk_4);
133  MAKE_NEXT_BLOCK_TX1(events, blk_5, blk_4r, miner, tx_2);
134  REWIND_BLOCKS(events, blk_5r, blk_5, miner);
135  MAKE_TX(events, tx_3, miner, alice, MK_COINS(50), blk_5);
136  MAKE_NEXT_BLOCK_TX1(events, blk_6, blk_5r, miner, tx_3);
137 
138  DO_CALLBACK(events, "verify_callback_1");
139  //e.t.c.
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  //MAKE_BLOCK_TX1(events, blk_3, 3, get_block_hash(blk_0), get_test_target(), first_miner_account, ts_start + 10, tx_0);
142  //DO_CALLBACK(events, "verify_callback_2");
143 
144 /* std::vector<const cryptonote::block*> chain;
145  map_hash2tx_t mtx;
146  if (!find_block_chain(events, chain, mtx, get_block_hash(blk_6)))
147  throw;
148  cout << "miner = " << get_balance(first_miner_account, events, chain, mtx) << endl;
149  cout << "alice = " << get_balance(alice, events, chain, mtx) << endl;*/
150 
151  return true;
152 }
153 
154 bool gen_simple_chain_001::verify_callback_1(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events)
155 {
156  return true;
157 }
158 
159 bool gen_simple_chain_001::verify_callback_2(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events)
160 {
161  return true;
162 }
#define MAKE_NEXT_BLOCK_TX1(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TX1)
Definition: chaingen.h:849
bool find_block_chain(const std::vector< test_event_entry > &events, std::vector< cryptonote::block > &blockchain, map_hash2tx_t &mtx, const crypto::hash &head)
Definition: chaingen.cpp:1072
bool generate(std::vector< test_event_entry > &events)
Definition: chaingen001.cpp:58
STL namespace.
#define MAKE_NEXT_BLOCK(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC)
Definition: chaingen.h:839
uint64_t get_balance(const cryptonote::account_base &addr, const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx)
Definition: chaingen.cpp:940
#define MAKE_TX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD)
Definition: chaingen.h:933
#define CHECK_TEST_CONDITION(cond)
Definition: chaingen.h:1057
bool get_blocks(uint64_t start_offset, size_t count, std::vector< std::pair< cryptonote::blobdata, block >> &blocks, std::vector< cryptonote::blobdata > &txs) const
Holds cryptonote related classes and helpers.
Definition: ban.cpp:40
std::unordered_map< crypto::hash, const cryptonote::transaction * > map_hash2tx_t
Definition: chaingen.h:163
handles core cryptonote functionality
#define MAKE_GENESIS_BLOCK(VEC_EVENTS, BLK_NAME, MINER_ACC, TS)
Definition: chaingen.h:833
#define REGISTER_CALLBACK(CB_NAME, CLBACK)
Definition: chaingen.h:827
unsigned __int64 uint64_t
Definition: stdint.h:136
bool verify_callback_1(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
#define MAKE_TX_LIST_START(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD)
Definition: chaingen.h:935
bool verify_1(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: chaingen001.cpp:69
#define MAKE_ACCOUNT(VEC_EVENTS, account)
Definition: chaingen.h:815
#define REWIND_BLOCKS(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC)
Definition: chaingen.h:890
#define MAKE_TX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, HEAD)
Definition: chaingen.h:903
crypto::hash get_block_hash(uint64_t height)
#define MK_COINS(amount)
Definition: chaingen.h:1060
#define GENERATE_ACCOUNT(account)
Definition: chaingen.h:801
#define DEFINE_TESTS_ERROR_CONTEXT(text)
Definition: chaingen.h:1056
bool verify_callback_2(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
#define DO_CALLBACK(VEC_EVENTS, CB_NAME)
Definition: chaingen.h:820
#define MAKE_NEXT_BLOCK_TX_LIST(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST)
Definition: chaingen.h:867
size_t get_blockchain_total_transactions() const
gets the total number of transactions on the main chain
bool generate(std::vector< test_event_entry > &events)