Fixed existing tests; add more unit tests for db_sidechain methods
This commit is contained in:
parent
b26e3bc8a1
commit
113ba26632
11 changed files with 388 additions and 85 deletions
|
|
@ -30,7 +30,7 @@ std::map< account_id_type, public_key_type> database::get_active_witnesses_keys(
|
|||
bool database::is_sidechain_fork_needed() const
|
||||
{
|
||||
const auto& params = get_global_properties().parameters.extensions.value.sidechain_parameters;
|
||||
return !params.valid();
|
||||
return !params;
|
||||
}
|
||||
|
||||
void database::perform_sidechain_fork()
|
||||
|
|
@ -275,7 +275,8 @@ void database::remove_sidechain_proposal_object( const proposal_object& proposal
|
|||
{ try {
|
||||
if( proposal.proposed_transaction.operations.size() == 1 &&
|
||||
( proposal.proposed_transaction.operations.back().which() == operation::tag<bitcoin_transaction_send_operation>::value ||
|
||||
proposal.proposed_transaction.operations.back().which() == operation::tag<bitcoin_issue_operation>::value ) )
|
||||
proposal.proposed_transaction.operations.back().which() == operation::tag<bitcoin_issue_operation>::value ||
|
||||
proposal.proposed_transaction.operations.back().which() == operation::tag<bitcoin_transaction_revert_operation>::value ) )
|
||||
{
|
||||
const auto& sidechain_proposal_idx = get_index_type<sidechain_proposal_index>().indices().get<by_proposal>();
|
||||
auto sidechain_proposal_itr = sidechain_proposal_idx.find( proposal.id );
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ class info_for_vout_object : public abstract_object<info_for_vout_object>
|
|||
}
|
||||
};
|
||||
|
||||
bool operator==( const info_for_vout_object& ifv ) const {
|
||||
return ( this->payer == ifv.payer ) &&
|
||||
( this->address == ifv.address ) &&
|
||||
( this->amount == ifv.amount );
|
||||
}
|
||||
|
||||
info_for_vout_id_type get_id()const { return id; }
|
||||
|
||||
account_id_type payer;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ namespace graphene { namespace chain {
|
|||
void operator()( const bitcoin_transaction_send_operation &v );
|
||||
|
||||
void operator()( const bitcoin_issue_operation &v );
|
||||
|
||||
void operator()( const bitcoin_transaction_revert_operation &v );
|
||||
};
|
||||
|
||||
class proposal_create_evaluator : public evaluator<proposal_create_evaluator>
|
||||
|
|
|
|||
|
|
@ -182,6 +182,23 @@ void sidechain_hardfork_visitor::operator()( const bitcoin_issue_operation &v )
|
|||
}
|
||||
}
|
||||
|
||||
void sidechain_hardfork_visitor::operator()( const bitcoin_transaction_revert_operation &v )
|
||||
{
|
||||
db.create<sidechain_proposal_object>([&]( sidechain_proposal_object& sch_prop ) {
|
||||
sch_prop.proposal_type = sidechain::sidechain_proposal_type::REVERT_BTC_TRANSACTION;
|
||||
sch_prop.proposal_id = prop_id;
|
||||
});
|
||||
|
||||
for( const auto& trx : v.transactions_info ) {
|
||||
const auto& trx_confirmations = db.bitcoin_confirmations.find<sidechain::by_hash>( trx.transaction_id );
|
||||
if( trx_confirmations.valid() ) {
|
||||
db.bitcoin_confirmations.modify<sidechain::by_hash>( trx.transaction_id, [&]( sidechain::bitcoin_transaction_confirmations& obj ) {
|
||||
obj.used = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void_result proposal_create_evaluator::do_evaluate(const proposal_create_operation& o)
|
||||
{ try {
|
||||
const database& d = db();
|
||||
|
|
@ -198,7 +215,8 @@ void_result proposal_create_evaluator::do_evaluate(const proposal_create_operati
|
|||
"Proposal review period must be less than its overall lifetime." );
|
||||
|
||||
bool pbtc_op = ( o.proposed_ops[0].op.which() == operation::tag<bitcoin_transaction_send_operation>::value ) ||
|
||||
( o.proposed_ops[0].op.which() == operation::tag<bitcoin_issue_operation>::value );
|
||||
( o.proposed_ops[0].op.which() == operation::tag<bitcoin_issue_operation>::value ) ||
|
||||
( o.proposed_ops[0].op.which() == operation::tag<bitcoin_transaction_revert_operation>::value );
|
||||
|
||||
if( d.is_sidechain_fork_needed() && pbtc_op ) {
|
||||
FC_THROW( "Currently the operation is unavailable." );
|
||||
|
|
|
|||
|
|
@ -6,6 +6,12 @@
|
|||
|
||||
namespace sidechain {
|
||||
|
||||
bool bitcoin_address::operator==( const bitcoin_address& btc_addr ) const {
|
||||
return ( this->address == btc_addr.address ) &&
|
||||
( this->type == btc_addr.type ) &&
|
||||
( this->raw_address == btc_addr.raw_address );
|
||||
}
|
||||
|
||||
bytes bitcoin_address::get_script() const
|
||||
{
|
||||
switch ( type ) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ public:
|
|||
bitcoin_address( const std::string& addr ) : address( addr ), type( determine_type() ),
|
||||
raw_address( determine_raw_address() ) {}
|
||||
|
||||
bool operator==( const bitcoin_address& btc_addr ) const;
|
||||
|
||||
payment_type get_type() const { return type; }
|
||||
|
||||
std::string get_address() const { return address; }
|
||||
|
|
|
|||
|
|
@ -380,3 +380,34 @@ processed_transaction _push_transaction( database& db, const signed_transaction&
|
|||
}
|
||||
|
||||
} }
|
||||
|
||||
namespace sidechain {
|
||||
|
||||
class test_environment
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
test_environment( database& db )
|
||||
{
|
||||
|
||||
for( size_t i = 1; i < 6; i++ ) {
|
||||
prev_out out{ std::string( 64, std::to_string( i )[0] ), static_cast<uint32_t>( i ), static_cast<uint64_t>( i * 10000 ) };
|
||||
db.i_w_info.insert_info_for_vin( out, std::to_string( i ), { 0x00, 0x01, 0x02 } );
|
||||
db.i_w_info.insert_info_for_vout( account_id_type( i ), "2Mt57VSFqBe7UpDad9QaYHev21E1VscAZMU", i * 5000 );
|
||||
}
|
||||
|
||||
vins = db.i_w_info.get_info_for_vins();
|
||||
pw_vin = *db.i_w_info.get_info_for_pw_vin();
|
||||
vouts = db.i_w_info.get_info_for_vouts();
|
||||
full_tx = db.create_btc_transaction( vins, vouts, pw_vin );
|
||||
}
|
||||
|
||||
std::vector<info_for_vin> vins;
|
||||
info_for_vin pw_vin;
|
||||
std::vector<info_for_vout> vouts;
|
||||
full_btc_transaction full_tx;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
262
tests/sidechain_tests/db_sidechain_tests.cpp
Normal file
262
tests/sidechain_tests/db_sidechain_tests.cpp
Normal file
|
|
@ -0,0 +1,262 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
#include "../common/database_fixture.hpp"
|
||||
|
||||
#include <fc/crypto/digest.hpp>
|
||||
|
||||
#include <graphene/chain/proposal_object.hpp>
|
||||
#include <graphene/chain/sidechain_proposal_object.hpp>
|
||||
#include <graphene/chain/witness_object.hpp>
|
||||
#include <graphene/chain/primary_wallet_vout_object.hpp>
|
||||
|
||||
using namespace graphene::chain;
|
||||
using namespace sidechain;
|
||||
|
||||
template< class SidechainOp >
|
||||
proposal_object create_op_and_prop( database& db, bool check_size = true )
|
||||
{
|
||||
const auto& sidechain_proposal_idx = db.get_index_type<sidechain_proposal_index>().indices().get<by_proposal>();
|
||||
|
||||
BOOST_CHECK( !check_size || sidechain_proposal_idx.size() == 0 );
|
||||
|
||||
const flat_set<witness_id_type>& active_witnesses = db.get_global_properties().active_witnesses;
|
||||
const witness_id_type& witness_id = *active_witnesses.begin();
|
||||
const witness_object witness = witness_id(db);
|
||||
const account_object& witness_account = witness.witness_account(db);
|
||||
|
||||
const auto& propose = db.create<proposal_object>( [&]( proposal_object& obj ){
|
||||
obj.expiration_time = db.head_block_time() + fc::days(1);
|
||||
obj.review_period_time = db.head_block_time() + fc::days(1);
|
||||
obj.proposed_transaction.operations.push_back( SidechainOp() );
|
||||
} );
|
||||
|
||||
const auto& spropose = db.create<sidechain_proposal_object>( [&]( sidechain_proposal_object& obj ){
|
||||
obj.proposal_id = propose.id;
|
||||
} );
|
||||
|
||||
return propose;
|
||||
}
|
||||
|
||||
template< class SidechainOp >
|
||||
void check_fork_prop( database& db )
|
||||
{
|
||||
db.modify( db.get_global_properties(), [&]( global_property_object& gpo ) {
|
||||
gpo.parameters.extensions.value.sidechain_parameters.reset();
|
||||
if( gpo.pending_parameters )
|
||||
gpo.pending_parameters->extensions.value.sidechain_parameters.reset();
|
||||
});
|
||||
|
||||
BOOST_CHECK( db.is_sidechain_fork_needed() );
|
||||
|
||||
transaction_evaluation_state context(&db);
|
||||
|
||||
proposal_create_operation proposal_op;
|
||||
proposal_op.fee_paying_account = account_id_type();
|
||||
proposal_op.proposed_ops.emplace_back( SidechainOp() );
|
||||
proposal_op.expiration_time = db.head_block_time() + fc::days(1);
|
||||
|
||||
BOOST_CHECK_THROW( db.apply_operation( context, proposal_op ), fc::exception );
|
||||
}
|
||||
|
||||
/////////////////////////////////// functions for roll_back tests
|
||||
|
||||
inline proposal_object create_proposals( database& db, bitcoin_transaction_send_operation op )
|
||||
{
|
||||
const auto& propose_send = db.create<proposal_object>( [&]( proposal_object& obj ){
|
||||
obj.expiration_time = db.head_block_time() + fc::days(1);
|
||||
obj.review_period_time = db.head_block_time() + fc::days(1);
|
||||
obj.proposed_transaction.operations.push_back( op );
|
||||
} );
|
||||
db.create<sidechain_proposal_object>( [&]( sidechain_proposal_object& obj ){
|
||||
obj.proposal_id = propose_send.id;
|
||||
obj.proposal_type = sidechain_proposal_type::SEND_BTC_TRANSACTION;
|
||||
} );
|
||||
|
||||
return propose_send;
|
||||
}
|
||||
|
||||
inline bitcoin_transaction_send_operation create_btc_tx_send_op( const test_environment& env, uint32_t offset = 0 )
|
||||
{
|
||||
bitcoin_transaction_send_operation op;
|
||||
op.pw_vin = env.pw_vin;
|
||||
op.vins = std::vector<info_for_vin>( env.vins.begin(), env.vins.end() - offset );
|
||||
for( const auto& vout : std::vector<info_for_vout>( env.vouts.begin(), env.vouts.end() - offset ) ) {
|
||||
op.vouts.push_back( vout.get_id() );
|
||||
}
|
||||
op.transaction = env.full_tx.first;
|
||||
op.fee_for_size = env.full_tx.second;
|
||||
return op;
|
||||
}
|
||||
|
||||
inline void mark_vin( database& db, const test_environment& env )
|
||||
{
|
||||
for( auto& iter: env.vins ) {
|
||||
db.i_w_info.mark_as_used_vin( iter );
|
||||
}
|
||||
}
|
||||
|
||||
inline void mark_vout( database& db, const test_environment& env )
|
||||
{
|
||||
for( auto& iter: env.vouts ) {
|
||||
db.i_w_info.mark_as_used_vout( iter );
|
||||
}
|
||||
}
|
||||
|
||||
inline void mark_vin_vout_pw( database& db, const test_environment& env )
|
||||
{
|
||||
mark_vin( db, env );
|
||||
mark_vout( db, env );
|
||||
db.pw_vout_manager.mark_as_used_vout( env.pw_vin.identifier );
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE( db_sidechain_tests, database_fixture )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( remove_sidechain_proposals_test )
|
||||
{
|
||||
const auto& sidechain_proposal_idx = db.get_index_type<sidechain_proposal_index>().indices().get<by_proposal>();
|
||||
|
||||
BOOST_CHECK_EQUAL( sidechain_proposal_idx.size(), 0 );
|
||||
|
||||
const auto& propose_send = create_op_and_prop<bitcoin_transaction_send_operation>( db, false );
|
||||
const auto& propose_issue = create_op_and_prop<bitcoin_issue_operation>( db, false );
|
||||
const auto& propose_revert = create_op_and_prop<bitcoin_transaction_revert_operation>( db, false );
|
||||
|
||||
create_op_and_prop<bitcoin_transaction_send_operation>( db, false );
|
||||
create_op_and_prop<bitcoin_issue_operation>( db, false );
|
||||
create_op_and_prop<bitcoin_transaction_revert_operation>( db, false );
|
||||
|
||||
BOOST_CHECK_EQUAL( sidechain_proposal_idx.size(), 6 );
|
||||
|
||||
db.remove_sidechain_proposal_object( propose_send );
|
||||
db.remove_sidechain_proposal_object( propose_issue );
|
||||
db.remove_sidechain_proposal_object( propose_revert );
|
||||
|
||||
BOOST_CHECK_EQUAL( sidechain_proposal_idx.size(), 3 );
|
||||
|
||||
const auto& propose_transfer = db.create<proposal_object>( [&]( proposal_object& obj ){
|
||||
obj.expiration_time = db.head_block_time() + fc::days(1);
|
||||
obj.review_period_time = db.head_block_time() + fc::days(1);
|
||||
obj.proposed_transaction.operations.push_back( transfer_operation() );
|
||||
} );
|
||||
|
||||
db.remove_sidechain_proposal_object( propose_transfer );
|
||||
|
||||
BOOST_CHECK_EQUAL( sidechain_proposal_idx.size(), 3 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( sidechain_fork_btc_issue_op_test )
|
||||
{
|
||||
check_fork_prop<bitcoin_issue_operation> ( db );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( sidechain_fork_btc_send_op_test )
|
||||
{
|
||||
check_fork_prop<bitcoin_transaction_send_operation> ( db );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( sidechain_fork_btc_revert_op_test )
|
||||
{
|
||||
check_fork_prop<bitcoin_transaction_revert_operation> ( db );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( roll_back_vin_test )
|
||||
{
|
||||
test_environment env( db );
|
||||
|
||||
mark_vin( db, env );
|
||||
|
||||
bitcoin_transaction_send_operation op = create_btc_tx_send_op( env );
|
||||
const auto& propose_send = create_proposals( db, op );
|
||||
|
||||
BOOST_CHECK_EQUAL( db.get_index_type<sidechain_proposal_index>().indices().get<by_proposal>().size(), 1 );
|
||||
BOOST_CHECK_EQUAL( db.i_w_info.get_info_for_vins().size(), 0 );
|
||||
BOOST_CHECK( !db.pw_vout_manager.get_vout( op.pw_vin.identifier )->used );
|
||||
|
||||
db.roll_back_vin_and_vout( propose_send );
|
||||
|
||||
BOOST_CHECK_EQUAL( db.i_w_info.get_info_for_vins().size(), 5 );
|
||||
|
||||
BOOST_CHECK( !db.pw_vout_manager.get_vout( op.pw_vin.identifier )->used );
|
||||
BOOST_CHECK_EQUAL( db.get_index_type<sidechain_proposal_index>().indices().get<by_proposal>().size(), 0 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( roll_back_vout_test )
|
||||
{
|
||||
test_environment env( db );
|
||||
|
||||
mark_vout( db, env );
|
||||
|
||||
bitcoin_transaction_send_operation op = create_btc_tx_send_op( env );
|
||||
const auto& propose_send = create_proposals( db, op );
|
||||
|
||||
BOOST_CHECK_EQUAL( db.get_index_type<sidechain_proposal_index>().indices().get<by_proposal>().size(), 1 );
|
||||
BOOST_CHECK_EQUAL( db.i_w_info.get_info_for_vouts().size(), 0 );
|
||||
BOOST_CHECK( !db.pw_vout_manager.get_vout( op.pw_vin.identifier )->used );
|
||||
|
||||
db.roll_back_vin_and_vout( propose_send );
|
||||
|
||||
BOOST_CHECK_EQUAL( db.i_w_info.get_info_for_vouts().size(), 5 );
|
||||
|
||||
BOOST_CHECK( !db.pw_vout_manager.get_vout( op.pw_vin.identifier )->used );
|
||||
BOOST_CHECK_EQUAL( db.get_index_type<sidechain_proposal_index>().indices().get<by_proposal>().size(), 0 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( roll_back_vin_and_vout_test )
|
||||
{
|
||||
test_environment env( db );
|
||||
|
||||
mark_vin_vout_pw( db, env );
|
||||
bitcoin_transaction_send_operation op = create_btc_tx_send_op( env );
|
||||
const auto& propose_send = create_proposals( db, op );
|
||||
|
||||
BOOST_CHECK_EQUAL( db.get_index_type<sidechain_proposal_index>().indices().get<by_proposal>().size(), 1 );
|
||||
BOOST_CHECK_EQUAL( db.i_w_info.get_info_for_vins().size(), 0 );
|
||||
BOOST_CHECK_EQUAL( db.i_w_info.get_info_for_vouts().size(), 0 );
|
||||
BOOST_CHECK( db.pw_vout_manager.get_vout( op.pw_vin.identifier )->used );
|
||||
db.roll_back_vin_and_vout( propose_send );
|
||||
|
||||
BOOST_CHECK_EQUAL( db.i_w_info.get_info_for_vins().size(), 5 );
|
||||
BOOST_CHECK_EQUAL( db.i_w_info.get_info_for_vouts().size(), 5 );
|
||||
|
||||
BOOST_CHECK( !db.pw_vout_manager.get_vout( op.pw_vin.identifier )->used );
|
||||
BOOST_CHECK_EQUAL( db.get_index_type<sidechain_proposal_index>().indices().get<by_proposal>().size(), 0 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( roll_back_part_test )
|
||||
{
|
||||
test_environment env( db );
|
||||
|
||||
mark_vin_vout_pw( db, env );
|
||||
bitcoin_transaction_send_operation op = create_btc_tx_send_op( env, 2 );
|
||||
|
||||
const auto& propose_send = create_proposals( db, op );
|
||||
BOOST_CHECK_EQUAL( db.get_index_type<sidechain_proposal_index>().indices().get<by_proposal>().size(), 1 );
|
||||
BOOST_CHECK_EQUAL( db.i_w_info.get_info_for_vins().size(), 0 );
|
||||
BOOST_CHECK_EQUAL( db.i_w_info.get_info_for_vouts().size(), 0 );
|
||||
BOOST_CHECK( db.pw_vout_manager.get_vout( op.pw_vin.identifier )->used );
|
||||
db.roll_back_vin_and_vout( propose_send );
|
||||
|
||||
BOOST_REQUIRE_EQUAL( db.i_w_info.get_info_for_vins().size(), 3 );
|
||||
BOOST_REQUIRE_EQUAL( db.i_w_info.get_info_for_vouts().size(), 3 );
|
||||
|
||||
BOOST_CHECK( !db.pw_vout_manager.get_vout( op.pw_vin.identifier )->used );
|
||||
BOOST_CHECK_EQUAL( db.get_index_type<sidechain_proposal_index>().indices().get<by_proposal>().size(), 0 );
|
||||
|
||||
auto info_vins = db.i_w_info.get_info_for_vins();
|
||||
auto info_vouts = db.i_w_info.get_info_for_vouts();
|
||||
|
||||
BOOST_REQUIRE_EQUAL( op.vins.size(), info_vins.size() );
|
||||
BOOST_REQUIRE_EQUAL( op.vouts.size(), info_vouts.size() );
|
||||
|
||||
// no match for `operator==`; but `operator!=` exists
|
||||
for( uint32_t indx = 0; indx < op.vins.size(); indx++ ) {
|
||||
BOOST_CHECK( !( op.vins[indx] != info_vins[indx] ) );
|
||||
}
|
||||
|
||||
for( uint32_t indx = 0; indx < info_vouts.size(); indx++ ) {
|
||||
BOOST_CHECK( env.vouts[indx] == info_vouts[indx] );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
@ -25,16 +25,28 @@ void create_primary_wallet_vouts( primary_wallet_vout_manager& pw_vout_manager,
|
|||
}
|
||||
}
|
||||
|
||||
fc::sha256 create_hash_id( const std::string& hash_tx, const uint32_t& n_vout, const uint64_t& id )
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::hex << id;
|
||||
std::string id_hex = std::string( 16 - ss.str().size(), '0' ) + ss.str();
|
||||
|
||||
std::string hash_str = fc::sha256::hash( hash_tx + std::to_string( n_vout ) ).str();
|
||||
std::string final_hash_id = std::string( hash_str.begin(), hash_str.begin() + 48 ) + id_hex;
|
||||
|
||||
return fc::sha256( final_hash_id );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( check_max_pw_vout_objects )
|
||||
{
|
||||
const auto& idx = db.get_index_type<primary_wallet_vout_index>().indices().get< graphene::chain::by_id >();
|
||||
|
||||
primary_wallet_vout_manager pw_vout_manager( db );
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 1 );
|
||||
BOOST_CHECK( idx.size() == 1 );
|
||||
BOOST_CHECK( idx.size() == 2 );
|
||||
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 24 );
|
||||
BOOST_CHECK( idx.size() == 25 );
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 25 );
|
||||
BOOST_CHECK( idx.size() == 27 );
|
||||
BOOST_CHECK( pw_vout_manager.is_max_vouts() == true );
|
||||
}
|
||||
|
||||
|
|
@ -44,19 +56,17 @@ BOOST_AUTO_TEST_CASE( check_pw_vout_objects_chain )
|
|||
primary_wallet_vout_manager pw_vout_manager( db );
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 24 );
|
||||
|
||||
auto itr = idx.begin();
|
||||
for( size_t i = 0; i < idx.size(); i++ ) {
|
||||
BOOST_CHECK( itr->hash_id == fc::sha256::hash( std::to_string( i ) + std::to_string( i )));
|
||||
itr++;
|
||||
for( auto itr: idx ) {
|
||||
BOOST_CHECK( itr.hash_id == create_hash_id( itr.vout.hash_tx, itr.vout.n_vout, itr.id.instance() ) );
|
||||
}
|
||||
|
||||
BOOST_CHECK( pw_vout_manager.get_latest_unused_vout().valid() );
|
||||
|
||||
auto pw_vout = *pw_vout_manager.get_latest_unused_vout();
|
||||
|
||||
BOOST_CHECK( pw_vout.vout.hash_tx == "23" );
|
||||
BOOST_CHECK( pw_vout.vout.n_vout == 23 );
|
||||
BOOST_CHECK( pw_vout.hash_id == fc::sha256::hash( "23" + std::to_string( 23 )));
|
||||
BOOST_CHECK_EQUAL( pw_vout.vout.hash_tx, "24" );
|
||||
BOOST_CHECK_EQUAL( pw_vout.vout.n_vout, 24 );
|
||||
BOOST_CHECK( pw_vout.hash_id == create_hash_id( "24", 24, pw_vout.id.instance() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( delete_pw_vout_objects )
|
||||
|
|
@ -65,57 +75,56 @@ BOOST_AUTO_TEST_CASE( delete_pw_vout_objects )
|
|||
primary_wallet_vout_manager pw_vout_manager( db );
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 24 );
|
||||
|
||||
BOOST_CHECK( idx.size() == 24 );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 25 );
|
||||
|
||||
pw_vout_manager.delete_vout_with_newer( fc::sha256::hash( "123" + std::to_string( 123 )));
|
||||
BOOST_CHECK( idx.size() == 24 );
|
||||
auto pw_vout = *pw_vout_manager.get_latest_unused_vout();
|
||||
pw_vout_manager.delete_vout_with_newer( create_hash_id( pw_vout.vout.hash_tx, pw_vout.vout.n_vout, pw_vout.id.instance() ) );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 24 );
|
||||
|
||||
pw_vout_manager.delete_vout_with_newer( create_hash_id( "13", 13, 13 ) );
|
||||
|
||||
pw_vout_manager.delete_vout_with_newer( fc::sha256::hash( "13" + std::to_string( 13 )));
|
||||
BOOST_CHECK( idx.size() == 13 );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 13 );
|
||||
|
||||
auto itr = idx.begin();
|
||||
for( size_t i = 0; i < idx.size(); i++ ) {
|
||||
BOOST_CHECK( itr->hash_id == fc::sha256::hash( std::to_string( i ) + std::to_string( i )));
|
||||
itr++;
|
||||
for( auto itr: idx ) {
|
||||
BOOST_CHECK( itr.hash_id == create_hash_id( itr.vout.hash_tx, itr.vout.n_vout, itr.id.instance() ) );
|
||||
}
|
||||
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 8 );
|
||||
pw_vout_manager.delete_vout_with_newer( fc::sha256::hash( "20" + std::to_string( 20 )));
|
||||
BOOST_CHECK( idx.size() == 20 );
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 8 );
|
||||
pw_vout_manager.delete_vout_with_newer( create_hash_id( "20", 20, 20 ) );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 21 );
|
||||
|
||||
itr = idx.begin();
|
||||
for( size_t i = 0; i < idx.size(); i++ ) {
|
||||
BOOST_CHECK( itr->hash_id == fc::sha256::hash( std::to_string( i ) + std::to_string( i )));
|
||||
itr++;
|
||||
for( auto itr: idx ) {
|
||||
BOOST_CHECK( itr.hash_id == create_hash_id( itr.vout.hash_tx, itr.vout.n_vout, itr.id.instance() ) );
|
||||
}
|
||||
|
||||
pw_vout_manager.delete_vout_with_newer( fc::sha256::hash( "0" + std::to_string( 0 )));
|
||||
BOOST_CHECK( idx.size() == 0 );
|
||||
auto itr_primary_wallet = idx.begin();
|
||||
pw_vout_manager.delete_vout_with_newer( create_hash_id( itr_primary_wallet->vout.hash_tx, itr_primary_wallet->vout.n_vout, itr_primary_wallet->id.instance() ) );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 0 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( confirm_pw_vout_objects )
|
||||
{
|
||||
const auto& idx = db.get_index_type<primary_wallet_vout_index>().indices().get< graphene::chain::by_id >();
|
||||
primary_wallet_vout_manager pw_vout_manager( db );
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 2 );
|
||||
|
||||
pw_vout_manager.confirm_vout( fc::sha256::hash( "0" + std::to_string( 0 )));
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 1 );
|
||||
|
||||
auto itr = idx.begin();
|
||||
BOOST_CHECK( itr->confirmed == true );
|
||||
pw_vout_manager.confirm_vout( create_hash_id( itr->vout.hash_tx, itr->vout.n_vout, itr->id.instance() ) );
|
||||
|
||||
pw_vout_manager.confirm_vout( fc::sha256::hash( "1" + std::to_string( 1 )));
|
||||
BOOST_CHECK( itr->confirmed == true );
|
||||
|
||||
itr++;
|
||||
pw_vout_manager.confirm_vout( create_hash_id( itr->vout.hash_tx, itr->vout.n_vout, itr->id.instance() ) );
|
||||
|
||||
BOOST_CHECK( itr->confirmed == true );
|
||||
BOOST_CHECK( idx.size() == 1 );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 1 );
|
||||
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 1 );
|
||||
itr++;
|
||||
pw_vout_manager.confirm_vout( fc::sha256::hash( "2" + std::to_string( 2 )));
|
||||
pw_vout_manager.confirm_vout( create_hash_id( itr->vout.hash_tx, itr->vout.n_vout, itr->id.instance() ) );
|
||||
|
||||
BOOST_CHECK( itr->confirmed == true );
|
||||
BOOST_CHECK( idx.size() == 1 );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 1 );
|
||||
|
||||
GRAPHENE_REQUIRE_THROW( pw_vout_manager.confirm_vout( fc::sha256::hash( "4" + std::to_string( 4 ))), fc::exception );
|
||||
GRAPHENE_REQUIRE_THROW( pw_vout_manager.confirm_vout( fc::sha256::hash( "123" + std::to_string( 123 ))), fc::exception );
|
||||
|
|
@ -126,23 +135,24 @@ BOOST_AUTO_TEST_CASE( use_pw_vout_objects )
|
|||
const auto& idx = db.get_index_type<primary_wallet_vout_index>().indices().get< graphene::chain::by_id >();
|
||||
primary_wallet_vout_manager pw_vout_manager( db );
|
||||
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 1 );
|
||||
pw_vout_manager.mark_as_used_vout( fc::sha256::hash( "0" + std::to_string( 0 )));
|
||||
|
||||
auto itr = idx.begin();
|
||||
pw_vout_manager.mark_as_used_vout( create_hash_id( itr->vout.hash_tx, itr->vout.n_vout, itr->id.instance() ) );
|
||||
|
||||
BOOST_CHECK( !pw_vout_manager.get_latest_unused_vout().valid() );
|
||||
BOOST_CHECK( itr->used == true );
|
||||
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 1 );
|
||||
pw_vout_manager.mark_as_used_vout( fc::sha256::hash( "1" + std::to_string( 1 )));
|
||||
itr++;
|
||||
pw_vout_manager.mark_as_used_vout( create_hash_id( itr->vout.hash_tx, itr->vout.n_vout, itr->id.instance() ) );
|
||||
|
||||
BOOST_CHECK( !pw_vout_manager.get_latest_unused_vout().valid() );
|
||||
BOOST_CHECK( itr->used == true );
|
||||
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 2 );
|
||||
itr++;
|
||||
itr++;
|
||||
|
||||
GRAPHENE_REQUIRE_THROW( pw_vout_manager.mark_as_used_vout( fc::sha256::hash( "3" + std::to_string( 3 ))), fc::exception );
|
||||
GRAPHENE_REQUIRE_THROW( pw_vout_manager.mark_as_used_vout( create_hash_id( itr->vout.hash_tx, itr->vout.n_vout, itr->id.instance() ) ), fc::exception );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
@ -203,6 +203,8 @@ BOOST_AUTO_TEST_CASE( bitcoin_transaction_revert_operation_test )
|
|||
create_bitcoin_issue_operation_environment( db );
|
||||
db.bitcoin_confirmations.insert( sidechain::bitcoin_transaction_confirmations( fc::sha256( std::string( 64, '1' ) ), std::set<fc::sha256>() ) );
|
||||
|
||||
auto vin = *vins_info_idx.find( fc::sha256( std::string( 64, '1' ) ) );
|
||||
|
||||
bitcoin_transaction_revert_operation revert_op;
|
||||
revert_trx_info info;
|
||||
info.transaction_id = fc::sha256( std::string( 64, '1' ) );
|
||||
|
|
@ -211,21 +213,11 @@ BOOST_AUTO_TEST_CASE( bitcoin_transaction_revert_operation_test )
|
|||
|
||||
db.apply_operation( context, revert_op );
|
||||
|
||||
BOOST_CHECK( vins_info_idx.size() == 1 );
|
||||
BOOST_CHECK_EQUAL( vins_info_idx.size(), 0 );
|
||||
BOOST_CHECK_EQUAL( btc_tx_idx.size(), 0 );
|
||||
|
||||
auto vin_itr = vins_info_idx.find( fc::sha256( std::string( 64, '1' ) ) );
|
||||
|
||||
BOOST_CHECK( vin_itr != vins_info_idx.end() );
|
||||
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 );
|
||||
auto vin_info = db.i_w_info.find_info_for_vin( fc::sha256::hash( vin.out.hash_tx + std::to_string( vin.out.n_vout ) ) );
|
||||
BOOST_CHECK( vin_info.valid() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
@ -12,33 +12,6 @@ using namespace sidechain;
|
|||
|
||||
BOOST_FIXTURE_TEST_SUITE( sidechain_proposal_checker_tests, database_fixture )
|
||||
|
||||
class test_environment
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
test_environment( database& db )
|
||||
{
|
||||
|
||||
for( size_t i = 1; i < 6; i++ ) {
|
||||
prev_out out{ std::string( 64, std::to_string( i )[0] ), static_cast<uint32_t>( i ), static_cast<uint64_t>( i * 10000 ) };
|
||||
db.i_w_info.insert_info_for_vin( out, std::to_string( i ), { 0x00, 0x01, 0x02 } );
|
||||
db.i_w_info.insert_info_for_vout( account_id_type( i ), "2Mt57VSFqBe7UpDad9QaYHev21E1VscAZMU", i * 5000 );
|
||||
}
|
||||
|
||||
vins = db.i_w_info.get_info_for_vins();
|
||||
pw_vin = *db.i_w_info.get_info_for_pw_vin();
|
||||
vouts = db.i_w_info.get_info_for_vouts();
|
||||
full_tx = db.create_btc_transaction( vins, vouts, pw_vin );
|
||||
}
|
||||
|
||||
std::vector<info_for_vin> vins;
|
||||
info_for_vin pw_vin;
|
||||
std::vector<info_for_vout> vouts;
|
||||
full_btc_transaction full_tx;
|
||||
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( check_reuse_normal_test )
|
||||
{
|
||||
sidechain_proposal_checker checker( db );
|
||||
|
|
|
|||
Loading…
Reference in a new issue