Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test buyramburn return values #141

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}

}
}
Loading