1
0
Fork 0
forked from lthn/blockchain

Merge remote-tracking branch 'origin/tests_improvements' into develop

This commit is contained in:
sowle 2025-04-08 23:20:13 +03:00
commit affa0a91ac
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
12 changed files with 49 additions and 46 deletions

View file

@ -1445,8 +1445,8 @@ namespace currency
uint64_t tx_version,
size_t tx_hardfork_id,
uint64_t unlock_time,
uint8_t tx_outs_attr,
bool shuffle)
uint8_t tx_outs_attr /* = CURRENCY_TO_KEY_OUT_RELAXED */,
bool shuffle /* = true */)
{
crypto::secret_key one_time_secret_key{};
return construct_tx(sender_account_keys, sources, destinations, std::vector<extra_v>(), attachments, tx, tx_version, tx_hardfork_id, one_time_secret_key, unlock_time, tx_outs_attr, shuffle);

View file

@ -2013,6 +2013,19 @@ bool construct_tx(const currency::account_keys& sender_account_keys,
);
}
bool construct_tx(const currency::account_keys& sender_account_keys,
const std::vector<currency::tx_source_entry>& sources,
const std::vector<currency::tx_destination_entry>& destinations,
const std::vector<test_event_entry> &events_to_get_hardfork_and_version,
const test_chain_unit_base* p_test_instance,
currency::transaction& result_tx)
{
size_t tx_hardfork_id{};
uint64_t tx_version = p_test_instance->get_tx_version_and_harfork_id_from_events(events_to_get_hardfork_and_version, tx_hardfork_id);
return construct_tx(sender_account_keys, sources, destinations, empty_attachment, result_tx, tx_version, tx_hardfork_id, 0);
}
uint64_t get_balance(const currency::account_keys& addr, const std::vector<currency::block>& blockchain, const map_hash2tx_t& mtx, bool dbg_log)
{
uint64_t res = 0;

View file

@ -727,6 +727,14 @@ bool construct_tx(const currency::account_keys& sender_account_keys,
currency::transaction& tx,
uint64_t tx_version);
bool construct_tx(const currency::account_keys& sender_account_keys,
const std::vector<currency::tx_source_entry>& sources,
const std::vector<currency::tx_destination_entry>& destinations,
const std::vector<test_event_entry> &events_to_get_hardfork_and_version,
const test_chain_unit_base* p_test_instance,
currency::transaction& result_tx);
void get_confirmed_txs(const std::vector<currency::block>& blockchain, const map_hash2tx_t& mtx, map_hash2tx_t& confirmed_txs);
bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<currency::block>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head);

View file

@ -182,8 +182,7 @@ bool pos_emission_test::generate(std::vector<test_event_entry> &events)
destinations.push_back(tx_destination_entry(pos_entry_amount, alice_acc.get_public_address()));
transaction tx_1{};
size_t tx_hardfork_id{};
r = construct_tx(preminer_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(preminer_acc.get_keys(), sources, destinations, events, this, tx_1);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
events.push_back(tx_1);
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_1);

View file

@ -1497,8 +1497,7 @@ bool escrow_custom_test::generate(std::vector<test_event_entry>& events) const
}
// no change back to the miner - it will become a fee
transaction tx_1{};
size_t tx_hardfork_id{};
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(miner_acc.get_keys(), sources, destinations, events, this, tx_1);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
events.push_back(tx_1);
@ -1953,7 +1952,7 @@ bool escrow_incorrect_cancel_proposal::generate(std::vector<test_event_entry>& e
// no change back to the miner - it will become a fee
transaction tx_1 = AUTO_VAL_INIT(tx_1);
size_t tx_hardfork_id{};
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(miner_acc.get_keys(), sources, destinations, events, this, tx_1);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
events.push_back(tx_1);

View file

@ -99,8 +99,7 @@ bool random_outs_and_burnt_coins::generate(std::vector<test_event_entry>& events
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed");
transaction tx_0{};
size_t tx_hardfork_id{};
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(miner_acc.get_keys(), sources, destinations, events, this, tx_0);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
uint64_t burned_tx_amount_total = get_burned_amount(tx_0);

View file

@ -158,9 +158,7 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const
destinations.push_back(tx_destination_entry(sources.front().amount - TX_MAX_TRANSFER_AMOUNT - TX_MAX_TRANSFER_AMOUNT + 1 - TESTS_DEFAULT_FEE, bob_addr));
currency::transaction tx_1{};
std::vector<currency::attachment_v> attachments;
size_t tx_hardfork_id{};
if (!construct_tx(miner_account.get_keys(), sources, destinations, attachments, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0))
if (!construct_tx(miner_account.get_keys(), sources, destinations, events, this, tx_1))
return false;
events.push_back(tx_1);
@ -185,9 +183,8 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const
destinations.push_back(de);
destinations.push_back(de);
currency::transaction tx_2;
std::vector<currency::attachment_v> attachments2;
if (!construct_tx(bob_account.get_keys(), sources, destinations, attachments2, tx_2, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0))
currency::transaction tx_2{};
if (!construct_tx(bob_account.get_keys(), sources, destinations, events, this, tx_2))
return false;
events.push_back(tx_2);

View file

@ -237,9 +237,8 @@ bool block_template_vs_invalid_txs_from_pool::generate(std::vector<test_event_en
std::vector<tx_source_entry> sources;
r = fill_tx_sources(sources, events, blk_0r, miner_acc.get_keys(), de.amount + TESTS_DEFAULT_FEE, 0);
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed");
transaction tx_1m;
size_t tx_hardfork_id{};
r = construct_tx(miner_acc.get_keys(), sources, std::vector<tx_destination_entry>({ de }), empty_attachment, tx_1m, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
transaction tx_1m{};
r = construct_tx(miner_acc.get_keys(), sources, std::vector<tx_destination_entry>({ de }), events, this, tx_1m);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
events.push_back(tx_1m);
@ -272,7 +271,7 @@ bool block_template_vs_invalid_txs_from_pool::generate(std::vector<test_event_en
se.ms_sigs_count = 1;
transaction tx_2m{};
r = construct_tx(bob_acc.get_keys(), std::vector<tx_source_entry>({ se }), std::vector<tx_destination_entry>({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, miner_acc.get_public_address()) }),
empty_attachment, tx_2m, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
events, this, tx_2m);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
bool input_fully_signed = false;
r = sign_multisig_input_in_tx(tx_2m, 0, bob_acc.get_keys(), tx_1m, &input_fully_signed);
@ -281,7 +280,7 @@ bool block_template_vs_invalid_txs_from_pool::generate(std::vector<test_event_en
transaction tx_2ma{};
r = construct_tx(bob_acc.get_keys(), std::vector<tx_source_entry>({ se }), std::vector<tx_destination_entry>({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, miner_acc.get_public_address()) }),
empty_attachment, tx_2ma, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
events, this, tx_2ma);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
input_fully_signed = false;
r = sign_multisig_input_in_tx(tx_2ma, 0, bob_acc.get_keys(), tx_1m, &input_fully_signed);
@ -438,8 +437,7 @@ bool test_blockchain_vs_spent_multisig_outs::generate(std::vector<test_event_ent
sources, destinations, true, true, 1);
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed");
transaction tx_0{};
size_t tx_hardfork_id{};
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(miner_acc.get_keys(), sources, destinations, events, this, tx_0);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
events.push_back(tx_0);
@ -460,7 +458,7 @@ bool test_blockchain_vs_spent_multisig_outs::generate(std::vector<test_event_ent
destinations.clear();
destinations.push_back(tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, miner_acc.get_public_address()));
transaction tx_1{};
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(miner_acc.get_keys(), sources, destinations, events, this, tx_1);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
bool is_fully_signed = false;
r = sign_multisig_input_in_tx(tx_1, 0, miner_acc.get_keys(), tx_0, &is_fully_signed);

View file

@ -498,9 +498,7 @@ bool assets_and_explicit_native_coins_in_outs::generate(std::vector<test_event_e
std::vector<tx_destination_entry> destinations;
r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc, alice_acc, m_alice_initial_balance, TESTS_DEFAULT_FEE, 0, sources, destinations, true /* spends */, false /* unlock time */);
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed");
size_t tx_hardfork_id{};
uint64_t tx_version = get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id);
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, tx_version, tx_hardfork_id, 0);
r = construct_tx(miner_acc.get_keys(), sources, destinations, events, this, tx_0);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
ADD_CUSTOM_EVENT(events, tx_0);
@ -706,9 +704,7 @@ bool asset_depoyment_and_few_zc_utxos::generate(std::vector<test_event_entry>& e
m_alice_initial_balance = TESTS_DEFAULT_FEE * 100;
r = fill_tx_sources(sources, events, blk_0r, miner_acc.get_keys(), m_alice_initial_balance + TESTS_DEFAULT_FEE, 0);
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed");
size_t tx_hardfork_id{};
uint64_t tx_version = get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id);
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, tx_version, tx_hardfork_id, 0);
r = construct_tx(miner_acc.get_keys(), sources, destinations, events, this, tx_0);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
ADD_CUSTOM_EVENT(events, tx_0);

View file

@ -174,8 +174,7 @@ bool pos_mining_with_decoys::generate(std::vector<test_event_entry>& events) con
destinations.emplace_back(COIN, carol_acc.get_public_address());
transaction tx_0{};
size_t tx_hardfork_id{};
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(miner_acc.get_keys(), sources, destinations, events, this, tx_0);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
events.push_back(tx_0);
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0);

View file

@ -1240,8 +1240,7 @@ bool tx_expiration_time::generate(std::vector<test_event_entry>& events) const
r = fill_tx_sources_and_destinations(events, blk_2, alice_acc.get_keys(), bob_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations);
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed");
transaction tx_2{};
size_t tx_hardfork_id{};
r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_2, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(alice_acc.get_keys(), sources, destinations, events, this, tx_2);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
set_tx_expiration_time(tx_2, ts_median + TX_EXPIRATION_MEDIAN_SHIFT + 1); // one second greather than minimum allowed
r = resign_tx(alice_acc.get_keys(), sources, tx_2);
@ -1258,8 +1257,8 @@ bool tx_expiration_time::generate(std::vector<test_event_entry>& events) const
destinations.clear();
r = fill_tx_sources_and_destinations(events, blk_3, alice_acc.get_keys(), bob_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations);
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed");
transaction tx_3 = AUTO_VAL_INIT(tx_3);
r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_3, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
transaction tx_3{};
r = construct_tx(alice_acc.get_keys(), sources, destinations, events, this, tx_3);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
set_tx_expiration_time(tx_3, ts_median + TX_EXPIRATION_MEDIAN_SHIFT + 0); // exact expiration time, should not pass (see core condition above)
r = resign_tx(alice_acc.get_keys(), sources, tx_3);
@ -1324,8 +1323,7 @@ bool tx_expiration_time_and_block_template::generate(std::vector<test_event_entr
bool r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc.get_keys(), miner_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations);
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed");
transaction tx_1{};
size_t tx_hardfork_id{};
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(miner_acc.get_keys(), sources, destinations, events, this, tx_1);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
uint64_t tx_1_expiration_time = ts_median + TX_EXPIRATION_MEDIAN_SHIFT + 1; // one second greather than minimum allowed
set_tx_expiration_time(tx_1, tx_1_expiration_time);
@ -1397,8 +1395,7 @@ bool tx_expiration_time_and_chain_switching::generate(std::vector<test_event_ent
r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc.get_keys(), miner_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations);
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed");
transaction tx_0{};
size_t tx_hardfork_id{};
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(miner_acc.get_keys(), sources, destinations, events, this, tx_0);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
uint64_t tx_0_expiration_time = ts_median + TX_EXPIRATION_MEDIAN_SHIFT + 0; // one second less than minimum allowed (see condition above)
set_tx_expiration_time(tx_0, tx_0_expiration_time);
@ -1519,8 +1516,7 @@ bool tx_key_image_pool_conflict::generate(std::vector<test_event_entry>& events)
r = fill_tx_sources_and_destinations(events, blk_0r, m_miner_acc.get_keys(), bob_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations);
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed");
transaction tx_0{};
size_t tx_hardfork_id{};
r = construct_tx(m_miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0);
r = construct_tx(m_miner_acc.get_keys(), sources, destinations, events, this, tx_0);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
LOG_PRINT_YELLOW("tx_0 = " << get_transaction_hash(tx_0), LOG_LEVEL_0);
// do not push tx_0 into events yet

View file

@ -520,8 +520,7 @@ bool zarcanum_txs_with_big_shuffled_decoy_set_shuffled::generate(std::vector<tes
CHECK_AND_ASSERT_MES(shuffle_source_entries(sources), false, "shuffle_source_entries failed");
transaction tx_1_a{};
size_t tx_hardfork_id{};
r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_1_a, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0 /* unlock time */);
r = construct_tx(alice_acc.get_keys(), sources, destinations, events, this, tx_1_a);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
ADD_CUSTOM_EVENT(events, tx_1_a);
MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1r, miner_acc, tx_1_a);
@ -533,7 +532,7 @@ bool zarcanum_txs_with_big_shuffled_decoy_set_shuffled::generate(std::vector<tes
CHECK_AND_ASSERT_MES(fill_tx_sources_and_destinations(events, blk_2, alice_acc, miner_acc, alice_amount - TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, nmix, sources, destinations), false, "");
CHECK_AND_ASSERT_MES(shuffle_source_entries(sources), false, "shuffle_source_entries failed");
transaction tx_1_b{};
r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_1_b, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0 /* unlock time */);
r = construct_tx(alice_acc.get_keys(), sources, destinations, events, this, tx_1_b);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
ADD_CUSTOM_EVENT(events, tx_1_b);
MAKE_NEXT_BLOCK_TX1(events, blk_3, blk_2, miner_acc, tx_1_b);
@ -572,7 +571,7 @@ bool zarcanum_txs_with_big_shuffled_decoy_set_shuffled::generate(std::vector<tes
CHECK_AND_ASSERT_MES(fill_tx_sources_and_destinations(events, blk_5r, alice_acc, miner_acc, alice_amount - TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, nmix, sources, destinations), false, "");
CHECK_AND_ASSERT_MES(shuffle_source_entries(sources), false, "shuffle_source_entries failed");
transaction tx_3_a{};
r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_3_a, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0 /* unlock time */);
r = construct_tx(alice_acc.get_keys(), sources, destinations, events, this, tx_3_a);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
ADD_CUSTOM_EVENT(events, tx_3_a);
MAKE_NEXT_BLOCK_TX1(events, blk_6, blk_5r, miner_acc, tx_3_a);
@ -584,7 +583,7 @@ bool zarcanum_txs_with_big_shuffled_decoy_set_shuffled::generate(std::vector<tes
CHECK_AND_ASSERT_MES(fill_tx_sources_and_destinations(events, blk_6, alice_acc, miner_acc, alice_amount - TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, nmix, sources, destinations), false, "");
CHECK_AND_ASSERT_MES(shuffle_source_entries(sources), false, "shuffle_source_entries failed");
transaction tx_3_b{};
r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_3_b, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0 /* unlock time */);
r = construct_tx(alice_acc.get_keys(), sources, destinations, events, this, tx_3_b);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
ADD_CUSTOM_EVENT(events, tx_3_b);
MAKE_NEXT_BLOCK_TX1(events, blk_7, blk_6, miner_acc, tx_3_b);