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

Merge branch 'system-contract-tests-fix' of github.com:EOSIO/eos into system-contract-tests-fix

......@@ -182,7 +182,7 @@ namespace eosiosystem {
* refunds the purchase price to the account. In this way there is no profit to be made through buying
* and selling ram.
*/
void system_contract::sellram( account_name account, uint32_t bytes ) {
void system_contract::sellram( account_name account, uint64_t bytes ) {
require_auth( account );
user_resources_table userres( _self, account );
......
......@@ -13,7 +13,7 @@
"base": "",
"fields": [
{"name":"account", "type":"account_name"},
{"name":"bytes", "type":"uint32"}
{"name":"bytes", "type":"uint64"}
]
},{
"name": "buyram",
......
......@@ -171,7 +171,7 @@ namespace eosiosystem {
* Reduces quota my bytes and then performs an inline transfer of tokens
* to receiver based upon the average purchase price of the original quota.
*/
void sellram( account_name receiver, uint32_t bytes );
void sellram( account_name receiver, uint64_t bytes );
/**
* This action is called after the delegation-period to claim all pending
......
......@@ -61,7 +61,6 @@ namespace eosio { namespace chain {
uint64_t block_cpu_limit = rl.get_block_cpu_limit();
if( !billed_cpu_time_us ) {
wdump((block_cpu_limit));
auto potential_deadline = fc::time_point::now() + fc::microseconds(block_cpu_limit);
if( potential_deadline < deadline ) deadline = potential_deadline;
}
......
......@@ -331,10 +331,30 @@ void print_result( const fc::variant& result ) { try {
const auto& processed = result["processed"];
const auto& transaction_id = processed["id"].as_string();
string status = processed["receipt"].is_object() ? processed["receipt"]["status"].as_string() : "failed";
auto net = processed["net_usage"].as_int64()*8;
auto cpu = processed["cpu_usage"].as_int64() / 1024;
int64_t net = -1;
int64_t cpu = -1;
if (processed.get_object().contains("receipt")) {
const auto& receipt = processed["receipt"];
if (receipt.is_object()) {
net = receipt["net_usage_words"].as_int64() * 8;
cpu = receipt["cpu_usage_us"].as_int64();
}
}
cerr << status << " transaction: " << transaction_id << " ";
if (net < 0) {
cerr << "<unknown>";
} else {
cerr << net;
}
cerr << " bytes ";
if (cpu < 0) {
cerr << "<unknown>";
} else {
cerr << cpu;
}
cerr << status << " transaction: " << transaction_id << " " << net << " bytes " << cpu << "k cycles\n";
cerr << " us\n";
if( status == "failed" ) {
auto soft_except = processed["except"].as<optional<fc::exception>>();
......
......@@ -215,7 +215,7 @@ public:
return push_action( payer, N(buyrambytes), mvo()( "payer",payer)("receiver",receiver)("bytes",numbytes) );
}
action_result sellram( const account_name& account, uint32_t numbytes ) {
action_result sellram( const account_name& account, uint64_t numbytes ) {
return push_action( account, N(sellram), mvo()( "account", account)("bytes",numbytes) );
}
......@@ -426,6 +426,54 @@ inline uint64_t M( const string& eos_str ) {
BOOST_AUTO_TEST_SUITE(eosio_system_tests)
BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
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( success(), stake( "eosio", "alice", "200.0000 EOS", "100.0000 EOS" ) );
auto total = get_total_stake( "alice" );
auto init_bytes = total["ram_bytes"].as_uint64();
BOOST_REQUIRE_EQUAL( success(), buyram( "alice", "alice", "200.0000 EOS" ) );
BOOST_REQUIRE_EQUAL( asset::from_string("800.0000 EOS"), get_balance( "alice" ) );
total = get_total_stake( "alice" );
auto bytes = total["ram_bytes"].as_uint64();
auto bought_bytes = bytes - init_bytes;
wdump((init_bytes)(bought_bytes)(bytes) );
BOOST_REQUIRE_EQUAL( true, 0 < bought_bytes );
BOOST_REQUIRE_EQUAL( success(), sellram( "alice", bought_bytes ) );
BOOST_REQUIRE_EQUAL( asset::from_string("999.9999 EOS"), get_balance( "alice" ) );
total = get_total_stake( "alice" );
BOOST_REQUIRE_EQUAL( true, total["ram_bytes"].as_uint64() == init_bytes );
transfer( "eosio", "alice", "100000000.0000 EOS", "eosio" );
BOOST_REQUIRE_EQUAL( asset::from_string("100000999.9999 EOS"), get_balance( "alice" ) );
BOOST_REQUIRE_EQUAL( success(), buyram( "alice", "alice", "10000000.0000 EOS" ) );
total = get_total_stake( "alice" );
bytes = total["ram_bytes"].as_uint64();
bought_bytes = bytes - init_bytes;
wdump((init_bytes)(bought_bytes)(bytes) );
BOOST_REQUIRE_EQUAL( success(), sellram( "alice", bought_bytes ) );
total = get_total_stake( "alice" );
bytes = total["ram_bytes"].as_uint64();
bought_bytes = bytes - init_bytes;
wdump((init_bytes)(bought_bytes)(bytes) );
BOOST_REQUIRE_EQUAL( true, total["ram_bytes"].as_uint64() == init_bytes );
BOOST_REQUIRE_EQUAL( asset::from_string("100000999.9993 EOS"), get_balance( "alice" ) );
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
//issue( "eosio", "1000.0000 EOS", config::system_account_name );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册