forked from lthn/blockchain
Merge branch 'develop' into release
This commit is contained in:
commit
1165101867
11 changed files with 343 additions and 63 deletions
|
|
@ -36,6 +36,8 @@ namespace epee
|
|||
inline std::string print_fixed_decimal_point(t_number amount, size_t decimal_point)
|
||||
{
|
||||
std::string s = boost::lexical_cast<std::string>(amount);
|
||||
if (decimal_point > 32)
|
||||
return std::string("!!") + s; // avoiding overflow issues
|
||||
if (s.size() < decimal_point + 1)
|
||||
{
|
||||
s.insert(0, decimal_point + 1 - s.size(), '0');
|
||||
|
|
|
|||
|
|
@ -3463,6 +3463,27 @@ namespace currency
|
|||
//---------------------------------------------------------------
|
||||
std::string print_money_brief(uint64_t amount, size_t decimal_point /* = CURRENCY_DISPLAY_DECIMAL_POINT */)
|
||||
{
|
||||
// TODO: temporary fix for insanely big decimal points
|
||||
// TODO: remove it after setting the limit to 18 -- sowle
|
||||
if (decimal_point > 32)
|
||||
return std::string("!!") + std::to_string(amount);
|
||||
if (decimal_point >= 20)
|
||||
{
|
||||
std::string r = std::to_string(amount);
|
||||
if (decimal_point + 1 > r.size())
|
||||
r.insert(0, decimal_point - r.size() + 1, '0');
|
||||
r.insert(r.begin() + 1, '.');
|
||||
size_t p = r.find_last_not_of('0');
|
||||
if (p != r.npos)
|
||||
{
|
||||
if (r[p] != '.' && p + 1 < r.size())
|
||||
r.erase(p + 1);
|
||||
else if (p + 2 < r.size())
|
||||
r.erase(p + 2);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64_t coin = decimal_point == CURRENCY_DISPLAY_DECIMAL_POINT ? COIN : crypto::constexpr_pow(decimal_point, 10);
|
||||
uint64_t remainder = amount % coin;
|
||||
amount /= coin;
|
||||
|
|
|
|||
|
|
@ -1089,17 +1089,24 @@ namespace currency
|
|||
bool operator()(const extra_user_data& ee)
|
||||
{
|
||||
tv.type = "user_data";
|
||||
tv.short_view = std::to_string(ee.buff.size()) + " bytes";
|
||||
tv.details_view = epee::string_tools::buff_to_hex_nodelimer(ee.buff);
|
||||
if (ee.buff.size() <= 8)
|
||||
tv.short_view = tv.details_view;
|
||||
else
|
||||
tv.short_view = std::to_string(ee.buff.size()) + " bytes";
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator()(const extra_padding& ee)
|
||||
{
|
||||
tv.type = "extra_padding";
|
||||
tv.short_view = std::to_string(ee.buff.size()) + " bytes";
|
||||
if (!ee.buff.empty())
|
||||
tv.details_view = epee::string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(&ee.buff[0]), ee.buff.size()));
|
||||
|
||||
if (ee.buff.size() <= 8)
|
||||
tv.short_view = tv.details_view;
|
||||
else
|
||||
tv.short_view = std::to_string(ee.buff.size()) + " bytes";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1144,17 +1151,25 @@ namespace currency
|
|||
bool operator()(const tx_derivation_hint& ee)
|
||||
{
|
||||
tv.type = "derivation_hint";
|
||||
tv.short_view = std::to_string(ee.msg.size()) + " bytes";
|
||||
tv.details_view = epee::string_tools::buff_to_hex_nodelimer(ee.msg);
|
||||
|
||||
if (ee.msg.size() <= 8)
|
||||
tv.short_view = tv.details_view;
|
||||
else
|
||||
tv.short_view = std::to_string(ee.msg.size()) + " bytes";
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator()(const std::string& ee)
|
||||
{
|
||||
tv.type = "string";
|
||||
tv.short_view = std::to_string(ee.size()) + " bytes";
|
||||
tv.details_view = epee::string_tools::buff_to_hex_nodelimer(ee);
|
||||
|
||||
if (ee.size() <= 8)
|
||||
tv.short_view = tv.details_view;
|
||||
else
|
||||
tv.short_view = std::to_string(ee.size()) + " bytes";
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator()(const etc_tx_flags16_t& dh)
|
||||
|
|
@ -1184,6 +1199,15 @@ namespace currency
|
|||
tv.type = "zc_balance_proof";
|
||||
return true;
|
||||
}
|
||||
bool operator()(const asset_descriptor_operation& ado)
|
||||
{
|
||||
tv.type = "asset operation";
|
||||
tv.short_view = std::string("op:") + get_asset_operation_type_string(ado.operation_type, true);
|
||||
if (ado.opt_asset_id.has_value())
|
||||
tv.short_view += std::string(" , id:") + crypto::pod_to_hex(ado.opt_asset_id);
|
||||
tv.details_view = tv.short_view + std::string(" , ticker:") + ado.descriptor.ticker + std::string(" , cur.supply:") + print_money_brief(ado.descriptor.current_supply, ado.descriptor.decimal_point);
|
||||
return true;
|
||||
}
|
||||
template<typename t_type>
|
||||
bool operator()(const t_type& t_t)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 0710887ae3231d329092691f326d91d90662149e
|
||||
Subproject commit 91e7fb00d8fb3808f0b435bfecc1b8a650211fbd
|
||||
|
|
@ -2162,24 +2162,29 @@ bool simple_wallet::emit_asset(const std::vector<std::string> &args)
|
|||
bool r = epee::string_tools::parse_tpod_from_hex_string(args[0], asset_id);
|
||||
if (!r)
|
||||
{
|
||||
fail_msg_writer() << "Failed to load asset_id from: " << args[0];
|
||||
fail_msg_writer() << "Failed to load asset id: " << args[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb);
|
||||
uint32_t asset_flags = 0;
|
||||
r = m_wallet->get_asset_info(asset_id, adb, asset_flags);
|
||||
if (!r)
|
||||
{
|
||||
fail_msg_writer() << "Unknown asset id: " << args[0];
|
||||
return true;
|
||||
}
|
||||
if (!(asset_flags & tools::wallet2::aif_own))
|
||||
{
|
||||
fail_msg_writer() << "The wallet appears to have no control over asset " << args[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t amount = 0;
|
||||
r = epee::string_tools::get_xtype_from_string(amount, args[1]);
|
||||
r = parse_amount(args[1], amount, adb.decimal_point);
|
||||
if (!r)
|
||||
{
|
||||
fail_msg_writer() << "Failed to load amount from: " << args[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb);
|
||||
r = m_wallet->daemon_get_asset_info(asset_id, adb);
|
||||
if (!r)
|
||||
{
|
||||
fail_msg_writer() << "Wallet seems to don't have control over asset: " << args[0];
|
||||
fail_msg_writer() << "Failed to read amount: " << args[1] << " (assuming decimal point is " << (int)adb.decimal_point << ")";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -2192,12 +2197,14 @@ bool simple_wallet::emit_asset(const std::vector<std::string> &args)
|
|||
currency::transaction result_tx = AUTO_VAL_INIT(result_tx);
|
||||
m_wallet->emit_asset(asset_id, destinations, result_tx);
|
||||
|
||||
success_msg_writer(true) << "Emitted " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL
|
||||
<< "Asset ID: " << asset_id << ENDL
|
||||
<< "Title: " << adb.full_name << ENDL
|
||||
<< "Ticker: " << adb.ticker << ENDL
|
||||
<< "Emitted: " << print_fixed_decimal_point(amount, adb.decimal_point) << ENDL
|
||||
<< "Max emission: " << print_fixed_decimal_point(adb.total_max_supply, adb.decimal_point) << ENDL
|
||||
success_msg_writer(true) << "Emitted " << print_money_brief(amount, adb.decimal_point) << " in tx " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL
|
||||
<< "Asset ID: " << asset_id << ENDL
|
||||
<< "Title: " << adb.full_name << ENDL
|
||||
<< "Ticker: " << adb.ticker << ENDL
|
||||
<< "Emitted now: " << print_money_brief(amount, adb.decimal_point) << ENDL
|
||||
<< "Emitted before: " << print_money_brief(adb.current_supply, adb.decimal_point) << ENDL
|
||||
<< "Emitted total: " << print_money_brief(adb.current_supply + amount, adb.decimal_point) << ENDL
|
||||
<< "Max emission: " << print_money_brief(adb.total_max_supply, adb.decimal_point) << ENDL
|
||||
;
|
||||
|
||||
SIMPLE_WALLET_CATCH_TRY_ENTRY();
|
||||
|
|
@ -2217,36 +2224,40 @@ bool simple_wallet::burn_asset(const std::vector<std::string> &args)
|
|||
bool r = epee::string_tools::parse_tpod_from_hex_string(args[0], asset_id);
|
||||
if (!r)
|
||||
{
|
||||
fail_msg_writer() << "Failed to load asset_id from: " << args[0];
|
||||
fail_msg_writer() << "Failed to load asset id: " << args[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t amount = 0;
|
||||
r = epee::string_tools::get_xtype_from_string(amount, args[1]);
|
||||
if (!r)
|
||||
{
|
||||
fail_msg_writer() << "Failed to load amount from: " << args[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb);
|
||||
r = m_wallet->daemon_get_asset_info(asset_id, adb);
|
||||
uint32_t asset_flags = 0;
|
||||
r = m_wallet->get_asset_info(asset_id, adb, asset_flags);
|
||||
if (!r)
|
||||
{
|
||||
fail_msg_writer() << "Wallet seems to don't have control over asset: " << args[0];
|
||||
fail_msg_writer() << "Unknown asset id: " << args[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
// as this is asset burning, its not necessary for the wallet to own this asset, so we don't check tools::wallet2::aif_own here
|
||||
|
||||
uint64_t amount = 0;
|
||||
r = parse_amount(args[1], amount, adb.decimal_point);
|
||||
if (!r)
|
||||
{
|
||||
fail_msg_writer() << "Failed to read amount: " << args[1] << " (assuming decimal point is " << (int)adb.decimal_point << ")";
|
||||
return true;
|
||||
}
|
||||
|
||||
currency::transaction result_tx = AUTO_VAL_INIT(result_tx);
|
||||
m_wallet->burn_asset(asset_id, amount, result_tx);
|
||||
|
||||
success_msg_writer(true) << "Burned " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL
|
||||
<< "Asset ID: " << asset_id << ENDL
|
||||
<< "Title: " << adb.full_name << ENDL
|
||||
<< "Ticker: " << adb.ticker << ENDL
|
||||
<< "Burned: " << print_fixed_decimal_point(amount, adb.decimal_point) << ENDL
|
||||
<< "Max emission: " << print_fixed_decimal_point(adb.total_max_supply, adb.decimal_point) << ENDL
|
||||
success_msg_writer(true) << "Burned " << print_money_brief(amount, adb.decimal_point) << " in tx " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL
|
||||
<< "Asset ID: " << asset_id << ENDL
|
||||
<< "Title: " << adb.full_name << ENDL
|
||||
<< "Ticker: " << adb.ticker << ENDL
|
||||
<< "Burned now: " << print_money_brief(amount, adb.decimal_point) << ENDL
|
||||
<< "Emitted before: " << print_money_brief(adb.current_supply, adb.decimal_point) << ENDL
|
||||
<< "Current supply: " << print_money_brief(adb.current_supply - amount, adb.decimal_point) << ENDL
|
||||
<< "Max emission: " << print_money_brief(adb.total_max_supply, adb.decimal_point) << ENDL
|
||||
;
|
||||
|
||||
SIMPLE_WALLET_CATCH_TRY_ENTRY();
|
||||
|
|
@ -2280,10 +2291,16 @@ bool simple_wallet::update_asset(const std::vector<std::string> &args)
|
|||
}
|
||||
|
||||
currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb);
|
||||
r = m_wallet->daemon_get_asset_info(asset_id, adb);
|
||||
uint32_t asset_flags = 0;
|
||||
r = m_wallet->get_asset_info(asset_id, adb, asset_flags);
|
||||
if (!r)
|
||||
{
|
||||
fail_msg_writer() << "Wallet seems to don't have control over asset: " << args[0];
|
||||
fail_msg_writer() << "Unknown asset id: " << args[0];
|
||||
return true;
|
||||
}
|
||||
if (!(asset_flags & tools::wallet2::aif_own))
|
||||
{
|
||||
fail_msg_writer() << "The wallet appears to have no control over asset " << args[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -2291,7 +2308,7 @@ bool simple_wallet::update_asset(const std::vector<std::string> &args)
|
|||
currency::transaction result_tx = AUTO_VAL_INIT(result_tx);
|
||||
m_wallet->update_asset(asset_id, adb, result_tx);
|
||||
|
||||
success_msg_writer(true) << "Asset metainfo update tx sent: " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL
|
||||
success_msg_writer(true) << "Asset metainfo successfully updated in tx " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL
|
||||
<< "Asset ID: " << asset_id << ENDL
|
||||
<< "Title: " << adb.full_name << ENDL
|
||||
<< "Ticker: " << adb.ticker << ENDL
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@
|
|||
#define PROJECT_REVISION "0"
|
||||
#define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION
|
||||
|
||||
#define PROJECT_VERSION_BUILD_NO 326
|
||||
#define PROJECT_VERSION_BUILD_NO 331
|
||||
#define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO)
|
||||
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"
|
||||
|
|
|
|||
|
|
@ -3823,6 +3823,15 @@ bool wallet2::get_asset_info(const crypto::public_key& asset_id, currency::asset
|
|||
return true;
|
||||
}
|
||||
|
||||
// own asset?
|
||||
auto it_own = m_own_asset_descriptors.find(asset_id);
|
||||
if (it_own != m_own_asset_descriptors.end())
|
||||
{
|
||||
asset_info = it_own->second;
|
||||
asset_flags |= aif_own;
|
||||
return true;
|
||||
}
|
||||
|
||||
// whitelisted?
|
||||
auto it_white = m_whitelisted_assets.find(asset_id);
|
||||
if (it_white != m_whitelisted_assets.end())
|
||||
|
|
@ -3840,14 +3849,6 @@ bool wallet2::get_asset_info(const crypto::public_key& asset_id, currency::asset
|
|||
return true;
|
||||
}
|
||||
|
||||
auto it_own = m_own_asset_descriptors.find(asset_id);
|
||||
if (it_own != m_own_asset_descriptors.end())
|
||||
{
|
||||
asset_info = it_own->second;
|
||||
asset_flags |= aif_own;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
|
@ -4049,7 +4050,7 @@ std::string wallet2::get_balance_str() const
|
|||
// 98.0 BGTVUW af2b12f3033337f9aea1845a6bc3fc966ed4d13227a3ace7706fca7dbcdaa7e2
|
||||
// 1000.034 DP3 d4aba1020f26927571771e04b585b4ffb211f52708d5e4c465bbdfa4a12e6271
|
||||
|
||||
static const char* header = " balance unlocked / [balance total] ticker asset id";
|
||||
static const char* header = " balance unlocked / [balance total] ticker asset id";
|
||||
std::stringstream ss;
|
||||
ss << header << ENDL;
|
||||
|
||||
|
|
@ -4058,11 +4059,11 @@ std::string wallet2::get_balance_str() const
|
|||
balance(balances, mined);
|
||||
for (const tools::wallet_public::asset_balance_entry& b : balances)
|
||||
{
|
||||
ss << " " << std::left << std::setw(20) << print_fixed_decimal_point_with_trailing_spaces(b.unlocked, b.asset_info.decimal_point);
|
||||
ss << " " << std::left << std::setw(21) << print_fixed_decimal_point_with_trailing_spaces(b.unlocked, b.asset_info.decimal_point);
|
||||
if (b.total == b.unlocked)
|
||||
ss << " ";
|
||||
ss << std::string(21 + 3, ' ');
|
||||
else
|
||||
ss << " / " << std::setw(20) << print_fixed_decimal_point_with_trailing_spaces(b.total, b.asset_info.decimal_point);
|
||||
ss << " / " << std::setw(21) << print_fixed_decimal_point_with_trailing_spaces(b.total, b.asset_info.decimal_point);
|
||||
ss << " " << std::setw(8) << std::left << b.asset_info.ticker << " " << b.asset_info.asset_id << ENDL;
|
||||
}
|
||||
|
||||
|
|
@ -4080,7 +4081,7 @@ std::string wallet2::get_balance_str_raw() const
|
|||
// 7d3f348fbebfffc4e61a3686189cf870ea393e1c88b8f636acbfdacf9e4b2db2 CT
|
||||
// ...
|
||||
|
||||
static const char* header = " balance unlocked / [balance total] DP asset id";
|
||||
static const char* header = " balance unlocked / [balance total] DP asset id";
|
||||
std::stringstream ss;
|
||||
ss << header << ENDL;
|
||||
|
||||
|
|
@ -4092,11 +4093,13 @@ std::string wallet2::get_balance_str_raw() const
|
|||
{
|
||||
size_t decimal_point = 0;
|
||||
bool has_known_decimal_point = get_asset_decimal_point(entry.first, &decimal_point);
|
||||
ss << " " << std::left << std::setw(20) << print_fixed_decimal_point_with_trailing_spaces(entry.second.unlocked, decimal_point);
|
||||
ss << " " << std::left << std::setw(21) << print_fixed_decimal_point_with_trailing_spaces(entry.second.unlocked, decimal_point);
|
||||
if(entry.second.total == entry.second.unlocked)
|
||||
ss << " ";
|
||||
ss << std::string(21 + 3, ' ');
|
||||
else
|
||||
ss << " / " << std::setw(20) << print_fixed_decimal_point_with_trailing_spaces(entry.second.total, decimal_point);
|
||||
ss << " / " << std::setw(21) << print_fixed_decimal_point_with_trailing_spaces(entry.second.total, decimal_point);
|
||||
|
||||
ss << " ";
|
||||
|
||||
if (has_known_decimal_point)
|
||||
ss << std::setw(2) << std::right << decimal_point;
|
||||
|
|
@ -5302,6 +5305,8 @@ void wallet2::request_alias_registration(currency::extra_alias_entry& ai, curren
|
|||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::deploy_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector<currency::tx_destination_entry>& destinations, currency::transaction& result_tx, crypto::public_key& new_asset_id)
|
||||
{
|
||||
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(asset_info.decimal_point <= 18, "too big decimal point: " << asset_info.decimal_point);
|
||||
|
||||
asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info);
|
||||
asset_reg_info.descriptor = asset_info;
|
||||
asset_reg_info.operation_type = ASSET_DESCRIPTOR_OPERATION_REGISTER;
|
||||
|
|
@ -7648,8 +7653,8 @@ void wallet2::finalize_transaction(currency::finalize_tx_param& ftp, currency::f
|
|||
ftp, result);
|
||||
//TIME_MEASURE_FINISH_MS(construct_tx_time);
|
||||
THROW_IF_FALSE_WALLET_EX(r, error::tx_not_constructed, ftp.sources, ftp.prepared_destinations, ftp.unlock_time);
|
||||
uint64_t effective_fee = get_tx_fee(result.tx);
|
||||
THROW_IF_FALSE_WALLET_CMN_ERR_EX(effective_fee <= WALLET_TX_MAX_ALLOWED_FEE, "tx fee is WAY too big: " << print_money_brief(effective_fee) << ", max allowed is " << print_money_brief(WALLET_TX_MAX_ALLOWED_FEE));
|
||||
uint64_t effective_fee = 0;
|
||||
THROW_IF_FALSE_WALLET_CMN_ERR_EX(!get_tx_fee(result.tx, effective_fee) || effective_fee <= WALLET_TX_MAX_ALLOWED_FEE, "tx fee is WAY too big: " << print_money_brief(effective_fee) << ", max allowed is " << print_money_brief(WALLET_TX_MAX_ALLOWED_FEE));
|
||||
|
||||
//TIME_MEASURE_START_MS(sign_ms_input_time);
|
||||
if (ftp.multisig_id != currency::null_hash)
|
||||
|
|
|
|||
|
|
@ -1288,6 +1288,7 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(zarcanum_block_with_txs);
|
||||
GENERATE_AND_PLAY(asset_depoyment_and_few_zc_utxos);
|
||||
GENERATE_AND_PLAY_HF(assets_and_pos_mining, "4-*");
|
||||
// GENERATE_AND_PLAY_HF(asset_emission_and_unconfirmed_balance, "4-*");
|
||||
|
||||
GENERATE_AND_PLAY_HF(pos_fuse_test, "4-*");
|
||||
|
||||
|
|
|
|||
|
|
@ -823,3 +823,67 @@ bool assets_and_pos_mining::c1(currency::core& c, size_t ev_index, const std::ve
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
asset_emission_and_unconfirmed_balance::asset_emission_and_unconfirmed_balance()
|
||||
{
|
||||
REGISTER_CALLBACK_METHOD(asset_emission_and_unconfirmed_balance, c1);
|
||||
}
|
||||
|
||||
bool asset_emission_and_unconfirmed_balance::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
uint64_t ts = test_core_time::get_time();
|
||||
m_accounts.resize(TOTAL_ACCS_COUNT);
|
||||
account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts);
|
||||
//account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts);
|
||||
miner_acc.generate();
|
||||
|
||||
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts);
|
||||
DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks
|
||||
REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3);
|
||||
|
||||
DO_CALLBACK(events, "c1");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool asset_emission_and_unconfirmed_balance::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
bool r = false;
|
||||
std::shared_ptr<tools::wallet2> miner_wlt = init_playtime_test_wallet(events, c, MINER_ACC_IDX);
|
||||
miner_wlt->refresh();
|
||||
|
||||
asset_descriptor_base adb{};
|
||||
adb.total_max_supply = UINT64_MAX;
|
||||
adb.full_name = "2**64";
|
||||
adb.ticker = "2POWER64";
|
||||
|
||||
std::vector<currency::tx_destination_entry> destinations;
|
||||
destinations.emplace_back(adb.total_max_supply, m_accounts[MINER_ACC_IDX].get_public_address(), null_pkey);
|
||||
|
||||
currency::transaction tx{};
|
||||
crypto::public_key asset_id = currency::null_pkey;
|
||||
miner_wlt->deploy_new_asset(adb, destinations, tx, asset_id);
|
||||
LOG_PRINT_L0("Deployed new asset: " << asset_id << ", tx_id: " << currency::get_transaction_hash(tx));
|
||||
|
||||
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count());
|
||||
|
||||
bool stub_bool = 0;
|
||||
miner_wlt->refresh();
|
||||
miner_wlt->scan_tx_pool(stub_bool);
|
||||
uint64_t total, unlocked, awaiting_in, awaiting_out, mined;
|
||||
balance_via_wallet(*miner_wlt, asset_id, &total, &unlocked, &awaiting_in, &awaiting_out, &mined);
|
||||
CHECK_AND_ASSERT_EQ(total, UINT64_MAX);
|
||||
CHECK_AND_ASSERT_EQ(unlocked, 0);
|
||||
CHECK_AND_ASSERT_EQ(awaiting_in, UINT64_MAX);
|
||||
CHECK_AND_ASSERT_EQ(awaiting_out, 0);
|
||||
//CHECK_AND_ASSERT_EQ(mined, 0);
|
||||
|
||||
r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed");
|
||||
|
||||
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,3 +41,9 @@ struct assets_and_pos_mining : public wallet_test
|
|||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
};
|
||||
|
||||
struct asset_emission_and_unconfirmed_balance : public wallet_test
|
||||
{
|
||||
asset_emission_and_unconfirmed_balance();
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -308,3 +308,143 @@ TEST(decompose_amount_randomly, 1)
|
|||
foo(1000000000000, 2, 3);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(print_money_brief, 1)
|
||||
{
|
||||
// decimal point 12 (default)
|
||||
ASSERT_EQ(print_money_brief( 0), "0.0");
|
||||
ASSERT_EQ(print_money_brief( 1), "0.000000000001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000000), "1.0");
|
||||
ASSERT_EQ(print_money_brief( 1900000000000), "1.9");
|
||||
ASSERT_EQ(print_money_brief( 1000000100000), "1.0000001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000001), "1.000000000001");
|
||||
ASSERT_EQ(print_money_brief( 9999999999999), "9.999999999999");
|
||||
ASSERT_EQ(print_money_brief( 90009990009900), "90.0099900099");
|
||||
ASSERT_EQ(print_money_brief(10109010000000000000), "10109010.0");
|
||||
ASSERT_EQ(print_money_brief(10109010010000000000), "10109010.01");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551610), "18446744.07370955161");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551614), "18446744.073709551614");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551615), "18446744.073709551615");
|
||||
|
||||
// decimal point 0
|
||||
ASSERT_EQ(print_money_brief( 0, 0), "0");
|
||||
ASSERT_EQ(print_money_brief( 1, 0), "1");
|
||||
ASSERT_EQ(print_money_brief( 1000000000000, 0), "1000000000000");
|
||||
ASSERT_EQ(print_money_brief( 1900000000000, 0), "1900000000000");
|
||||
ASSERT_EQ(print_money_brief( 1000000100000, 0), "1000000100000");
|
||||
ASSERT_EQ(print_money_brief( 1000000000001, 0), "1000000000001");
|
||||
ASSERT_EQ(print_money_brief( 9999999999999, 0), "9999999999999");
|
||||
ASSERT_EQ(print_money_brief( 90009990009900, 0), "90009990009900");
|
||||
ASSERT_EQ(print_money_brief(10109010000000000000, 0), "10109010000000000000");
|
||||
ASSERT_EQ(print_money_brief(10109010010000000000, 0), "10109010010000000000");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551610, 0), "18446744073709551610");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551614, 0), "18446744073709551614");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551615, 0), "18446744073709551615");
|
||||
|
||||
// decimal point 1
|
||||
ASSERT_EQ(print_money_brief( 0, 1), "0.0");
|
||||
ASSERT_EQ(print_money_brief( 1, 1), "0.1");
|
||||
ASSERT_EQ(print_money_brief( 1000000000000, 1), "100000000000.0");
|
||||
ASSERT_EQ(print_money_brief( 1900000000000, 1), "190000000000.0");
|
||||
ASSERT_EQ(print_money_brief( 1000000100000, 1), "100000010000.0");
|
||||
ASSERT_EQ(print_money_brief( 1000000000001, 1), "100000000000.1");
|
||||
ASSERT_EQ(print_money_brief( 9999999999999, 1), "999999999999.9");
|
||||
ASSERT_EQ(print_money_brief( 90009990009900, 1), "9000999000990.0");
|
||||
ASSERT_EQ(print_money_brief(10109010000000000000, 1), "1010901000000000000.0");
|
||||
ASSERT_EQ(print_money_brief(10109010010000000000, 1), "1010901001000000000.0");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551610, 1), "1844674407370955161.0");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551614, 1), "1844674407370955161.4");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551615, 1), "1844674407370955161.5");
|
||||
|
||||
// decimal point 2
|
||||
ASSERT_EQ(print_money_brief( 0, 2), "0.0");
|
||||
ASSERT_EQ(print_money_brief( 1, 2), "0.01");
|
||||
ASSERT_EQ(print_money_brief( 1000000000000, 2), "10000000000.0");
|
||||
ASSERT_EQ(print_money_brief( 1900000000000, 2), "19000000000.0");
|
||||
ASSERT_EQ(print_money_brief( 1000000100000, 2), "10000001000.0");
|
||||
ASSERT_EQ(print_money_brief( 1000000000001, 2), "10000000000.01");
|
||||
ASSERT_EQ(print_money_brief( 9999999999999, 2), "99999999999.99");
|
||||
ASSERT_EQ(print_money_brief( 90009990009900, 2), "900099900099.0");
|
||||
ASSERT_EQ(print_money_brief(10109010000000000000, 2), "101090100000000000.0");
|
||||
ASSERT_EQ(print_money_brief(10109010010000000000, 2), "101090100100000000.0");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551610, 2), "184467440737095516.1");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551614, 2), "184467440737095516.14");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551615, 2), "184467440737095516.15");
|
||||
|
||||
// decimal point 3
|
||||
ASSERT_EQ(print_money_brief( 0, 3), "0.0");
|
||||
ASSERT_EQ(print_money_brief( 1, 3), "0.001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000000, 3), "1000000000.0");
|
||||
ASSERT_EQ(print_money_brief( 1900000000000, 3), "1900000000.0");
|
||||
ASSERT_EQ(print_money_brief( 1000000100000, 3), "1000000100.0");
|
||||
ASSERT_EQ(print_money_brief( 1000000000001, 3), "1000000000.001");
|
||||
ASSERT_EQ(print_money_brief( 9999999999999, 3), "9999999999.999");
|
||||
ASSERT_EQ(print_money_brief( 90009990009900, 3), "90009990009.9");
|
||||
ASSERT_EQ(print_money_brief(10109010000000000000, 3), "10109010000000000.0");
|
||||
ASSERT_EQ(print_money_brief(10109010010000000000, 3), "10109010010000000.0");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551610, 3), "18446744073709551.61");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551614, 3), "18446744073709551.614");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551615, 3), "18446744073709551.615");
|
||||
|
||||
// decimal point 18
|
||||
ASSERT_EQ(print_money_brief( 0, 18), "0.0");
|
||||
ASSERT_EQ(print_money_brief( 1, 18), "0.000000000000000001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000000, 18), "0.000001");
|
||||
ASSERT_EQ(print_money_brief( 1900000000000, 18), "0.0000019");
|
||||
ASSERT_EQ(print_money_brief( 1000000100000, 18), "0.0000010000001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000001, 18), "0.000001000000000001");
|
||||
ASSERT_EQ(print_money_brief( 9999999999999, 18), "0.000009999999999999");
|
||||
ASSERT_EQ(print_money_brief( 90009990009900, 18), "0.0000900099900099");
|
||||
ASSERT_EQ(print_money_brief(10109010000000000000, 18), "10.10901");
|
||||
ASSERT_EQ(print_money_brief(10109010010000000000, 18), "10.10901001");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551610, 18), "18.44674407370955161");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551614, 18), "18.446744073709551614");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551615, 18), "18.446744073709551615");
|
||||
|
||||
// decimal point 19
|
||||
ASSERT_EQ(print_money_brief( 0, 19), "0.0");
|
||||
ASSERT_EQ(print_money_brief( 1, 19), "0.0000000000000000001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000000, 19), "0.0000001");
|
||||
ASSERT_EQ(print_money_brief( 1900000000000, 19), "0.00000019");
|
||||
ASSERT_EQ(print_money_brief( 1000000100000, 19), "0.00000010000001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000001, 19), "0.0000001000000000001");
|
||||
ASSERT_EQ(print_money_brief( 9999999999999, 19), "0.0000009999999999999");
|
||||
ASSERT_EQ(print_money_brief( 90009990009900, 19), "0.00000900099900099");
|
||||
ASSERT_EQ(print_money_brief(10109010000000000000, 19), "1.010901");
|
||||
ASSERT_EQ(print_money_brief(10109010010000000000, 19), "1.010901001");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551610, 19), "1.844674407370955161");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551614, 19), "1.8446744073709551614");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551615, 19), "1.8446744073709551615");
|
||||
|
||||
// TODO: remove it after setting reasonable limit of 18
|
||||
// decimal point 20
|
||||
ASSERT_EQ(print_money_brief( 0, 20), "0.0");
|
||||
ASSERT_EQ(print_money_brief( 1, 20), "0.00000000000000000001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000000, 20), "0.00000001");
|
||||
ASSERT_EQ(print_money_brief( 1900000000000, 20), "0.000000019");
|
||||
ASSERT_EQ(print_money_brief( 1000000100000, 20), "0.000000010000001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000001, 20), "0.00000001000000000001");
|
||||
ASSERT_EQ(print_money_brief( 9999999999999, 20), "0.00000009999999999999");
|
||||
ASSERT_EQ(print_money_brief( 90009990009900, 20), "0.000000900099900099");
|
||||
ASSERT_EQ(print_money_brief(10109010000000000000, 20), "0.1010901");
|
||||
ASSERT_EQ(print_money_brief(10109010010000000000, 20), "0.1010901001");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551610, 20), "0.1844674407370955161");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551614, 20), "0.18446744073709551614");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551615, 20), "0.18446744073709551615");
|
||||
|
||||
// TODO: remove it after setting reasonable limit of 18
|
||||
// decimal point 21
|
||||
ASSERT_EQ(print_money_brief( 0, 21), "0.0");
|
||||
ASSERT_EQ(print_money_brief( 1, 21), "0.000000000000000000001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000000, 21), "0.000000001");
|
||||
ASSERT_EQ(print_money_brief( 1900000000000, 21), "0.0000000019");
|
||||
ASSERT_EQ(print_money_brief( 1000000100000, 21), "0.0000000010000001");
|
||||
ASSERT_EQ(print_money_brief( 1000000000001, 21), "0.000000001000000000001");
|
||||
ASSERT_EQ(print_money_brief( 9999999999999, 21), "0.000000009999999999999");
|
||||
ASSERT_EQ(print_money_brief( 90009990009900, 21), "0.0000000900099900099");
|
||||
ASSERT_EQ(print_money_brief(10109010000000000000, 21), "0.01010901");
|
||||
ASSERT_EQ(print_money_brief(10109010010000000000, 21), "0.01010901001");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551610, 21), "0.01844674407370955161");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551614, 21), "0.018446744073709551614");
|
||||
ASSERT_EQ(print_money_brief(18446744073709551615, 21), "0.018446744073709551615");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue