Мade executable for sidechain tests and added bitcoin_transaction_revert_operation_test

This commit is contained in:
Alexander Suslikov 2019-02-08 16:30:26 +03:00 committed by Anzhy Cherrnyavski
parent a9ca86cab2
commit 774e7b34cb
12 changed files with 117 additions and 42 deletions

5
.gitignore vendored
View file

@ -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

View file

@ -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 )

View file

@ -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 <cstdlib>
#include <iostream>
#include <boost/test/included/unit_test.hpp>
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;
}

View file

@ -5,7 +5,7 @@
#include <fc/crypto/digest.hpp>
#include <iostream>
#include <algorithm>
#include <numeric>
BOOST_AUTO_TEST_SUITE( sidechain_condensing_tx_tests )

View file

@ -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>([&]( 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<bitcoin_address_index>().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::sha256>() ) );
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<bitcoin_transaction_index>().indices().get< by_id >();
const auto& vins_info_idx = db.get_index_type<info_for_used_vin_index>().indices().get< by_identifier >();
const auto& vouts_info_idx = db.get_index_type<info_for_vout_index>().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<fc::sha256>() ) );
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()

View file

@ -1,30 +0,0 @@
#include <boost/test/unit_test.hpp>
#include "../common/database_fixture.hpp"
#include <fc/crypto/digest.hpp>
#include <graphene/chain/bitcoin_address_object.hpp>
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<bitcoin_address_index>().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()