From ee6ee272902c17d9e9986b8e833736da46d48565 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Mon, 24 Oct 2016 17:44:53 -0400 Subject: [PATCH] clean up tests and add some utility methods --- CMakeLists.txt | 74 +++------------------------------ CMakeModules/FindReadline.cmake | 2 + include/fc/crypto/sha256.hpp | 12 ++++++ include/fc/io/raw_fwd.hpp | 3 ++ tests/CMakeLists.txt | 69 ++++++++++++++++++++++++++++++ tests/crypto/blind.cpp | 14 +++---- 6 files changed, 99 insertions(+), 75 deletions(-) create mode 100644 tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e24f7a..8498657 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,6 +151,11 @@ ENDIF() find_package(OpenSSL REQUIRED) +set(RAPIDJSON_USE_SSE2 ON) +set(RAPIDJSON_USE_SSE42 ON) +find_package(RapidJSON REQUIRED) + + set( CMAKE_FIND_LIBRARY_SUFFIXES ${ORIGINAL_LIB_SUFFIXES} ) option( UNITY_BUILD OFF ) @@ -375,76 +380,9 @@ add_definitions(-DBOOST_TEST_DYN_LINK) ENDIF(MSVC) ENDIF() -add_executable( bip_lock tests/bip_lock.cpp ) -target_link_libraries( bip_lock fc ) - -add_executable( api tests/api.cpp ) -target_link_libraries( api fc ) - -if( ECC_IMPL STREQUAL secp256k1 ) - add_executable( blind tests/all_tests.cpp tests/crypto/blind.cpp ) - target_link_libraries( blind fc ) -endif() - include_directories( vendor/websocketpp ) -add_executable( ntp_test tests/all_tests.cpp tests/network/ntp_test.cpp ) -target_link_libraries( ntp_test fc ) - -add_executable( task_cancel_test tests/all_tests.cpp tests/thread/task_cancel.cpp ) -target_link_libraries( task_cancel_test fc ) - - -add_executable( bloom_test tests/all_tests.cpp tests/bloom_test.cpp ) -target_link_libraries( bloom_test fc ) - -add_executable( real128_test tests/all_tests.cpp tests/real128_test.cpp ) -target_link_libraries( real128_test fc ) - -add_executable( hmac_test tests/hmac_test.cpp ) -target_link_libraries( hmac_test fc ) - -add_executable( blinding_test tests/blinding_test.cpp ) -target_link_libraries( blinding_test fc ) - - -add_executable( udt_server tests/udts.cpp ) -target_link_libraries( udt_server fc udt ) - -add_executable( udt_client tests/udtc.cpp ) -target_link_libraries( udt_client fc udt ) - -add_executable( ecc_test tests/crypto/ecc_test.cpp ) -target_link_libraries( ecc_test fc ) - -add_executable( log_test tests/crypto/log_test.cpp ) -target_link_libraries( log_test fc ) - -#add_executable( test_aes tests/aes_test.cpp ) -#target_link_libraries( test_aes fc ${rt_library} ${pthread_library} ) -#add_executable( test_sleep tests/sleep.cpp ) -#target_link_libraries( test_sleep fc ) -#add_executable( test_rate_limiting tests/rate_limiting.cpp ) -#target_link_libraries( test_rate_limiting fc ) - -add_executable( all_tests tests/all_tests.cpp - tests/compress/compress.cpp - tests/crypto/aes_test.cpp - tests/crypto/base_n_tests.cpp - tests/crypto/bigint_test.cpp - tests/crypto/blind.cpp - tests/crypto/blowfish_test.cpp - tests/crypto/dh_test.cpp - tests/crypto/rand_test.cpp - tests/crypto/sha_tests.cpp - tests/network/ntp_test.cpp - tests/network/http/websocket_test.cpp - tests/thread/task_cancel.cpp - tests/bloom_test.cpp - tests/real128_test.cpp - tests/utf8_test.cpp - ) -target_link_libraries( all_tests fc ) +add_subdirectory(tests) if(WIN32) # add addtional import library on windows platform diff --git a/CMakeModules/FindReadline.cmake b/CMakeModules/FindReadline.cmake index 745cfe5..f1d0d74 100644 --- a/CMakeModules/FindReadline.cmake +++ b/CMakeModules/FindReadline.cmake @@ -45,3 +45,5 @@ mark_as_advanced( Readline_INCLUDE_DIR Readline_LIBRARY ) + +MESSAGE( STATUS "Found Readline: ${Readline_LIBRARY}" ) diff --git a/include/fc/crypto/sha256.hpp b/include/fc/crypto/sha256.hpp index a7e8deb..58bba9e 100644 --- a/include/fc/crypto/sha256.hpp +++ b/include/fc/crypto/sha256.hpp @@ -118,5 +118,17 @@ namespace std } }; } + +namespace boost +{ + template<> + struct hash + { + size_t operator()( const fc::sha256& s )const + { + return s._hash[3];//*((size_t*)&s); + } + }; +} #include FC_REFLECT_TYPENAME( fc::sha256 ) diff --git a/include/fc/io/raw_fwd.hpp b/include/fc/io/raw_fwd.hpp index c98b932..f397202 100644 --- a/include/fc/io/raw_fwd.hpp +++ b/include/fc/io/raw_fwd.hpp @@ -28,6 +28,9 @@ namespace fc { template class fixed_string; namespace raw { + template + inline size_t pack_size( const T& v ); + template inline void pack( Stream& s, const fc::fixed_string& u ); template inline void unpack( Stream& s, fc::fixed_string& u ); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..50ff992 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,69 @@ + +add_executable( bip_lock bip_lock.cpp ) +target_link_libraries( bip_lock fc ) + +add_executable( api api.cpp ) +target_link_libraries( api fc ) + +if( ECC_IMPL STREQUAL secp256k1 ) + add_executable( blind all_tests.cpp crypto/blind.cpp ) + target_link_libraries( blind fc ) +endif() + +add_executable( ntp_test all_tests.cpp network/ntp_test.cpp ) +target_link_libraries( ntp_test fc ) + +add_executable( task_cancel_test all_tests.cpp thread/task_cancel.cpp ) +target_link_libraries( task_cancel_test fc ) + + +add_executable( bloom_test all_tests.cpp bloom_test.cpp ) +target_link_libraries( bloom_test fc ) + +add_executable( real128_test all_tests.cpp real128_test.cpp ) +target_link_libraries( real128_test fc ) + +add_executable( hmac_test hmac_test.cpp ) +target_link_libraries( hmac_test fc ) + +add_executable( blinding_test blinding_test.cpp ) +target_link_libraries( blinding_test fc ) + + +add_executable( udt_server udts.cpp ) +target_link_libraries( udt_server fc udt ) + +add_executable( udt_client udtc.cpp ) +target_link_libraries( udt_client fc udt ) + +add_executable( ecc_test crypto/ecc_test.cpp ) +target_link_libraries( ecc_test fc ) + +add_executable( log_test crypto/log_test.cpp ) +target_link_libraries( log_test fc ) + +#add_executable( test_aes aes_test.cpp ) +#target_link_libraries( test_aes fc ${rt_library} ${pthread_library} ) +#add_executable( test_sleep sleep.cpp ) +#target_link_libraries( test_sleep fc ) +#add_executable( test_rate_limiting rate_limiting.cpp ) +#target_link_libraries( test_rate_limiting fc ) + +add_executable( all_tests all_tests.cpp + compress/compress.cpp + crypto/aes_test.cpp + crypto/base_n_tests.cpp + crypto/bigint_test.cpp + crypto/blind.cpp + crypto/blowfish_test.cpp + crypto/dh_test.cpp + crypto/rand_test.cpp + crypto/sha_tests.cpp + network/ntp_test.cpp + network/http/websocket_test.cpp + thread/task_cancel.cpp + bloom_test.cpp + real128_test.cpp + utf8_test.cpp + ) +target_link_libraries( all_tests fc ) diff --git a/tests/crypto/blind.cpp b/tests/crypto/blind.cpp index 29f81f9..33dfb46 100644 --- a/tests/crypto/blind.cpp +++ b/tests/crypto/blind.cpp @@ -50,15 +50,15 @@ BOOST_AUTO_TEST_CASE(blind_test) auto B4 = fc::sha256::hash("B4"); auto C1 = fc::ecc::blind( B1, 1 ); auto C2 = fc::ecc::blind( B2, 2 ); - auto c3 = fc::ecc::blind( b3, 3 ); - auto C4 = fc::ecc::blind( B4, -1 ); + /*auto c3 = */fc::ecc::blind( b3, 3 ); + /*auto C4 = */fc::ecc::blind( B4, -1 ); auto B3 = fc::ecc::blind_sum( {B1,B2}, 2 ); auto C3 = fc::ecc::blind( B3, 3 ); auto B2m1 = fc::ecc::blind_sum( {B2,B1}, 1 ); - auto C2m1 = fc::ecc::blind( B2m1, 1 ); + /*auto C2m1 = */fc::ecc::blind( B2m1, 1 ); BOOST_CHECK( fc::ecc::verify_sum( {C1,C2}, {C3}, 0 ) ); BOOST_CHECK( fc::ecc::verify_sum( {C1,C2}, {C3}, 0 ) ); @@ -68,9 +68,9 @@ BOOST_AUTO_TEST_CASE(blind_test) { auto B1 = fc::sha256::hash("B1"); - auto B2 = fc::sha256::hash("B2"); - auto B3 = fc::sha256::hash("B3"); - auto B4 = fc::sha256::hash("B4"); + /*auto B2 = */fc::sha256::hash("B2"); + /*auto B3 = */fc::sha256::hash("B3"); + /*auto B4 = */fc::sha256::hash("B4"); //secp256k1_scalar_get_b32((unsigned char*)&B1, (const secp256k1_scalar_t*)&B2); //B1 = fc::variant("b2e5da56ef9f2a34d3e22fd12634bc99261e95c87b9960bf94ed3d27b30").as(); @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(blind_test) auto C1 = fc::ecc::blind( B1, INT64_MAX ); auto C2 = fc::ecc::blind( B1, 0 ); auto C3 = fc::ecc::blind( B1, 1 ); - auto C4 = fc::ecc::blind( B1, 2 ); + /*auto C4 = */fc::ecc::blind( B1, 2 ); BOOST_CHECK( fc::ecc::verify_sum( {C2}, {C3}, -1 ) ); BOOST_CHECK( fc::ecc::verify_sum( {C1}, {C1}, 0 ) );