Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uia_tests in cli_test #2385

Merged
merged 3 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/wallet/include/graphene/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ class wallet_api

/** Read a memo.
*
* @param memo JSON-enconded memo.
* @param memo JSON-encoded memo.
* @returns string with decrypted message.
*/
string read_memo(const memo_data& memo);
Expand Down
2 changes: 1 addition & 1 deletion libraries/wallet/operation_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ string operation_printer::operator()(const transfer_operation& op) const
string operation_printer::operator()(const override_transfer_operation& op) const
{
out << wallet.get_account(op.issuer).name
<< " transfer " << format_asset(op.amount)
<< " force-transfer " << format_asset(op.amount)
<< " from " << wallet.get_account(op.from).name << " to " << wallet.get_account(op.to).name;
std::string memo = print_memo( op.memo );
print_fee(op.fee);
Expand Down
131 changes: 131 additions & 0 deletions tests/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,137 @@ BOOST_FIXTURE_TEST_CASE( create_new_account, cli_fixture )
}
}

BOOST_FIXTURE_TEST_CASE( uia_tests, cli_fixture )
{
try
{
BOOST_TEST_MESSAGE("Cli UIA Tests");

INVOKE(upgrade_nathan_account);

account_object nathan_acct = con.wallet_api_ptr->get_account("nathan");

auto formatters = con.wallet_api_ptr->get_result_formatters();

auto check_account_last_history = [&]( string account, string keyword ) {
auto history = con.wallet_api_ptr->get_relative_account_history(account, 0, 1, 0);
BOOST_REQUIRE_GT( history.size(), 0 );
BOOST_CHECK( history[0].description.find( keyword ) != string::npos );
};
auto check_nathan_last_history = [&]( string keyword ) {
check_account_last_history( "nathan", keyword );
};

// Create new asset called BOBCOIN
{
BOOST_TEST_MESSAGE("Create UIA 'BOBCOIN'");
graphene::chain::asset_options asset_ops;
asset_ops.issuer_permissions = DEFAULT_UIA_ASSET_ISSUER_PERMISSION;
asset_ops.flags = charge_market_fee | override_authority;
asset_ops.max_supply = 1000000;
asset_ops.core_exchange_rate = price(asset(2),asset(1,asset_id_type(1)));
auto result = con.wallet_api_ptr->create_asset("nathan", "BOBCOIN", 4, asset_ops, {}, true);
if( formatters.find("create_asset") != formatters.end() )
{
BOOST_TEST_MESSAGE("Testing formatter of create_asset");
string output = formatters["create_asset"](
fc::variant(result, FC_PACK_MAX_DEPTH), fc::variants());
BOOST_CHECK( output.find("BOBCOIN") != string::npos );
}
}
BOOST_CHECK(generate_block(app1));

check_nathan_last_history( "Create User-Issue Asset" );
check_nathan_last_history( "BOBCOIN" );

auto bobcoin = con.wallet_api_ptr->get_asset("BOBCOIN");

bool balance_formatter_tested = false;
auto check_bobcoin_balance = [&](string account, int64_t amount) {
auto balances = con.wallet_api_ptr->list_account_balances( account );
size_t count = 0;
for( auto& bal : balances )
{
if( bal.asset_id == bobcoin.id )
{
++count;
BOOST_CHECK_EQUAL( bal.amount.value, amount );
}
}
BOOST_CHECK_EQUAL(count, 1u);

// Testing result formatter
if( !balance_formatter_tested && formatters.find("list_account_balances") != formatters.end() )
{
BOOST_TEST_MESSAGE("Testing formatter of list_account_balances");
string output = formatters["list_account_balances"](
fc::variant(balances, FC_PACK_MAX_DEPTH ), fc::variants());
BOOST_CHECK( output.find("BOBCOIN") != string::npos );
balance_formatter_tested = true;
}
};
auto check_nathan_bobcoin_balance = [&](int64_t amount) {
check_bobcoin_balance( "nathan", amount );
};

{
// Issue asset
BOOST_TEST_MESSAGE("Issue asset");
con.wallet_api_ptr->issue_asset("init0", "3", "BOBCOIN", "new coin for you", true);
}
BOOST_CHECK(generate_block(app1));

check_nathan_last_history( "nathan issue 3 BOBCOIN to init0" );
check_nathan_last_history( "new coin for you" );
check_account_last_history( "init0", "nathan issue 3 BOBCOIN to init0" );
check_account_last_history( "init0", "new coin for you" );

check_bobcoin_balance( "init0", 30000 );

{
// Override transfer
BOOST_TEST_MESSAGE("Override-transfer BOBCOIN from init0");
auto handle = con.wallet_api_ptr->begin_builder_transaction();
override_transfer_operation op;
op.issuer = con.wallet_api_ptr->get_account( "nathan" ).id;
op.from = con.wallet_api_ptr->get_account( "init0" ).id;
op.to = con.wallet_api_ptr->get_account( "nathan" ).id;
op.amount = bobcoin.amount(10000);
op.memo = con.wallet_api_ptr->sign_memo( "nathan", "init0", "get back some coin" );
con.wallet_api_ptr->add_operation_to_builder_transaction( handle, op );
con.wallet_api_ptr->set_fees_on_builder_transaction( handle, "1.3.0" );
con.wallet_api_ptr->sign_builder_transaction( handle, true );

auto memo = con.wallet_api_ptr->read_memo( *op.memo );
BOOST_CHECK_EQUAL( memo, "get back some coin" );
}
BOOST_CHECK(generate_block(app1));

check_nathan_last_history( "nathan force-transfer 1 BOBCOIN from init0 to nathan" );
check_nathan_last_history( "get back some coin" );
check_account_last_history( "init0", "nathan force-transfer 1 BOBCOIN from init0 to nathan" );
check_account_last_history( "init0", "get back some coin" );

check_bobcoin_balance( "init0", 20000 );
check_bobcoin_balance( "nathan", 10000 );

{
// Reserve / burn asset
BOOST_TEST_MESSAGE("Reserve/burn asset");
con.wallet_api_ptr->reserve_asset("nathan", "1", "BOBCOIN", true);
}
BOOST_CHECK(generate_block(app1));

check_nathan_last_history( "Reserve (burn) 1 BOBCOIN" );

check_nathan_bobcoin_balance( 0 );

} catch( fc::exception& e ) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture )
{
try
Expand Down