diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/difficulty/difficulty.cpp | 1 | ||||
-rw-r--r-- | tests/functional_tests/transactions_flow_test.cpp | 16 | ||||
-rw-r--r-- | tests/fuzz/fuzzer.cpp | 4 | ||||
-rw-r--r-- | tests/unit_tests/epee_utils.cpp | 57 | ||||
-rw-r--r-- | tests/unit_tests/multisig.cpp | 2 | ||||
-rw-r--r-- | tests/unit_tests/ringdb.cpp | 8 | ||||
-rw-r--r-- | tests/unit_tests/wipeable_string.cpp | 7 |
7 files changed, 81 insertions, 14 deletions
diff --git a/tests/difficulty/difficulty.cpp b/tests/difficulty/difficulty.cpp index 736a58237..996913a19 100644 --- a/tests/difficulty/difficulty.cpp +++ b/tests/difficulty/difficulty.cpp @@ -34,6 +34,7 @@ #include <iostream> #include <vector> #include <algorithm> +#include <stdexcept> #include "cryptonote_config.h" #include "cryptonote_basic/difficulty.h" diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index 7248efade..ffe500d21 100644 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -84,10 +84,10 @@ bool do_send_money(tools::wallet2& w1, tools::wallet2& w2, size_t mix_in_factor, try { - tools::wallet2::pending_tx ptx; - std::vector<size_t> indices = w1.select_available_outputs([](const tools::wallet2::transfer_details&) { return true; }); - w1.transfer(dsts, mix_in_factor, indices, 0, TEST_FEE, std::vector<uint8_t>(), tools::detail::null_split_strategy, tools::tx_dust_policy(TEST_DUST_THRESHOLD), tx, ptx); - w1.commit_tx(ptx); + std::vector<tools::wallet2::pending_tx> ptx; + ptx = w1.create_transactions_2(dsts, mix_in_factor, 0, 0, std::vector<uint8_t>(), 0, {}); + for (auto &p: ptx) + w1.commit_tx(p); return true; } catch (const std::exception&) @@ -138,7 +138,7 @@ bool transactions_flow_test(std::string& working_folder, return false; } - w1.init(true, daemon_addr_a); + w1.init(daemon_addr_a); uint64_t blocks_fetched = 0; bool received_money; @@ -149,7 +149,7 @@ bool transactions_flow_test(std::string& working_folder, return false; } - w2.init(true, daemon_addr_b); + w2.init(daemon_addr_b); MGINFO_GREEN("Using wallets: " << ENDL << "Source: " << w1.get_account().get_public_address_str(MAINNET) << ENDL << "Path: " << working_folder + "/" + path_source_wallet << ENDL @@ -167,8 +167,8 @@ bool transactions_flow_test(std::string& working_folder, daemon_req.miner_address = w1.get_account().get_public_address_str(MAINNET); daemon_req.threads_count = 9; r = net_utils::invoke_http_json("/start_mining", daemon_req, daemon_rsp, http_client, std::chrono::seconds(10)); - CHECK_AND_ASSERT_MES(r, false, "failed to get getrandom_outs"); - CHECK_AND_ASSERT_MES(daemon_rsp.status == CORE_RPC_STATUS_OK, false, "failed to getrandom_outs.bin"); + CHECK_AND_ASSERT_MES(r, false, "failed to start mining getrandom_outs"); + CHECK_AND_ASSERT_MES(daemon_rsp.status == CORE_RPC_STATUS_OK, false, "failed to start mining"); //wait for money, until balance will have enough money w1.refresh(true, blocks_fetched, received_money, ok); diff --git a/tests/fuzz/fuzzer.cpp b/tests/fuzz/fuzzer.cpp index b81bf80fe..032ff049a 100644 --- a/tests/fuzz/fuzzer.cpp +++ b/tests/fuzz/fuzzer.cpp @@ -52,6 +52,10 @@ int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer) return 1; } +#ifdef __AFL_HAVE_MANUAL_CONTROL + __AFL_INIT(); +#endif + int ret = fuzzer.init(); if (ret) return ret; diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index 3474000d8..c2b0b7647 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -166,12 +166,17 @@ TEST(Span, Traits) TEST(Span, MutableConstruction) { struct no_conversion{}; + struct inherited : no_conversion {}; EXPECT_TRUE(std::is_constructible<epee::span<char>>()); EXPECT_TRUE((std::is_constructible<epee::span<char>, char*, std::size_t>())); EXPECT_FALSE((std::is_constructible<epee::span<char>, const char*, std::size_t>())); EXPECT_FALSE((std::is_constructible<epee::span<char>, unsigned char*, std::size_t>())); + EXPECT_TRUE(std::is_constructible<epee::span<no_conversion>>()); + EXPECT_TRUE((std::is_constructible<epee::span<no_conversion>, no_conversion*, std::size_t>())); + EXPECT_FALSE((std::is_constructible<epee::span<no_conversion>, inherited*, std::size_t>())); + EXPECT_TRUE((can_construct<epee::span<char>, std::nullptr_t>())); EXPECT_TRUE((can_construct<epee::span<char>, char(&)[1]>())); @@ -193,12 +198,19 @@ TEST(Span, MutableConstruction) TEST(Span, ImmutableConstruction) { struct no_conversion{}; + struct inherited : no_conversion {}; EXPECT_TRUE(std::is_constructible<epee::span<const char>>()); EXPECT_TRUE((std::is_constructible<epee::span<const char>, char*, std::size_t>())); EXPECT_TRUE((std::is_constructible<epee::span<const char>, const char*, std::size_t>())); EXPECT_FALSE((std::is_constructible<epee::span<const char>, unsigned char*, std::size_t>())); + EXPECT_TRUE(std::is_constructible<epee::span<const no_conversion>>()); + EXPECT_TRUE((std::is_constructible<epee::span<const no_conversion>, const no_conversion*, std::size_t>())); + EXPECT_TRUE((std::is_constructible<epee::span<const no_conversion>, no_conversion*, std::size_t>())); + EXPECT_FALSE((std::is_constructible<epee::span<const no_conversion>, const inherited*, std::size_t>())); + EXPECT_FALSE((std::is_constructible<epee::span<const no_conversion>, inherited*, std::size_t>())); + EXPECT_FALSE((can_construct<epee::span<const char>, std::string>())); EXPECT_FALSE((can_construct<epee::span<const char>, std::vector<char>>())); EXPECT_FALSE((can_construct<epee::span<const char>, const std::vector<char>>())); @@ -231,7 +243,6 @@ TEST(Span, NoExcept) const epee::span<char> clvalue(data); EXPECT_TRUE(noexcept(epee::span<char>())); EXPECT_TRUE(noexcept(epee::span<char>(nullptr))); - EXPECT_TRUE(noexcept(epee::span<char>(nullptr, 0))); EXPECT_TRUE(noexcept(epee::span<char>(data))); EXPECT_TRUE(noexcept(epee::span<char>(lvalue))); EXPECT_TRUE(noexcept(epee::span<char>(clvalue))); @@ -284,6 +295,25 @@ TEST(Span, Writing) EXPECT_TRUE(boost::range::equal(expected, span)); } +TEST(Span, RemovePrefix) +{ + const std::array<unsigned, 4> expected{0, 1, 2, 3}; + auto span = epee::to_span(expected); + + EXPECT_EQ(expected.begin(), span.begin()); + EXPECT_EQ(expected.end(), span.end()); + + EXPECT_EQ(2u, span.remove_prefix(2)); + EXPECT_EQ(expected.begin() + 2, span.begin()); + EXPECT_EQ(expected.end(), span.end()); + + EXPECT_EQ(2u, span.remove_prefix(3)); + EXPECT_EQ(span.begin(), span.end()); + EXPECT_EQ(expected.end(), span.begin()); + + EXPECT_EQ(0u, span.remove_prefix(100)); +} + TEST(Span, ToByteSpan) { const char expected[] = {56, 44, 11, 5}; @@ -318,6 +348,30 @@ TEST(Span, AsByteSpan) ); } +TEST(Span, AsMutByteSpan) +{ + struct some_pod { char value[4]; }; + some_pod actual {}; + + auto span = epee::as_mut_byte_span(actual); + boost::range::iota(span, 1); + EXPECT_TRUE( + boost::range::equal( + std::array<unsigned char, 4>{{1, 2, 3, 4}}, actual.value + ) + ); +} + +TEST(Span, ToMutSpan) +{ + std::vector<unsigned> mut; + mut.resize(4); + + auto span = epee::to_mut_span(mut); + boost::range::iota(span, 1); + EXPECT_EQ((std::vector<unsigned>{1, 2, 3, 4}), mut); +} + TEST(ToHex, String) { EXPECT_TRUE(epee::to_hex::string(nullptr).empty()); @@ -330,6 +384,7 @@ TEST(ToHex, String) EXPECT_EQ( std_to_hex(all_bytes), epee::to_hex::string(epee::to_span(all_bytes)) ); + } TEST(ToHex, Array) diff --git a/tests/unit_tests/multisig.cpp b/tests/unit_tests/multisig.cpp index eb453b960..83924c7af 100644 --- a/tests/unit_tests/multisig.cpp +++ b/tests/unit_tests/multisig.cpp @@ -61,7 +61,7 @@ static void make_wallet(unsigned int idx, tools::wallet2 &wallet) try { - wallet.init(false, ""); + wallet.init(""); wallet.set_subaddress_lookahead(1, 1); wallet.generate("", "", spendkey, true, false); ASSERT_TRUE(test_addresses[idx].address == wallet.get_account().get_public_address_str(cryptonote::TESTNET)); diff --git a/tests/unit_tests/ringdb.cpp b/tests/unit_tests/ringdb.cpp index 9b842569a..416ae0890 100644 --- a/tests/unit_tests/ringdb.cpp +++ b/tests/unit_tests/ringdb.cpp @@ -59,17 +59,17 @@ static crypto::key_image generate_key_image() return key_image; } -static crypto::public_key generate_output() +static std::pair<uint64_t, uint64_t> generate_output() { - return rct::rct2pk(rct::scalarmultBase(rct::skGen())); + return std::make_pair(rand(), rand()); } static const crypto::chacha_key KEY_1 = generate_chacha_key(); static const crypto::chacha_key KEY_2 = generate_chacha_key(); static const crypto::key_image KEY_IMAGE_1 = generate_key_image(); -static const crypto::public_key OUTPUT_1 = generate_output(); -static const crypto::public_key OUTPUT_2 = generate_output(); +static const std::pair<uint64_t, uint64_t> OUTPUT_1 = generate_output(); +static const std::pair<uint64_t, uint64_t> OUTPUT_2 = generate_output(); class RingDB: public tools::ringdb { diff --git a/tests/unit_tests/wipeable_string.cpp b/tests/unit_tests/wipeable_string.cpp index 5ea1c1729..65718fd45 100644 --- a/tests/unit_tests/wipeable_string.cpp +++ b/tests/unit_tests/wipeable_string.cpp @@ -32,6 +32,7 @@ #include "misc_log_ex.h" #include "wipeable_string.h" +#include "hex.h" TEST(wipeable_string, ctor) { @@ -202,3 +203,9 @@ TEST(wipeable_string, parse_hexstr) ASSERT_TRUE((s = epee::wipeable_string("414243").parse_hexstr())); ASSERT_EQ(*s, epee::wipeable_string("ABC")); } + +TEST(wipeable_string, to_hex) +{ + ASSERT_TRUE(epee::to_hex::wipeable_string(epee::span<const uint8_t>((const uint8_t*)"", 0)) == epee::wipeable_string("")); + ASSERT_TRUE(epee::to_hex::wipeable_string(epee::span<const uint8_t>((const uint8_t*)"abc", 3)) == epee::wipeable_string("616263")); +} |