提交 afa5cc22 编写于 作者: A Anton Perkov

system contract test fixes

上级 5950dff1
......@@ -130,6 +130,7 @@ namespace eosiosystem {
eosio_assert( 0 < storage_bytes, "stake is too small to increase storage even by 1 byte" );
print( "delegatebw: from = ", del.from, " receiver = ", del.receiver, "\n" );
auto itr = del_index.find( del.receiver);
if( itr != nullptr ) {
del_index.emplace( del.from, [&]( auto& dbo ){
......@@ -188,7 +189,9 @@ namespace eosiosystem {
//eosio_assert( is_account( del.receiver ), "can only delegate resources to an existing account" );
const auto& dbw = del_index.get(del.receiver);
print ("undelegatebw: from = ", del.from, " receiver = ", del.receiver, "\n");
const auto& dbw = del_index.get( del.receiver );
eosio_assert( dbw.net_weight >= del.unstake_net_quantity, "insufficient staked net bandwidth" );
eosio_assert( dbw.cpu_weight >= del.unstake_cpu_quantity, "insufficient staked cpu bandwidth" );
......@@ -196,7 +199,7 @@ namespace eosiosystem {
system_token_type storage_stake_decrease = totals.storage_stake * del.unstake_storage_bytes / totals.storage_bytes;
auto total_refund = system_token_type(del.unstake_cpu_quantity) + system_token_type(del.unstake_net_quantity) + storage_stake_decrease;
eosio_assert( total_refund.quantity >= 0, "must unstake a positive amount" );
//eosio_assert( total_refund.quantity >= 0, "must unstake a positive amount" );
del_index.update( dbw, del.from, [&]( auto& dbo ){
dbo.net_weight -= del.unstake_net_quantity;
......@@ -215,7 +218,8 @@ namespace eosiosystem {
set_resource_limits( totals.owner, totals.storage_bytes, totals.net_weight.quantity, totals.cpu_weight.quantity, 0 );
/// TODO: implement / enforce time delays on withdrawing
currency::inline_transfer( SystemAccount, del.from, asset( total_refund.quantity ), "unstake bandwidth" );
print( "undelegatebw: ", total_refund.quantity, "\n" );
currency::inline_transfer( SystemAccount, del.from, asset( static_cast<int64_t>( total_refund.quantity )), "unstake bandwidth" );
auto parameters = eosio_parameters_singleton::get();
parameters.total_storage_bytes_reserved -= del.unstake_storage_bytes;
......
......@@ -52,7 +52,7 @@
{"name":"receiver", "type":"account_name"},
{"name":"unstake_net", "type":"asset"},
{"name":"unstake_cpu", "type":"asset"},
{"name":"stake_storage_bytes", "type":"uint64"}
{"name":"unstake_bytes", "type":"uint64"}
]
},{
"name": "total_resources",
......
......@@ -11,7 +11,7 @@ extern "C" {
/// The apply method implements the dispatch of events to this contract
void apply( uint64_t code, uint64_t act ) {
print( eosio::name(code), "::", eosio::name(act) );
//print( eosio::name(code), "::", eosio::name(act) );
eosiosystem::contract<N(eosio)>::apply( code, act );
}
}
......@@ -30,7 +30,8 @@ namespace eosiosystem {
}
static void apply( account_name code, action_name act ) {
if( !eosio::dispatch<contract, typename delegate_bandwith<SystemAccount>::delegatebw,
if ( !eosio::dispatch<currency, typename currency::transfer, typename currency::issue>( code, act ) ) {
if( !eosio::dispatch<contract, typename delegate_bandwith<SystemAccount>::delegatebw,
typename delegate_bandwith<SystemAccount>::undelegatebw,
typename voting<SystemAccount>::register_proxy,
typename voting<SystemAccount>::unregister_proxy,
......@@ -40,7 +41,6 @@ namespace eosiosystem {
typename voting<SystemAccount>::unstake_vote,
typename voting<SystemAccount>::unstake_vote_deferred,
nonce>( code, act) ) {
if ( !eosio::dispatch<currency, typename currency::transfer, typename currency::issue>( code, act ) ) {
eosio::print("Unexpected action: ", eosio::name(act), "\n");
eosio_assert( false, "received unexpected action");
}
......
......@@ -510,4 +510,15 @@ void set_blockchain_parameters(const struct blockchain_parameters* params) {
set_blockchain_parameters_packed( data.data(), data.size() );
}
int get_blockchain_parameters_packed(char* data, size_t datalen);
void get_blockchain_parameters(struct blockchain_parameters* params) {
char buf[sizeof(struct blockchain_parameters)];
size_t size = get_blockchain_parameters_packed( buf, sizeof(buf) );
eosio_assert( size <= sizeof(buf), "buffer is too small" );
static_assert(sizeof(blockchain_parameters) == sizeof(eosio::blockchain_parameters), "data structures are not the same");
eosio::datastream<const char*> ds( buf, size_t(size) );
ds >> *reinterpret_cast<eosio::blockchain_parameters*>(params);
}
}
......@@ -85,8 +85,7 @@ BOOST_AUTO_TEST_SUITE(eosio_system_tests)
BOOST_FIXTURE_TEST_CASE( delegate_to_myself, eosio_system_tester ) try {
issue( "alice", "1000.0000 EOS", config::system_account_name );
auto balance = get_balance( "alice" );
std::cout << "Balance: " << N(alice) << ": " << balance << std::endl;
BOOST_REQUIRE_EQUAL( asset::from_string("1000.0000 EOS"), get_balance( "alice" ) );
push_action(N(alice), N(delegatebw), mvo()
("from", "alice")
......@@ -97,13 +96,30 @@ BOOST_FIXTURE_TEST_CASE( delegate_to_myself, eosio_system_tester ) try {
);
auto stake = get_total_stake( "alice" );
BOOST_REQUIRE_EQUAL( 2000000, stake["net_weight"].as_uint64());
BOOST_REQUIRE_EQUAL( 1000000, stake["cpu_weight"].as_uint64());
BOOST_REQUIRE_EQUAL( 3000000, stake["storage_stake"].as_uint64());
BOOST_REQUIRE_EQUAL( asset::from_string("200.0000 EOS").amount, stake["net_weight"].as_uint64());
BOOST_REQUIRE_EQUAL( asset::from_string("100.0000 EOS").amount, stake["cpu_weight"].as_uint64());
BOOST_REQUIRE_EQUAL( asset::from_string("300.0000 EOS").amount, stake["storage_stake"].as_uint64());
balance = get_balance( "alice" );
std::cout << "Balance: " << balance << std::endl;
auto bytes = stake["storage_bytes"].as_uint64();
BOOST_REQUIRE_EQUAL( true, 0 < bytes );
} FC_LOG_AND_RETHROW()
BOOST_REQUIRE_EQUAL( asset::from_string("400.0000 EOS"), get_balance( "alice" ) );
push_action(N(alice), N(undelegatebw), mvo()
("from", "alice")
("receiver", "alice")
("unstake_net", "200.0000 EOS")
("unstake_cpu", "100.0000 EOS")
("unstake_bytes", bytes)
);
stake = get_total_stake( "alice" );
std::cout << "STAKE: " << stake["net_weight"].as_uint64() << ' ' << stake["cpu_weight"].as_uint64() << std::endl;
BOOST_REQUIRE_EQUAL( asset::from_string("0.0000 EOS").amount, stake["net_weight"].as_uint64());
BOOST_REQUIRE_EQUAL( asset::from_string("0.0000 EOS").amount, stake["cpu_weight"].as_uint64());
//BOOST_REQUIRE_EQUAL( asset::from_string("0.0000 EOS").amount, stake["storage_stake"].as_uint64());
} FC_LOG_AND_RETHROW()
BOOST_AUTO_TEST_SUITE_END()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册