forked from lthn/blockchain
Merge branch 'develop' into secp256k1
This commit is contained in:
commit
65af445ebb
6 changed files with 130 additions and 9 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 2fb143cc67280f0e0cfcd3165e1c087ba8279edf
|
||||
Subproject commit 748e8e96d8f2653e6e698a11f67c172c1f84c2b2
|
||||
|
|
@ -8,6 +8,6 @@
|
|||
#define PROJECT_REVISION "0"
|
||||
#define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION
|
||||
|
||||
#define PROJECT_VERSION_BUILD_NO 335
|
||||
#define PROJECT_VERSION_BUILD_NO 336
|
||||
#define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO)
|
||||
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"
|
||||
|
|
|
|||
|
|
@ -1217,6 +1217,7 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(tx_expiration_time_and_block_template);
|
||||
GENERATE_AND_PLAY(tx_expiration_time_and_chain_switching);
|
||||
GENERATE_AND_PLAY(tx_key_image_pool_conflict);
|
||||
//GENERATE_AND_PLAY_HF(tx_version_against_hardfork, "4-*");
|
||||
|
||||
// Double spend
|
||||
GENERATE_AND_PLAY(gen_double_spend_in_tx<false>);
|
||||
|
|
|
|||
|
|
@ -1620,3 +1620,84 @@ bool tx_key_image_pool_conflict::generate(std::vector<test_event_entry>& events)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
bool tx_version_against_hardfork::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
// Test idea: make sure that tx with incorrect for the activated HF version won't be accepted.
|
||||
|
||||
bool r = false;
|
||||
GENERATE_ACCOUNT(miner_acc);
|
||||
|
||||
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time());
|
||||
DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks
|
||||
REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
|
||||
// 0 ... 10 11 12 13 14 <- height
|
||||
// (0 )- (0r)- (1 )- !2b!- <- chain A, block 2b is invalid
|
||||
// tx_0 tx_1 tx_0 is accepted, tx_1 is rejected
|
||||
// \
|
||||
// \(2 ) <- chain B
|
||||
// tx_1 tx_1 is accepted
|
||||
|
||||
uint64_t tx_version_good = 0, tx_version_bad = 0;
|
||||
|
||||
// select good and bad tx versions based on active hardfork
|
||||
size_t most_recent_hardfork_id = m_hardforks.get_the_most_recent_hardfork_id_for_height(get_block_height(blk_0r));
|
||||
switch(most_recent_hardfork_id)
|
||||
{
|
||||
case ZANO_HARDFORK_04_ZARCANUM:
|
||||
case ZANO_HARDFORK_05:
|
||||
tx_version_good = TRANSACTION_VERSION_POST_HF4;
|
||||
tx_version_bad = TRANSACTION_VERSION_PRE_HF4;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("hardfork " << most_recent_hardfork_id << " is not supported by this test");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<tx_source_entry> sources;
|
||||
std::vector<tx_destination_entry> destinations;
|
||||
|
||||
//
|
||||
// 1/2 tx with good version, should go okay
|
||||
//
|
||||
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{};
|
||||
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, tx_version_good, 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);
|
||||
|
||||
sources.clear();
|
||||
destinations.clear();
|
||||
|
||||
//
|
||||
// 2/2 tx with bad version, should be rejected by tx pool and by the core
|
||||
//
|
||||
r = fill_tx_sources_and_destinations(events, blk_0, 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{};
|
||||
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, tx_version_bad, 0);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
|
||||
// check tx pool rejection
|
||||
DO_CALLBACK(events, "mark_invalid_tx");
|
||||
events.push_back(tx_1);
|
||||
|
||||
// now add tx_1 as onboard transaction (directly to a block, skipping tx pool)
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true));
|
||||
events.push_back(tx_1);
|
||||
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
|
||||
|
||||
// make sure the block with tx_1 is invalid
|
||||
DO_CALLBACK(events, "mark_invalid_block");
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_2b, blk_1, miner_acc, tx_1);
|
||||
|
||||
|
||||
// just one more block to make sure everyting is okay
|
||||
MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,3 +155,8 @@ struct tx_key_image_pool_conflict : public test_chain_unit_enchanced
|
|||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
mutable currency::account_base m_miner_acc;
|
||||
};
|
||||
|
||||
struct tx_version_against_hardfork : public test_chain_unit_enchanced
|
||||
{
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -26,14 +26,20 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
#define TEST_pos(int_type, expected, str) \
|
||||
TEST(get_xtype_from_string, handles_pos_ ## int_type ## _ ## expected) \
|
||||
{ \
|
||||
do_pos_test<int_type>(expected, str); \
|
||||
}
|
||||
#define MAKE_TEST_NAME(prefix, int_type, ln, test_type) \
|
||||
test_type ## _ ## prefix ## _ ## int_type ## _ ## ln
|
||||
|
||||
#define DO_MAKE_NEG_TEST_NAME(prefix, int_type, ln) prefix ## int_type ## _ ## ln
|
||||
#define MAKE_NEG_TEST_NAME(prefix, int_type, ln) DO_MAKE_NEG_TEST_NAME(prefix, int_type, ln)
|
||||
#define MAKE_POS_TEST_NAME(prefix, int_type, ln) \
|
||||
MAKE_TEST_NAME(prefix, int_type, ln, POS)
|
||||
|
||||
#define MAKE_NEG_TEST_NAME(prefix, int_type, ln) \
|
||||
MAKE_TEST_NAME(prefix, int_type, ln, NEG)
|
||||
|
||||
#define TEST_pos(int_type, expected, str) \
|
||||
TEST(get_xtype_from_string, MAKE_POS_TEST_NAME(handles_pos, int_type, __LINE__)) \
|
||||
{ \
|
||||
do_pos_test<int_type>(expected, str); \
|
||||
}
|
||||
|
||||
#define TEST_neg(int_type, str) \
|
||||
TEST(get_xtype_from_string, MAKE_NEG_TEST_NAME(handles_neg, int_type, __LINE__)) \
|
||||
|
|
@ -134,3 +140,31 @@ TEST_neg(uint64_t, "1w1");
|
|||
TEST_neg(uint64_t, "18446744073709551615w");
|
||||
|
||||
TEST_neg(uint64_t, "18446744073709551616");
|
||||
|
||||
TEST_pos(int16_t, 32'767, "32767"); // 2^15 - 1
|
||||
TEST_pos(int16_t, -32'768, "-32768"); // -2^15
|
||||
TEST_pos(int16_t, 0, "-0");
|
||||
TEST_pos(int16_t, 0, "+0");
|
||||
|
||||
TEST_neg(int16_t, "32768"); // 2^15
|
||||
TEST_neg(int16_t, "+32768"); // 2^15
|
||||
TEST_neg(int16_t, "-32769"); // -2^15 - 1
|
||||
TEST_neg(int16_t, "");
|
||||
|
||||
TEST_pos(int32_t, 2'147'483'647, "2147483647"); // 2^31 - 1
|
||||
TEST_pos(int32_t, -2'147'483'648, "-2147483648"); // -2^31
|
||||
TEST_pos(int32_t, 0, "-0");
|
||||
TEST_pos(int32_t, 0, "+0");
|
||||
|
||||
TEST_neg(int32_t, "-2147483649");
|
||||
TEST_neg(int32_t, "2147483648");
|
||||
TEST_neg(int32_t, "");
|
||||
|
||||
TEST_pos(int64_t, 9'223'372'036'854'775'807LL, "9223372036854775807"); // 2^63 - 1
|
||||
TEST_pos(int64_t, -9'223'372'036'854'775'807LL - 1LL, "-9223372036854775808"); // -2^63
|
||||
TEST_pos(int64_t, 0LL, "-0");
|
||||
TEST_pos(int64_t, 0LL, "+0");
|
||||
|
||||
TEST_neg(int64_t, "-9223372036854775809"); // -2^63 - 1
|
||||
TEST_neg(int64_t, "9223372036854775808"); // 2^63
|
||||
TEST_neg(int64_t, "");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue