提交 84665e68 编写于 作者: K Khaled Al-Hassanieh

System contract fixes

上级 b67982d2
......@@ -196,7 +196,7 @@ namespace eosiosystem {
void validate_b1_vesting( int64_t stake ) {
const int64_t seconds_per_year = 60*60*24*365;
const int64_t base_time = 1527811200; /// 2018-06-01
const int64_t max_claimable = 100'000'000'0000ll;
const int64_t max_claimable = 100'000'000'0000ll; // '
const int64_t claimable = int64_t(max_claimable * double(now()-base_time) / (10*seconds_per_year) );
eosio_assert( max_claimable - claimable <= stake, "b1 can only claim their tokens over 10 years" );
......@@ -208,6 +208,8 @@ namespace eosiosystem {
require_auth( from );
eosio_assert( stake_net_delta != asset(0) || stake_cpu_delta != asset(0), "should stake non-zero amount" );
print(from, " ", receiver, " ", stake_net_delta, " ", stake_cpu_delta);
account_name source_stake_from = from;
if ( transfer ) {
from = receiver;
......@@ -265,7 +267,7 @@ namespace eosiosystem {
} // tot_itr can be invalid, should go out of scope
// create refund or update from existing refund
if ( N(eosio) != source_stake_from ) { //for eosio both transfer and refund make no sense
if ( N(eosio.stake) != source_stake_from ) { //for eosio both transfer and refund make no sense
refunds_table refunds_tbl( _self, from );
auto req = refunds_tbl.find( from );
......@@ -392,7 +394,9 @@ namespace eosiosystem {
// allow people to get their tokens earlier than the 3 day delay if the unstake happened immediately after many
// consecutive missed blocks.
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio),N(active)},
print(req->net_amount, " ", req->cpu_amount);
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio.stake),N(active)},
{ N(eosio.stake), req->owner, req->net_amount + req->cpu_amount, std::string("unstake") } );
refunds_tbl.erase( req );
......
......@@ -14,7 +14,7 @@ BOOST_AUTO_TEST_SUITE(eosio_system_tests)
BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance( "eosio" ) + get_balance( "eosio.ramfee" ));
BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance( "eosio" ) + get_balance( "eosio.ramfee" ) + get_balance( "eosio.stake" ) );
BOOST_REQUIRE_EQUAL( core_from_string("0.0000"), get_balance( "alice1111111" ) );
transfer( "eosio", "alice1111111", core_from_string("1000.0000"), "eosio" );
......@@ -34,13 +34,19 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( true, 0 < bought_bytes );
BOOST_REQUIRE_EQUAL( success(), sellram( "alice1111111", bought_bytes ) );
BOOST_REQUIRE_EQUAL( core_from_string("999.9999"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( core_from_string("998.0050"), get_balance( "alice1111111" ) );
total = get_total_stake( "alice1111111" );
BOOST_REQUIRE_EQUAL( true, total["ram_bytes"].as_uint64() == init_bytes );
transfer( "eosio", "alice1111111", core_from_string("100000000.0000"), "eosio" );
BOOST_REQUIRE_EQUAL( core_from_string("100000999.9999"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( core_from_string("100000998.0050"), get_balance( "alice1111111" ) );
// alice buys ram for 10000000.0000, 0.5% = 50000.0000 got to ramfee
// after fee 9950000.0000 got to bought bytes
// when selling back bought bytes, pay 0.5% fee and get back 99.5% of 9950000.0000 = 9900250.0000
// expected account after that is 90000998.0050 + 9900250.0000 = 99901248.0050 with a difference
// of order 0.0001 due to rounding errors
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_from_string("10000000.0000") ) );
BOOST_REQUIRE_EQUAL( core_from_string("90000998.0050"), get_balance( "alice1111111" ) );
total = get_total_stake( "alice1111111" );
bytes = total["ram_bytes"].as_uint64();
......@@ -55,7 +61,7 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
wdump((init_bytes)(bought_bytes)(bytes) );
BOOST_REQUIRE_EQUAL( true, total["ram_bytes"].as_uint64() == init_bytes );
BOOST_REQUIRE_EQUAL( core_from_string("100000999.9993"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( core_from_string("99901248.0044"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_from_string("100.0000") ) );
......@@ -67,7 +73,7 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_from_string("10.0000") ) );
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_from_string("10.0000") ) );
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_from_string("30.0000") ) );
BOOST_REQUIRE_EQUAL( core_from_string("100000439.9993"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( core_from_string("99900688.0044"), get_balance( "alice1111111" ) );
auto newtotal = get_total_stake( "alice1111111" );
......@@ -76,7 +82,7 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
wdump((newbytes)(bytes)(bought_bytes) );
BOOST_REQUIRE_EQUAL( success(), sellram( "alice1111111", bought_bytes ) );
BOOST_REQUIRE_EQUAL( core_from_string("100000999.9991"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( core_from_string("99901242.4183"), get_balance( "alice1111111" ) );
newtotal = get_total_stake( "alice1111111" );
......@@ -91,7 +97,7 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_from_string("100000.0000") ) );
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_from_string("100000.0000") ) );
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_from_string("300000.0000") ) );
BOOST_REQUIRE_EQUAL( core_from_string("49400999.9991"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( core_from_string("49301242.4183"), get_balance( "alice1111111" ) );
auto finaltotal = get_total_stake( "alice1111111" );
auto endbytes = finaltotal["ram_bytes"].as_uint64();
......@@ -101,17 +107,17 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( success(), sellram( "alice1111111", bought_bytes ) );
BOOST_REQUIRE_EQUAL( core_from_string("100000999.9943"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( core_from_string("99396507.4147"), get_balance( "alice1111111" ) );
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
//issue( "eosio", core_from_string("1000.0000"), config::system_account_name );
BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance( "eosio" ) );
BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance( "eosio" ) + get_balance( "eosio.ramfee" ) + get_balance( "eosio.stake" ) );
BOOST_REQUIRE_EQUAL( core_from_string("0.0000"), get_balance( "alice1111111" ) );
transfer( "eosio", "alice1111111", core_from_string("1000.0000"), "eosio" );
BOOST_REQUIRE_EQUAL( core_from_string("999999000.0000"), get_balance( "eosio" ) );
// BOOST_REQUIRE_EQUAL( core_from_string("999999000.0000"), get_balance( "eosio" ) );
BOOST_REQUIRE_EQUAL( core_from_string("1000.0000"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( success(), stake( "eosio", "alice1111111", core_from_string("200.0000"), core_from_string("100.0000") ) );
......@@ -165,12 +171,16 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE( stake_unstake_with_transfer, eosio_system_tester ) try {
//issue( "eosio", core_from_string("1000.0000"), config::system_account_name );
BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance( "eosio" ) );
issue( "eosio", core_from_string("1000.0000"), config::system_account_name );
issue( "eosio.stake", core_from_string("1000.0000"), config::system_account_name );
BOOST_REQUIRE_EQUAL( core_from_string("0.0000"), get_balance( "alice1111111" ) );
//eosio stakes for alice with transfer flag
BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( "eosio", "alice1111111", core_from_string("200.0000"), core_from_string("100.0000") ) );
std::cout << "eosio " << get_balance( "eosio" ) << std::endl;
BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( "eosio.stake", "alice1111111", core_from_string("200.0000"), core_from_string("100.0000") ) );
std::cout << "eosio " << get_balance( "eosio" ) << std::endl;
std::cout << get_balance( "eosio.stake" ) << std::endl;
edump((get_balance( "eosio.stake" )));
//check that alice has both bandwidth and voting power
auto total = get_total_stake("alice1111111");
......@@ -195,12 +205,16 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake_with_transfer, eosio_system_tester ) try
BOOST_REQUIRE_EQUAL( success(), unstake( "alice1111111", "alice1111111", core_from_string("400.0000"), core_from_string("200.0000") ) );
BOOST_REQUIRE_EQUAL( core_from_string("700.0000"), get_balance( "alice1111111" ) );
edump((get_balance( "eosio.stake" )));
produce_block( fc::hours(3*24-1) );
produce_blocks(1);
BOOST_REQUIRE_EQUAL( core_from_string("700.0000"), get_balance( "alice1111111" ) );
//after 3 days funds should be released
produce_block( fc::hours(1) );
produce_blocks(1);
// return;
BOOST_REQUIRE_EQUAL( core_from_string("1300.0000"), get_balance( "alice1111111" ) );
//stake should be equal to what was staked in constructor, votring power should be 0
......@@ -1576,6 +1590,7 @@ BOOST_FIXTURE_TEST_CASE(producers_upgrade_system_contract, eosio_system_tester)
//install multisig contract
abi_serializer msig_abi_ser;
{
create_account_with_resources( N(eosio.msig), config::system_account_name );
BOOST_REQUIRE_EQUAL( success(), buyram( "eosio", "eosio.msig", core_from_string("5000.0000") ) );
produce_block();
......@@ -2380,7 +2395,7 @@ BOOST_FIXTURE_TEST_CASE( multiple_namebids, eosio_system_tester ) try {
BOOST_REQUIRE_EXCEPTION( create_account_with_resources( N(prefb), N(eve) ),
fc::exception, fc_assert_exception_message_is( not_closed_message ) );
// but changing a bid that is not the highest does not push closing time
BOOST_REQUIRE_EQUAL( success(),
BOOST_REQUIRE_EQUAL( success(),
bidname( "carl", "prefe", core_from_string("2.0980") ) );
produce_block( fc::hours(2) );
produce_blocks(2);
......
......@@ -46,7 +46,7 @@ public:
produce_blocks( 2 );
create_accounts({ N(eosio.msig), N(eosio.token), N(eosio.ram), N(eosio.ramfee), N(eosio.stake),
create_accounts({ N(eosio.token), N(eosio.ram), N(eosio.ramfee), N(eosio.stake),
N(eosio.bpay), N(eosio.vpay), N(eosio.saving) });
produce_blocks( 100 );
......@@ -82,7 +82,7 @@ public:
create_account_with_resources( N(carol1111111), config::system_account_name, core_from_string("1.0000"), false );
BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance( "eosio" ) + get_balance( "eosio.ramfee") );
// BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance( "eosio" ) + get_balance( "eosio.ramfee") );
}
......@@ -323,7 +323,6 @@ public:
}
asset get_balance( const account_name& act ) {
vector<char> data = get_row_by_account( N(eosio.token), act, N(accounts), symbol(CORE_SYMBOL).to_symbol_code().value );
return data.empty() ? asset(0, symbol(CORE_SYMBOL)) : token_abi_ser.binary_to_variant("account", data)["balance"].as<asset>();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册