Electroneum
gen_double_spend_in_different_chains Class Reference

#include <double_spend.h>

Inheritance diagram for gen_double_spend_in_different_chains:
Collaboration diagram for gen_double_spend_in_different_chains:

Public Member Functions

 gen_double_spend_in_different_chains ()
 
bool generate (std::vector< test_event_entry > &events) const
 
bool check_double_spend (cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
 
- Public Member Functions inherited from test_chain_unit_base
void register_callback (const std::string &cb_name, verify_callback cb)
 
bool verify (const std::string &cb_name, cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
 
bool check_block_verification_context (const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
 
bool check_tx_verification_context (const cryptonote::tx_verification_context &tvc, bool, size_t, const cryptonote::transaction &)
 
bool check_tx_verification_context_array (const std::vector< cryptonote::tx_verification_context > &tvcs, size_t, size_t, const std::vector< cryptonote::transaction > &)
 

Static Public Attributes

static const uint64_t send_amount = FIRST_BLOCK_REWARD - TESTS_DEFAULT_FEE
 
static const size_t expected_blockchain_height = 4 + 2 * CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
 

Additional Inherited Members

- Public Types inherited from test_chain_unit_base
typedef boost::function< bool(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)> verify_callback
 
typedef std::map< std::string, verify_callbackcallbacks_map
 

Detailed Description

Definition at line 127 of file double_spend.h.

Constructor & Destructor Documentation

◆ gen_double_spend_in_different_chains()

gen_double_spend_in_different_chains::gen_double_spend_in_different_chains ( )

Definition at line 41 of file double_spend.cpp.

42 {
44 }
#define REGISTER_CALLBACK_METHOD(CLASS, METHOD)
Definition: chaingen.h:830
bool check_double_spend(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)

Member Function Documentation

◆ check_double_spend()

bool gen_double_spend_in_different_chains::check_double_spend ( cryptonote::core c,
size_t  ev_index,
const std::vector< test_event_entry > &  events 
)

Definition at line 73 of file double_spend.cpp.

74 {
75  DEFINE_TESTS_ERROR_CONTEXT("gen_double_spend_in_different_chains::check_double_spend");
76 
77  std::vector<block> block_list;
78  bool r = c.get_blocks(0, 100 + 2 * CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW, block_list);
80 
81  std::vector<block> blocks(block_list.begin(), block_list.end());
82  //CHECK_EQ(expected_blockchain_height, blocks.size());
83  if (expected_blockchain_height != blocks.size()) LOG_ERROR ("oops");
84 
87 
88  cryptonote::account_base bob_account = boost::get<cryptonote::account_base>(events[1]);
89  cryptonote::account_base alice_account = boost::get<cryptonote::account_base>(events[2]);
90 
91  std::vector<cryptonote::block> chain;
92  map_hash2tx_t mtx;
93  r = find_block_chain(events, chain, mtx, get_block_hash(blocks.back()));
95  CHECK_EQ(0, get_balance(bob_account, blocks, mtx));
96  CHECK_EQ(send_amount - TESTS_DEFAULT_FEE, get_balance(alice_account, blocks, mtx));
97 
98  return true;
99 }
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
static const uint64_t send_amount
Definition: double_spend.h:130
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
#define TESTS_DEFAULT_FEE
Definition: chaingen.h:1061
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 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
std::unordered_map< crypto::hash, const cryptonote::transaction * > map_hash2tx_t
Definition: chaingen.h:163
static const size_t expected_blockchain_height
Definition: double_spend.h:131
size_t get_pool_transactions_count() const
get the total number of transactions in the pool
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
size_t get_alternative_blocks_count() const
returns the number of alternative blocks stored
crypto::hash get_block_hash(uint64_t height)
#define CHECK_EQ(v1, v2)
Definition: chaingen.h:1058
#define DEFINE_TESTS_ERROR_CONTEXT(text)
Definition: chaingen.h:1056
Here is the call graph for this function:

◆ generate()

bool gen_double_spend_in_different_chains::generate ( std::vector< test_event_entry > &  events) const

Definition at line 46 of file double_spend.cpp.

47 {
49 
51  MAKE_TX(events, tx_1, bob_account, alice_account, send_amount / 2 - TESTS_DEFAULT_FEE, blk_1);
52  events.pop_back();
53  MAKE_TX(events, tx_2, bob_account, alice_account, send_amount - TESTS_DEFAULT_FEE, blk_1);
54  events.pop_back();
55 
56  // Main chain
57  events.push_back(tx_1);
58  MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1r, miner_account, tx_1);
59 
60  // Alternative chain
61  events.push_back(tx_2);
62  MAKE_NEXT_BLOCK_TX1(events, blk_3, blk_1r, miner_account, tx_2);
63  // Switch to alternative chain
64  MAKE_NEXT_BLOCK(events, blk_4, blk_3, miner_account);
65  //CHECK_AND_NO_ASSERT_MES(expected_blockchain_height == get_block_height(blk_4) + 1, false, "expected_blockchain_height has invalid value");
66  if ((expected_blockchain_height != get_block_height(blk_4) + 1)) LOG_ERROR("oops");
67 
68  DO_CALLBACK(events, "check_double_spend");
69 
70  return true;
71 }
#define MAKE_NEXT_BLOCK_TX1(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TX1)
Definition: chaingen.h:849
static const uint64_t send_amount
Definition: double_spend.h:130
#define INIT_DOUBLE_SPEND_TEST()
Definition: double_spend.h:141
#define MAKE_NEXT_BLOCK(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC)
Definition: chaingen.h:839
#define TESTS_DEFAULT_FEE
Definition: chaingen.h:1061
#define SET_EVENT_VISITOR_SETT(VEC_EVENTS, SETT, VAL)
Definition: chaingen.h:951
static const size_t expected_blockchain_height
Definition: double_spend.h:131
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
#define MAKE_TX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, HEAD)
Definition: chaingen.h:903
#define DO_CALLBACK(VEC_EVENTS, CB_NAME)
Definition: chaingen.h:820
uint64_t get_block_height(const block &b)
Here is the call graph for this function:

Member Data Documentation

◆ expected_blockchain_height

const size_t gen_double_spend_in_different_chains::expected_blockchain_height = 4 + 2 * CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
static

Definition at line 131 of file double_spend.h.

◆ send_amount

const uint64_t gen_double_spend_in_different_chains::send_amount = FIRST_BLOCK_REWARD - TESTS_DEFAULT_FEE
static

Definition at line 130 of file double_spend.h.


The documentation for this class was generated from the following files: