From 8027ce0c75f882de0523e668defa0bc3c8564e96 Mon Sep 17 00:00:00 2001 From: kenshi84 Date: Fri, 27 Jan 2017 00:07:23 +0900 Subject: extract some basic code from libcryptonote_core into libcryptonote_basic --- tests/unit_tests/CMakeLists.txt | 2 +- tests/unit_tests/base58.cpp | 2 +- tests/unit_tests/block_reward.cpp | 2 +- tests/unit_tests/blockchain_db.cpp | 2 +- tests/unit_tests/canonical_amounts.cpp | 2 +- tests/unit_tests/checkpoints.cpp | 2 +- tests/unit_tests/decompose_amount_into_digits.cpp | 2 +- tests/unit_tests/hardfork.cpp | 2 +- tests/unit_tests/parse_amount.cpp | 2 +- tests/unit_tests/serialization.cpp | 4 +- tests/unit_tests/test_format_utils.cpp | 205 ---------------------- tests/unit_tests/test_tx_utils.cpp | 205 ++++++++++++++++++++++ tests/unit_tests/varint.cpp | 4 +- 13 files changed, 218 insertions(+), 218 deletions(-) delete mode 100644 tests/unit_tests/test_format_utils.cpp create mode 100644 tests/unit_tests/test_tx_utils.cpp (limited to 'tests/unit_tests') diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index 08c8213e4..5db4e2ad5 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -49,7 +49,7 @@ set(unit_tests_sources parse_amount.cpp serialization.cpp slow_memmem.cpp - test_format_utils.cpp + test_tx_utils.cpp test_peerlist.cpp test_protocol_pack.cpp thread_group.cpp diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp index 53f7f2673..d2c767956 100644 --- a/tests/unit_tests/base58.cpp +++ b/tests/unit_tests/base58.cpp @@ -33,7 +33,7 @@ #include #include "common/base58.cpp" -#include "cryptonote_core/cryptonote_basic_impl.h" +#include "cryptonote_basic/cryptonote_basic_impl.h" #include "serialization/binary_utils.h" using namespace tools; diff --git a/tests/unit_tests/block_reward.cpp b/tests/unit_tests/block_reward.cpp index 5d93c3084..f8a944770 100644 --- a/tests/unit_tests/block_reward.cpp +++ b/tests/unit_tests/block_reward.cpp @@ -30,7 +30,7 @@ #include "gtest/gtest.h" -#include "cryptonote_core/cryptonote_basic_impl.h" +#include "cryptonote_basic/cryptonote_basic_impl.h" using namespace cryptonote; diff --git a/tests/unit_tests/blockchain_db.cpp b/tests/unit_tests/blockchain_db.cpp index 127a15b44..8fc10be10 100644 --- a/tests/unit_tests/blockchain_db.cpp +++ b/tests/unit_tests/blockchain_db.cpp @@ -40,7 +40,7 @@ #ifdef BERKELEY_DB #include "blockchain_db/berkeleydb/db_bdb.h" #endif -#include "cryptonote_core/cryptonote_format_utils.h" +#include "cryptonote_basic/cryptonote_format_utils.h" using namespace cryptonote; using epee::string_tools::pod_to_hex; diff --git a/tests/unit_tests/canonical_amounts.cpp b/tests/unit_tests/canonical_amounts.cpp index 9bef58d4b..c5a27d47d 100644 --- a/tests/unit_tests/canonical_amounts.cpp +++ b/tests/unit_tests/canonical_amounts.cpp @@ -29,7 +29,7 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "gtest/gtest.h" -#include "cryptonote_core/cryptonote_format_utils.h" +#include "cryptonote_basic/cryptonote_format_utils.h" static const uint64_t valid_decomposed_outputs[] = { (uint64_t)1, (uint64_t)2, (uint64_t)3, (uint64_t)4, (uint64_t)5, (uint64_t)6, (uint64_t)7, (uint64_t)8, (uint64_t)9, // 1 piconero diff --git a/tests/unit_tests/checkpoints.cpp b/tests/unit_tests/checkpoints.cpp index b1d251d26..bc18c2b9e 100644 --- a/tests/unit_tests/checkpoints.cpp +++ b/tests/unit_tests/checkpoints.cpp @@ -30,7 +30,7 @@ #include "gtest/gtest.h" -#include "cryptonote_core/checkpoints.cpp" +#include "cryptonote_basic/checkpoints.cpp" using namespace cryptonote; diff --git a/tests/unit_tests/decompose_amount_into_digits.cpp b/tests/unit_tests/decompose_amount_into_digits.cpp index e40208113..b1fa79aa1 100644 --- a/tests/unit_tests/decompose_amount_into_digits.cpp +++ b/tests/unit_tests/decompose_amount_into_digits.cpp @@ -33,7 +33,7 @@ #include #include -#include "cryptonote_core/cryptonote_format_utils.h" +#include "cryptonote_basic/cryptonote_format_utils.h" #define VEC_FROM_ARR(vec) \ std::vector vec; \ diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp index 2682f15d3..81cf32c8b 100644 --- a/tests/unit_tests/hardfork.cpp +++ b/tests/unit_tests/hardfork.cpp @@ -32,7 +32,7 @@ #include "gtest/gtest.h" #include "blockchain_db/lmdb/db_lmdb.h" -#include "cryptonote_core/hardfork.h" +#include "cryptonote_basic/hardfork.h" using namespace cryptonote; diff --git a/tests/unit_tests/parse_amount.cpp b/tests/unit_tests/parse_amount.cpp index 6c61d63f1..23e7eb292 100644 --- a/tests/unit_tests/parse_amount.cpp +++ b/tests/unit_tests/parse_amount.cpp @@ -30,7 +30,7 @@ #include "gtest/gtest.h" -#include "cryptonote_core/cryptonote_format_utils.h" +#include "cryptonote_basic/cryptonote_format_utils.h" using namespace cryptonote; diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp index 1083dd4cc..5b8486a19 100644 --- a/tests/unit_tests/serialization.cpp +++ b/tests/unit_tests/serialization.cpp @@ -35,8 +35,8 @@ #include #include #include -#include "cryptonote_core/cryptonote_basic.h" -#include "cryptonote_core/cryptonote_basic_impl.h" +#include "cryptonote_basic/cryptonote_basic.h" +#include "cryptonote_basic/cryptonote_basic_impl.h" #include "ringct/rctSigs.h" #include "serialization/serialization.h" #include "serialization/binary_archive.h" diff --git a/tests/unit_tests/test_format_utils.cpp b/tests/unit_tests/test_format_utils.cpp deleted file mode 100644 index 463d62529..000000000 --- a/tests/unit_tests/test_format_utils.cpp +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright (c) 2014-2016, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be -// used to endorse or promote products derived from this software without specific -// prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers - -#include "gtest/gtest.h" - -#include - -#include "common/util.h" -#include "cryptonote_core/cryptonote_format_utils.h" - -namespace -{ - uint64_t const TEST_FEE = 5000000000; // 5 * 10^9 -} - -TEST(parse_tx_extra, handles_empty_extra) -{ - std::vector extra;; - std::vector 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 extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); - std::vector 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(tx_extra_fields[0]).size); -} - -TEST(parse_tx_extra, handles_padding_only_size_2) -{ - const uint8_t extra_arr[] = {0, 0}; - std::vector extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); - std::vector 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(tx_extra_fields[0]).size); -} - -TEST(parse_tx_extra, handles_padding_only_max_size) -{ - std::vector extra(TX_EXTRA_NONCE_MAX_COUNT, 0); - std::vector 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(tx_extra_fields[0]).size); -} - -TEST(parse_tx_extra, handles_padding_only_exceed_max_size) -{ - std::vector extra(TX_EXTRA_NONCE_MAX_COUNT + 1, 0); - std::vector tx_extra_fields; - ASSERT_FALSE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); -} - -TEST(parse_tx_extra, handles_invalid_padding_only) -{ - std::vector extra(2, 0); - extra[1] = 42; - std::vector 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 extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); - std::vector 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 extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); - std::vector 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(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 extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); - std::vector 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"; - ASSERT_TRUE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_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, fails_on_big_extra_nonce) -{ - cryptonote::transaction tx = AUTO_VAL_INIT(tx); - cryptonote::account_base acc; - acc.generate(); - cryptonote::blobdata b(TX_EXTRA_NONCE_MAX_COUNT + 1, 0); - ASSERT_FALSE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1)); -} -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; - std::vector tx_extra_fields; - ASSERT_FALSE(cryptonote::parse_tx_extra(tx.extra, tx_extra_fields)); -} -TEST(validate_parse_amount_case, validate_parse_amount) -{ - uint64_t res = 0; - bool r = cryptonote::parse_amount(res, "0.0001"); - ASSERT_TRUE(r); - ASSERT_EQ(res, 100000000); - - r = cryptonote::parse_amount(res, "100.0001"); - ASSERT_TRUE(r); - ASSERT_EQ(res, 100000100000000); - - r = cryptonote::parse_amount(res, "000.0000"); - ASSERT_TRUE(r); - ASSERT_EQ(res, 0); - - r = cryptonote::parse_amount(res, "0"); - ASSERT_TRUE(r); - ASSERT_EQ(res, 0); - - - r = cryptonote::parse_amount(res, " 100.0001 "); - ASSERT_TRUE(r); - ASSERT_EQ(res, 100000100000000); - - r = cryptonote::parse_amount(res, " 100.0000 "); - ASSERT_TRUE(r); - ASSERT_EQ(res, 100000000000000); - - r = cryptonote::parse_amount(res, " 100. 0000 "); - ASSERT_FALSE(r); - - r = cryptonote::parse_amount(res, "100. 0000"); - ASSERT_FALSE(r); - - r = cryptonote::parse_amount(res, "100 . 0000"); - ASSERT_FALSE(r); - - r = cryptonote::parse_amount(res, "100.00 00"); - ASSERT_FALSE(r); - - r = cryptonote::parse_amount(res, "1 00.00 00"); - ASSERT_FALSE(r); -} diff --git a/tests/unit_tests/test_tx_utils.cpp b/tests/unit_tests/test_tx_utils.cpp new file mode 100644 index 000000000..91d5d5d67 --- /dev/null +++ b/tests/unit_tests/test_tx_utils.cpp @@ -0,0 +1,205 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#include "gtest/gtest.h" + +#include + +#include "common/util.h" +#include "cryptonote_core/cryptonote_tx_utils.h" + +namespace +{ + uint64_t const TEST_FEE = 5000000000; // 5 * 10^9 +} + +TEST(parse_tx_extra, handles_empty_extra) +{ + std::vector extra;; + std::vector 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 extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); + std::vector 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(tx_extra_fields[0]).size); +} + +TEST(parse_tx_extra, handles_padding_only_size_2) +{ + const uint8_t extra_arr[] = {0, 0}; + std::vector extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); + std::vector 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(tx_extra_fields[0]).size); +} + +TEST(parse_tx_extra, handles_padding_only_max_size) +{ + std::vector extra(TX_EXTRA_NONCE_MAX_COUNT, 0); + std::vector 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(tx_extra_fields[0]).size); +} + +TEST(parse_tx_extra, handles_padding_only_exceed_max_size) +{ + std::vector extra(TX_EXTRA_NONCE_MAX_COUNT + 1, 0); + std::vector tx_extra_fields; + ASSERT_FALSE(cryptonote::parse_tx_extra(extra, tx_extra_fields)); +} + +TEST(parse_tx_extra, handles_invalid_padding_only) +{ + std::vector extra(2, 0); + extra[1] = 42; + std::vector 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 extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); + std::vector 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 extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); + std::vector 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(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 extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr)); + std::vector 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"; + ASSERT_TRUE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_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, fails_on_big_extra_nonce) +{ + cryptonote::transaction tx = AUTO_VAL_INIT(tx); + cryptonote::account_base acc; + acc.generate(); + cryptonote::blobdata b(TX_EXTRA_NONCE_MAX_COUNT + 1, 0); + ASSERT_FALSE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1)); +} +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; + std::vector tx_extra_fields; + ASSERT_FALSE(cryptonote::parse_tx_extra(tx.extra, tx_extra_fields)); +} +TEST(validate_parse_amount_case, validate_parse_amount) +{ + uint64_t res = 0; + bool r = cryptonote::parse_amount(res, "0.0001"); + ASSERT_TRUE(r); + ASSERT_EQ(res, 100000000); + + r = cryptonote::parse_amount(res, "100.0001"); + ASSERT_TRUE(r); + ASSERT_EQ(res, 100000100000000); + + r = cryptonote::parse_amount(res, "000.0000"); + ASSERT_TRUE(r); + ASSERT_EQ(res, 0); + + r = cryptonote::parse_amount(res, "0"); + ASSERT_TRUE(r); + ASSERT_EQ(res, 0); + + + r = cryptonote::parse_amount(res, " 100.0001 "); + ASSERT_TRUE(r); + ASSERT_EQ(res, 100000100000000); + + r = cryptonote::parse_amount(res, " 100.0000 "); + ASSERT_TRUE(r); + ASSERT_EQ(res, 100000000000000); + + r = cryptonote::parse_amount(res, " 100. 0000 "); + ASSERT_FALSE(r); + + r = cryptonote::parse_amount(res, "100. 0000"); + ASSERT_FALSE(r); + + r = cryptonote::parse_amount(res, "100 . 0000"); + ASSERT_FALSE(r); + + r = cryptonote::parse_amount(res, "100.00 00"); + ASSERT_FALSE(r); + + r = cryptonote::parse_amount(res, "1 00.00 00"); + ASSERT_FALSE(r); +} diff --git a/tests/unit_tests/varint.cpp b/tests/unit_tests/varint.cpp index a483cbd5f..a87eeb14b 100644 --- a/tests/unit_tests/varint.cpp +++ b/tests/unit_tests/varint.cpp @@ -34,8 +34,8 @@ #include #include #include -#include "cryptonote_core/cryptonote_basic.h" -#include "cryptonote_core/cryptonote_basic_impl.h" +#include "cryptonote_basic/cryptonote_basic.h" +#include "cryptonote_basic/cryptonote_basic_impl.h" #include "serialization/serialization.h" #include "serialization/binary_archive.h" #include "serialization/json_archive.h" -- cgit v1.2.3