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

Add return value (what and how much is refunded) to virtual limit_order_cancel operation #2729

Merged
merged 3 commits into from
Mar 20, 2023
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
5 changes: 4 additions & 1 deletion libraries/chain/db_market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,10 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_
}

if( create_virtual_op )
push_applied_operation( vop );
{
auto op_id = push_applied_operation( vop );
set_applied_operation_result( op_id, refunded );
}

remove(order);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/graphene/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#define GRAPHENE_MAX_NESTED_OBJECTS (200)

const std::string GRAPHENE_CURRENT_DB_VERSION = "20220930";
const std::string GRAPHENE_CURRENT_DB_VERSION = "20230319";

#define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4
#define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3
Expand Down
41 changes: 34 additions & 7 deletions tests/tests/history_api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ BOOST_AUTO_TEST_CASE(get_account_history) {
}
}

BOOST_AUTO_TEST_CASE(get_account_history_virtual_operation_test) {
try {
BOOST_AUTO_TEST_CASE(get_account_history_virtual_operation_test)
{ try {
graphene::app::history_api hist_api(app);

asset_id_type usd_id = create_user_issued_asset("USD").get_id();
Expand All @@ -164,11 +164,38 @@ BOOST_AUTO_TEST_CASE(get_account_history_virtual_operation_test) {
BOOST_CHECK( histories.front().block_time == db.head_block_time() );
BOOST_CHECK( histories.front().is_virtual );

} catch (fc::exception &e) {
edump((e.to_detail_string()));
throw;
}
}
// Create a limit order that expires in 300 seconds
create_sell_order( dan_id, asset(10, usd_id), asset(10), db.head_block_time() + 300 );

generate_block();
fc::usleep(fc::milliseconds(100));

auto order_create_op_id = operation::tag<limit_order_create_operation>::value;

histories = hist_api.get_account_history("dan", operation_history_id_type(),
100, operation_history_id_type());

BOOST_REQUIRE_GT( histories.size(), 0 );
BOOST_CHECK_EQUAL( histories.front().op.which(), order_create_op_id );
BOOST_CHECK( histories.front().block_time == db.head_block_time() );
BOOST_CHECK( !histories.front().is_virtual );

// Let the limit order expire
generate_blocks( db.head_block_time() + 300 );
generate_block();
fc::usleep(fc::milliseconds(100));

auto order_cancel_op_id = operation::tag<limit_order_cancel_operation>::value;

histories = hist_api.get_account_history("dan", operation_history_id_type(),
100, operation_history_id_type());

BOOST_REQUIRE_GT( histories.size(), 0 );
BOOST_CHECK_EQUAL( histories.front().op.which(), order_cancel_op_id );
BOOST_CHECK( histories.front().is_virtual );
BOOST_CHECK( histories.front().result.is_type<asset>() );

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(get_account_history_notify_all_on_creation) {
try {
Expand Down