Skip to content

Commit

Permalink
Merge pull request #2729 from bitshares/order-cancel-vop-result
Browse files Browse the repository at this point in the history
Save the result of virtual `limit_order_cancel` operation
  • Loading branch information
abitmore authored Mar 20, 2023
2 parents b810d59 + 40be62a commit d50e2db
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
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

0 comments on commit d50e2db

Please sign in to comment.