提交 4a79aead 编写于 作者: A Anton Perkov

unregister producer, more tests for system contracts, change in static_variant reverted

上级 c75a6ff1
......@@ -95,13 +95,22 @@
{"name":"inflation_rate", "type":"uint32"},
{"name":"storage_reserve_ratio", "type":"uint32"},
]
},,{
},{
"name": "eosio_global_state",
"base": "eosio_parameters",
"fields": [
{"name":"total_storage_bytes_reserved", "type":"uint64"},
{"name":"total_storage_stake", "type":"uint64"}
]
},{
"name": "producer_info",
"base": "",
"fields": [
{"name":"owner", "type":"uint64"},
{"name":"total_votes", "type":"uint128"},
{"name":"prefs", "type":"eosio_parameters"},
{"name":"packed_key", "type":"uint8[]"}
]
},{
"name": "regproducer",
"base": "",
......
......@@ -43,11 +43,11 @@ namespace eosiosystem {
static constexpr uint32_t unstake_payments = 26; // during 26 weeks
struct producer_info {
account_name owner;
uint64_t padding = 0;
uint128_t total_votes = 0;
account_name owner;
uint64_t padding = 0;
uint128_t total_votes = 0;
eosio_parameters prefs;
eosio::bytes packed_key; /// a packed public key object
eosio::bytes packed_key; /// a packed public key object
uint64_t primary_key()const { return owner; }
uint128_t by_votes()const { return total_votes; }
......@@ -82,8 +82,8 @@ namespace eosiosystem {
typedef eosio::multi_index< N(voters), voter_info> voters_table;
ACTION( SystemAccount, regproducer ) {
account_name producer;
bytes producer_key;
account_name producer;
bytes producer_key;
eosio_parameters prefs;
EOSLIB_SERIALIZE( regproducer, (producer)(producer_key)(prefs) )
......@@ -106,6 +106,7 @@ namespace eosiosystem {
if ( prod ) {
producers_tbl.update( *prod, reg.producer, [&]( producer_info& info ){
info.prefs = reg.prefs;
info.packed_key = reg.producer_key;
});
} else {
producers_tbl.emplace( reg.producer, [&]( producer_info& info ){
......@@ -117,6 +118,24 @@ namespace eosiosystem {
}
}
ACTION( SystemAccount, unregproducer ) {
account_name producer;
EOSLIB_SERIALIZE( unregproducer, (producer) )
};
static void on( const unregproducer& unreg ) {
require_auth( unreg.producer );
producers_table producers_tbl( SystemAccount, SystemAccount );
const auto* prod = producers_tbl.find( unreg.producer );
eosio_assert( bool(prod), "producer not found" );
producers_tbl.update( *prod, 0, [&]( producer_info& info ){
info.packed_key.clear();
});
}
ACTION( SystemAccount, stakevote ) {
account_name voter;
system_token_type amount;
......
......@@ -5,7 +5,7 @@
namespace eosio {
struct blockchain_parameters : ::blockchain_parameters {
EOSLIB_SERIALIZE( blockchain_parameters, (target_block_size)(max_block_size)(target_block_acts_per_scope)
(max_block_acts_per_scope)(target_block_acts)(max_block_acts)(max_storage_size)
(max_transaction_lifetime)(max_transaction_exec_time)(max_authority_depth)
......
......@@ -195,7 +195,7 @@ class static_variant {
static_assert(impl::type_info<Types...>::no_reference_types, "Reference types are not permitted in static_variant.");
static_assert(impl::type_info<Types...>::no_duplicates, "static_variant type arguments contain duplicate types.");
uint32_t _tag;
int _tag;
char storage[impl::type_info<Types...>::size];
template<typename X>
......
......@@ -74,7 +74,7 @@ public:
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 );
return abi_ser.binary_to_variant( "eosio_global_state", data );
return abi_ser.binary_to_variant( "producer_info", data );
}
abi_serializer abi_ser;
......@@ -545,16 +545,52 @@ BOOST_FIXTURE_TEST_CASE( producer_register_unregister, eosio_system_tester ) try
("inflation_rate", 1051)
("storage_reserve_ratio", 1005);
vector<char> key = fc::raw::pack( fc::crypto::public_key( std::string("EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV") ) );
BOOST_REQUIRE_EQUAL( success(), push_action(N(alice), N(regproducer), mvo()
("producer", "alice")
("producer_key", fc::raw::pack( fc::crypto::public_key( std::string("EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV") ) ) )
("producer_key", key )
("prefs", params)
)
);
auto info = get_producer_info( "alice" );
BOOST_REQUIRE_EQUAL( true, info.is_object() );
REQUIRE_EQUAL_OBJECTS( params, info );
BOOST_REQUIRE_EQUAL( N(alice), info["owner"].as_uint64() );
BOOST_REQUIRE_EQUAL( 0, info["total_votes"].as_uint64() );
REQUIRE_EQUAL_OBJECTS( params, info["prefs"] );
BOOST_REQUIRE_EQUAL( string(key.begin(), key.end()), to_string(info["packed_key"]) );
//do regproducer again to change parameters
fc::variant params2 = mutable_variant_object()
("target_block_size", 1024 * 1024 + 1)
("max_block_size", 10 * 1024 + 1)
("target_block_acts_per_scope", 1002)
("max_block_acts_per_scope", 10002)
("target_block_acts", 1102)
("max_block_acts", 11002)
("max_storage_size", 2002)
("max_transaction_lifetime", 3602)
("max_transaction_exec_time", 9997)
("max_authority_depth", 7)
("max_inline_depth", 5)
("max_inline_action_size", 4095)
("max_generated_transaction_size", 64*1025)
("inflation_rate", 1052)
("storage_reserve_ratio", 1006);
vector<char> key2 = fc::raw::pack( fc::crypto::public_key( std::string("EOSR16EPHFSKVYHBjQgxVGQPrwCxTg7BbZ69H9i4gztN9deKTEXYne4") ) );
BOOST_REQUIRE_EQUAL( success(), push_action(N(alice), N(regproducer), mvo()
("producer", "alice")
("producer_key", key2 )
("prefs", params2)
)
);
info = get_producer_info( "alice" );
BOOST_REQUIRE_EQUAL( N(alice), info["owner"].as_uint64() );
BOOST_REQUIRE_EQUAL( 0, info["total_votes"].as_uint64() );
REQUIRE_EQUAL_OBJECTS( params2, info["prefs"] );
BOOST_REQUIRE_EQUAL( string(key2.begin(), key2.end()), to_string(info["packed_key"]) );
} FC_LOG_AND_RETHROW()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册