Skip to content

Commit d381110

Browse files
committed
Add tests for order_update fee if paid in CORE
1 parent 663ecd9 commit d381110

File tree

1 file changed

+70
-8
lines changed

1 file changed

+70
-8
lines changed

tests/tests/fee_tests.cpp

+70-8
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ BOOST_AUTO_TEST_CASE( fee_refund_test )
733733
issue_uia( bob_id, asset( bob_b0, usd_id ) );
734734

735735
int64_t order_create_fee = 537;
736+
int64_t order_update_fee = 437;
736737
int64_t order_cancel_fee = 129;
737738

738739
uint32_t skip = database::skip_witness_signature
@@ -745,13 +746,19 @@ BOOST_AUTO_TEST_CASE( fee_refund_test )
745746

746747
generate_block( skip );
747748

748-
for( int i=0; i<2; i++ )
749+
for( int i=0; i<5; i++ )
749750
{
750751
if( i == 1 )
751752
{
752753
generate_blocks( HARDFORK_445_TIME, true, skip );
753754
generate_block( skip );
754755
}
756+
else if( i == 2 )
757+
{
758+
generate_blocks( HARDFORK_CORE_1604_TIME, true, skip );
759+
generate_block( skip );
760+
}
761+
755762

756763
// enable_fees() and change_fees() modifies DB directly, and results will be overwritten by block generation
757764
// so we have to do it every time we stop generating/popping blocks and start doing tx's
@@ -771,6 +778,11 @@ BOOST_AUTO_TEST_CASE( fee_refund_test )
771778
create_fee_params.fee = order_create_fee;
772779
new_fees.insert( create_fee_params );
773780
}
781+
{
782+
limit_order_update_operation::fee_params_t update_fee_params;
783+
update_fee_params.fee = order_update_fee;
784+
new_fees.insert( update_fee_params );
785+
}
774786
{
775787
limit_order_cancel_operation::fee_params_t cancel_fee_params;
776788
cancel_fee_params.fee = order_cancel_fee;
@@ -795,6 +807,21 @@ BOOST_AUTO_TEST_CASE( fee_refund_test )
795807
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - order_create_fee );
796808
BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_b0 - 500 );
797809

810+
int64_t update_net_fee = order_cancel_fee * order_update_fee / order_create_fee ;
811+
int64_t bob_update_fees = 0;
812+
if( i == 2 )
813+
{
814+
// Bob updates order
815+
update_limit_order( bo1_id, {}, asset(100, usd_id) );
816+
817+
bob_update_fees += update_net_fee;
818+
819+
BOOST_CHECK_EQUAL( get_balance( alice_id, core_id ), alice_b0 - 1000 - order_create_fee );
820+
BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_b0 );
821+
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - bob_update_fees - order_update_fee );
822+
BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_b0 - 600 );
823+
}
824+
798825
// Bob cancels order
799826
cancel_limit_order( bo1_id(db) );
800827

@@ -806,35 +833,70 @@ BOOST_AUTO_TEST_CASE( fee_refund_test )
806833

807834
BOOST_CHECK_EQUAL( get_balance( alice_id, core_id ), alice_b0 - 1000 - order_create_fee );
808835
BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_b0 );
809-
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - cancel_net_fee );
836+
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - bob_update_fees - cancel_net_fee );
810837
BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_b0 );
811838

812839
// Alice cancels order
813840
cancel_limit_order( ao1_id(db) );
814841

815842
BOOST_CHECK_EQUAL( get_balance( alice_id, core_id ), alice_b0 - cancel_net_fee );
816843
BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_b0 );
817-
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - cancel_net_fee );
844+
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - bob_update_fees - cancel_net_fee );
818845
BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_b0 );
819846

820847
// Check partial fill
821848
const limit_order_object* ao2 = create_sell_order( alice_id, asset(1000), asset(200, usd_id) );
849+
850+
BOOST_REQUIRE( ao2 != nullptr );
851+
852+
int64_t alice_update_fees = order_create_fee;
853+
int64_t alice_update_amounts = 0;
854+
if( i == 3 )
855+
{
856+
// Alice updates order
857+
update_limit_order( *ao2, {}, asset(100) );
858+
859+
alice_update_fees = update_net_fee + order_update_fee;
860+
alice_update_amounts = 100;
861+
862+
BOOST_CHECK_EQUAL( get_balance( alice_id, core_id ), alice_b0 - cancel_net_fee - alice_update_fees
863+
- 1000 - alice_update_amounts );
864+
BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_b0 );
865+
}
866+
822867
const limit_order_object* bo2 = create_sell_order( bob_id, asset(100, usd_id), asset(500) );
823868

824-
BOOST_CHECK( ao2 != nullptr );
825869
BOOST_CHECK( bo2 == nullptr );
826870

827-
BOOST_CHECK_EQUAL( get_balance( alice_id, core_id ), alice_b0 - cancel_net_fee - order_create_fee - 1000 );
871+
BOOST_CHECK_EQUAL( get_balance( alice_id, core_id ), alice_b0 - cancel_net_fee - alice_update_fees
872+
- 1000 - alice_update_amounts );
828873
BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_b0 + 100 );
829-
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - cancel_net_fee - order_create_fee + 500 );
874+
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - bob_update_fees - cancel_net_fee
875+
- order_create_fee + 500 );
830876
BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_b0 - 100 );
831877

878+
if( i == 4 )
879+
{
880+
// Alice updates order
881+
update_limit_order( *ao2, {}, asset(100) );
882+
883+
BOOST_CHECK_EQUAL( get_balance( alice_id, core_id ), alice_b0 - cancel_net_fee - alice_update_fees
884+
- 1000 - alice_update_amounts
885+
- order_update_fee - 100 );
886+
BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_b0 + 100 );
887+
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - bob_update_fees - cancel_net_fee
888+
- order_create_fee + 500 );
889+
BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_b0 - 100 );
890+
}
891+
832892
// cancel Alice order, show that entire deferred_fee was consumed by partial match
833893
cancel_limit_order( *ao2 );
834894

835-
BOOST_CHECK_EQUAL( get_balance( alice_id, core_id ), alice_b0 - cancel_net_fee - order_create_fee - 500 - order_cancel_fee );
895+
BOOST_CHECK_EQUAL( get_balance( alice_id, core_id ), alice_b0 - cancel_net_fee - alice_update_fees - 500
896+
- order_cancel_fee );
836897
BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_b0 + 100 );
837-
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - cancel_net_fee - order_create_fee + 500 );
898+
BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_b0 - bob_update_fees - cancel_net_fee
899+
- order_create_fee + 500 );
838900
BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_b0 - 100 );
839901

840902
// TODO: Check multiple fill

0 commit comments

Comments
 (0)