some fixes

This commit is contained in:
Antonio Juarez 2014-03-20 11:46:11 +00:00
parent 296ae46ed8
commit 8efa1313f3
67 changed files with 1523 additions and 757 deletions

View file

@ -40,13 +40,6 @@ target_link_libraries(unit_tests cryptonote_core common crypto gtest_main ${Boos
target_link_libraries(net_load_tests_clt cryptonote_core common crypto gtest_main ${Boost_LIBRARIES})
target_link_libraries(net_load_tests_srv cryptonote_core common crypto gtest_main ${Boost_LIBRARIES})
if(NOT WIN32)
target_link_libraries(coretests rt)
target_link_libraries(functional_tests rt)
target_link_libraries(performance_tests rt)
target_link_libraries(core_proxy rt)
target_link_libraries(unit_tests rt)
endif()
if(NOT MSVC)
set_property(TARGET gtest gtest_main unit_tests net_load_tests_clt net_load_tests_srv APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-sign-compare")
endif()
@ -57,8 +50,8 @@ set_property(TARGET coretests crypto-tests functional_tests difficulty-tests gte
add_test(coretests coretests --generate_and_play_test_data)
add_test(crypto crypto-tests ${CMAKE_CURRENT_SOURCE_DIR}/crypto/tests.txt)
add_test(difficulty difficulty-tests ${CMAKE_CURRENT_SOURCE_DIR}/difficulty/data.txt)
foreach(hash IN ITEMS fast slow tree)# extra-blake extra-groestl extra-jh extra-skein)
add_test(hash-${hash} hash-tests ${hash} ${CMAKE_CURRENT_SOURCE_DIR}/hash/tests-${hash}.txt)
foreach(hash IN ITEMS fast slow tree extra-blake extra-groestl extra-jh extra-skein)
add_test(hash-${hash} hash-tests ${hash} ${CMAKE_CURRENT_SOURCE_DIR}/hash/tests-${hash}.txt)
endforeach(hash)
add_test(hash-target hash-target-tests)
add_test(unit_tests unit_tests)

View file

@ -102,7 +102,8 @@ bool transactions_flow_test(std::string& working_folder,
return false;
}
size_t blocks_fetched = 0;
if(!w1.refresh(blocks_fetched))
tools::wallet2::fail_details fd;
if(!w1.refresh(blocks_fetched, fd))
{
LOG_ERROR( "failed to refresh source wallet from " << daemon_addr_a );
return false;
@ -134,11 +135,11 @@ bool transactions_flow_test(std::string& working_folder,
CHECK_AND_ASSERT_MES(daemon_rsp.status == CORE_RPC_STATUS_OK, false, "failed to getrandom_outs.bin");
//wait for money, until balance will have enough money
w1.refresh(blocks_fetched);
w1.refresh(blocks_fetched, fd);
while(w1.unlocked_balance() < amount_to_transfer)
{
misc_utils::sleep_no_w(1000);
w1.refresh(blocks_fetched);
w1.refresh(blocks_fetched, fd);
}
//lets make a lot of small outs to ourselves
@ -165,7 +166,7 @@ bool transactions_flow_test(std::string& working_folder,
}else
{
misc_utils::sleep_no_w(1000);
w1.refresh();
w1.refresh(fd);
}
}
//do actual transfer
@ -187,7 +188,7 @@ bool transactions_flow_test(std::string& working_folder,
{
misc_utils::sleep_no_w(1000);
LOG_PRINT_L0("not enough money, waiting for cashback or mining");
w1.refresh(blocks_fetched);
w1.refresh(blocks_fetched, fd);
}
transaction tx;
@ -202,7 +203,7 @@ bool transactions_flow_test(std::string& working_folder,
if(!do_send_money(w1, w2, mix_in_factor, amount_to_tx, tx))
{
LOG_PRINT_L0("failed to transfer money, tx: " << get_transaction_hash(tx) << ", refresh and try again" );
w1.refresh(blocks_fetched);
w1.refresh(blocks_fetched, fd);
if(!do_send_money(w1, w2, mix_in_factor, amount_to_tx, tx))
{
LOG_PRINT_L0( "failed to transfer money, second chance. tx: " << get_transaction_hash(tx) << ", exit" );
@ -227,7 +228,7 @@ bool transactions_flow_test(std::string& working_folder,
misc_utils::sleep_no_w(DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN*20*1000);//wait two blocks before sync on another wallet on another daemon
LOG_PRINT_L0( "refreshing...");
bool recvd_money = false;
while(w2.refresh(blocks_fetched, recvd_money) && ( (blocks_fetched && recvd_money) || !blocks_fetched ) )
while(w2.refresh(blocks_fetched, recvd_money, fd) && ( (blocks_fetched && recvd_money) || !blocks_fetched ) )
{
misc_utils::sleep_no_w(DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN*1000);//wait two blocks before sync on another wallet on another daemon
}

View file

@ -12,6 +12,7 @@
#include "gtest/gtest.h"
#include "include_base_utils.h"
#include "misc_language.h"
#include "misc_log_ex.h"
#include "storages/levin_abstract_invoke2.h"
@ -33,7 +34,8 @@ namespace
{
if (predicate())
return true;
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_ms));
//std::this_thread::sleep_for(std::chrono::milliseconds(sleep_ms));
epee::misc_utils::sleep_no_w(sleep_ms);
}
return false;
}
@ -292,7 +294,8 @@ namespace
return true;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
//std::this_thread::sleep_for(std::chrono::seconds(1));
epee::misc_utils::sleep_no_w(1000);
}
return false;

View file

@ -399,9 +399,12 @@ TEST_encode_decode_addr(PuT7GAdgbA83uoWF3eanGG1aRoG, 0x1122334455667788, "\x
TEST_encode_decode_addr(PuT7GAdgbA83vT1umSHMYJ4oNVdu, 0x1122334455667788, "\x77\x77\x77\x77\x77\x77\x77");
TEST_encode_decode_addr(PuT7GAdgbA83w6XaVDyvpoGQBEWbB, 0x1122334455667788, "\x88\x88\x88\x88\x88\x88\x88\x88");
TEST_encode_decode_addr(PuT7GAdgbA83wk3FD1gW7J2KVGofA1r, 0x1122334455667788, "\x99\x99\x99\x99\x99\x99\x99\x99\x99");
TEST_encode_decode_addr(15p2yAV, 0, "");
TEST_encode_decode_addr(FNQ3D6A, 0x7F, "");
TEST_encode_decode_addr(26k9QWweu, 0x80, "");
TEST_encode_decode_addr(3BzAD7n3y, 0xFF, "");
TEST_encode_decode_addr(11efCaY6UjG7JrxuB, 0, "\x11\x22\x33\x44\x55\x66\x77");
TEST_encode_decode_addr(21rhHRT48LN4PriP9, 6, "\x11\x22\x33\x44\x55\x66\x77");
TEST_encode_decode_addr(3BzAD7n3y, 0xFF, "");
#define TEST_decode_addr_neg(addr, test_name) \
@ -421,6 +424,14 @@ TEST_decode_addr_neg("\0uT7GAdgbA819VwdWVDP", decode_fails_due_invalid_char_00);
TEST_decode_addr_neg("PuT7GAdgbA819VwdWVD", decode_fails_due_invalid_lenght);
TEST_decode_addr_neg("11efCaY6UjG7JrxuC", handles_invalid_checksum);
TEST_decode_addr_neg("jerj2e4mESo", handles_non_correct_tag); // "jerj2e4mESo" == "\xFF\x00\xFF\xFF\x5A\xD9\xF1\x1C"
TEST_decode_addr_neg("1", decode_fails_due_invalid_block_len_0);
TEST_decode_addr_neg("1111", decode_fails_due_invalid_block_len_1);
TEST_decode_addr_neg("11", decode_fails_due_address_too_short_0);
TEST_decode_addr_neg("111", decode_fails_due_address_too_short_1);
TEST_decode_addr_neg("11111", decode_fails_due_address_too_short_2);
TEST_decode_addr_neg("111111", decode_fails_due_address_too_short_3);
TEST_decode_addr_neg("999999", decode_fails_due_address_too_short_4);
TEST_decode_addr_neg("ZZZZZZ", decode_fails_due_address_too_short_5);
namespace
{

View file

@ -56,8 +56,7 @@ namespace
TEST_F(decompose_amount_into_digits_test, is_correct_0)
{
uint64_t expected_chunks_arr[] = {0};
VEC_FROM_ARR(expected_chunks);
std::vector<uint64_t> expected_chunks;
cryptonote::decompose_amount_into_digits(0, 0, m_chunk_handler, m_dust_handler);
ASSERT_EQ(m_chunk_handler.m_chunks, expected_chunks);
ASSERT_EQ(m_dust_handler.m_has_dust, false);
@ -65,8 +64,7 @@ TEST_F(decompose_amount_into_digits_test, is_correct_0)
TEST_F(decompose_amount_into_digits_test, is_correct_1)
{
uint64_t expected_chunks_arr[] = {0};
VEC_FROM_ARR(expected_chunks);
std::vector<uint64_t> expected_chunks;
cryptonote::decompose_amount_into_digits(0, 10, m_chunk_handler, m_dust_handler);
ASSERT_EQ(m_chunk_handler.m_chunks, expected_chunks);
ASSERT_EQ(m_dust_handler.m_has_dust, false);

View file

@ -0,0 +1,133 @@
// Copyright (c) 2012-2013 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "gtest/gtest.h"
#include <string_tools.h>
using namespace epee::string_tools;
namespace
{
template<typename T>
void do_pos_test(T expected, const std::string& str)
{
T val;
ASSERT_TRUE(get_xtype_from_string(val, str));
ASSERT_EQ(expected, val);
}
template<typename T>
void do_neg_test(const std::string& str)
{
T val;
ASSERT_FALSE(get_xtype_from_string(val, str));
}
}
#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 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 TEST_neg(int_type, str) \
TEST(get_xtype_from_string, MAKE_NEG_TEST_NAME(handles_neg, int_type, __LINE__)) \
{ \
do_neg_test<int_type>(str); \
}
TEST_pos(uint16_t, 0, "0");
TEST_pos(uint16_t, 1, "1");
TEST_pos(uint16_t, 65535, "65535");
TEST_neg(uint16_t, "+0");
TEST_neg(uint16_t, "+1");
TEST_neg(uint16_t, "+65535");
TEST_neg(uint16_t, "+65536");
TEST_neg(uint16_t, "-0");
TEST_neg(uint16_t, "-1");
TEST_neg(uint16_t, "-65535");
TEST_neg(uint16_t, "-65536");
TEST_neg(uint16_t, ".0");
TEST_neg(uint16_t, ".1");
TEST_neg(uint16_t, "0.0");
TEST_neg(uint16_t, "0.1");
TEST_neg(uint16_t, "1.0");
TEST_neg(uint16_t, "1.1");
TEST_neg(uint16_t, "w");
TEST_neg(uint16_t, "0w");
TEST_neg(uint16_t, "1w");
TEST_neg(uint16_t, "1w1");
TEST_neg(uint16_t, "65535w");
TEST_neg(uint16_t, "65536");
TEST_neg(uint16_t, "4294967296");
TEST_neg(uint16_t, "18446744073709551616");
TEST_pos(uint32_t, 0, "0");
TEST_pos(uint32_t, 1, "1");
TEST_pos(uint32_t, 4294967295, "4294967295");
TEST_neg(uint32_t, "+0");
TEST_neg(uint32_t, "+1");
TEST_neg(uint32_t, "+4294967295");
TEST_neg(uint32_t, "+4294967296");
TEST_neg(uint32_t, "-0");
TEST_neg(uint32_t, "-1");
TEST_neg(uint32_t, "-4294967295");
TEST_neg(uint32_t, "-4294967296");
TEST_neg(uint32_t, ".0");
TEST_neg(uint32_t, ".1");
TEST_neg(uint32_t, "0.0");
TEST_neg(uint32_t, "0.1");
TEST_neg(uint32_t, "1.0");
TEST_neg(uint32_t, "1.1");
TEST_neg(uint32_t, "w");
TEST_neg(uint32_t, "0w");
TEST_neg(uint32_t, "1w");
TEST_neg(uint32_t, "1w1");
TEST_neg(uint32_t, "4294967295w");
TEST_neg(uint32_t, "4294967296");
TEST_neg(uint32_t, "18446744073709551616");
TEST_pos(uint64_t, 0, "0");
TEST_pos(uint64_t, 1, "1");
TEST_pos(uint64_t, 18446744073709551615ULL, "18446744073709551615");
TEST_neg(uint64_t, "+0");
TEST_neg(uint64_t, "+1");
TEST_neg(uint64_t, "+18446744073709551615");
TEST_neg(uint64_t, "+18446744073709551616");
TEST_neg(uint64_t, "-0");
TEST_neg(uint64_t, "-1");
TEST_neg(uint64_t, "-18446744073709551615");
TEST_neg(uint64_t, "-18446744073709551616");
TEST_neg(uint64_t, ".0");
TEST_neg(uint64_t, ".1");
TEST_neg(uint64_t, "0.0");
TEST_neg(uint64_t, "0.1");
TEST_neg(uint64_t, "1.0");
TEST_neg(uint64_t, "1.1");
TEST_neg(uint64_t, "w");
TEST_neg(uint64_t, "0w");
TEST_neg(uint64_t, "1w");
TEST_neg(uint64_t, "1w1");
TEST_neg(uint64_t, "18446744073709551615w");
TEST_neg(uint64_t, "18446744073709551616");