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 )
|
||||
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 )
|
||||
|
||||
|
||||
|
|
@ -358,7 +358,10 @@ target_link_libraries( ecc_test 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.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 )
|
||||
|
||||
if(WIN32)
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <fc/crypto/elliptic.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <fc/io/raw.hpp>
|
||||
#include <fc/variant.hpp>
|
||||
#include <fc/reflect/variant.hpp>
|
||||
|
||||
//extern "C" {
|
||||
//#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); }
|
||||
BOOST_AUTO_TEST_SUITE(fc_crypto)
|
||||
|
||||
int main( int argc, char** argv )
|
||||
BOOST_AUTO_TEST_CASE(blind_test)
|
||||
{
|
||||
try {
|
||||
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,OutC2}, 0 ) );
|
||||
BOOST_CHECK( fc::ecc::verify_sum( {InC1,InC2}, {OutC1,OutC2}, 0 ) );
|
||||
auto nonce = fc::sha256::hash("nonce");
|
||||
|
||||
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 );
|
||||
wdump((result));
|
||||
FC_ASSERT( result.max_value >= 60 );
|
||||
FC_ASSERT( result.min_value >= 0 );
|
||||
// wdump((result));
|
||||
BOOST_CHECK( result.max_value >= 60 );
|
||||
BOOST_CHECK( result.min_value >= 0 );
|
||||
|
||||
|
||||
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 C2m1 = fc::ecc::blind( B2m1, 1 );
|
||||
|
||||
FC_ASSERT( fc::ecc::verify_sum( {C1,C2}, {C3}, 0 ) );
|
||||
FC_ASSERT( fc::ecc::verify_sum( {C1,C2}, {C3}, 0 ) );
|
||||
FC_ASSERT( fc::ecc::verify_sum( {C3}, {C1,C2}, 0 ) );
|
||||
FC_ASSERT( fc::ecc::verify_sum( {C3}, {C1,C2}, 0 ) );
|
||||
BOOST_CHECK( fc::ecc::verify_sum( {C1,C2}, {C3}, 0 ) );
|
||||
BOOST_CHECK( fc::ecc::verify_sum( {C1,C2}, {C3}, 0 ) );
|
||||
BOOST_CHECK( 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 C4 = fc::ecc::blind( B1, 2 );
|
||||
|
||||
FC_ASSERT( fc::ecc::verify_sum( {C2}, {C3}, -1 ) );
|
||||
FC_ASSERT( fc::ecc::verify_sum( {C1}, {C1}, 0 ) );
|
||||
FC_ASSERT( fc::ecc::verify_sum( {C2}, {C2}, 0 ) );
|
||||
FC_ASSERT( fc::ecc::verify_sum( {C3}, {C2}, 1 ) );
|
||||
FC_ASSERT( fc::ecc::verify_sum( {C1}, {C2}, INT64_MAX ) );
|
||||
FC_ASSERT( 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}, {C3}, -1 ) );
|
||||
BOOST_CHECK( fc::ecc::verify_sum( {C1}, {C1}, 0 ) );
|
||||
BOOST_CHECK( fc::ecc::verify_sum( {C2}, {C2}, 0 ) );
|
||||
BOOST_CHECK( fc::ecc::verify_sum( {C3}, {C2}, 1 ) );
|
||||
BOOST_CHECK( fc::ecc::verify_sum( {C1}, {C2}, INT64_MAX ) );
|
||||
BOOST_CHECK( fc::ecc::verify_sum( {C1}, {C2}, 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 In0 = fc::ecc::blind( InBlind, 0 );
|
||||
|
||||
FC_ASSERT( fc::ecc::verify_sum( {InC}, {OutC1,OutC2}, 0 ) );
|
||||
FC_ASSERT( fc::ecc::verify_sum( {InC}, {In0}, 1000 ) );
|
||||
BOOST_CHECK( fc::ecc::verify_sum( {InC}, {OutC1,OutC2}, 0 ) );
|
||||
BOOST_CHECK( fc::ecc::verify_sum( {InC}, {In0}, 1000 ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch ( const fc::exception& e )
|
||||
{
|
||||
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/exception/exception.hpp>
|
||||
#include <fc/reflect/variant.hpp>
|
||||
|
|
@ -10,10 +12,8 @@
|
|||
|
||||
using namespace fc;
|
||||
|
||||
int main( int argc, char** argv )
|
||||
static bloom_parameters setup_parameters()
|
||||
{
|
||||
try {
|
||||
|
||||
bloom_parameters parameters;
|
||||
|
||||
// How many elements roughly do we expect to insert?
|
||||
|
|
@ -27,25 +27,31 @@ int main( int argc, char** argv )
|
|||
|
||||
if (!parameters)
|
||||
{
|
||||
std::cout << "Error - Invalid set of bloom filter parameters!" << std::endl;
|
||||
return 1;
|
||||
BOOST_FAIL( "Error - Invalid set of bloom filter parameters!" );
|
||||
}
|
||||
|
||||
parameters.compute_optimal_parameters();
|
||||
|
||||
//Instantiate Bloom Filter
|
||||
bloom_filter filter(parameters);
|
||||
return parameters;
|
||||
}
|
||||
|
||||
if( argc > 1 )
|
||||
BOOST_AUTO_TEST_SUITE(fc_crypto)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(bloom_test_1)
|
||||
{
|
||||
try {
|
||||
|
||||
//Instantiate Bloom Filter
|
||||
bloom_filter filter(setup_parameters());
|
||||
|
||||
uint32_t count = 0;
|
||||
std::string line;
|
||||
std::ifstream in(argv[1]);
|
||||
std::ifstream in("README.md");
|
||||
std::ofstream words("words.txt");
|
||||
while( !in.eof() && count < 100000 )
|
||||
{
|
||||
std::getline(in, line);
|
||||
std::cout << "'"<<line<<"'\n";
|
||||
// std::cout << "'"<<line<<"'\n";
|
||||
if( !filter.contains(line) )
|
||||
{
|
||||
filter.insert( line );
|
||||
|
|
@ -53,21 +59,27 @@ int main( int argc, char** argv )
|
|||
++count;
|
||||
}
|
||||
}
|
||||
wdump((filter));
|
||||
// wdump((filter));
|
||||
auto packed_filter = fc::raw::pack(filter);
|
||||
wdump((packed_filter.size()));
|
||||
wdump((packed_filter));
|
||||
std::ofstream out(argv[2]);
|
||||
std::string str = fc::json::to_string(packed_filter);
|
||||
// wdump((packed_filter.size()));
|
||||
// wdump((packed_filter));
|
||||
std::stringstream out;
|
||||
// std::string str = fc::json::to_string(packed_filter);
|
||||
auto b64 = fc::base64_encode( packed_filter.data(), packed_filter.size() );
|
||||
for( uint32_t i = 0; i < b64.size(); i += 1024 )
|
||||
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" };
|
||||
|
||||
|
|
@ -91,19 +103,13 @@ int main( int argc, char** argv )
|
|||
// Query the existence of strings
|
||||
for (std::size_t i = 0; i < (sizeof(str_list) / sizeof(std::string)); ++i)
|
||||
{
|
||||
if (filter.contains(str_list[i]))
|
||||
{
|
||||
std::cout << "BF contains: " << str_list[i] << std::endl;
|
||||
}
|
||||
BOOST_CHECK( filter.contains(str_list[i]) );
|
||||
}
|
||||
|
||||
// Query the existence of numbers
|
||||
for (std::size_t i = 0; i < 100; ++i)
|
||||
{
|
||||
if (filter.contains(i))
|
||||
{
|
||||
std::cout << "BF contains: " << i << std::endl;
|
||||
}
|
||||
BOOST_CHECK( filter.contains(i) );
|
||||
}
|
||||
|
||||
std::string invalid_str_list[] = { "AbCX", "iJkX", "XYZX" };
|
||||
|
|
@ -111,31 +117,20 @@ int main( int argc, char** argv )
|
|||
// Query the existence of invalid strings
|
||||
for (std::size_t i = 0; i < (sizeof(invalid_str_list) / sizeof(std::string)); ++i)
|
||||
{
|
||||
if (filter.contains(invalid_str_list[i]))
|
||||
{
|
||||
std::cout << "BF falsely contains: " << invalid_str_list[i] << std::endl;
|
||||
}
|
||||
BOOST_CHECK( !filter.contains(invalid_str_list[i]) );
|
||||
}
|
||||
|
||||
// Query the existence of invalid numbers
|
||||
for (int i = -1; i > -100; --i)
|
||||
{
|
||||
if (filter.contains(i))
|
||||
{
|
||||
std::cout << "BF falsely contains: " << i << std::endl;
|
||||
BOOST_CHECK( !filter.contains(i) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wdump((filter));
|
||||
auto packed_filter = fc::raw::pack(filter);
|
||||
wdump((packed_filter.size()));
|
||||
wdump((packed_filter));
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch ( const fc::exception& e )
|
||||
{
|
||||
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 <fc/thread/thread.hpp>
|
||||
|
|
@ -8,6 +7,8 @@
|
|||
#include <fc/exception/exception.hpp>
|
||||
#include <fc/thread/non_preemptable_scope_check.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(fc_thread)
|
||||
|
||||
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_AUTO_TEST_SUITE_END()
|
||||
|
|
|
|||
Loading…
Reference in a new issue