diff --git a/.gitignore b/.gitignore index 5df52280..bdcefcdc 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,11 @@ tests/chain_bench tests/chain_test tests/intense_test tests/performance_test +tests/betting_test +tests/tournament_test +tests/random_test +tests/sidechain_test +tests/generate_empty_blocks/generate_empty_blocks doxygen diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 57a451aa..5874d0c9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -41,4 +41,8 @@ file(GLOB RANDOM_SOURCES "random/*.cpp") add_executable( random_test ${RANDOM_SOURCES} ${COMMON_SOURCES} ) target_link_libraries( random_test graphene_chain graphene_app graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +file(GLOB SIDECHAIN_TESTS "sidechain_tests/*.cpp") +add_executable( sidechain_test ${SIDECHAIN_TESTS} ${COMMON_SOURCES} ) +target_link_libraries( sidechain_test graphene_chain graphene_app graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) + add_subdirectory( generate_empty_blocks ) diff --git a/tests/tests/bitcoin_address_tests.cpp b/tests/sidechain_tests/bitcoin_address_tests.cpp similarity index 100% rename from tests/tests/bitcoin_address_tests.cpp rename to tests/sidechain_tests/bitcoin_address_tests.cpp diff --git a/tests/tests/bitcoin_sign_tests.cpp b/tests/sidechain_tests/bitcoin_sign_tests.cpp similarity index 100% rename from tests/tests/bitcoin_sign_tests.cpp rename to tests/sidechain_tests/bitcoin_sign_tests.cpp diff --git a/tests/tests/bitcoin_transaction_tests.cpp b/tests/sidechain_tests/bitcoin_transaction_tests.cpp similarity index 100% rename from tests/tests/bitcoin_transaction_tests.cpp rename to tests/sidechain_tests/bitcoin_transaction_tests.cpp diff --git a/tests/tests/input_withdrawal_info_tests.cpp b/tests/sidechain_tests/input_withdrawal_info_tests.cpp similarity index 100% rename from tests/tests/input_withdrawal_info_tests.cpp rename to tests/sidechain_tests/input_withdrawal_info_tests.cpp diff --git a/tests/sidechain_tests/main.cpp b/tests/sidechain_tests/main.cpp new file mode 100644 index 00000000..405e7c10 --- /dev/null +++ b/tests/sidechain_tests/main.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include +#include +#include + +extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; + +boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { + std::srand(time(NULL)); + std::cout << "Random number generator seeded to " << time(NULL) << std::endl; + const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); + if( genesis_timestamp_str != nullptr ) + { + GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); + } + std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; + return nullptr; +} diff --git a/tests/tests/primary_wallet_vout_manager_tests.cpp b/tests/sidechain_tests/primary_wallet_vout_manager_tests.cpp similarity index 100% rename from tests/tests/primary_wallet_vout_manager_tests.cpp rename to tests/sidechain_tests/primary_wallet_vout_manager_tests.cpp diff --git a/tests/tests/sidechain_condensing_tx_tests.cpp b/tests/sidechain_tests/sidechain_condensing_tx_tests.cpp similarity index 99% rename from tests/tests/sidechain_condensing_tx_tests.cpp rename to tests/sidechain_tests/sidechain_condensing_tx_tests.cpp index 61c127d0..56c1268b 100644 --- a/tests/tests/sidechain_condensing_tx_tests.cpp +++ b/tests/sidechain_tests/sidechain_condensing_tx_tests.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include BOOST_AUTO_TEST_SUITE( sidechain_condensing_tx_tests ) diff --git a/tests/tests/bitcoin_issue_tests.cpp b/tests/sidechain_tests/sidechain_operation_tests.cpp similarity index 69% rename from tests/tests/bitcoin_issue_tests.cpp rename to tests/sidechain_tests/sidechain_operation_tests.cpp index a5726c07..bc5f6aa6 100644 --- a/tests/tests/bitcoin_issue_tests.cpp +++ b/tests/sidechain_tests/sidechain_operation_tests.cpp @@ -11,7 +11,7 @@ using namespace graphene::chain; -BOOST_FIXTURE_TEST_SUITE( bitcoin_issue_tests, database_fixture ) +BOOST_FIXTURE_TEST_SUITE( sidechain_operation_tests, database_fixture ) void create_bitcoin_issue_operation_environment( database& db ) { @@ -27,6 +27,8 @@ void create_bitcoin_issue_operation_environment( database& db ) auto vin_id = db.create([&]( info_for_used_vin_object& obj ) { obj.identifier = fc::sha256( std::string( 64, std::to_string( i )[0] ) ); obj.out.amount = 100000 + i * 100000; + obj.out.hash_tx = std::string( 64, std::to_string( i )[0] ); + obj.out.n_vout = 0; obj.address = std::to_string( i ); }); @@ -49,6 +51,24 @@ void create_bitcoin_issue_operation_environment( database& db ) }); } +BOOST_AUTO_TEST_CASE( create_bitcoin_address_test ) +{ + transaction_evaluation_state context(&db); + + bitcoin_address_create_operation op; + op.payer = account_id_type(); + op.owner = account_id_type(); + + const auto& idx = db.get_index_type().indices().get< by_id >(); + + BOOST_CHECK( idx.size() == 1 ); + + db.apply_operation( context, op ); + + auto btc_address = idx.begin(); + BOOST_CHECK( btc_address->count_invalid_pub_key == 1 ); +} + BOOST_AUTO_TEST_CASE( check_deleting_all_btc_transaction_information ) { transaction_evaluation_state context(&db); @@ -60,20 +80,20 @@ BOOST_AUTO_TEST_CASE( check_deleting_all_btc_transaction_information ) create_bitcoin_issue_operation_environment( db ); db.bitcoin_confirmations.insert( sidechain::bitcoin_transaction_confirmations( fc::sha256( std::string( 64,'1' ) ), std::set() ) ); - FC_ASSERT( btc_trx_idx.size() == 1 ); - FC_ASSERT( vins_info_idx.size() == 3 ); - FC_ASSERT( vouts_info_idx.size() == 3 ); - FC_ASSERT( db.bitcoin_confirmations.size() == 1 ); + BOOST_CHECK( btc_trx_idx.size() == 1 ); + BOOST_CHECK( vins_info_idx.size() == 3 ); + BOOST_CHECK( vouts_info_idx.size() == 3 ); + BOOST_CHECK( db.bitcoin_confirmations.size() == 1 ); bitcoin_issue_operation op; op.payer = db.get_sidechain_account_id(); op.transaction_ids = { fc::sha256( std::string( 64,'1' ) ) }; db.apply_operation( context, op ); - FC_ASSERT( btc_trx_idx.size() == 0 ); - FC_ASSERT( vins_info_idx.size() == 0 ); - FC_ASSERT( vouts_info_idx.size() == 0 ); - FC_ASSERT( db.bitcoin_confirmations.size() == 0 ); + BOOST_CHECK( btc_trx_idx.size() == 0 ); + BOOST_CHECK( vins_info_idx.size() == 0 ); + BOOST_CHECK( vouts_info_idx.size() == 0 ); + BOOST_CHECK( db.bitcoin_confirmations.size() == 0 ); } BOOST_AUTO_TEST_CASE( check_adding_issue_to_accounts ) @@ -91,9 +111,9 @@ BOOST_AUTO_TEST_CASE( check_adding_issue_to_accounts ) for( auto i = 0; i < 3; i++ ){ auto itr = btc_trx_idx.find( boost::make_tuple( account_id_type( i ), db.get_sidechain_asset_id() ) ); - FC_ASSERT( itr != btc_trx_idx.end() ); + BOOST_CHECK( itr != btc_trx_idx.end() ); - FC_ASSERT( itr->balance == 100000 + i * 100000 ); + BOOST_CHECK( itr->balance == 100000 + i * 100000 ); } } @@ -173,5 +193,41 @@ BOOST_AUTO_TEST_CASE( check_bitcoin_issue_operation_throw ) } } +BOOST_AUTO_TEST_CASE( bitcoin_transaction_revert_operation_test ) +{ + transaction_evaluation_state context(&db); + const auto& btc_tx_idx = db.get_index_type().indices().get< by_id >(); + const auto& vins_info_idx = db.get_index_type().indices().get< by_identifier >(); + const auto& vouts_info_idx = db.get_index_type().indices().get< by_id >(); + + create_bitcoin_issue_operation_environment( db ); + db.bitcoin_confirmations.insert( sidechain::bitcoin_transaction_confirmations( fc::sha256( std::string( 64, '1' ) ), std::set() ) ); + + bitcoin_transaction_revert_operation revert_op; + revert_trx_info info; + info.transaction_id = fc::sha256( std::string( 64, '1' ) ); + info.valid_vins.insert( fc::sha256( std::string( 64, '1' ) ) ); + revert_op.transactions_info.push_back( info ); + + db.apply_operation( context, revert_op ); + + BOOST_CHECK( vins_info_idx.size() == 1 ); + + auto vin_itr = vins_info_idx.find( fc::sha256( std::string( 64, '1' ) ) ); + + BOOST_CHECK( vin_itr != vins_info_idx.end() ); + BOOST_CHECK( vin_itr->resend ); + + BOOST_CHECK( vouts_info_idx.size() == 3 ); + + auto vout_itr = vouts_info_idx.begin(); + while( vout_itr == vouts_info_idx.end() ) { + + BOOST_CHECK( !vout_itr->used ); + vout_itr++; + } + + BOOST_CHECK( btc_tx_idx.size() == 0 ); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/tests/tests/sidechain_proposal_checker_tests.cpp b/tests/sidechain_tests/sidechain_proposal_checker_tests.cpp similarity index 100% rename from tests/tests/sidechain_proposal_checker_tests.cpp rename to tests/sidechain_tests/sidechain_proposal_checker_tests.cpp diff --git a/tests/tests/bitcoin_address_obj_tests.cpp b/tests/tests/bitcoin_address_obj_tests.cpp deleted file mode 100644 index 47aadbb8..00000000 --- a/tests/tests/bitcoin_address_obj_tests.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include "../common/database_fixture.hpp" - -#include - -#include - -using namespace graphene::chain; - -BOOST_FIXTURE_TEST_SUITE( bitcoin_addresses_obj_tests, database_fixture ) - -BOOST_AUTO_TEST_CASE( create_bitcoin_address_test ) -{ - transaction_evaluation_state context(&db); - - bitcoin_address_create_operation op; - op.payer = account_id_type(); - op.owner = account_id_type(); - - const auto& idx = db.get_index_type().indices().get< by_id >(); - - BOOST_CHECK( idx.size() == 1 ); - - db.apply_operation( context, op ); - - auto btc_address = idx.begin(); - BOOST_CHECK( btc_address->count_invalid_pub_key == 1 ); -} - -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file