未验证 提交 aaae7167 编写于 作者: K Kevin Heifner 提交者: GitHub

Merge pull request #2743 from EOSIO/decimals

Fix for #2322 - issue and transfer quantities are processed the same way
......@@ -45,6 +45,10 @@ void token::issue( account_name to, asset quantity, string memo )
require_auth( st.issuer );
eosio_assert( quantity.is_valid(), "invalid quantity" );
eosio_assert( quantity.amount > 0, "must issue positive quantity" );
if ( quantity.symbol.precision() != st.supply.symbol.precision() )
quantity.adjust_precision( st.supply.symbol );
eosio_assert( quantity <= st.max_supply - st.supply, "quantity exceeds available supply");
statstable.modify( st, 0, [&]( auto& s ) {
......
......@@ -257,7 +257,6 @@ namespace eosio {
return;
eosio_assert(ref_sym.precision() >= this->symbol.precision(), "asset symbol has higher precision than expected");
for (uint8_t i = 0; i < ref_sym.precision() - this->symbol.precision(); ++i) {
printi(amount);
this->amount *= 10;
}
this->symbol.value = ref_sym.value;
......
......@@ -63,6 +63,16 @@ class currency_tester : public TESTER {
return trace;
}
auto issue(const account_name& to, const std::string& quantity, const std::string& memo = "") {
auto trace = push_action(N(eosio.token), N(issue), mutable_variant_object()
("to", to)
("quantity", quantity)
("memo", memo)
);
produce_block();
return trace;
}
currency_tester()
:TESTER(),abi_ser(json::from_string(eosio_token_abi).as<abi_def>())
{
......@@ -571,6 +581,41 @@ BOOST_FIXTURE_TEST_CASE( test_input_quantity, currency_tester ) try {
eosio_assert_message_is("asset symbol has higher precision than expected") );
}
// transfer using different symbol name fails
{
BOOST_REQUIRE_THROW(transfer(N(alice), N(carl), "20.50 USD"), fc::assert_exception);
}
// issue to alice using right precision
{
auto trace = issue(N(alice), "25.0256 CUR");
BOOST_CHECK_EQUAL(true, chain_has_transaction(trace->id));
BOOST_CHECK_EQUAL(asset::from_string("112.0256 CUR"), get_balance(N(alice)));
}
// issue to alice again using lower precision
{
auto trace = issue(N(alice), "21.03 CUR");
BOOST_CHECK_EQUAL(true, chain_has_transaction(trace->id));
BOOST_CHECK_EQUAL(asset::from_string("133.0556 CUR"), get_balance(N(alice)));
}
// no decimal point
{
auto trace = issue(N(alice), "67 CUR");
BOOST_CHECK_EQUAL(true, chain_has_transaction(trace->id));
BOOST_CHECK_EQUAL(asset::from_string("200.0556 CUR"), get_balance(N(alice)));
}
// issue using higher precision fails
{
BOOST_REQUIRE_EXCEPTION(issue(N(alice), "5.340067 CUR"), fc::assert_exception,
eosio_assert_message_is("asset symbol has higher precision than expected") );
}
} FC_LOG_AND_RETHROW() /// test_currency
BOOST_AUTO_TEST_SUITE_END()
......@@ -239,11 +239,11 @@ BOOST_FIXTURE_TEST_CASE( issue_tests, eosio_token_tester ) try {
issue( N(alice), N(alice), asset::from_string("-1.000 TKN"), "hola" )
);
BOOST_REQUIRE_EQUAL( error( "condition: assertion failed: comparison of assets with different symbols is not allowed" ),
BOOST_REQUIRE_EQUAL( success(),
issue( N(alice), N(alice), asset::from_string("1.00 TKN"), "hola" )
);
BOOST_REQUIRE_EQUAL( error( "condition: assertion failed: comparison of assets with different symbols is not allowed" ),
BOOST_REQUIRE_EQUAL( error( "condition: assertion failed: asset symbol has higher precision than expected" ),
issue( N(alice), N(alice), asset::from_string("1.0000 TKN"), "hola" )
);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册