From aecfed0c1f0e96325ab7860caaf0d2275efc3f9f Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 21 Mar 2021 08:28:27 -0400 Subject: [PATCH 1/3] Fix typo in docs of CLI read_memo command --- libraries/wallet/include/graphene/wallet/wallet.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index c7933a58ea..c3a0d3a561 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -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); From 021dd8c9242ccd6464debbc94301cf080b32a993 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 21 Mar 2021 08:29:00 -0400 Subject: [PATCH 2/3] Update formatter of override_transfer in CLI --- libraries/wallet/operation_printer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/wallet/operation_printer.cpp b/libraries/wallet/operation_printer.cpp index 9faa2ee047..8d5baace58 100644 --- a/libraries/wallet/operation_printer.cpp +++ b/libraries/wallet/operation_printer.cpp @@ -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); From bd8bd2b86ae240bf3a9511aba3af05dd65478d43 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 21 Mar 2021 08:29:47 -0400 Subject: [PATCH 3/3] Add uia_tests in cli_test --- tests/cli/main.cpp | 131 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index ca24aff710..6063f6fed3 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -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