Electroneum
Loading...
Searching...
No Matches
gen_v2_tx_validation_base Struct Reference

#include <v2_tests.h>

Inheritance diagram for gen_v2_tx_validation_base:
Collaboration diagram for gen_v2_tx_validation_base:

Public Member Functions

 gen_v2_tx_validation_base ()
bool check_tx_verification_context (const cryptonote::tx_verification_context &tvc, bool tx_added, size_t event_idx, const cryptonote::transaction &)
bool check_block_verification_context (const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
bool mark_invalid_block (cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
bool mark_invalid_tx (cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
bool generate_with (std::vector< test_event_entry > &events, const int *out_idx, int mixin, uint64_t amount_paid, bool valid) const
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 > &)

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 35 of file v2_tests.h.

Constructor & Destructor Documentation

◆ gen_v2_tx_validation_base()

gen_v2_tx_validation_base::gen_v2_tx_validation_base ( )
inline

Definition at line 37 of file v2_tests.h.

38 : m_invalid_tx_index(0)
39 , m_invalid_block_index(0)
40 {
43 }
#define REGISTER_CALLBACK_METHOD(CLASS, METHOD)
Definition chaingen.h:830
bool mark_invalid_tx(cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
Definition v2_tests.h:67
bool mark_invalid_block(cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
Definition v2_tests.h:61
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ check_block_verification_context()

bool gen_v2_tx_validation_base::check_block_verification_context ( const cryptonote::block_verification_context & bvc,
size_t event_idx,
const cryptonote::block &  )
inline

Definition at line 53 of file v2_tests.h.

54 {
55 if (m_invalid_block_index == event_idx)
56 return bvc.m_verification_failed;
57 else
58 return !bvc.m_verification_failed;
59 }

◆ check_tx_verification_context()

bool gen_v2_tx_validation_base::check_tx_verification_context ( const cryptonote::tx_verification_context & tvc,
bool tx_added,
size_t event_idx,
const cryptonote::transaction &  )
inline

Definition at line 45 of file v2_tests.h.

46 {
47 if (m_invalid_tx_index == event_idx)
48 return tvc.m_verification_failed;
49 else
50 return !tvc.m_verification_failed && tx_added;
51 }

◆ generate_with()

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

Definition at line 42 of file v2_tests.cpp.

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],
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,
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;
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 }
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}
#define MAKE_GENESIS_BLOCK(VEC_EVENTS, BLK_NAME, MINER_ACC, TS)
Definition chaingen.h:833
#define DO_CALLBACK(VEC_EVENTS, CB_NAME)
Definition chaingen.h:820
#define GENERATE_ACCOUNT(account)
Definition chaingen.h:801
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
Definition account.cpp:158
#define DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
POD_CLASS hash
Definition hash.h:50
bool is_valid_decomposed_amount(uint64_t amount)
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
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)
std::string print_etn(uint64_t amount, unsigned int decimal_point)
unsigned __int64 uint64_t
Definition stdint.h:136
uint64_t amount
account_public_address addr
crypto::public_key real_out_tx_key
uint64_t amount
bool rct
size_t real_output
void push_output(uint64_t idx, const crypto::public_key &k, uint64_t amount)
size_t real_output_in_tx_index
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mark_invalid_block()

bool gen_v2_tx_validation_base::mark_invalid_block ( cryptonote::core & ,
size_t ev_index,
const std::vector< test_event_entry > &  )
inline

Definition at line 61 of file v2_tests.h.

62 {
63 m_invalid_block_index = ev_index + 1;
64 return true;
65 }
Here is the caller graph for this function:

◆ mark_invalid_tx()

bool gen_v2_tx_validation_base::mark_invalid_tx ( cryptonote::core & ,
size_t ev_index,
const std::vector< test_event_entry > &  )
inline

Definition at line 67 of file v2_tests.h.

68 {
69 m_invalid_tx_index = ev_index + 1;
70 return true;
71 }
Here is the caller graph for this function:

The documentation for this struct was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/tests/core_tests/v2_tests.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/tests/core_tests/v2_tests.cpp