Skip to content

Commit bd15e7f

Browse files
committed
Tests withdraw_permission_claim 'from' check #942
1 parent f125c43 commit bd15e7f

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

tests/tests/operation_tests2.cpp

+111
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,117 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_nominal_case )
551551
BOOST_CHECK_EQUAL(get_balance(dan_id, asset_id_type()), 25);
552552
} FC_LOG_AND_RETHROW() }
553553

554+
/**
555+
* Test asset whitelisting feature for withdrawals.
556+
* Reproduces https://github.com/bitshares/bitshares-core/issues/942 and tests the fix for it.
557+
*/
558+
BOOST_AUTO_TEST_CASE( withdraw_permission_whitelist_asset_test )
559+
{ try {
560+
561+
uint32_t skip = database::skip_witness_signature
562+
| database::skip_transaction_signatures
563+
| database::skip_transaction_dupe_check
564+
| database::skip_block_size_check
565+
| database::skip_tapos_check
566+
| database::skip_authority_check
567+
| database::skip_merkle_check
568+
;
569+
570+
generate_blocks( HARDFORK_415_TIME, true, skip ); // get over Graphene 415 asset whitelisting bug
571+
generate_block( skip );
572+
573+
for( int i=0; i<2; i++ )
574+
{
575+
if( i == 1 )
576+
{
577+
generate_blocks( HARDFORK_CORE_942_TIME, true, skip );
578+
generate_block( skip );
579+
}
580+
581+
int blocks = 0;
582+
set_expiration( db, trx );
583+
584+
ACTORS( (nathan)(dan)(izzy) );
585+
586+
const asset_id_type uia_id = create_user_issued_asset( "ADVANCED", izzy_id(db), white_list ).id;
587+
588+
issue_uia( nathan_id, asset(1000, uia_id) );
589+
590+
// Make a whitelist authority
591+
{
592+
BOOST_TEST_MESSAGE( "Changing the whitelist authority" );
593+
asset_update_operation uop;
594+
uop.issuer = izzy_id;
595+
uop.asset_to_update = uia_id;
596+
uop.new_options = uia_id(db).options;
597+
uop.new_options.whitelist_authorities.insert(izzy_id);
598+
trx.operations.push_back(uop);
599+
PUSH_TX( db, trx, ~0 );
600+
trx.operations.clear();
601+
}
602+
603+
// Add dan to whitelist
604+
{
605+
upgrade_to_lifetime_member( izzy_id );
606+
607+
account_whitelist_operation wop;
608+
wop.authorizing_account = izzy_id;
609+
wop.account_to_list = dan_id;
610+
wop.new_listing = account_whitelist_operation::white_listed;
611+
trx.operations.push_back( wop );
612+
PUSH_TX( db, trx, ~0 );
613+
trx.operations.clear();
614+
}
615+
616+
// create withdraw permission
617+
{
618+
withdraw_permission_create_operation op;
619+
op.authorized_account = dan_id;
620+
op.withdraw_from_account = nathan_id;
621+
op.withdrawal_limit = asset(5, uia_id);
622+
op.withdrawal_period_sec = fc::hours(1).to_seconds();
623+
op.periods_until_expiration = 5;
624+
op.period_start_time = db.head_block_time() + 1;
625+
trx.operations.push_back(op);
626+
PUSH_TX( db, trx, ~0 );
627+
trx.operations.clear();
628+
}
629+
630+
withdraw_permission_id_type first_permit_id; // first object must have id 0
631+
632+
generate_block( skip ); // get to the time point that able to withdraw
633+
++blocks;
634+
set_expiration( db, trx );
635+
636+
// try claim a withdrawal
637+
{
638+
withdraw_permission_claim_operation op;
639+
op.withdraw_permission = first_permit_id;
640+
op.withdraw_from_account = nathan_id;
641+
op.withdraw_to_account = dan_id;
642+
op.amount_to_withdraw = asset(5, uia_id);
643+
trx.operations.push_back(op);
644+
if( i == 0 ) // before hard fork, should pass
645+
PUSH_TX( db, trx, ~0 );
646+
else // after hard fork, should throw
647+
GRAPHENE_CHECK_THROW( PUSH_TX( db, trx, ~0 ), fc::assert_exception );
648+
trx.operations.clear();
649+
}
650+
651+
// TODO add test cases for other white-listing features
652+
653+
// undo above tx's and reset
654+
generate_block( skip );
655+
++blocks;
656+
while( blocks > 0 )
657+
{
658+
db.pop_block();
659+
--blocks;
660+
}
661+
}
662+
663+
} FC_LOG_AND_RETHROW() }
664+
554665

555666
/**
556667
* This case checks to see whether the amount claimed within any particular withdrawal period

0 commit comments

Comments
 (0)