Skip to content

Commit

Permalink
Merge pull request #141 from eosnetworkfoundation/ehp/tokenomics-tests
Browse files Browse the repository at this point in the history
Test buyramburn return values
  • Loading branch information
ericpassmore authored May 15, 2024
2 parents e904aa0 + 3f14898 commit 969290f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
16 changes: 15 additions & 1 deletion tests/eosio.system_ram_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ BOOST_FIXTURE_TEST_CASE( buy_ram_burn, eosio_system_tester ) try {
const account_name alice = accounts[0];
const account_name null_account = "eosio.null"_n;

const char* expected_buyramburn_return_data = R"=====(
{
"payer": "alice",
"receiver": "alice",
"quantity": "1.0000 TST",
"bytes_purchased": 68374,
"ram_bytes": 86357,
"fee": "0.0050 TST"
}
)=====";

create_accounts_with_resources( accounts );
transfer( config::system_account_name, alice, core_sym::from_string("100.0000"), config::system_account_name );

Expand All @@ -191,6 +202,9 @@ BOOST_FIXTURE_TEST_CASE( buy_ram_burn, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( alice_before_buyramburn, alice_after_buyramburn );
BOOST_REQUIRE_EQUAL( true, null_before_buyramburn < null_after_buyramburn );
BOOST_REQUIRE_EQUAL( initial_alice_balance - ten_core_token, get_balance(alice));

validate_buyramburn_return(alice, core_sym::from_string("1.0000"), "burn RAM memo",
"action_return_buyram", expected_buyramburn_return_data );
} FC_LOG_AND_RETHROW()

// buyramself
Expand Down Expand Up @@ -221,4 +235,4 @@ BOOST_FIXTURE_TEST_CASE( buy_ram_self, eosio_system_tester ) try {
} FC_LOG_AND_RETHROW()


BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
26 changes: 25 additions & 1 deletion tests/eosio.system_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,30 @@ class eosio_system_tester : public TESTER {
return push_action(payer, "buyramburn"_n, mvo()("payer", payer)("quantity", quantity)("memo", memo));
}

void validate_buyramburn_return(const name& payer, const asset& quantity,
const std::string& memo, const type_name& type, const std::string& json) {
// create hex return from provided json
std::string expected_hex = convert_json_to_hex(type, json);
// initialize string that will hold actual return
std::string actual_hex;

// execute transaction and get traces must use base_tester
auto trace = base_tester::push_action(config::system_account_name, "buyramburn"_n, payer,
mvo()("payer",payer)("quantity",quantity)("memo", memo));
produce_block();

// confirm we have trances and find the right one (should be trace idx == 0)
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trace->id));

// the first trace always has the return value
int i = 0;
std::string copy_trace = std::string(trace->action_traces[i].return_value.begin(), trace->action_traces[i].return_value.end());
actual_hex = convert_ordinals_to_hex(copy_trace);

// test fails here actual_hex is
BOOST_REQUIRE_EQUAL(expected_hex,actual_hex);
}

void validate_ramburn_return(const account_name& owner, uint32_t bytes, const std::string& memo,
const type_name& type, const std::string& json) {
// create hex return from provided json
Expand Down Expand Up @@ -1525,4 +1549,4 @@ inline uint64_t M( const string& eos_str ) {
return core_sym::from_string( eos_str ).get_amount();
}

}
}

0 comments on commit 969290f

Please sign in to comment.