From 32a1efd0976ee5043098f516a7c77ba87a675072 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 22 May 2018 15:08:45 -0400 Subject: [PATCH] Use new get_amount() of asset --- programs/cleos/main.cpp | 6 +-- unittests/bootseq_tests.cpp | 2 +- unittests/currency_tests.cpp | 14 +++--- unittests/eosio.system_tests.cpp | 78 ++++++++++++++++---------------- unittests/eosio.token_tests.cpp | 6 ++- unittests/misc_tests.cpp | 24 +++++----- 6 files changed, 66 insertions(+), 64 deletions(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index fda8327ad..23f5e4388 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -576,7 +576,7 @@ authority parse_json_authority_or_key(const std::string& authorityJsonOrFile) { asset to_asset( const string& code, const string& s ) { static map cache; auto a = asset::from_string( s ); - eosio::chain::symbol_code sym = a.sym.to_symbol_code(); + eosio::chain::symbol_code sym = a.get_symbol().to_symbol_code(); auto it = cache.find( sym ); auto sym_str = a.symbol_name(); if ( it == cache.end() ) { @@ -588,7 +588,7 @@ asset to_asset( const string& code, const string& s ) { auto obj_it = obj.find( sym_str ); if (obj_it != obj.end()) { auto result = obj_it->value().as(); - auto p = cache.insert(make_pair( sym, result.max_supply.sym )); + auto p = cache.insert(make_pair( sym, result.max_supply.get_symbol() )); it = p.first; } else { FC_THROW("Symbol ${s} is not supported by token contract ${c}", ("s", sym_str)("c", code)); @@ -598,7 +598,7 @@ asset to_asset( const string& code, const string& s ) { if ( a.decimals() < expected_symbol.decimals() ) { auto factor = expected_symbol.precision() / a.precision(); auto a_old = a; - a = asset( a.amount * factor, expected_symbol ); + a = asset( a.get_amount() * factor, expected_symbol ); } else if ( a.decimals() > expected_symbol.decimals() ) { FC_THROW("Too many decimal digits in ${a}, only ${d} supported", ("a", a)("d", expected_symbol.decimals())); } // else precision matches diff --git a/unittests/bootseq_tests.cpp b/unittests/bootseq_tests.cpp index 786c64146..7c140d21f 100644 --- a/unittests/bootseq_tests.cpp +++ b/unittests/bootseq_tests.cpp @@ -309,7 +309,7 @@ BOOST_FIXTURE_TEST_CASE( bootseq_test, bootseq_tester ) { produce_min_num_of_blocks_to_spend_time_wo_inactive_prod(fc::seconds(30 * 24 * 3600)); // 30 days // Since the total activated stake is larger than 150,000,000, pool should be filled reward should be bigger than zero claim_rewards(N(runnerup1)); - BOOST_TEST(get_balance(N(runnerup1)).amount > 0); + BOOST_TEST(get_balance(N(runnerup1)).get_amount() > 0); const auto first_june_2018 = fc::seconds(1527811200); // 2018-06-01 const auto first_june_2028 = fc::seconds(1843430400); // 2028-06-01 diff --git a/unittests/currency_tests.cpp b/unittests/currency_tests.cpp index 6e46d8af2..eb5ba9613 100644 --- a/unittests/currency_tests.cpp +++ b/unittests/currency_tests.cpp @@ -329,7 +329,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try { // Missing decimal point, should create asset with 0 decimals { asset a = asset::from_string("10 CUR"); - BOOST_REQUIRE_EQUAL(a.amount, 10); + BOOST_REQUIRE_EQUAL(a.get_amount(), 10); BOOST_REQUIRE_EQUAL(a.precision(), 1); BOOST_REQUIRE_EQUAL(a.decimals(), 0); BOOST_REQUIRE_EQUAL(a.symbol_name(), "CUR"); @@ -356,7 +356,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try { // Multiple spaces { asset a = asset::from_string("1000000000.00000 CUR"); - BOOST_REQUIRE_EQUAL(a.amount, 100000000000000); + BOOST_REQUIRE_EQUAL(a.get_amount(), 100000000000000); BOOST_REQUIRE_EQUAL(a.decimals(), 5); BOOST_REQUIRE_EQUAL(a.symbol_name(), "CUR"); BOOST_REQUIRE_EQUAL(a.to_string(), "1000000000.00000 CUR"); @@ -365,7 +365,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try { // Valid asset { asset a = asset::from_string("1000000000.00000 CUR"); - BOOST_REQUIRE_EQUAL(a.amount, 100000000000000); + BOOST_REQUIRE_EQUAL(a.get_amount(), 100000000000000); BOOST_REQUIRE_EQUAL(a.decimals(), 5); BOOST_REQUIRE_EQUAL(a.symbol_name(), "CUR"); BOOST_REQUIRE_EQUAL(a.to_string(), "1000000000.00000 CUR"); @@ -374,7 +374,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try { // Negative asset { asset a = asset::from_string("-001000000.00010 CUR"); - BOOST_REQUIRE_EQUAL(a.amount, -100000000010); + BOOST_REQUIRE_EQUAL(a.get_amount(), -100000000010); BOOST_REQUIRE_EQUAL(a.decimals(), 5); BOOST_REQUIRE_EQUAL(a.symbol_name(), "CUR"); BOOST_REQUIRE_EQUAL(a.to_string(), "-1000000.00010 CUR"); @@ -383,7 +383,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try { // Negative asset below 1 { asset a = asset::from_string("-000000000.00100 CUR"); - BOOST_REQUIRE_EQUAL(a.amount, -100); + BOOST_REQUIRE_EQUAL(a.get_amount(), -100); BOOST_REQUIRE_EQUAL(a.decimals(), 5); BOOST_REQUIRE_EQUAL(a.symbol_name(), "CUR"); BOOST_REQUIRE_EQUAL(a.to_string(), "-0.00100 CUR"); @@ -392,7 +392,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try { // Negative asset below 1 { asset a = asset::from_string("-0.0001 PPP"); - BOOST_REQUIRE_EQUAL(a.amount, -1); + BOOST_REQUIRE_EQUAL(a.get_amount(), -1); BOOST_REQUIRE_EQUAL(a.decimals(), 4); BOOST_REQUIRE_EQUAL(a.symbol_name(), "PPP"); BOOST_REQUIRE_EQUAL(a.to_string(), "-0.0001 PPP"); @@ -575,7 +575,7 @@ BOOST_FIXTURE_TEST_CASE( test_input_quantity, currency_tester ) try { BOOST_CHECK_EQUAL(true, chain_has_transaction(trace->id)); BOOST_CHECK_EQUAL(asset::from_string( "100.0000 CUR"), get_balance(N(alice))); - BOOST_CHECK_EQUAL(1000000, get_balance(N(alice)).amount); + BOOST_CHECK_EQUAL(1000000, get_balance(N(alice)).get_amount()); } diff --git a/unittests/eosio.system_tests.cpp b/unittests/eosio.system_tests.cpp index 80b5d98c3..4edcd3478 100644 --- a/unittests/eosio.system_tests.cpp +++ b/unittests/eosio.system_tests.cpp @@ -353,7 +353,7 @@ public: double stake2votes( asset stake ) { auto now = control->pending_block_time().time_since_epoch().count() / 1000000; - return stake.amount * pow(2, int64_t((now - (config::block_timestamp_epoch / 1000)) / (86400 * 7))/ double(52) ); // 52 week periods (i.e. ~years) + return stake.get_amount() * pow(2, int64_t((now - (config::block_timestamp_epoch / 1000)) / (86400 * 7))/ double(52) ); // 52 week periods (i.e. ~years) } double stake2votes( const string& s ) { @@ -398,7 +398,7 @@ fc::mutable_variant_object voter( account_name acct ) { } fc::mutable_variant_object voter( account_name acct, const asset& vote_stake ) { - return voter( acct )( "staked", vote_stake.amount ); + return voter( acct )( "staked", vote_stake.get_amount() ); } fc::mutable_variant_object voter( account_name acct, int64_t vote_stake ) { @@ -410,7 +410,7 @@ fc::mutable_variant_object proxy( account_name acct ) { } inline uint64_t M( const string& eos_str ) { - return core_from_string( eos_str ).amount; + return core_from_string( eos_str ).get_amount(); } BOOST_AUTO_TEST_SUITE(eosio_system_tests) @@ -542,8 +542,8 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try { BOOST_REQUIRE_EQUAL( core_from_string("110.0000"), total["cpu_weight"].as()); total = get_total_stake( "alice1111111" ); - BOOST_REQUIRE_EQUAL( core_from_string("210.0000").amount, total["net_weight"].as().amount ); - BOOST_REQUIRE_EQUAL( core_from_string("110.0000").amount, total["cpu_weight"].as().amount ); + BOOST_REQUIRE_EQUAL( core_from_string("210.0000").get_amount(), total["net_weight"].as().get_amount() ); + BOOST_REQUIRE_EQUAL( core_from_string("110.0000").get_amount(), total["cpu_weight"].as().get_amount() ); REQUIRE_MATCHING_OBJECT( voter( "alice1111111", core_from_string("300.0000")), get_voter_info( "alice1111111" ) ); @@ -1480,22 +1480,22 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t BOOST_REQUIRE_EQUAL(0, initial_perblock_bucket); BOOST_REQUIRE_EQUAL(0, initial_pervote_bucket); - BOOST_REQUIRE_EQUAL(int64_t( ( initial_supply.amount * double(secs_between_fills) * continuous_rate ) / secs_per_year ), - supply.amount - initial_supply.amount); - BOOST_REQUIRE_EQUAL(int64_t( ( initial_supply.amount * double(secs_between_fills) * (4. * continuous_rate/ 5.) / secs_per_year ) ), + BOOST_REQUIRE_EQUAL(int64_t( ( initial_supply.get_amount() * double(secs_between_fills) * continuous_rate ) / secs_per_year ), + supply.get_amount() - initial_supply.get_amount()); + BOOST_REQUIRE_EQUAL(int64_t( ( initial_supply.get_amount() * double(secs_between_fills) * (4. * continuous_rate/ 5.) / secs_per_year ) ), savings - initial_savings); - BOOST_REQUIRE_EQUAL(int64_t( ( initial_supply.amount * double(secs_between_fills) * (0.25 * continuous_rate/ 5.) / secs_per_year ) ), - balance.amount - initial_balance.amount); + BOOST_REQUIRE_EQUAL(int64_t( ( initial_supply.get_amount() * double(secs_between_fills) * (0.25 * continuous_rate/ 5.) / secs_per_year ) ), + balance.get_amount() - initial_balance.get_amount()); - int64_t from_perblock_bucket = int64_t( initial_supply.amount * double(secs_between_fills) * (0.25 * continuous_rate/ 5.) / secs_per_year ) ; - int64_t from_pervote_bucket = int64_t( initial_supply.amount * double(secs_between_fills) * (0.75 * continuous_rate/ 5.) / secs_per_year ) ; + int64_t from_perblock_bucket = int64_t( initial_supply.get_amount() * double(secs_between_fills) * (0.25 * continuous_rate/ 5.) / secs_per_year ) ; + int64_t from_pervote_bucket = int64_t( initial_supply.get_amount() * double(secs_between_fills) * (0.75 * continuous_rate/ 5.) / secs_per_year ) ; if (from_pervote_bucket >= 100 * 10000) { - BOOST_REQUIRE_EQUAL(from_perblock_bucket + from_pervote_bucket, balance.amount - initial_balance.amount); + BOOST_REQUIRE_EQUAL(from_perblock_bucket + from_pervote_bucket, balance.get_amount() - initial_balance.get_amount()); BOOST_REQUIRE_EQUAL(0, pervote_bucket); } else { - BOOST_REQUIRE_EQUAL(from_perblock_bucket, balance.amount - initial_balance.amount); + BOOST_REQUIRE_EQUAL(from_perblock_bucket, balance.get_amount() - initial_balance.get_amount()); BOOST_REQUIRE_EQUAL(from_pervote_bucket, pervote_bucket); } } @@ -1557,20 +1557,20 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t BOOST_REQUIRE_EQUAL(claim_time, prod["last_claim_time"].as()); auto usecs_between_fills = claim_time - initial_claim_time; - BOOST_REQUIRE_EQUAL(int64_t( ( double(initial_supply.amount) * double(usecs_between_fills) * continuous_rate / usecs_per_year ) ), - supply.amount - initial_supply.amount); - BOOST_REQUIRE_EQUAL( (supply.amount - initial_supply.amount) - (supply.amount - initial_supply.amount) / 5, + BOOST_REQUIRE_EQUAL(int64_t( ( double(initial_supply.get_amount()) * double(usecs_between_fills) * continuous_rate / usecs_per_year ) ), + supply.get_amount() - initial_supply.get_amount()); + BOOST_REQUIRE_EQUAL( (supply.get_amount() - initial_supply.get_amount()) - (supply.get_amount() - initial_supply.get_amount()) / 5, savings - initial_savings); - int64_t to_producer = int64_t( (double(initial_supply.amount) * double(usecs_between_fills) * continuous_rate) / usecs_per_year ) / 5; + int64_t to_producer = int64_t( (double(initial_supply.get_amount()) * double(usecs_between_fills) * continuous_rate) / usecs_per_year ) / 5; int64_t to_perblock_bucket = to_producer / 4; int64_t to_pervote_bucket = to_producer - to_perblock_bucket; if (to_pervote_bucket + initial_pervote_bucket >= 100 * 10000) { - BOOST_REQUIRE_EQUAL(to_perblock_bucket + to_pervote_bucket + initial_pervote_bucket, balance.amount - initial_balance.amount); + BOOST_REQUIRE_EQUAL(to_perblock_bucket + to_pervote_bucket + initial_pervote_bucket, balance.get_amount() - initial_balance.get_amount()); BOOST_REQUIRE_EQUAL(0, pervote_bucket); } else { - BOOST_REQUIRE_EQUAL(to_perblock_bucket, balance.amount - initial_balance.amount); + BOOST_REQUIRE_EQUAL(to_perblock_bucket, balance.get_amount() - initial_balance.get_amount()); BOOST_REQUIRE_EQUAL(to_pervote_bucket + initial_pervote_bucket, pervote_bucket); } } @@ -1599,8 +1599,8 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t const int64_t savings = get_global_state()["savings"].as(); // Amount issued per year is very close to the 5% inflation target. Small difference (500 tokens out of 50'000'000 issued) // is due to compounding every 8 hours in this test as opposed to theoretical continuous compounding - BOOST_REQUIRE(500 * 10000 > int64_t(double(initial_supply.amount) * double(0.05)) - (supply.amount - initial_supply.amount)); - BOOST_REQUIRE(500 * 10000 > int64_t(double(initial_supply.amount) * double(0.04)) - (savings - initial_savings)); + BOOST_REQUIRE(500 * 10000 > int64_t(double(initial_supply.get_amount()) * double(0.05)) - (supply.get_amount() - initial_supply.get_amount())); + BOOST_REQUIRE(500 * 10000 > int64_t(double(initial_supply.get_amount()) * double(0.04)) - (savings - initial_savings)); } } FC_LOG_AND_RETHROW() @@ -1757,12 +1757,12 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni const int32_t secs_between_fills = static_cast(usecs_between_fills / 1000000); - const double expected_supply_growth = initial_supply.amount * double(usecs_between_fills) * cont_rate / usecs_per_year; - BOOST_REQUIRE_EQUAL( int64_t(expected_supply_growth), supply.amount - initial_supply.amount ); + const double expected_supply_growth = initial_supply.get_amount() * double(usecs_between_fills) * cont_rate / usecs_per_year; + BOOST_REQUIRE_EQUAL( int64_t(expected_supply_growth), supply.get_amount() - initial_supply.get_amount() ); BOOST_REQUIRE_EQUAL( int64_t(expected_supply_growth) - int64_t(expected_supply_growth)/5, savings - initial_savings ); - const int64_t expected_perblock_bucket = int64_t( initial_supply.amount * secs_between_fills * (0.25 * cont_rate/ 5.) / secs_per_year ) ; - const int64_t expected_pervote_bucket = int64_t( initial_supply.amount * secs_between_fills * (0.75 * cont_rate/ 5.) / secs_per_year ) ; + const int64_t expected_perblock_bucket = int64_t( initial_supply.get_amount() * secs_between_fills * (0.25 * cont_rate/ 5.) / secs_per_year ) ; + const int64_t expected_pervote_bucket = int64_t( initial_supply.get_amount() * secs_between_fills * (0.75 * cont_rate/ 5.) / secs_per_year ) ; const int64_t from_perblock_bucket = initial_unpaid_blocks * expected_perblock_bucket / initial_tot_unpaid_blocks ; const int64_t from_pervote_bucket = int64_t( vote_shares[prod_index] * expected_pervote_bucket); @@ -1770,10 +1770,10 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni BOOST_REQUIRE( 1 >= abs(int32_t(initial_tot_unpaid_blocks - tot_unpaid_blocks) - int32_t(initial_unpaid_blocks - unpaid_blocks)) ); if (from_pervote_bucket >= 100 * 10000) { - BOOST_REQUIRE_EQUAL(from_perblock_bucket + from_pervote_bucket, balance.amount - initial_balance.amount); + BOOST_REQUIRE_EQUAL(from_perblock_bucket + from_pervote_bucket, balance.get_amount() - initial_balance.get_amount()); BOOST_REQUIRE_EQUAL(expected_pervote_bucket - from_pervote_bucket, pervote_bucket); } else { - BOOST_REQUIRE_EQUAL(from_perblock_bucket, balance.amount - initial_balance.amount); + BOOST_REQUIRE_EQUAL(from_perblock_bucket, balance.get_amount() - initial_balance.get_amount()); BOOST_REQUIRE_EQUAL(expected_pervote_bucket, pervote_bucket); } @@ -1788,7 +1788,7 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni const auto prod_name = producer_names[prod_index]; BOOST_REQUIRE_EQUAL(success(), push_action(prod_name, N(claimrewards), mvo()("owner", prod_name))); - BOOST_REQUIRE_EQUAL(0, get_balance(prod_name).amount); + BOOST_REQUIRE_EQUAL(0, get_balance(prod_name).get_amount()); BOOST_REQUIRE_EQUAL(wasm_assert_msg("already claimed rewards within past day"), push_action(prod_name, N(claimrewards), mvo()("owner", prod_name))); } @@ -1826,23 +1826,23 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni const uint64_t usecs_between_fills = claim_time - initial_claim_time; - const double expected_supply_growth = initial_supply.amount * double(usecs_between_fills) * cont_rate / usecs_per_year; - BOOST_REQUIRE_EQUAL( int64_t(expected_supply_growth), supply.amount - initial_supply.amount ); + const double expected_supply_growth = initial_supply.get_amount() * double(usecs_between_fills) * cont_rate / usecs_per_year; + BOOST_REQUIRE_EQUAL( int64_t(expected_supply_growth), supply.get_amount() - initial_supply.get_amount() ); BOOST_REQUIRE_EQUAL( int64_t(expected_supply_growth) - int64_t(expected_supply_growth)/5, savings - initial_savings ); - const int64_t expected_perblock_bucket = int64_t( initial_supply.amount * double(usecs_between_fills) * (0.25 * cont_rate/ 5.) / usecs_per_year ) + const int64_t expected_perblock_bucket = int64_t( initial_supply.get_amount() * double(usecs_between_fills) * (0.25 * cont_rate/ 5.) / usecs_per_year ) + initial_perblock_bucket; - const int64_t expected_pervote_bucket = int64_t( initial_supply.amount * double(usecs_between_fills) * (0.75 * cont_rate/ 5.) / usecs_per_year ) + const int64_t expected_pervote_bucket = int64_t( initial_supply.get_amount() * double(usecs_between_fills) * (0.75 * cont_rate/ 5.) / usecs_per_year ) + initial_pervote_bucket; const int64_t from_perblock_bucket = initial_unpaid_blocks * expected_perblock_bucket / initial_tot_unpaid_blocks ; const int64_t from_pervote_bucket = int64_t( vote_shares[prod_index] * expected_pervote_bucket); BOOST_REQUIRE( 1 >= abs(int32_t(initial_tot_unpaid_blocks - tot_unpaid_blocks) - int32_t(initial_unpaid_blocks - unpaid_blocks)) ); if (from_pervote_bucket >= 100 * 10000) { - BOOST_REQUIRE_EQUAL(from_perblock_bucket + from_pervote_bucket, balance.amount - initial_balance.amount); + BOOST_REQUIRE_EQUAL(from_perblock_bucket + from_pervote_bucket, balance.get_amount() - initial_balance.get_amount()); BOOST_REQUIRE_EQUAL(expected_pervote_bucket - from_pervote_bucket, pervote_bucket); } else { - BOOST_REQUIRE_EQUAL(from_perblock_bucket, balance.amount - initial_balance.amount); + BOOST_REQUIRE_EQUAL(from_perblock_bucket, balance.get_amount() - initial_balance.get_amount()); BOOST_REQUIRE_EQUAL(expected_pervote_bucket, pervote_bucket); } @@ -1857,7 +1857,7 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni const auto prod_name = producer_names[prod_index]; BOOST_REQUIRE_EQUAL(success(), push_action(prod_name, N(claimrewards), mvo()("owner", prod_name))); - BOOST_REQUIRE(100 * 10000 <= get_balance(prod_name).amount); + BOOST_REQUIRE(100 * 10000 <= get_balance(prod_name).get_amount()); BOOST_REQUIRE_EQUAL(wasm_assert_msg("already claimed rewards within past day"), push_action(prod_name, N(claimrewards), mvo()("owner", prod_name))); } @@ -2142,10 +2142,10 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try { BOOST_CHECK_EQUAL(0, get_global_state()["total_unpaid_blocks"].as()); BOOST_REQUIRE_EQUAL(wasm_assert_msg("not enough has been staked for producers to claim rewards"), push_action(producer_names.front(), N(claimrewards), mvo()("owner", producer_names.front()))); - BOOST_REQUIRE_EQUAL(0, get_balance(producer_names.front()).amount); + BOOST_REQUIRE_EQUAL(0, get_balance(producer_names.front()).get_amount()); BOOST_REQUIRE_EQUAL(wasm_assert_msg("not enough has been staked for producers to claim rewards"), push_action(producer_names.back(), N(claimrewards), mvo()("owner", producer_names.back()))); - BOOST_REQUIRE_EQUAL(0, get_balance(producer_names.back()).amount); + BOOST_REQUIRE_EQUAL(0, get_balance(producer_names.back()).get_amount()); } // stake across 15% boundary @@ -2187,7 +2187,7 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try { BOOST_REQUIRE_EQUAL(true, rest_didnt_produce); BOOST_REQUIRE_EQUAL(success(), push_action(producer_names.front(), N(claimrewards), mvo()("owner", producer_names.front()))); - BOOST_REQUIRE(0 < get_balance(producer_names.front()).amount); + BOOST_REQUIRE(0 < get_balance(producer_names.front()).get_amount()); } } FC_LOG_AND_RETHROW() diff --git a/unittests/eosio.token_tests.cpp b/unittests/eosio.token_tests.cpp index ea084bd0d..692d7d1d6 100644 --- a/unittests/eosio.token_tests.cpp +++ b/unittests/eosio.token_tests.cpp @@ -149,7 +149,8 @@ BOOST_FIXTURE_TEST_CASE( create_max_supply, eosio_token_tester ) try { produce_blocks(1); asset max(10, symbol(SY(0, NKT))); - max.amount = 4611686018427387904; + share_type amount = 4611686018427387904; + memcpy(&max, &amount, sizeof(share_type)); // hack in an invalid amount BOOST_CHECK_EXCEPTION( create( N(alice), max) , asset_type_exception, [](const asset_type_exception& e) { return expect_assert_message(e, "magnitude of asset amount must be less than 2^62"); @@ -171,7 +172,8 @@ BOOST_FIXTURE_TEST_CASE( create_max_decimals, eosio_token_tester ) try { asset max(10, symbol(SY(0, NKT))); //1.0000000000000000000 => 0x8ac7230489e80000L - max.amount = 0x8ac7230489e80000L; + share_type amount = 0x8ac7230489e80000L; + memcpy(&max, &amount, sizeof(share_type)); // hack in an invalid amount BOOST_CHECK_EXCEPTION( create( N(alice), max) , asset_type_exception, [](const asset_type_exception& e) { return expect_assert_message(e, "magnitude of asset amount must be less than 2^62"); diff --git a/unittests/misc_tests.cpp b/unittests/misc_tests.cpp index 2635aeb32..4453adc9c 100644 --- a/unittests/misc_tests.cpp +++ b/unittests/misc_tests.cpp @@ -59,23 +59,23 @@ BOOST_AUTO_TEST_CASE(asset_from_string_overflow) // precision = 19, magnitude < 2^61 BOOST_CHECK_EXCEPTION( asset::from_string("0.1000000000000000000 CUR") , assert_exception, [](const assert_exception& e) { - return expect_assert_message(e, "precision should be <= 18"); + return expect_assert_message(e, "precision 19 should be <= 18"); }); BOOST_CHECK_EXCEPTION( asset::from_string("-0.1000000000000000000 CUR") , assert_exception, [](const assert_exception& e) { - return expect_assert_message(e, "precision should be <= 18"); + return expect_assert_message(e, "precision 19 should be <= 18"); }); BOOST_CHECK_EXCEPTION( asset::from_string("1.0000000000000000000 CUR") , assert_exception, [](const assert_exception& e) { - return expect_assert_message(e, "precision should be <= 18"); + return expect_assert_message(e, "precision 19 should be <= 18"); }); BOOST_CHECK_EXCEPTION( asset::from_string("-1.0000000000000000000 CUR") , assert_exception, [](const assert_exception& e) { - return expect_assert_message(e, "precision should be <= 18"); + return expect_assert_message(e, "precision 19 should be <= 18"); }); // precision = 18, magnitude < 2^58 a = asset::from_string("0.100000000000000000 CUR"); - BOOST_CHECK_EQUAL(a.amount, 100000000000000000L); + BOOST_CHECK_EQUAL(a.get_amount(), 100000000000000000L); a = asset::from_string("-0.100000000000000000 CUR"); - BOOST_CHECK_EQUAL(a.amount, -100000000000000000L); + BOOST_CHECK_EQUAL(a.get_amount(), -100000000000000000L); // precision = 18, magnitude = 2^62 BOOST_CHECK_EXCEPTION( asset::from_string("4.611686018427387904 CUR") , asset_type_exception, [](const asset_type_exception& e) { @@ -93,9 +93,9 @@ BOOST_AUTO_TEST_CASE(asset_from_string_overflow) // precision = 18, magnitude = 2^62-1 a = asset::from_string("4.611686018427387903 CUR"); - BOOST_CHECK_EQUAL(a.amount, 4611686018427387903L); + BOOST_CHECK_EQUAL(a.get_amount(), 4611686018427387903L); a = asset::from_string("-4.611686018427387903 CUR"); - BOOST_CHECK_EQUAL(a.amount, -4611686018427387903L); + BOOST_CHECK_EQUAL(a.get_amount(), -4611686018427387903L); // precision = 0, magnitude = 2^62 BOOST_CHECK_EXCEPTION( asset::from_string("4611686018427387904 CUR") , asset_type_exception, [](const asset_type_exception& e) { @@ -107,9 +107,9 @@ BOOST_AUTO_TEST_CASE(asset_from_string_overflow) // precision = 0, magnitude = 2^62-1 a = asset::from_string("4611686018427387903 CUR"); - BOOST_CHECK_EQUAL(a.amount, 4611686018427387903L); + BOOST_CHECK_EQUAL(a.get_amount(), 4611686018427387903L); a = asset::from_string("-4611686018427387903 CUR"); - BOOST_CHECK_EQUAL(a.amount, -4611686018427387903L); + BOOST_CHECK_EQUAL(a.get_amount(), -4611686018427387903L); // precision = 18, magnitude = 2^65 BOOST_CHECK_EXCEPTION( asset::from_string("36.893488147419103232 CUR") , overflow_exception, [](const overflow_exception& e) { @@ -137,10 +137,10 @@ BOOST_AUTO_TEST_CASE(asset_from_string_overflow) // precision = 20, magnitude > 2^142 BOOST_CHECK_EXCEPTION( asset::from_string("100000000000000000000000.00000000000000000000 CUR") , assert_exception, [](const assert_exception& e) { - return expect_assert_message(e, "precision should be <= 18"); + return expect_assert_message(e, "precision 20 should be <= 18"); }); BOOST_CHECK_EXCEPTION( asset::from_string("-100000000000000000000000.00000000000000000000 CUR") , assert_exception, [](const assert_exception& e) { - return expect_assert_message(e, "precision should be <= 18"); + return expect_assert_message(e, "precision 20 should be <= 18"); }); } -- GitLab