提交 9a1fd45b 编写于 作者: D Daniel Larimer

Fix bugs with system staking

1. transfers are now prevented where from/to are same
2. inline transfers to self are now skipped (eosio staking for others)
3. unit test updated to demonstrate staking works
上级 acbc4c2c
......@@ -129,8 +129,10 @@ namespace eosiosystem {
require_auth( payer );
eosio_assert( quant.amount > 0, "must purchase a positive amount" );
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)},
{ payer, N(eosio), quant, std::string("buy ram") } );
if( payer != N(eosio) ) {
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)},
{ payer, N(eosio), quant, std::string("buy ram") } );
}
const double system_token_supply = eosio::token(N(eosio.token)).get_supply(eosio::symbol_type(system_token_symbol).name()).amount;
const double unstaked_token_supply = system_token_supply - _gstate.total_storage_stake.amount;
......@@ -205,8 +207,10 @@ namespace eosiosystem {
});
set_resource_limits( res_itr->owner, res_itr->storage_bytes, uint64_t(res_itr->net_weight.amount), uint64_t(res_itr->cpu_weight.amount) );
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio),N(active)},
{ N(eosio), account, asset(tokens_out), std::string("sell ram") } );
if( N(eosio) != account ) {
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio),N(active)},
{ N(eosio), account, asset(tokens_out), std::string("sell ram") } );
}
}
void system_contract::delegatebw( account_name from, account_name receiver,
......@@ -259,8 +263,10 @@ namespace eosiosystem {
set_resource_limits( tot_itr->owner, tot_itr->storage_bytes, uint64_t(tot_itr->net_weight.amount), uint64_t(tot_itr->cpu_weight.amount) );
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {from,N(active)},
{ from, N(eosio), asset(total_stake), std::string("stake bandwidth") } );
if( N(eosio) != from) {
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {from,N(active)},
{ from, N(eosio), asset(total_stake), std::string("stake bandwidth") } );
}
print( "voters" );
auto from_voter = _voters.find(from);
......
......@@ -64,7 +64,8 @@ void token::transfer( account_name from,
asset quantity,
string /*memo*/ )
{
print( "transfer" );
print( "transfer from ", eosio::name{from}, " to ", eosio::name{to}, " ", quantity, "\n" );
eosio_assert( from != to, "cannot transfer to self" );
require_auth( from );
eosio_assert( is_account( to ), "to account does not exist");
auto sym = quantity.symbol.name();
......@@ -99,6 +100,7 @@ void token::sub_balance( account_name owner, asset value, const currency_stats&
from_acnts.modify( from, owner, [&]( auto& a ) {
a.balance -= value;
print( eosio::name{owner}, " balance: ", a.balance, "\n" );
});
}
......@@ -110,11 +112,13 @@ void token::add_balance( account_name owner, asset value, const currency_stats&
eosio_assert( !st.enforce_whitelist, "can only transfer to white listed accounts" );
to_acnts.emplace( ram_payer, [&]( auto& a ){
a.balance = value;
print( eosio::name{owner}, " balance: ", a.balance, "\n" );
});
} else {
eosio_assert( !st.enforce_whitelist || to->whitelist, "receiver requires whitelist by issuer" );
to_acnts.modify( to, 0, [&]( auto& a ) {
a.balance += value;
print( eosio::name{owner}, " balance: ", a.balance, "\n" );
});
}
}
......
......@@ -48,9 +48,13 @@ public:
produce_blocks();
create_account_with_resources( N(alice), N(eosio), asset::from_string("0.5000 EOS"), false );//{ N(alice), N(bob), N(carol) } );
create_account_with_resources( N(bob), N(eosio), asset::from_string("0.5000 EOS"), false );//{ N(alice), N(bob), N(carol) } );
create_account_with_resources( N(carol), N(eosio), asset::from_string("0.5000 EOS"), false );//{ N(alice), N(bob), N(carol) } );
BOOST_REQUIRE_EQUAL( asset::from_string("1000000000.0000 EOS"), get_balance( "eosio" ) );
create_account_with_resources( N(alice), N(eosio), asset::from_string("1.0000 EOS"), false );//{ N(alice), N(bob), N(carol) } );
create_account_with_resources( N(bob), N(eosio), asset::from_string("1.0000 EOS"), false );//{ N(alice), N(bob), N(carol) } );
create_account_with_resources( N(carol), N(eosio), asset::from_string("1.0000 EOS"), false );//{ N(alice), N(bob), N(carol) } );
BOOST_REQUIRE_EQUAL( asset::from_string("1000000000.0000 EOS"), get_balance( "eosio" ) );
// eosio pays it self for these...
//BOOST_REQUIRE_EQUAL( asset::from_string("999999998.5000 EOS"), get_balance( "eosio" ) );
produce_blocks();
......@@ -229,6 +233,15 @@ public:
("memo", "")
);
}
void transfer( name from, name to, const string& amount, name manager = config::system_account_name ) {
base_tester::push_action( N(eosio.token), N(transfer), manager, mutable_variant_object()
("from", from)
("to", to )
("quantity", asset::from_string(amount) )
("memo", "")
);
}
abi_serializer abi_ser;
};
......@@ -263,9 +276,16 @@ BOOST_AUTO_TEST_SUITE(eosio_system_tests)
BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
//issue( "eosio", "1000.0000 EOS", config::system_account_name );
//BOOST_REQUIRE_EQUAL( asset::from_string("1000.0000 EOS"), get_balance( "eosio" ) );
BOOST_REQUIRE_EQUAL( asset::from_string("1000000000.0000 EOS"), get_balance( "eosio" ) );
BOOST_REQUIRE_EQUAL( asset::from_string("0.0000 EOS"), get_balance( "alice" ) );
transfer( "eosio", "alice", "1000.0000 EOS", "eosio" );
BOOST_REQUIRE_EQUAL( asset::from_string("999999000.0000 EOS"), get_balance( "eosio" ) );
BOOST_REQUIRE_EQUAL( asset::from_string("1000.0000 EOS"), get_balance( "alice" ) );
BOOST_REQUIRE_EQUAL( success(), stake( "eosio", "alice", "200.0000 EOS", "100.0000 EOS" ) );
BOOST_REQUIRE_EQUAL( success(), stake( "alice", "alice", "200.0000 EOS", "100.0000 EOS" ) );
BOOST_REQUIRE_EQUAL( asset::from_string("700.0000 EOS"), get_balance( "alice" ) );
auto total = get_total_stake( "alice" );
idump((total));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册