diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core_tests/block_validation.cpp | 4 | ||||
-rw-r--r-- | tests/core_tests/chaingen.cpp | 7 | ||||
-rw-r--r-- | tests/core_tests/double_spend.inl | 4 | ||||
-rw-r--r-- | tests/core_tests/integer_overflow.cpp | 8 | ||||
-rw-r--r-- | tests/core_tests/transaction_tests.cpp | 6 | ||||
-rw-r--r-- | tests/functional_tests/transactions_flow_test.cpp | 4 | ||||
-rw-r--r-- | tests/gtest/include/gtest/internal/gtest-port.h | 2 | ||||
-rw-r--r-- | tests/performance_tests/check_ring_signature.h | 2 | ||||
-rw-r--r-- | tests/performance_tests/construct_tx.h | 2 | ||||
-rw-r--r-- | tests/performance_tests/performance_utils.h | 2 | ||||
-rw-r--r-- | tests/unit_tests/test_format_utils.cpp | 132 |
11 files changed, 126 insertions, 47 deletions
diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index 36e769c65..57e147133 100644 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -323,7 +323,7 @@ bool gen_block_miner_tx_has_2_in::generate(std::vector<test_event_entry>& events destinations.push_back(de); transaction tmp_tx; - if (!construct_tx(miner_account.get_keys(), sources, destinations, tmp_tx, 0)) + if (!construct_tx(miner_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tmp_tx, 0)) return false; MAKE_MINER_TX_MANUALLY(miner_tx, blk_0); @@ -365,7 +365,7 @@ bool gen_block_miner_tx_with_txin_to_key::generate(std::vector<test_event_entry> destinations.push_back(de); transaction tmp_tx; - if (!construct_tx(miner_account.get_keys(), sources, destinations, tmp_tx, 0)) + if (!construct_tx(miner_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tmp_tx, 0)) return false; MAKE_MINER_TX_MANUALLY(miner_tx, blk_1); diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index f00323518..124800db7 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -425,9 +425,12 @@ bool fill_tx_sources(std::vector<tx_source_entry>& sources, const std::vector<te ts.amount = oi.amount; ts.real_output_in_tx_index = oi.out_no; ts.real_out_tx_key = get_tx_pub_key_from_extra(*oi.p_tx); // incoming tx public key - if (!fill_output_entries(outs[o.first], sender_out, nmix, ts.real_output, ts.outputs)) + size_t realOutput; + if (!fill_output_entries(outs[o.first], sender_out, nmix, realOutput, ts.outputs)) continue; + ts.real_output = realOutput; + sources.push_back(ts); sources_amount += ts.amount; @@ -528,7 +531,7 @@ bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote vector<tx_destination_entry> destinations; fill_tx_sources_and_destinations(events, blk_head, from, to, amount, fee, nmix, sources, destinations); - return construct_tx(from.get_keys(), sources, destinations, tx, 0); + return construct_tx(from.get_keys(), sources, destinations, std::vector<uint8_t>(), tx, 0); } transaction construct_tx_with_fee(std::vector<test_event_entry>& events, const block& blk_head, diff --git a/tests/core_tests/double_spend.inl b/tests/core_tests/double_spend.inl index 38873a8b4..2d75d994a 100644 --- a/tests/core_tests/double_spend.inl +++ b/tests/core_tests/double_spend.inl @@ -1,4 +1,4 @@ -#pragma once +#pragma once //====================================================================================================================== @@ -113,7 +113,7 @@ bool gen_double_spend_in_tx<txs_keeped_by_block>::generate(std::vector<test_even destinations.push_back(de); cryptonote::transaction tx_1; - if (!construct_tx(bob_account.get_keys(), sources, destinations, tx_1, 0)) + if (!construct_tx(bob_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_1, 0)) return false; SET_EVENT_VISITOR_SETT(events, event_visitor_settings::set_txs_keeped_by_block, txs_keeped_by_block); diff --git a/tests/core_tests/integer_overflow.cpp b/tests/core_tests/integer_overflow.cpp index 82bfb2150..5c619e97c 100644 --- a/tests/core_tests/integer_overflow.cpp +++ b/tests/core_tests/integer_overflow.cpp @@ -72,7 +72,7 @@ bool gen_uint_overflow_base::mark_last_valid_block(cryptonote::core& c, size_t e bool gen_uint_overflow_1::generate(std::vector<test_event_entry>& events) const { - uint64_t ts_start = 1338224400; + uint64_t ts_start = 1338224400; GENERATE_ACCOUNT(miner_account); MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start); @@ -116,7 +116,7 @@ bool gen_uint_overflow_1::generate(std::vector<test_event_entry>& events) const bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const { - uint64_t ts_start = 1338224400; + uint64_t ts_start = 1338224400; GENERATE_ACCOUNT(miner_account); MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start); @@ -148,7 +148,7 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const destinations.push_back(tx_destination_entry(sources.front().amount - MONEY_SUPPLY - MONEY_SUPPLY + 1 - TESTS_DEFAULT_FEE, bob_addr)); cryptonote::transaction tx_1; - if (!construct_tx(miner_account.get_keys(), sources, destinations, tx_1, 0)) + if (!construct_tx(miner_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_1, 0)) return false; events.push_back(tx_1); @@ -174,7 +174,7 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const destinations.push_back(de); cryptonote::transaction tx_2; - if (!construct_tx(bob_account.get_keys(), sources, destinations, tx_2, 0)) + if (!construct_tx(bob_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_2, 0)) return false; events.push_back(tx_2); diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp index 07e6661d8..635c41503 100644 --- a/tests/core_tests/transaction_tests.cpp +++ b/tests/core_tests/transaction_tests.cpp @@ -81,9 +81,7 @@ bool test_transaction_generation_and_ring_signature() oe.second = boost::get<txout_to_key>(tx_mine_6.vout[0].target).key; src.outputs.push_back(oe); - crypto::public_key tx_pub_key = null_pkey; - cryptonote::parse_and_validate_tx_extra(tx_mine_2, tx_pub_key); - src.real_out_tx_key = tx_pub_key; + src.real_out_tx_key = cryptonote::get_tx_pub_key_from_extra(tx_mine_2); src.real_output = 1; src.real_output_in_tx_index = 0; } @@ -95,7 +93,7 @@ bool test_transaction_generation_and_ring_signature() destinations.push_back(td); transaction tx_rc1; - bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, tx_rc1, 0); + bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_rc1, 0); CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction"); crypto::hash pref_hash = get_transaction_prefix_hash(tx_rc1); diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index ce65c8f20..4c6d5b07f 100644 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -52,7 +52,7 @@ bool do_send_money(tools::wallet2& w1, tools::wallet2& w2, size_t mix_in_factor, try { - w1.transfer(dsts, mix_in_factor, 0, DEFAULT_FEE, tools::detail::null_split_strategy, tools::tx_dust_policy(DEFAULT_FEE), tx); + w1.transfer(dsts, mix_in_factor, 0, DEFAULT_FEE, std::vector<uint8_t>(), tools::detail::null_split_strategy, tools::tx_dust_policy(DEFAULT_FEE), tx); return true; } catch (const std::exception&) @@ -144,7 +144,7 @@ bool transactions_flow_test(std::string& working_folder, } //lets make a lot of small outs to ourselves - //since it is not possible to start from transaction that bigger than 20Kb, we gonna make transactions + //since it is not possible to start from transaction that bigger than 20Kb, we gonna make transactions //with 500 outs (about 18kb), and we have to wait appropriate count blocks, mined for test wallet while(true) { diff --git a/tests/gtest/include/gtest/internal/gtest-port.h b/tests/gtest/include/gtest/internal/gtest-port.h index fbf28cd4e..157b47f86 100644 --- a/tests/gtest/include/gtest/internal/gtest-port.h +++ b/tests/gtest/include/gtest/internal/gtest-port.h @@ -204,8 +204,6 @@ #define GTEST_NAME_ "Google Test" #define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/" -#define GTEST_HAS_TR1_TUPLE 0 - // Determines the version of gcc that is used to compile this. #ifdef __GNUC__ // 40302 means version 4.3.2. diff --git a/tests/performance_tests/check_ring_signature.h b/tests/performance_tests/check_ring_signature.h index fc7574f92..dafa172e3 100644 --- a/tests/performance_tests/check_ring_signature.h +++ b/tests/performance_tests/check_ring_signature.h @@ -36,7 +36,7 @@ public: std::vector<tx_destination_entry> destinations; destinations.push_back(tx_destination_entry(this->m_source_amount, m_alice.get_keys().m_account_address)); - if (!construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, m_tx, 0)) + if (!construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, std::vector<uint8_t>(), m_tx, 0)) return false; get_transaction_prefix_hash(m_tx, m_tx_prefix_hash); diff --git a/tests/performance_tests/construct_tx.h b/tests/performance_tests/construct_tx.h index 36507d6f3..1e7005941 100644 --- a/tests/performance_tests/construct_tx.h +++ b/tests/performance_tests/construct_tx.h @@ -42,7 +42,7 @@ public: bool test() { - return cryptonote::construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, m_destinations, m_tx, 0); + return cryptonote::construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, m_destinations, std::vector<uint8_t>(), m_tx, 0); } private: diff --git a/tests/performance_tests/performance_utils.h b/tests/performance_tests/performance_utils.h index fe1e1c7cd..45ca5b27b 100644 --- a/tests/performance_tests/performance_utils.h +++ b/tests/performance_tests/performance_utils.h @@ -14,7 +14,7 @@ void set_process_affinity(int core) { -#if defined(__APPLE__) +#if defined (__APPLE__) return; #elif defined(BOOST_WINDOWS) DWORD_PTR mask = 1; diff --git a/tests/unit_tests/test_format_utils.cpp b/tests/unit_tests/test_format_utils.cpp index dfc05f55a..4dd877591 100644 --- a/tests/unit_tests/test_format_utils.cpp +++ b/tests/unit_tests/test_format_utils.cpp @@ -4,52 +4,132 @@ #include "gtest/gtest.h" +#include <vector> + #include "common/util.h" #include "cryptonote_core/cryptonote_format_utils.h" -TEST(parse_and_validate_tx_extra, is_correct_parse_and_validate_tx_extra) + +TEST(parse_tx_extra, handles_empty_extra) +{ + std::vector<uint8_t> extra;; + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); + ASSERT_TRUE(tx_extra_fields.empty()); +} + +TEST(parse_tx_extra, handles_padding_only_size_1) +{ + const uint8_t extra_arr[] = {0}; + std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); + ASSERT_EQ(1, tx_extra_fields.size()); + ASSERT_EQ(typeid(cryptonote::tx_extra_padding), tx_extra_fields[0].type()); + ASSERT_EQ(1, boost::get<cryptonote::tx_extra_padding>(tx_extra_fields[0]).size); +} + +TEST(parse_tx_extra, handles_padding_only_size_2) +{ + const uint8_t extra_arr[] = {0, 0}; + std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); + ASSERT_EQ(1, tx_extra_fields.size()); + ASSERT_EQ(typeid(cryptonote::tx_extra_padding), tx_extra_fields[0].type()); + ASSERT_EQ(2, boost::get<cryptonote::tx_extra_padding>(tx_extra_fields[0]).size); +} + +TEST(parse_tx_extra, handles_padding_only_max_size) +{ + std::vector<uint8_t> extra(TX_EXTRA_NONCE_MAX_COUNT, 0); + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); + ASSERT_EQ(1, tx_extra_fields.size()); + ASSERT_EQ(typeid(cryptonote::tx_extra_padding), tx_extra_fields[0].type()); + ASSERT_EQ(TX_EXTRA_NONCE_MAX_COUNT, boost::get<cryptonote::tx_extra_padding>(tx_extra_fields[0]).size); +} + +TEST(parse_tx_extra, handles_padding_only_exceed_max_size) +{ + std::vector<uint8_t> extra(TX_EXTRA_NONCE_MAX_COUNT + 1, 0); + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + ASSERT_FALSE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); +} + +TEST(parse_tx_extra, handles_invalid_padding_only) +{ + std::vector<uint8_t> extra(2, 0); + extra[1] = 42; + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + ASSERT_FALSE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); +} + +TEST(parse_tx_extra, handles_pub_key_only) +{ + const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228, + 80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230}; + std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); + ASSERT_EQ(1, tx_extra_fields.size()); + ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type()); +} + +TEST(parse_tx_extra, handles_extra_nonce_only) +{ + const uint8_t extra_arr[] = {2, 1, 42}; + std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); + ASSERT_EQ(1, tx_extra_fields.size()); + ASSERT_EQ(typeid(cryptonote::tx_extra_nonce), tx_extra_fields[0].type()); + cryptonote::tx_extra_nonce extra_nonce = boost::get<cryptonote::tx_extra_nonce>(tx_extra_fields[0]); + ASSERT_EQ(1, extra_nonce.nonce.size()); + ASSERT_EQ(42, extra_nonce.nonce[0]); +} + +TEST(parse_tx_extra, handles_pub_key_and_padding) +{ + const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228, + 80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); + ASSERT_EQ(2, tx_extra_fields.size()); + ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type()); + ASSERT_EQ(typeid(cryptonote::tx_extra_padding), tx_extra_fields[1].type()); +} + +TEST(parse_and_validate_tx_extra, is_valid_tx_extra_parsed) { cryptonote::transaction tx = AUTO_VAL_INIT(tx); cryptonote::account_base acc; acc.generate(); cryptonote::blobdata b = "dsdsdfsdfsf"; - bool r = cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1); - ASSERT_TRUE(r); - crypto::public_key tx_pub_key; - r = cryptonote::parse_and_validate_tx_extra(tx, tx_pub_key); - ASSERT_TRUE(r); + ASSERT_TRUE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1)); + crypto::public_key tx_pub_key = cryptonote::get_tx_pub_key_from_extra(tx); + ASSERT_NE(tx_pub_key, cryptonote::null_pkey); } -TEST(parse_and_validate_tx_extra, is_correct_extranonce_too_big) +TEST(parse_and_validate_tx_extra, fails_on_big_extra_nonce) { cryptonote::transaction tx = AUTO_VAL_INIT(tx); cryptonote::account_base acc; acc.generate(); - cryptonote::blobdata b(260, 0); - bool r = cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1); - ASSERT_FALSE(r); + cryptonote::blobdata b(TX_EXTRA_NONCE_MAX_COUNT + 1, 0); + ASSERT_FALSE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1)); } -TEST(parse_and_validate_tx_extra, is_correct_wrong_extra_couner_too_big) +TEST(parse_and_validate_tx_extra, fails_on_wrong_size_in_extra_nonce) { cryptonote::transaction tx = AUTO_VAL_INIT(tx); tx.extra.resize(20, 0); tx.extra[0] = TX_EXTRA_NONCE; tx.extra[1] = 255; - crypto::public_key tx_pub_key; - bool r = parse_and_validate_tx_extra(tx, tx_pub_key); - ASSERT_FALSE(r); + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + ASSERT_FALSE(cryptonote::parse_tx_extra(tx.extra, tx_extra_fields)); } -TEST(parse_and_validate_tx_extra, is_correct_wrong_extra_nonce_double_entry) -{ - cryptonote::transaction tx = AUTO_VAL_INIT(tx); - tx.extra.resize(20, 0); - cryptonote::blobdata v = "asasdasd"; - cryptonote::add_tx_extra_nonce(tx, v); - cryptonote::add_tx_extra_nonce(tx, v); - crypto::public_key tx_pub_key; - bool r = parse_and_validate_tx_extra(tx, tx_pub_key); - ASSERT_FALSE(r); -} - TEST(validate_parse_amount_case, validate_parse_amount) { uint64_t res = 0; |