More tests refactored
This commit is contained in:
parent
dda63f4fc8
commit
5f4ff1aa21
4 changed files with 72 additions and 74 deletions
|
|
@ -331,7 +331,7 @@ include_directories( vendor/websocketpp )
|
||||||
add_executable( ntp_test ntp_test.cpp )
|
add_executable( ntp_test ntp_test.cpp )
|
||||||
target_link_libraries( ntp_test fc )
|
target_link_libraries( ntp_test fc )
|
||||||
|
|
||||||
add_executable( task_cancel_test tests/task_cancel.cpp )
|
add_executable( task_cancel_test tests/all_tests.cpp tests/task_cancel.cpp )
|
||||||
target_link_libraries( task_cancel_test fc )
|
target_link_libraries( task_cancel_test fc )
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -358,7 +358,10 @@ target_link_libraries( ecc_test fc )
|
||||||
#add_executable( test_rate_limiting tests/rate_limiting.cpp )
|
#add_executable( test_rate_limiting tests/rate_limiting.cpp )
|
||||||
#target_link_libraries( test_rate_limiting fc )
|
#target_link_libraries( test_rate_limiting fc )
|
||||||
|
|
||||||
add_executable( all_tests tests/all_tests.cpp tests/compress.cpp tests/real128_test.cpp )
|
add_executable( all_tests tests/all_tests.cpp tests/blind.cpp
|
||||||
|
tests/bloom_test.cpp
|
||||||
|
tests/compress.cpp tests/real128_test.cpp
|
||||||
|
tests/task_cancel.cpp )
|
||||||
target_link_libraries( all_tests fc )
|
target_link_libraries( all_tests fc )
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include <fc/crypto/elliptic.hpp>
|
#include <fc/crypto/elliptic.hpp>
|
||||||
#include <fc/log/logger.hpp>
|
#include <fc/log/logger.hpp>
|
||||||
#include <fc/io/raw.hpp>
|
#include <fc/io/raw.hpp>
|
||||||
#include <fc/variant.hpp>
|
#include <fc/variant.hpp>
|
||||||
#include <fc/reflect/variant.hpp>
|
#include <fc/reflect/variant.hpp>
|
||||||
|
|
||||||
//extern "C" {
|
BOOST_AUTO_TEST_SUITE(fc_crypto)
|
||||||
//#include <secp256k1.h>
|
|
||||||
//}
|
|
||||||
//struct secp256k1_scalar_t { uint64_t v[4]; };
|
|
||||||
//extern "C" { void secp256k1_scalar_get_b32(unsigned char *bin, const struct secp256k1_scalar_t* a); }
|
|
||||||
|
|
||||||
int main( int argc, char** argv )
|
BOOST_AUTO_TEST_CASE(blind_test)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
auto InB1 = fc::sha256::hash("InB1");
|
auto InB1 = fc::sha256::hash("InB1");
|
||||||
|
|
@ -34,16 +32,16 @@ int main( int argc, char** argv )
|
||||||
//FC_ASSERT( fc::ecc::verify_sum( {InC1,InC2}, {OutC1}, -60 ) );
|
//FC_ASSERT( fc::ecc::verify_sum( {InC1,InC2}, {OutC1}, -60 ) );
|
||||||
|
|
||||||
|
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {InC1,InC2}, {OutC1,OutC2}, 0 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {InC1,InC2}, {OutC1,OutC2}, 0 ) );
|
||||||
auto nonce = fc::sha256::hash("nonce");
|
auto nonce = fc::sha256::hash("nonce");
|
||||||
|
|
||||||
auto proof = fc::ecc::range_proof_sign( 0, OutC1, OutB1, nonce, 0, 0, 40 );
|
auto proof = fc::ecc::range_proof_sign( 0, OutC1, OutB1, nonce, 0, 0, 40 );
|
||||||
wdump( (proof.size()));
|
// wdump( (proof.size()));
|
||||||
|
|
||||||
auto result = fc::ecc::range_get_info( proof );
|
auto result = fc::ecc::range_get_info( proof );
|
||||||
wdump((result));
|
// wdump((result));
|
||||||
FC_ASSERT( result.max_value >= 60 );
|
BOOST_CHECK( result.max_value >= 60 );
|
||||||
FC_ASSERT( result.min_value >= 0 );
|
BOOST_CHECK( result.min_value >= 0 );
|
||||||
|
|
||||||
|
|
||||||
auto B1 = fc::sha256::hash("B1");
|
auto B1 = fc::sha256::hash("B1");
|
||||||
|
|
@ -62,10 +60,10 @@ int main( int argc, char** argv )
|
||||||
auto B2m1 = fc::ecc::blind_sum( {B2,B1}, 1 );
|
auto B2m1 = fc::ecc::blind_sum( {B2,B1}, 1 );
|
||||||
auto C2m1 = fc::ecc::blind( B2m1, 1 );
|
auto C2m1 = fc::ecc::blind( B2m1, 1 );
|
||||||
|
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C1,C2}, {C3}, 0 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C1,C2}, {C3}, 0 ) );
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C1,C2}, {C3}, 0 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C1,C2}, {C3}, 0 ) );
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C3}, {C1,C2}, 0 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C3}, {C1,C2}, 0 ) );
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C3}, {C1,C2}, 0 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C3}, {C1,C2}, 0 ) );
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -82,13 +80,13 @@ int main( int argc, char** argv )
|
||||||
auto C3 = fc::ecc::blind( B1, 1 );
|
auto C3 = fc::ecc::blind( B1, 1 );
|
||||||
auto C4 = fc::ecc::blind( B1, 2 );
|
auto C4 = fc::ecc::blind( B1, 2 );
|
||||||
|
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C2}, {C3}, -1 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C2}, {C3}, -1 ) );
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C1}, {C1}, 0 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C1}, {C1}, 0 ) );
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C2}, {C2}, 0 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C2}, {C2}, 0 ) );
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C3}, {C2}, 1 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C3}, {C2}, 1 ) );
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C1}, {C2}, INT64_MAX ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C1}, {C2}, INT64_MAX ) );
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C1}, {C2}, INT64_MAX ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C1}, {C2}, INT64_MAX ) );
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {C2}, {C1}, -INT64_MAX ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {C2}, {C1}, -INT64_MAX ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -101,16 +99,15 @@ int main( int argc, char** argv )
|
||||||
auto InC = fc::ecc::blind( InBlind, 1000 );
|
auto InC = fc::ecc::blind( InBlind, 1000 );
|
||||||
auto In0 = fc::ecc::blind( InBlind, 0 );
|
auto In0 = fc::ecc::blind( InBlind, 0 );
|
||||||
|
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {InC}, {OutC1,OutC2}, 0 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {InC}, {OutC1,OutC2}, 0 ) );
|
||||||
FC_ASSERT( fc::ecc::verify_sum( {InC}, {In0}, 1000 ) );
|
BOOST_CHECK( fc::ecc::verify_sum( {InC}, {In0}, 1000 ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( const fc::exception& e )
|
catch ( const fc::exception& e )
|
||||||
{
|
{
|
||||||
edump((e.to_detail_string()));
|
edump((e.to_detail_string()));
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include <fc/bloom_filter.hpp>
|
#include <fc/bloom_filter.hpp>
|
||||||
#include <fc/exception/exception.hpp>
|
#include <fc/exception/exception.hpp>
|
||||||
#include <fc/reflect/variant.hpp>
|
#include <fc/reflect/variant.hpp>
|
||||||
|
|
@ -10,10 +12,8 @@
|
||||||
|
|
||||||
using namespace fc;
|
using namespace fc;
|
||||||
|
|
||||||
int main( int argc, char** argv )
|
static bloom_parameters setup_parameters()
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
|
|
||||||
bloom_parameters parameters;
|
bloom_parameters parameters;
|
||||||
|
|
||||||
// How many elements roughly do we expect to insert?
|
// How many elements roughly do we expect to insert?
|
||||||
|
|
@ -27,25 +27,31 @@ int main( int argc, char** argv )
|
||||||
|
|
||||||
if (!parameters)
|
if (!parameters)
|
||||||
{
|
{
|
||||||
std::cout << "Error - Invalid set of bloom filter parameters!" << std::endl;
|
BOOST_FAIL( "Error - Invalid set of bloom filter parameters!" );
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters.compute_optimal_parameters();
|
parameters.compute_optimal_parameters();
|
||||||
|
|
||||||
//Instantiate Bloom Filter
|
return parameters;
|
||||||
bloom_filter filter(parameters);
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(fc_crypto)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(bloom_test_1)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
//Instantiate Bloom Filter
|
||||||
|
bloom_filter filter(setup_parameters());
|
||||||
|
|
||||||
if( argc > 1 )
|
|
||||||
{
|
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
std::string line;
|
std::string line;
|
||||||
std::ifstream in(argv[1]);
|
std::ifstream in("README.md");
|
||||||
std::ofstream words("words.txt");
|
std::ofstream words("words.txt");
|
||||||
while( !in.eof() && count < 100000 )
|
while( !in.eof() && count < 100000 )
|
||||||
{
|
{
|
||||||
std::getline(in, line);
|
std::getline(in, line);
|
||||||
std::cout << "'"<<line<<"'\n";
|
// std::cout << "'"<<line<<"'\n";
|
||||||
if( !filter.contains(line) )
|
if( !filter.contains(line) )
|
||||||
{
|
{
|
||||||
filter.insert( line );
|
filter.insert( line );
|
||||||
|
|
@ -53,23 +59,29 @@ int main( int argc, char** argv )
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wdump((filter));
|
// wdump((filter));
|
||||||
auto packed_filter = fc::raw::pack(filter);
|
auto packed_filter = fc::raw::pack(filter);
|
||||||
wdump((packed_filter.size()));
|
// wdump((packed_filter.size()));
|
||||||
wdump((packed_filter));
|
// wdump((packed_filter));
|
||||||
std::ofstream out(argv[2]);
|
std::stringstream out;
|
||||||
std::string str = fc::json::to_string(packed_filter);
|
// std::string str = fc::json::to_string(packed_filter);
|
||||||
auto b64 = fc::base64_encode( packed_filter.data(), packed_filter.size() );
|
auto b64 = fc::base64_encode( packed_filter.data(), packed_filter.size() );
|
||||||
for( uint32_t i = 0; i < b64.size(); i += 1024 )
|
for( uint32_t i = 0; i < b64.size(); i += 1024 )
|
||||||
out << '"' << b64.substr( i, 1024 ) << "\",\n";
|
out << '"' << b64.substr( i, 1024 ) << "\",\n";
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
catch ( const fc::exception& e )
|
||||||
|
{
|
||||||
|
edump((e.to_detail_string()) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(bloom_test_2)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//Instantiate Bloom Filter
|
||||||
|
bloom_filter filter(setup_parameters());
|
||||||
|
|
||||||
|
std::string str_list[] = { "AbC", "iJk", "XYZ" };
|
||||||
|
|
||||||
std::string str_list[] = { "AbC", "iJk", "XYZ" };
|
|
||||||
|
|
||||||
// Insert into Bloom Filter
|
// Insert into Bloom Filter
|
||||||
{
|
{
|
||||||
|
|
@ -91,19 +103,13 @@ int main( int argc, char** argv )
|
||||||
// Query the existence of strings
|
// Query the existence of strings
|
||||||
for (std::size_t i = 0; i < (sizeof(str_list) / sizeof(std::string)); ++i)
|
for (std::size_t i = 0; i < (sizeof(str_list) / sizeof(std::string)); ++i)
|
||||||
{
|
{
|
||||||
if (filter.contains(str_list[i]))
|
BOOST_CHECK( filter.contains(str_list[i]) );
|
||||||
{
|
|
||||||
std::cout << "BF contains: " << str_list[i] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the existence of numbers
|
// Query the existence of numbers
|
||||||
for (std::size_t i = 0; i < 100; ++i)
|
for (std::size_t i = 0; i < 100; ++i)
|
||||||
{
|
{
|
||||||
if (filter.contains(i))
|
BOOST_CHECK( filter.contains(i) );
|
||||||
{
|
|
||||||
std::cout << "BF contains: " << i << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string invalid_str_list[] = { "AbCX", "iJkX", "XYZX" };
|
std::string invalid_str_list[] = { "AbCX", "iJkX", "XYZX" };
|
||||||
|
|
@ -111,31 +117,20 @@ int main( int argc, char** argv )
|
||||||
// Query the existence of invalid strings
|
// Query the existence of invalid strings
|
||||||
for (std::size_t i = 0; i < (sizeof(invalid_str_list) / sizeof(std::string)); ++i)
|
for (std::size_t i = 0; i < (sizeof(invalid_str_list) / sizeof(std::string)); ++i)
|
||||||
{
|
{
|
||||||
if (filter.contains(invalid_str_list[i]))
|
BOOST_CHECK( !filter.contains(invalid_str_list[i]) );
|
||||||
{
|
|
||||||
std::cout << "BF falsely contains: " << invalid_str_list[i] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the existence of invalid numbers
|
// Query the existence of invalid numbers
|
||||||
for (int i = -1; i > -100; --i)
|
for (int i = -1; i > -100; --i)
|
||||||
{
|
{
|
||||||
if (filter.contains(i))
|
BOOST_CHECK( !filter.contains(i) );
|
||||||
{
|
|
||||||
std::cout << "BF falsely contains: " << i << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wdump((filter));
|
|
||||||
auto packed_filter = fc::raw::pack(filter);
|
|
||||||
wdump((packed_filter.size()));
|
|
||||||
wdump((packed_filter));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
catch ( const fc::exception& e )
|
catch ( const fc::exception& e )
|
||||||
{
|
{
|
||||||
edump((e.to_detail_string()) );
|
edump((e.to_detail_string()) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
#define BOOST_TEST_MODULE fc_task_cancel_tests
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include <fc/thread/thread.hpp>
|
#include <fc/thread/thread.hpp>
|
||||||
|
|
@ -8,6 +7,8 @@
|
||||||
#include <fc/exception/exception.hpp>
|
#include <fc/exception/exception.hpp>
|
||||||
#include <fc/thread/non_preemptable_scope_check.hpp>
|
#include <fc/thread/non_preemptable_scope_check.hpp>
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(fc_thread)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( leave_mutex_locked )
|
BOOST_AUTO_TEST_CASE( leave_mutex_locked )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
@ -239,3 +240,5 @@ BOOST_AUTO_TEST_CASE( cancel_scheduled_task )
|
||||||
}
|
}
|
||||||
BOOST_CHECK_EQUAL(task_execute_count, 2);
|
BOOST_CHECK_EQUAL(task_execute_count, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue