提交 acbc4c2c 编写于 作者: D Daniel Larimer

Merge branch 'dan-slim2' into slim

...@@ -71,11 +71,49 @@ namespace eosiosystem { ...@@ -71,11 +71,49 @@ namespace eosiosystem {
EOSLIB_SERIALIZE( refund_request, (owner)(request_time)(amount) ) EOSLIB_SERIALIZE( refund_request, (owner)(request_time)(amount) )
}; };
/**
* These tables are designed to be constructed in the scope of the relevant user, this
* facilitates simpler API for per-user queries
*/
typedef eosio::multi_index< N(userres), user_resources> user_resources_table; typedef eosio::multi_index< N(userres), user_resources> user_resources_table;
typedef eosio::multi_index< N(delband), delegated_bandwidth> del_bandwidth_table; typedef eosio::multi_index< N(delband), delegated_bandwidth> del_bandwidth_table;
typedef eosio::multi_index< N(refunds), refund_request> refunds_table; typedef eosio::multi_index< N(refunds), refund_request> refunds_table;
/**
* Called after a new account is created. This code enforces resource-limits rules
* for new accounts as well as new account naming conventions.
*
* 1. accounts cannot contain '.' symbols which forces all acccounts to be 12
* characters long without '.' until a future account auction process is implemented
* which prevents name squatting.
*
* 2. new accounts must stake a minimal number of tokens (as set in system parameters)
* therefore, this method will execute an inline buyram from receiver for newacnt in
* an amount equal to the current new account creation fee.
*/
void native::newaccount( account_name creator,
account_name newact
/* no need to parse authorites
const authority& owner,
const authority& active,
const authority& recovery*/ ) {
eosio::print( eosio::name{creator}, " created ", eosio::name{newact}, "\n");
user_resources_table userres( _self, newact);
auto r = userres.emplace( newact, [&]( auto& res ) {
res.owner = newact;
});
set_resource_limits( newact,
0,// r->storage_bytes,
0, 0 );
// r->net_weight.amount,
// r->cpu_weight.amount );
}
/** /**
* When buying ram the payer irreversiblly transfers quant to system contract and only * When buying ram the payer irreversiblly transfers quant to system contract and only
...@@ -87,34 +125,33 @@ namespace eosiosystem { ...@@ -87,34 +125,33 @@ namespace eosiosystem {
*/ */
void system_contract::buyram( account_name payer, account_name receiver, asset quant ) void system_contract::buyram( account_name payer, account_name receiver, asset quant )
{ {
print( "\n payer: ", eosio::name{payer}, " buys ram for ", eosio::name{receiver}, " with ", quant, "\n" );
require_auth( payer ); require_auth( payer );
eosio_assert( quant.amount > 0, "must purchase a positive amount" ); eosio_assert( quant.amount > 0, "must purchase a positive amount" );
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)}, INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)},
{ payer, N(eosio), quant, std::string("buy ram") } ); { payer, N(eosio), quant, std::string("buy ram") } );
global_state_singleton gstate_table( _self, _self );
auto gstate = gstate_table.exists() ? gstate_table.get() : get_default_parameters();
const double system_token_supply = eosio::token(N(eosio.token)).get_supply(eosio::symbol_type(system_token_symbol).name()).amount; 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; const double unstaked_token_supply = system_token_supply - _gstate.total_storage_stake.amount;
print( "free ram: ", _gstate.free_ram(), " tokens: ", system_token_supply, " unstaked: ", unstaked_token_supply, "\n" );
const double E = quant.amount; const double E = quant.amount;
const double R = unstaked_token_supply - E; const double R = unstaked_token_supply - E;
const double C = gstate.free_ram(); //free_ram; const double C = _gstate.free_ram(); //free_ram;
const double F = .10; /// 10% reserve ratio pricing, assumes only 10% of tokens will ever want to stake for ram const double F = 1./(_gstate.storage_reserve_ratio/10000.0); /// 10% reserve ratio pricing, assumes only 10% of tokens will ever want to stake for ram
const double ONE(1.0); const double ONE(1.0);
double T = C * (std::pow( ONE + E/R, F ) - ONE); double T = C * (std::pow( ONE + E/R, F ) - ONE);
T *= .99; /// 1% fee on every conversion T *= .99; /// 1% fee on every conversion
int64_t bytes_out = static_cast<int64_t>(T); int64_t bytes_out = static_cast<int64_t>(T);
print( "ram bytes out: ", bytes_out, "\n" );
eosio_assert( bytes_out > 0, "must reserve a positive amount" ); eosio_assert( bytes_out > 0, "must reserve a positive amount" );
gstate.total_storage_bytes_reserved += uint64_t(bytes_out); _gstate.total_storage_bytes_reserved += uint64_t(bytes_out);
gstate.total_storage_stake.amount += quant.amount; _gstate.total_storage_stake.amount += quant.amount;
gstate_table.set( gstate, _self );
user_resources_table userres( _self, receiver ); user_resources_table userres( _self, receiver );
auto res_itr = userres.find( receiver ); auto res_itr = userres.find( receiver );
...@@ -143,15 +180,12 @@ namespace eosiosystem { ...@@ -143,15 +180,12 @@ namespace eosiosystem {
eosio_assert( res_itr != userres.end(), "no resource row" ); eosio_assert( res_itr != userres.end(), "no resource row" );
eosio_assert( res_itr->storage_bytes >= bytes, "insufficient quota" ); eosio_assert( res_itr->storage_bytes >= bytes, "insufficient quota" );
global_state_singleton gstate_table( _self, _self );
auto gstate = gstate_table.exists() ? gstate_table.get() : get_default_parameters();
const double system_token_supply = eosio::token(N(eosio.token)).get_supply(eosio::symbol_type(system_token_symbol).name()).amount; 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; const double unstaked_token_supply = system_token_supply - _gstate.total_storage_stake.amount;
const double R = unstaked_token_supply; const double R = unstaked_token_supply;
const double C = gstate.free_ram() + bytes; const double C = _gstate.free_ram() + bytes;
const double F = .10; const double F = _gstate.storage_reserve_ratio / 10000.0;
const double T = bytes; const double T = bytes;
const double ONE(1.0); const double ONE(1.0);
...@@ -163,10 +197,8 @@ namespace eosiosystem { ...@@ -163,10 +197,8 @@ namespace eosiosystem {
int64_t tokens_out = int64_t(E); int64_t tokens_out = int64_t(E);
eosio_assert( tokens_out > 0, "must free at least one token" ); eosio_assert( tokens_out > 0, "must free at least one token" );
gstate.total_storage_bytes_reserved -= bytes; _gstate.total_storage_bytes_reserved -= bytes;
gstate.total_storage_stake.amount -= tokens_out; _gstate.total_storage_stake.amount -= tokens_out;
gstate_table.set( gstate, _self );
userres.modify( res_itr, account, [&]( auto& res ) { userres.modify( res_itr, account, [&]( auto& res ) {
res.storage_bytes -= bytes; res.storage_bytes -= bytes;
...@@ -183,13 +215,15 @@ namespace eosiosystem { ...@@ -183,13 +215,15 @@ namespace eosiosystem {
{ {
require_auth( from ); require_auth( from );
print( "from: ", eosio::name{from}, " to: ", eosio::name{receiver}, " net: ", stake_net_quantity, " cpu: ", stake_cpu_quantity );
eosio_assert( stake_cpu_quantity.amount >= 0, "must stake a positive amount" ); eosio_assert( stake_cpu_quantity >= asset(0), "must stake a positive amount" );
eosio_assert( stake_net_quantity.amount >= 0, "must stake a positive amount" ); eosio_assert( stake_net_quantity >= asset(0), "must stake a positive amount" );
asset total_stake = stake_cpu_quantity + stake_net_quantity; auto total_stake = stake_cpu_quantity.amount + stake_net_quantity.amount;
eosio_assert( total_stake.amount > 0, "must stake a positive amount" ); eosio_assert( total_stake > 0, "must stake a positive amount" );
print( "deltable" );
del_bandwidth_table del_tbl( _self, from ); del_bandwidth_table del_tbl( _self, from );
auto itr = del_tbl.find( receiver ); auto itr = del_tbl.find( receiver );
if( itr == del_tbl.end() ) { if( itr == del_tbl.end() ) {
...@@ -207,6 +241,7 @@ namespace eosiosystem { ...@@ -207,6 +241,7 @@ namespace eosiosystem {
}); });
} }
print( "totals" );
user_resources_table totals_tbl( _self, receiver ); user_resources_table totals_tbl( _self, receiver );
auto tot_itr = totals_tbl.find( receiver ); auto tot_itr = totals_tbl.find( receiver );
if( tot_itr == totals_tbl.end() ) { if( tot_itr == totals_tbl.end() ) {
...@@ -225,34 +260,52 @@ namespace eosiosystem { ...@@ -225,34 +260,52 @@ 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) ); 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)}, INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {from,N(active)},
{ from, N(eosio), total_stake, std::string("stake bandwidth") } ); { from, N(eosio), asset(total_stake), std::string("stake bandwidth") } );
print( "voters" );
auto from_voter = _voters.find(from);
if( from_voter == _voters.end() ) {
print( " create voter" );
from_voter = _voters.emplace( from, [&]( auto& v ) {
v.owner = from;
v.staked = uint64_t(total_stake);
});
} else {
_voters.modify( from_voter, 0, [&]( auto& v ) {
v.staked += uint64_t(total_stake);
});
}
adjust_voting_power( from, (stake_net_quantity.amount + stake_cpu_quantity.amount) ); print( "voteproducer" );
voteproducer( from, from_voter->proxy, from_voter->producers );
} // delegatebw } // delegatebw
void system_contract::undelegatebw( account_name from, account_name receiver, void system_contract::undelegatebw( account_name from, account_name receiver,
asset unstake_net_quantity, asset unstake_cpu_quantity ) asset unstake_net_quantity, asset unstake_cpu_quantity )
{ {
eosio_assert( unstake_cpu_quantity.amount >= 0, "must unstake a positive amount" ); eosio_assert( unstake_cpu_quantity >= asset(), "must unstake a positive amount" );
eosio_assert( unstake_net_quantity.amount >= 0, "must unstake a positive amount" ); eosio_assert( unstake_net_quantity >= asset(), "must unstake a positive amount" );
require_auth( from ); require_auth( from );
//eosio_assert( is_account( receiver ), "can only delegate resources to an existing account" );
del_bandwidth_table del_tbl( _self, from ); del_bandwidth_table del_tbl( _self, from );
const auto& dbw = del_tbl.get( receiver ); const auto& dbw = del_tbl.get( receiver );
eosio_assert( dbw.net_weight >= unstake_net_quantity, "insufficient staked net bandwidth" ); eosio_assert( dbw.net_weight.amount >= unstake_net_quantity.amount, "insufficient staked net bandwidth" );
eosio_assert( dbw.cpu_weight >= unstake_cpu_quantity, "insufficient staked cpu bandwidth" ); eosio_assert( dbw.cpu_weight.amount >= unstake_cpu_quantity.amount, "insufficient staked cpu bandwidth" );
auto total_refund = unstake_cpu_quantity.amount + unstake_net_quantity.amount;
_voters.modify( _voters.get(from), 0, [&]( auto& v ) {
v.staked -= uint64_t(total_refund);
});
eosio::asset total_refund = unstake_cpu_quantity + unstake_net_quantity;
eosio_assert( total_refund.amount > 0, "must unstake a positive amount" ); eosio_assert( total_refund > 0, "must unstake a positive amount" );
del_tbl.modify( dbw, from, [&]( auto& dbo ){ del_tbl.modify( dbw, from, [&]( auto& dbo ){
dbo.net_weight -= unstake_net_quantity; dbo.net_weight -= unstake_net_quantity;
dbo.cpu_weight -= unstake_cpu_quantity; dbo.cpu_weight -= unstake_cpu_quantity;
}); });
user_resources_table totals_tbl( _self, receiver ); user_resources_table totals_tbl( _self, receiver );
...@@ -260,9 +313,9 @@ namespace eosiosystem { ...@@ -260,9 +313,9 @@ namespace eosiosystem {
totals_tbl.modify( totals, 0, [&]( auto& tot ) { totals_tbl.modify( totals, 0, [&]( auto& tot ) {
tot.net_weight -= unstake_net_quantity; tot.net_weight -= unstake_net_quantity;
tot.cpu_weight -= unstake_cpu_quantity; tot.cpu_weight -= unstake_cpu_quantity;
}); });
set_resource_limits( totals.owner, totals.storage_bytes, uint64_t(totals.net_weight.amount), uint64_t(totals.cpu_weight.amount) ); set_resource_limits( receiver, totals.storage_bytes, totals.net_weight.amount, totals.cpu_weight.amount );
refunds_table refunds_tbl( _self, from ); refunds_table refunds_tbl( _self, from );
//create refund request //create refund request
...@@ -279,6 +332,7 @@ namespace eosiosystem { ...@@ -279,6 +332,7 @@ namespace eosiosystem {
r.request_time = now(); r.request_time = now();
}); });
} }
//create or replace deferred transaction //create or replace deferred transaction
//refund act; //refund act;
//act.owner = from; //act.owner = from;
...@@ -287,8 +341,8 @@ namespace eosiosystem { ...@@ -287,8 +341,8 @@ namespace eosiosystem {
out.delay_sec = refund_delay; out.delay_sec = refund_delay;
out.send( from, receiver ); out.send( from, receiver );
adjust_voting_power( from, -(unstake_net_quantity.amount + unstake_cpu_quantity.amount) ); const auto& fromv = _voters.get( from );
voteproducer( from, fromv.proxy, fromv.producers );
} // undelegatebw } // undelegatebw
...@@ -309,20 +363,16 @@ namespace eosiosystem { ...@@ -309,20 +363,16 @@ namespace eosiosystem {
refunds_tbl.erase( req ); refunds_tbl.erase( req );
} }
void system_contract::setparams( uint64_t max_storage_size, uint32_t storage_reserve_ratio ) { void system_contract::setparams( uint64_t max_storage_size, uint32_t storage_reserve_ratio ) {
require_auth( _self ); require_auth( _self );
eosio_assert( storage_reserve_ratio > 0, "invalid reserve ratio" );
global_state_singleton gs( _self, _self ); eosio_assert( storage_reserve_ratio > 0, "invalid reserve ratio" );
auto parameters = gs.exists() ? gs.get() : get_default_parameters();
eosio_assert( max_storage_size > parameters.total_storage_bytes_reserved, "attempt to set max below reserved" ); eosio_assert( max_storage_size > _gstate.total_storage_bytes_reserved, "attempt to set max below reserved" );
parameters.max_storage_size = max_storage_size; _gstate.max_storage_size = max_storage_size;
parameters.storage_reserve_ratio = storage_reserve_ratio; _gstate.storage_reserve_ratio = storage_reserve_ratio;
gs.set( parameters, _self ); _global.set( _gstate, _self );
} }
} //namespace eosiosystem } //namespace eosiosystem
...@@ -7,34 +7,12 @@ ...@@ -7,34 +7,12 @@
{"name":"value", "type":"string"} {"name":"value", "type":"string"}
] ]
},{ },{
"name": "transfer", "name": "buyram",
"base": "", "base": "",
"fields": [ "fields": [
{"name":"from", "type":"account_name"}, {"name":"payer", "type":"account_name"},
{"name":"to", "type":"account_name"}, {"name":"receiver", "type":"account_name"},
{"name":"quantity", "type":"asset"}, {"name":"quant", "type":"asset"}
{"name":"memo", "type":"string"}
]
},{
"name": "issue",
"base": "",
"fields": [
{"name":"to", "type":"account_name"},
{"name":"quantity", "type":"asset"}
]
},{
"name": "account",
"base": "",
"fields": [
{"name":"currency", "type":"uint64"},
{"name":"balance", "type":"uint64"}
]
},{
"name": "currency_stats",
"base": "",
"fields": [
{"name":"currency", "type":"uint64"},
{"name":"supply", "type":"uint64"}
] ]
},{ },{
"name": "delegatebw", "name": "delegatebw",
...@@ -44,7 +22,6 @@ ...@@ -44,7 +22,6 @@
{"name":"receiver", "type":"account_name"}, {"name":"receiver", "type":"account_name"},
{"name":"stake_net_quantity", "type":"asset"}, {"name":"stake_net_quantity", "type":"asset"},
{"name":"stake_cpu_quantity", "type":"asset"}, {"name":"stake_cpu_quantity", "type":"asset"},
{"name":"stake_storage_quantity", "type":"asset"}
] ]
},{ },{
"name": "undelegatebw", "name": "undelegatebw",
...@@ -54,7 +31,6 @@ ...@@ -54,7 +31,6 @@
{"name":"receiver", "type":"account_name"}, {"name":"receiver", "type":"account_name"},
{"name":"unstake_net_quantity", "type":"asset"}, {"name":"unstake_net_quantity", "type":"asset"},
{"name":"unstake_cpu_quantity", "type":"asset"}, {"name":"unstake_cpu_quantity", "type":"asset"},
{"name":"unstake_storage_bytes", "type":"uint64"}
] ]
},{ },{
"name": "refund", "name": "refund",
...@@ -70,7 +46,6 @@ ...@@ -70,7 +46,6 @@
{"name":"to", "type":"account_name"}, {"name":"to", "type":"account_name"},
{"name":"net_weight", "type":"uint64"}, {"name":"net_weight", "type":"uint64"},
{"name":"cpu_weight", "type":"uint64"}, {"name":"cpu_weight", "type":"uint64"},
{"name":"storage_stake", "type":"uint64"},
{"name":"storage_bytes", "type":"uint64"} {"name":"storage_bytes", "type":"uint64"}
] ]
},{ },{
...@@ -80,7 +55,6 @@ ...@@ -80,7 +55,6 @@
{"name":"owner", "type":"account_name"}, {"name":"owner", "type":"account_name"},
{"name":"net_weight", "type":"asset"}, {"name":"net_weight", "type":"asset"},
{"name":"cpu_weight", "type":"asset"}, {"name":"cpu_weight", "type":"asset"},
{"name":"storage_stake", "type":"asset"},
{"name":"storage_bytes", "type":"uint64"} {"name":"storage_bytes", "type":"uint64"}
] ]
},{ },{
...@@ -170,12 +144,7 @@ ...@@ -170,12 +144,7 @@
"base": "", "base": "",
"fields": [ "fields": [
{"name":"proxy", "type":"account_name"} {"name":"proxy", "type":"account_name"}
] {"name":"isproxy", "type":"bool"}
},{
"name": "unregproxy",
"base": "",
"fields": [
{"name":"proxy", "type":"account_name"}
] ]
},{ },{
"name": "voteproducer", "name": "voteproducer",
...@@ -189,17 +158,16 @@ ...@@ -189,17 +158,16 @@
"name": "voter_info", "name": "voter_info",
"base": "", "base": "",
"fields": [ "fields": [
{"name":"owner", "type":"account_name"}, {"name":"owner", "type":"account_name"},
{"name":"proxy", "type":"account_name"}, {"name":"proxy", "type":"account_name"},
{"name":"last_update", "type":"time"}, {"name":"producers", "type":"account_name[]"},
{"name":"is_proxy", "type":"uint32"}, {"name":"staked", "type":"uint64"},
{"name":"staked", "type":"asset"}, {"name":"last_vote_weight", "type":"float64"},
{"name":"unstaking", "type":"asset"}, {"name":"proxied_vote_weight", "type":"float64"},
{"name":"unstake_per_week", "type":"asset"}, {"name":"is_proxy", "type":"bool"},
{"name":"proxied_votes", "type":"uint128"}, {"name":"deferred_trx_id", "type":"uint32"},
{"name":"producers", "type":"account_name[]"}, {"name":"last_unstake_time", "type":"time"},
{"name":"deferred_trx_id", "type":"uint32"}, {"name":"unstaking", "type":"asset"},
{"name":"last_unstake", "type":"uint32"}
] ]
},{ },{
"name": "claimrewards", "name": "claimrewards",
...@@ -209,13 +177,10 @@ ...@@ -209,13 +177,10 @@
] ]
} }
], ],
"actions": [{ "actions": [
"name": "transfer", {
"type": "transfer", "name": "buyram",
"ricardian_contract": "" "type": "buyram",
},{
"name": "issue",
"type": "issue",
"ricardian_contract": "" "ricardian_contract": ""
},{ },{
"name": "delegatebw", "name": "delegatebw",
...@@ -245,10 +210,6 @@ ...@@ -245,10 +210,6 @@
"name": "regproxy", "name": "regproxy",
"type": "regproxy", "type": "regproxy",
"ricardian_contract": "" "ricardian_contract": ""
},{
"name": "unregproxy",
"type": "unregproxy",
"ricardian_contract": ""
},{ },{
"name": "voteproducer", "name": "voteproducer",
"type": "voteproducer", "type": "voteproducer",
......
...@@ -5,20 +5,48 @@ ...@@ -5,20 +5,48 @@
#include "producer_pay.cpp" #include "producer_pay.cpp"
#include "voting.cpp" #include "voting.cpp"
namespace eosiosystem {
system_contract::system_contract( account_name s )
:native(s),
_voters(_self,_self),
_producers(_self,_self),
_global(_self,_self)
{
print( "construct system\n" );
_gstate = _global.exists() ? _global.get() : get_default_parameters();
}
eosio_global_state system_contract::get_default_parameters() {
eosio_global_state dp;
get_blockchain_parameters(dp);
return dp;
}
system_contract::~system_contract() {
print( "destruct system\n" );
_global.set( _gstate, _self );
eosio_exit(0);
}
} /// eosio.system
EOSIO_ABI( eosiosystem::system_contract, EOSIO_ABI( eosiosystem::system_contract,
(setparams) (setparams)
// delegate_bandwith.cpp // delegate_bandwith.cpp
(delegatebw)(undelegatebw)(refund) (delegatebw)(undelegatebw)(refund)
(buyram)(sellram) (buyram)(sellram)
(regproxy) // voting.cpp
// voting.cpp (regproxy)(regproducer)(unregprod)(voteproducer)
(unregproxy)(regproducer)(unregprod)(voteproducer) // producer_pay.cpp
// producer_pay.cpp (claimrewards)
(claimrewards) // native.hpp
// native.hpp //XXX
//XXX (onblock)
(onblock) (newaccount)(updateauth)(deleteauth)(linkauth)(unlinkauth)(postrecovery)(passrecovery)(vetorecovery)(onerror)(canceldelay)
(newaccount)(updateauth)(deleteauth)(linkauth)(unlinkauth)(postrecovery)(passrecovery)(vetorecovery)(onerror)(canceldelay) // defined in eosio.system.hpp
// defined in eosio.system.hpp (nonce)
(nonce)
) )
...@@ -18,9 +18,9 @@ namespace eosiosystem { ...@@ -18,9 +18,9 @@ namespace eosiosystem {
using eosio::const_mem_fun; using eosio::const_mem_fun;
struct eosio_parameters : eosio::blockchain_parameters { struct eosio_parameters : eosio::blockchain_parameters {
uint64_t max_storage_size = 1024 * 1024 * 1024; uint64_t max_storage_size = 64ll*1024 * 1024 * 1024;
uint32_t percent_of_max_inflation_rate = 0; uint32_t percent_of_max_inflation_rate = 0;
uint32_t storage_reserve_ratio = 2000; // ratio * 1000 uint32_t storage_reserve_ratio = 100; // ratio * 10000
// explicit serialization macro is not necessary, used here only to improve compilation time // explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE_DERIVED( eosio_parameters, eosio::blockchain_parameters, (max_storage_size)(percent_of_max_inflation_rate)(storage_reserve_ratio) ) EOSLIB_SERIALIZE_DERIVED( eosio_parameters, eosio::blockchain_parameters, (max_storage_size)(percent_of_max_inflation_rate)(storage_reserve_ratio) )
...@@ -65,7 +65,41 @@ namespace eosiosystem { ...@@ -65,7 +65,41 @@ namespace eosiosystem {
(time_became_active)(last_produced_block_time) ) (time_became_active)(last_produced_block_time) )
}; };
typedef eosio::multi_index< N(producerinfo), producer_info, struct voter_info {
account_name owner = 0; /// the voter
account_name proxy = 0; /// the proxy set by the voter, if any
std::vector<account_name> producers; /// the producers approved by this voter if no proxy set
uint64_t staked = 0;
/**
* Every time a vote is cast we must first "undo" the last vote weight, before casting the
* new vote weight. Vote weight is calculated as:
*
* stated.amount * 2 ^ ( weeks_since_launch/weeks_per_year)
*/
double last_vote_weight = 0; /// the vote weight cast the last time the vote was updated
/**
* Total vote weight delegated to this voter.
*/
double proxied_vote_weight= 0; /// the total vote weight delegated to this voter as a proxy
bool is_proxy = 0; /// whether the voter is a proxy for others
uint32_t deferred_trx_id = 0; /// the ID of the 3-day delay deferred transaction
time last_unstake_time = 0; /// the time when the deferred_trx_id was sent
eosio::asset unstaking; /// the total unstaking (pending 3 day delay)
uint64_t primary_key()const { return owner; }
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE( voter_info, (owner)(proxy)(producers)(staked)(last_vote_weight)(proxied_vote_weight)(is_proxy)(deferred_trx_id)(last_unstake_time)(unstaking) )
};
typedef eosio::multi_index< N(voters), voter_info> voters_table;
typedef eosio::multi_index< N(producers), producer_info,
indexed_by<N(prototalvote), const_mem_fun<producer_info, double, &producer_info::by_votes> > indexed_by<N(prototalvote), const_mem_fun<producer_info, double, &producer_info::by_votes> >
> producers_table; > producers_table;
...@@ -76,8 +110,16 @@ namespace eosiosystem { ...@@ -76,8 +110,16 @@ namespace eosiosystem {
static constexpr uint64_t system_token_symbol = S(4,EOS); static constexpr uint64_t system_token_symbol = S(4,EOS);
class system_contract : public native { class system_contract : public native {
private:
voters_table _voters;
producers_table _producers;
global_state_singleton _global;
eosio_global_state _gstate;
public: public:
using native::native; system_contract( account_name s );
[[noreturn]] ~system_contract();
// Actions: // Actions:
void onblock( const block_id_type&, uint32_t timestamp_slot, account_name producer ); void onblock( const block_id_type&, uint32_t timestamp_slot, account_name producer );
...@@ -135,12 +177,9 @@ namespace eosiosystem { ...@@ -135,12 +177,9 @@ namespace eosiosystem {
void setparams( uint64_t max_storage_size, uint32_t storage_reserve_ratio ); void setparams( uint64_t max_storage_size, uint32_t storage_reserve_ratio );
void voteproducer( const account_name voter, const account_name proxy, const std::vector<account_name>& producers ); void voteproducer( const account_name voter, const account_name proxy, const std::vector<account_name>& producers );
void regproxy( const account_name proxy ); void regproxy( const account_name proxy, bool isproxy );
void unregproxy( const account_name proxy );
void nonce( const std::string& /*value*/ ) {} void nonce( const std::string& /*value*/ ) {}
......
...@@ -85,10 +85,7 @@ namespace eosiosystem { ...@@ -85,10 +85,7 @@ namespace eosiosystem {
/* no need to parse authorites /* no need to parse authorites
const authority& owner, const authority& owner,
const authority& active, const authority& active,
const authority& recovery*/ ) { const authority& recovery*/ );
eosio::print( eosio::name{creator}, " created ", eosio::name{newact});
set_resource_limits( newact, 3000, 0, 0 );
}
void updateauth( /*account_name account, void updateauth( /*account_name account,
......
此差异已折叠。
此差异已折叠。
...@@ -18,7 +18,7 @@ extern "C" { ...@@ -18,7 +18,7 @@ extern "C" {
* @{ * @{
*/ */
void set_resource_limits( account_name account, uint64_t ram_bytes, uint64_t net_weight, uint64_t cpu_weight ); void set_resource_limits( account_name account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight );
bool set_active_producers( char *producer_data, uint32_t producer_data_size ); bool set_active_producers( char *producer_data, uint32_t producer_data_size );
......
...@@ -81,6 +81,7 @@ namespace eosio { namespace chain { ...@@ -81,6 +81,7 @@ namespace eosio { namespace chain {
built_in_types.emplace("uint128", pack_unpack<boost::multiprecision::uint128_t>()); built_in_types.emplace("uint128", pack_unpack<boost::multiprecision::uint128_t>());
built_in_types.emplace("uint256", pack_unpack<boost::multiprecision::uint256_t>()); built_in_types.emplace("uint256", pack_unpack<boost::multiprecision::uint256_t>());
built_in_types.emplace("varuint32", pack_unpack<fc::unsigned_int>()); built_in_types.emplace("varuint32", pack_unpack<fc::unsigned_int>());
built_in_types.emplace("bool", pack_unpack<uint8_t>());
built_in_types.emplace("int8", pack_unpack<int8_t>()); built_in_types.emplace("int8", pack_unpack<int8_t>());
built_in_types.emplace("int16", pack_unpack<int16_t>()); built_in_types.emplace("int16", pack_unpack<int16_t>());
built_in_types.emplace("int32", pack_unpack<int32_t>()); built_in_types.emplace("int32", pack_unpack<int32_t>());
......
...@@ -92,6 +92,10 @@ namespace eosio { namespace testing { ...@@ -92,6 +92,10 @@ namespace eosio { namespace testing {
transaction_trace_ptr push_action( const account_name& code, const action_name& acttype, const vector<account_name>& actors, const variant_object& data, uint32_t expiration = DEFAULT_EXPIRATION_DELTA, uint32_t delay_sec = 0 ); transaction_trace_ptr push_action( const account_name& code, const action_name& acttype, const vector<account_name>& actors, const variant_object& data, uint32_t expiration = DEFAULT_EXPIRATION_DELTA, uint32_t delay_sec = 0 );
transaction_trace_ptr push_action( const account_name& code, const action_name& acttype, const vector<permission_level>& auths, const variant_object& data, uint32_t expiration = DEFAULT_EXPIRATION_DELTA, uint32_t delay_sec = 0 ); transaction_trace_ptr push_action( const account_name& code, const action_name& acttype, const vector<permission_level>& auths, const variant_object& data, uint32_t expiration = DEFAULT_EXPIRATION_DELTA, uint32_t delay_sec = 0 );
action get_action( account_name code, action_name acttype, vector<permission_level> auths,
const variant_object& data )const;
void set_transaction_headers(signed_transaction& trx, void set_transaction_headers(signed_transaction& trx,
uint32_t expiration = DEFAULT_EXPIRATION_DELTA, uint32_t expiration = DEFAULT_EXPIRATION_DELTA,
uint32_t delay_sec = 0)const; uint32_t delay_sec = 0)const;
......
...@@ -218,7 +218,8 @@ namespace eosio { namespace testing { ...@@ -218,7 +218,8 @@ namespace eosio { namespace testing {
try { try {
push_transaction(trx); push_transaction(trx);
} catch (const fc::exception& ex) { } catch (const fc::exception& ex) {
return error(ex.top_message()); //return error(ex.top_message());
return error(ex.to_detail_string());
} }
produce_block(); produce_block();
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id()));
...@@ -264,6 +265,18 @@ namespace eosio { namespace testing { ...@@ -264,6 +265,18 @@ namespace eosio { namespace testing {
) )
{ try { { try {
signed_transaction trx;
trx.actions.emplace_back(get_action( code, acttype, auths, data ));
set_transaction_headers(trx, expiration, delay_sec);
for (const auto& auth : auths) {
trx.sign(get_private_key(auth.actor, auth.permission.to_string()), chain_id_type());
}
return push_transaction(trx);
} FC_CAPTURE_AND_RETHROW( (code)(acttype)(auths)(data)(expiration) ) }
action base_tester::get_action( account_name code, action_name acttype, vector<permission_level> auths,
const variant_object& data )const {
const auto& acnt = control->db().get<account_object,by_name>(code); const auto& acnt = control->db().get<account_object,by_name>(code);
auto abi = acnt.get_abi(); auto abi = acnt.get_abi();
chain::abi_serializer abis(abi); chain::abi_serializer abis(abi);
...@@ -278,17 +291,8 @@ namespace eosio { namespace testing { ...@@ -278,17 +291,8 @@ namespace eosio { namespace testing {
act.name = acttype; act.name = acttype;
act.authorization = auths; act.authorization = auths;
act.data = abis.variant_to_binary(action_type_name, data); act.data = abis.variant_to_binary(action_type_name, data);
return act;
signed_transaction trx; }
trx.actions.emplace_back(std::move(act));
set_transaction_headers(trx, expiration, delay_sec);
for (const auto& auth : auths) {
trx.sign(get_private_key(auth.actor, auth.permission.to_string()), chain_id_type());
}
return push_transaction(trx);
} FC_CAPTURE_AND_RETHROW( (code)(acttype)(auths)(data)(expiration) ) }
transaction_trace_ptr base_tester::push_reqauth( account_name from, const vector<permission_level>& auths, const vector<private_key_type>& keys ) { transaction_trace_ptr base_tester::push_reqauth( account_name from, const vector<permission_level>& auths, const vector<private_key_type>& keys ) {
variant pretty_trx = fc::mutable_variant_object() variant pretty_trx = fc::mutable_variant_object()
("actions", fc::variants({ ("actions", fc::variants({
......
...@@ -35,8 +35,7 @@ public: ...@@ -35,8 +35,7 @@ public:
produce_blocks( 2 ); produce_blocks( 2 );
create_accounts( { N(eosio.token) } ); create_accounts( { N(eosio.token) } );
create_accounts( { N(alice), N(bob), N(carol) } ); produce_blocks( 100 );
produce_blocks( 1000 );
set_code( config::system_account_name, eosio_system_wast ); set_code( config::system_account_name, eosio_system_wast );
set_abi( config::system_account_name, eosio_system_abi ); set_abi( config::system_account_name, eosio_system_abi );
...@@ -44,8 +43,14 @@ public: ...@@ -44,8 +43,14 @@ public:
set_code( N(eosio.token), eosio_token_wast ); set_code( N(eosio.token), eosio_token_wast );
set_abi( N(eosio.token), eosio_token_abi ); set_abi( N(eosio.token), eosio_token_abi );
create_currency( N(eosio.token), config::system_account_name, asset::from_string("20000000.0000 EOS") ); create_currency( N(eosio.token), config::system_account_name, asset::from_string("1000000000.0000 EOS") );
issue(config::system_account_name, "10000000.0000 EOS"); issue(config::system_account_name, "1000000000.0000 EOS");
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) } );
produce_blocks(); produce_blocks();
...@@ -60,6 +65,39 @@ public: ...@@ -60,6 +65,39 @@ public:
*/ */
} }
transaction_trace_ptr create_account_with_resources( account_name a, account_name creator, asset ramfunds, bool multisig ) {
signed_transaction trx;
set_transaction_headers(trx);
authority owner_auth;
if (multisig) {
// multisig between account's owner key and creators active permission
owner_auth = authority(2, {key_weight{get_public_key( a, "owner" ), 1}}, {permission_level_weight{{creator, config::active_name}, 1}});
} else {
owner_auth = authority( get_public_key( a, "owner" ) );
}
trx.actions.emplace_back( vector<permission_level>{{creator,config::active_name}},
newaccount{
.creator = creator,
.name = a,
.owner = owner_auth,
.active = authority( get_public_key( a, "active" ) ),
.recovery = authority( get_public_key( a, "recovery" ) ),
});
trx.actions.emplace_back( get_action( N(eosio), N(buyram), vector<permission_level>{{creator,config::active_name}},
mvo()
("payer", creator)
("receiver", a)
("quant", ramfunds) )
);
set_transaction_headers(trx);
trx.sign( get_private_key( creator, "active" ), chain_id_type() );
return push_transaction( trx );
}
action_result push_action( const account_name& signer, const action_name &name, const variant_object &data, bool auth = true ) { action_result push_action( const account_name& signer, const action_name &name, const variant_object &data, bool auth = true ) {
string action_type_name = abi_ser.get_action_type(name); string action_type_name = abi_ser.get_action_type(name);
...@@ -71,32 +109,30 @@ public: ...@@ -71,32 +109,30 @@ public:
return base_tester::push_action( std::move(act), auth ? uint64_t(signer) : signer == N(bob) ? N(alice) : N(bob) ); return base_tester::push_action( std::move(act), auth ? uint64_t(signer) : signer == N(bob) ? N(alice) : N(bob) );
} }
action_result stake( const account_name& from, const account_name& to, const string& net, const string& cpu, const string& storage ) { action_result stake( const account_name& from, const account_name& to, const string& net, const string& cpu ) {
return push_action( name(from), N(delegatebw), mvo() return push_action( name(from), N(delegatebw), mvo()
("from", from) ("from", from)
("receiver", to) ("receiver", to)
("stake_net_quantity", net) ("stake_net_quantity", net)
("stake_cpu_quantity", cpu) ("stake_cpu_quantity", cpu)
("stake_storage_quantity", storage)
); );
} }
action_result stake( const account_name& acnt, const string& net, const string& cpu, const string& storage ) { action_result stake( const account_name& acnt, const string& net, const string& cpu ) {
return stake( acnt, acnt, net, cpu, storage ); return stake( acnt, acnt, net, cpu );
} }
action_result unstake( const account_name& from, const account_name& to, const string& net, const string& cpu, uint64_t bytes ) { action_result unstake( const account_name& from, const account_name& to, const string& net, const string& cpu ) {
return push_action( name(from), N(undelegatebw), mvo() return push_action( name(from), N(undelegatebw), mvo()
("from", from) ("from", from)
("receiver", to) ("receiver", to)
("unstake_net_quantity", net) ("unstake_net_quantity", net)
("unstake_cpu_quantity", cpu) ("unstake_cpu_quantity", cpu)
("unstake_storage_bytes", bytes)
); );
} }
action_result unstake( const account_name& acnt, const string& net, const string& cpu, uint64_t bytes ) { action_result unstake( const account_name& acnt, const string& net, const string& cpu ) {
return unstake( acnt, acnt, net, cpu, bytes ); return unstake( acnt, acnt, net, cpu );
} }
static fc::variant_object producer_parameters_example( int n ) { static fc::variant_object producer_parameters_example( int n ) {
...@@ -132,7 +168,7 @@ public: ...@@ -132,7 +168,7 @@ public:
return push_action( acnt, N(regproducer), mvo() return push_action( acnt, N(regproducer), mvo()
("producer", acnt ) ("producer", acnt )
("producer_key", fc::raw::pack( get_public_key( acnt, "active" ) ) ) ("producer_key", fc::raw::pack( get_public_key( acnt, "active" ) ) )
("prefs", producer_parameters_example( params_fixture ) ) ("url", "" )
); );
} }
...@@ -161,7 +197,7 @@ public: ...@@ -161,7 +197,7 @@ public:
} }
fc::variant get_total_stake( const account_name& act ) { fc::variant get_total_stake( const account_name& act ) {
vector<char> data = get_row_by_account( config::system_account_name, act, N(totalband), act ); vector<char> data = get_row_by_account( config::system_account_name, act, N(userres), act );
return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "total_resources", data ); return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "total_resources", data );
} }
...@@ -171,7 +207,7 @@ public: ...@@ -171,7 +207,7 @@ public:
} }
fc::variant get_producer_info( const account_name& act ) { fc::variant get_producer_info( const account_name& act ) {
vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, N(producerinfo), act ); vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, N(producers), act );
return abi_ser.binary_to_variant( "producer_info", data ); return abi_ser.binary_to_variant( "producer_info", data );
} }
...@@ -226,16 +262,17 @@ inline uint64_t M( const string& eos_str ) { ...@@ -226,16 +262,17 @@ inline uint64_t M( const string& eos_str ) {
BOOST_AUTO_TEST_SUITE(eosio_system_tests) BOOST_AUTO_TEST_SUITE(eosio_system_tests)
BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try { BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
issue( "alice", "1000.0000 EOS", config::system_account_name ); //issue( "eosio", "1000.0000 EOS", config::system_account_name );
BOOST_REQUIRE_EQUAL( asset::from_string("1000.0000 EOS"), get_balance( "alice" ) ); //BOOST_REQUIRE_EQUAL( asset::from_string("1000.0000 EOS"), get_balance( "eosio" ) );
BOOST_REQUIRE_EQUAL( success(), stake( "alice", "200.0000 EOS", "100.0000 EOS", "500.0000 EOS" ) ); BOOST_REQUIRE_EQUAL( success(), stake( "eosio", "alice", "200.0000 EOS", "100.0000 EOS" ) );
auto total = get_total_stake( "alice" ); auto total = get_total_stake( "alice" );
idump((total));
return;
BOOST_REQUIRE_EQUAL( asset::from_string("200.0000 EOS").amount, total["net_weight"].as<asset>().amount ); BOOST_REQUIRE_EQUAL( asset::from_string("200.0000 EOS").amount, total["net_weight"].as<asset>().amount );
BOOST_REQUIRE_EQUAL( asset::from_string("100.0000 EOS").amount, total["cpu_weight"].as<asset>().amount ); BOOST_REQUIRE_EQUAL( asset::from_string("100.0000 EOS").amount, total["cpu_weight"].as<asset>().amount );
BOOST_REQUIRE_EQUAL( asset::from_string("500.0000 EOS").amount, total["storage_stake"].as<asset>().amount );
REQUIRE_MATCHING_OBJECT( voter( "alice", "300.0000 EOS"), get_voter_info( "alice" ) ); REQUIRE_MATCHING_OBJECT( voter( "alice", "300.0000 EOS"), get_voter_info( "alice" ) );
...@@ -245,12 +282,12 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try { ...@@ -245,12 +282,12 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( asset::from_string("200.0000 EOS"), get_balance( "alice" ) ); BOOST_REQUIRE_EQUAL( asset::from_string("200.0000 EOS"), get_balance( "alice" ) );
//unstake //unstake
BOOST_REQUIRE_EQUAL( success(), unstake( "alice", "200.0000 EOS", "100.0000 EOS", bytes ) ); BOOST_REQUIRE_EQUAL( success(), unstake( "alice", "200.0000 EOS", "100.0000 EOS" ) );
total = get_total_stake( "alice" ); total = get_total_stake( "alice" );
BOOST_REQUIRE_EQUAL( asset::from_string("0.0000 EOS").amount, total["net_weight"].as<asset>().amount); BOOST_REQUIRE_EQUAL( asset::from_string("0.0000 EOS").amount, total["net_weight"].as<asset>().amount);
BOOST_REQUIRE_EQUAL( asset::from_string("0.0000 EOS").amount, total["cpu_weight"].as<asset>().amount); BOOST_REQUIRE_EQUAL( asset::from_string("0.0000 EOS").amount, total["cpu_weight"].as<asset>().amount);
BOOST_REQUIRE_EQUAL( asset::from_string("0.0000 EOS").amount, total["storage_stake"].as<asset>().amount);
BOOST_REQUIRE_EQUAL( 0, total["storage_bytes"].as_uint64());
REQUIRE_MATCHING_OBJECT( voter( "alice", "0.0000 EOS" ), get_voter_info( "alice" ) ); REQUIRE_MATCHING_OBJECT( voter( "alice", "0.0000 EOS" ), get_voter_info( "alice" ) );
produce_blocks(1); produce_blocks(1);
BOOST_REQUIRE_EQUAL( asset::from_string("200.0000 EOS"), get_balance( "alice" ) ); BOOST_REQUIRE_EQUAL( asset::from_string("200.0000 EOS"), get_balance( "alice" ) );
...@@ -266,7 +303,7 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try { ...@@ -266,7 +303,7 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
} FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW()
#if 0
BOOST_FIXTURE_TEST_CASE( fail_without_auth, eosio_system_tester ) try { BOOST_FIXTURE_TEST_CASE( fail_without_auth, eosio_system_tester ) try {
issue( "alice", "1000.0000 EOS", config::system_account_name ); issue( "alice", "1000.0000 EOS", config::system_account_name );
...@@ -287,7 +324,6 @@ BOOST_FIXTURE_TEST_CASE( fail_without_auth, eosio_system_tester ) try { ...@@ -287,7 +324,6 @@ BOOST_FIXTURE_TEST_CASE( fail_without_auth, eosio_system_tester ) try {
("receiver", "bob") ("receiver", "bob")
("unstake_net_quantity", "200.0000 EOS") ("unstake_net_quantity", "200.0000 EOS")
("unstake_cpu_quantity", "100.0000 EOS") ("unstake_cpu_quantity", "100.0000 EOS")
("unstake_storage_bytes", 0)
,false ,false
) )
); );
...@@ -321,23 +357,23 @@ BOOST_FIXTURE_TEST_CASE( stake_negative, eosio_system_tester ) try { ...@@ -321,23 +357,23 @@ BOOST_FIXTURE_TEST_CASE( stake_negative, eosio_system_tester ) try {
BOOST_FIXTURE_TEST_CASE( unstake_negative, eosio_system_tester ) try { BOOST_FIXTURE_TEST_CASE( unstake_negative, eosio_system_tester ) try {
issue( "alice", "1000.0000 EOS", config::system_account_name ); issue( "alice", "1000.0000 EOS", config::system_account_name );
BOOST_REQUIRE_EQUAL( success(), stake( "alice", "bob", "200.0001 EOS", "100.0001 EOS", "300.0000 EOS" ) ); BOOST_REQUIRE_EQUAL( success(), stake( "alice", "bob", "200.0001 EOS", "100.0001 EOS" ) );
auto total = get_total_stake( "bob" ); auto total = get_total_stake( "bob" );
BOOST_REQUIRE_EQUAL( asset::from_string("200.0001 EOS"), total["net_weight"].as<asset>()); BOOST_REQUIRE_EQUAL( asset::from_string("200.0001 EOS"), total["net_weight"].as<asset>());
REQUIRE_MATCHING_OBJECT( voter( "alice", "300.0002 EOS" ), get_voter_info( "alice" ) ); REQUIRE_MATCHING_OBJECT( voter( "alice", "300.0002 EOS" ), get_voter_info( "alice" ) );
BOOST_REQUIRE_EQUAL( error("condition: assertion failed: must unstake a positive amount"), BOOST_REQUIRE_EQUAL( error("condition: assertion failed: must unstake a positive amount"),
unstake( "alice", "bob", "-1.0000 EOS", "0.0000 EOS", 0 ) unstake( "alice", "bob", "-1.0000 EOS", "0.0000 EOS" )
); );
BOOST_REQUIRE_EQUAL( error("condition: assertion failed: must unstake a positive amount"), BOOST_REQUIRE_EQUAL( error("condition: assertion failed: must unstake a positive amount"),
unstake( "alice", "bob", "0.0000 EOS", "-1.0000 EOS", 0 ) unstake( "alice", "bob", "0.0000 EOS", "-1.0000 EOS" )
); );
//unstake all zeros //unstake all zeros
BOOST_REQUIRE_EQUAL( error("condition: assertion failed: must unstake a positive amount"), BOOST_REQUIRE_EQUAL( error("condition: assertion failed: must unstake a positive amount"),
unstake( "alice", "bob", "0.0000 EOS", "0.0000 EOS", 0 ) unstake( "alice", "bob", "0.0000 EOS", "0.0000 EOS" )
); );
} FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW()
...@@ -350,11 +386,8 @@ BOOST_FIXTURE_TEST_CASE( unstake_more_than_at_stake, eosio_system_tester ) try { ...@@ -350,11 +386,8 @@ BOOST_FIXTURE_TEST_CASE( unstake_more_than_at_stake, eosio_system_tester ) try {
auto total = get_total_stake( "alice" ); auto total = get_total_stake( "alice" );
BOOST_REQUIRE_EQUAL( asset::from_string("200.0000 EOS"), total["net_weight"].as<asset>()); BOOST_REQUIRE_EQUAL( asset::from_string("200.0000 EOS"), total["net_weight"].as<asset>());
BOOST_REQUIRE_EQUAL( asset::from_string("100.0000 EOS"), total["cpu_weight"].as<asset>()); BOOST_REQUIRE_EQUAL( asset::from_string("100.0000 EOS"), total["cpu_weight"].as<asset>());
BOOST_REQUIRE_EQUAL( asset::from_string("150.0000 EOS"), total["storage_stake"].as<asset>());
auto bytes = total["storage_bytes"].as_uint64();
BOOST_REQUIRE_EQUAL( true, 0 < bytes );
BOOST_REQUIRE_EQUAL( asset::from_string("550.0000 EOS"), get_balance( "alice" ) ); BOOST_REQUIRE_EQUAL( asset::from_string("300.0000 EOS"), get_balance( "alice" ) );
//trying to unstake more net bandwith than at stake //trying to unstake more net bandwith than at stake
BOOST_REQUIRE_EQUAL( error("condition: assertion failed: insufficient staked net bandwidth"), BOOST_REQUIRE_EQUAL( error("condition: assertion failed: insufficient staked net bandwidth"),
...@@ -1504,5 +1537,6 @@ BOOST_FIXTURE_TEST_CASE( elect_producers_and_parameters, eosio_system_tester ) t ...@@ -1504,5 +1537,6 @@ BOOST_FIXTURE_TEST_CASE( elect_producers_and_parameters, eosio_system_tester ) t
REQUIRE_EQUAL_OBJECTS(prod3_config, config); REQUIRE_EQUAL_OBJECTS(prod3_config, config);
} FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW()
#endif
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册