fix uia_transfer test, update transfer error messages
This commit is contained in:
parent
014e6e7b79
commit
10bd652168
2 changed files with 35 additions and 27 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
void_result transfer_evaluator::do_evaluate( const transfer_operation& op )
|
void_result transfer_evaluator::do_evaluate( const transfer_operation& op )
|
||||||
{ try {
|
{ try {
|
||||||
|
|
||||||
database& d = db();
|
database& d = db();
|
||||||
|
|
||||||
const account_object& from_account = op.from(d);
|
const account_object& from_account = op.from(d);
|
||||||
|
|
@ -29,35 +30,41 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op )
|
||||||
const asset_object& asset_type = op.amount.asset_id(d);
|
const asset_object& asset_type = op.amount.asset_id(d);
|
||||||
const asset_object& fee_asset_type = op.fee.asset_id(d);
|
const asset_object& fee_asset_type = op.fee.asset_id(d);
|
||||||
|
|
||||||
if( asset_type.options.flags & white_list )
|
try {
|
||||||
{
|
|
||||||
GRAPHENE_ASSERT(
|
|
||||||
from_account.is_authorized_asset( asset_type ),
|
|
||||||
transfer_from_account_not_whitelisted,
|
|
||||||
"'from' account ${from} is not whitelisted for asset ${asset}",
|
|
||||||
("from",op.from)
|
|
||||||
("asset",op.amount.asset_id)
|
|
||||||
);
|
|
||||||
GRAPHENE_ASSERT(
|
|
||||||
to_account.is_authorized_asset( asset_type ),
|
|
||||||
transfer_to_account_not_whitelisted,
|
|
||||||
"'to' account ${to} is not whitelisted for asset ${asset}",
|
|
||||||
("to",op.to)
|
|
||||||
("asset",op.amount.asset_id)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( fee_asset_type.options.flags & white_list )
|
if( asset_type.options.flags & white_list )
|
||||||
FC_ASSERT( from_account.is_authorized_asset( asset_type ) );
|
{
|
||||||
|
GRAPHENE_ASSERT(
|
||||||
|
from_account.is_authorized_asset( asset_type ),
|
||||||
|
transfer_from_account_not_whitelisted,
|
||||||
|
"'from' account ${from} is not whitelisted for asset ${asset}",
|
||||||
|
("from",op.from)
|
||||||
|
("asset",op.amount.asset_id)
|
||||||
|
);
|
||||||
|
GRAPHENE_ASSERT(
|
||||||
|
to_account.is_authorized_asset( asset_type ),
|
||||||
|
transfer_to_account_not_whitelisted,
|
||||||
|
"'to' account ${to} is not whitelisted for asset ${asset}",
|
||||||
|
("to",op.to)
|
||||||
|
("asset",op.amount.asset_id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if( asset_type.is_transfer_restricted() )
|
if( fee_asset_type.options.flags & white_list )
|
||||||
FC_ASSERT( from_account.id == asset_type.issuer || to_account.id == asset_type.issuer );
|
FC_ASSERT( from_account.is_authorized_asset( asset_type ) );
|
||||||
|
|
||||||
FC_ASSERT( d.get_balance( from_account, asset_type ).amount >= op.amount.amount,
|
if( asset_type.is_transfer_restricted() )
|
||||||
"", ("total_transfer",op.amount)("balance",d.get_balance(from_account, asset_type).amount) );
|
FC_ASSERT( from_account.id == asset_type.issuer || to_account.id == asset_type.issuer );
|
||||||
|
|
||||||
return void_result();
|
bool insufficient_balance = d.get_balance( from_account, asset_type ).amount >= op.amount.amount;
|
||||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
FC_ASSERT( insufficient_balance,
|
||||||
|
"Insufficient Balance: ${balance}, unable to transfer '${total_transfer}' from account '${a}' to '${t}'",
|
||||||
|
("a",from_account.name)("t",to_account.name)("total_transfer",d.to_pretty_string(op.amount))("balance",d.to_pretty_string(d.get_balance(from_account, asset_type))) );
|
||||||
|
|
||||||
|
return void_result();
|
||||||
|
} FC_RETHROW_EXCEPTIONS( error, "Unable to transfer ${a} from ${f} to ${t}", ("a",d.to_pretty_string(op.amount))("f",op.from(d).name)("t",op.to(d).name) );
|
||||||
|
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
void_result transfer_evaluator::do_apply( const transfer_operation& o )
|
void_result transfer_evaluator::do_apply( const transfer_operation& o )
|
||||||
{ try {
|
{ try {
|
||||||
|
|
|
||||||
|
|
@ -704,10 +704,11 @@ BOOST_AUTO_TEST_CASE( transfer_uia )
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(get_balance(nathan, uia), 10000000);
|
BOOST_CHECK_EQUAL(get_balance(nathan, uia), 10000000);
|
||||||
transfer_operation top;
|
transfer_operation top;
|
||||||
top.to = nathan.id;
|
top.from = nathan.id;
|
||||||
top.from = genesis.id;
|
top.to = genesis.id;
|
||||||
top.amount = uia.amount(5000);
|
top.amount = uia.amount(5000);
|
||||||
trx.operations.push_back(top);
|
trx.operations.push_back(top);
|
||||||
|
BOOST_TEST_MESSAGE( "Transfering 5000 TEST from nathan to genesis" );
|
||||||
PUSH_TX( db, trx, ~0 );
|
PUSH_TX( db, trx, ~0 );
|
||||||
BOOST_CHECK_EQUAL(get_balance(nathan, uia), 10000000 - 5000);
|
BOOST_CHECK_EQUAL(get_balance(nathan, uia), 10000000 - 5000);
|
||||||
BOOST_CHECK_EQUAL(get_balance(genesis, uia), 5000);
|
BOOST_CHECK_EQUAL(get_balance(genesis, uia), 5000);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue