@@ -776,28 +776,52 @@ BOOST_AUTO_TEST_CASE( liquidity_pool_exchange_test )
776776
777777 // The owner do the initial deposit
778778 generic_exchange_operation_result result;
779- result = deposit_to_liquidity_pool ( sam_id, lp_id, asset ( 1000 , eur_id ), asset ( 1200 , usd_id ) );
779+ result = deposit_to_liquidity_pool ( sam_id, lp_id, asset ( 100 , eur_id ), asset ( 120 , usd_id ) );
780780
781781 BOOST_REQUIRE_EQUAL ( result.paid .size (), 2u );
782- BOOST_CHECK ( result.paid .front () == asset ( 1000 , eur_id ) );
783- BOOST_CHECK ( result.paid .back () == asset ( 1200 , usd_id ) );
782+ BOOST_CHECK ( result.paid .front () == asset ( 100 , eur_id ) );
783+ BOOST_CHECK ( result.paid .back () == asset ( 120 , usd_id ) );
784784 BOOST_REQUIRE_EQUAL ( result.received .size (), 1u );
785- BOOST_CHECK ( result.received .front () == asset ( 1200 , lpa_id ) );
785+ BOOST_CHECK ( result.received .front () == asset ( 120 , lpa_id ) );
786786 BOOST_REQUIRE_EQUAL ( result.fees .size (), 0u );
787787
788- expected_pool_balance_a = 1000 ;
789- expected_pool_balance_b = 1200 ;
790- expected_lp_supply = 1200 ;
788+ expected_pool_balance_a = 100 ;
789+ expected_pool_balance_b = 120 ;
790+ expected_lp_supply = 120 ;
791791 BOOST_CHECK_EQUAL ( lpo.balance_a .value , expected_pool_balance_a);
792792 BOOST_CHECK_EQUAL ( lpo.balance_b .value , expected_pool_balance_b);
793793 BOOST_CHECK ( lpo.virtual_value == fc::uint128_t (expected_pool_balance_a) * expected_pool_balance_b );
794794 BOOST_CHECK_EQUAL ( lpa.dynamic_data (db).current_supply .value , expected_lp_supply );
795795
796- expected_balance_sam_eur -= 1000 ;
797- expected_balance_sam_usd -= 1200 ;
798- expected_balance_sam_lpa += 1200 ;
796+ expected_balance_sam_eur -= 100 ;
797+ expected_balance_sam_usd -= 120 ;
798+ expected_balance_sam_lpa += 120 ;
799+ check_balances ();
800+
801+ // Deposit again with 900 EUR and 3000 USD, the pool only takes 900 EUR and 1080 USD
802+ result = deposit_to_liquidity_pool ( sam_id, lp_id, asset ( 900 , eur_id ), asset ( 3000 , usd_id ) );
803+
804+ BOOST_REQUIRE_EQUAL ( result.paid .size (), 2u );
805+ BOOST_CHECK ( result.paid .front () == asset ( 900 , eur_id ) );
806+ BOOST_CHECK ( result.paid .back () == asset ( 1080 , usd_id ) );
807+ BOOST_REQUIRE_EQUAL ( result.received .size (), 1u );
808+ BOOST_CHECK ( result.received .front () == asset ( 1080 , lpa_id ) );
809+ BOOST_REQUIRE_EQUAL ( result.fees .size (), 0u );
810+
811+ expected_pool_balance_a += 900 ;
812+ expected_pool_balance_b += 1080 ;
813+ expected_lp_supply += 1080 ;
814+ BOOST_CHECK_EQUAL ( lpo.balance_a .value , expected_pool_balance_a);
815+ BOOST_CHECK_EQUAL ( lpo.balance_b .value , expected_pool_balance_b);
816+ BOOST_CHECK ( lpo.virtual_value == fc::uint128_t (expected_pool_balance_a) * expected_pool_balance_b );
817+ BOOST_CHECK_EQUAL ( lpa.dynamic_data (db).current_supply .value , expected_lp_supply );
818+
819+ expected_balance_sam_eur -= 900 ;
820+ expected_balance_sam_usd -= 1080 ;
821+ expected_balance_sam_lpa += 1080 ;
799822 check_balances ();
800823
824+
801825 // Unable to exchange if data is invalid
802826 // non-positive amounts
803827 for ( int64_t i = -1 ; i <= 1 ; ++i )
@@ -938,6 +962,9 @@ BOOST_AUTO_TEST_CASE( liquidity_pool_exchange_test )
938962 expected_balance_ted_usd -= 1000 ;
939963 check_balances ();
940964
965+ // Withdraw
966+ result = withdraw_from_liquidity_pool ( sam_id, lp_id, asset ( 1000 , lpa_id) );
967+
941968 // Generates a block
942969 generate_block ();
943970 BOOST_CHECK_EQUAL ( eur_id (db).dynamic_data (db).accumulated_fees .value , expected_accumulated_fees_eur );
@@ -948,6 +975,16 @@ BOOST_AUTO_TEST_CASE( liquidity_pool_exchange_test )
948975 BOOST_CHECK_EQUAL ( ticker.total_exchange_a2b_count , 1u );
949976 BOOST_CHECK_EQUAL ( ticker._24h_exchange_b2a_count , 1u );
950977 BOOST_CHECK_EQUAL ( ticker.total_exchange_b2a_count , 1u );
978+ BOOST_CHECK_EQUAL ( ticker._24h_deposit_count , 2u );
979+ BOOST_CHECK ( ticker._24h_deposit_amount_a == 1000u );
980+ BOOST_CHECK ( ticker._24h_deposit_amount_b == 1200u );
981+ BOOST_CHECK ( ticker._24h_deposit_share_amount == 1200u );
982+ BOOST_CHECK_EQUAL ( ticker.total_deposit_count , 2u );
983+ BOOST_CHECK ( ticker.total_deposit_amount_a == 1000u );
984+ BOOST_CHECK ( ticker.total_deposit_amount_b == 1200u );
985+ BOOST_CHECK ( ticker.total_deposit_share_amount == 1200u );
986+ BOOST_CHECK_EQUAL ( ticker._24h_withdrawal_count , 1u );
987+ BOOST_CHECK_EQUAL ( ticker.total_withdrawal_count , 1u );
951988
952989 // Check database API
953990 graphene::app::database_api db_api ( db, &( app.get_options () ) );
@@ -968,29 +1005,49 @@ BOOST_AUTO_TEST_CASE( liquidity_pool_exchange_test )
9681005 BOOST_CHECK_EQUAL ( pools.front ()->statistics ->total_exchange_a2b_count , 1u );
9691006 BOOST_CHECK_EQUAL ( pools.front ()->statistics ->_24h_exchange_b2a_count , 1u );
9701007 BOOST_CHECK_EQUAL ( pools.front ()->statistics ->total_exchange_b2a_count , 1u );
1008+ BOOST_CHECK_EQUAL ( pools.front ()->statistics ->_24h_deposit_count , 2u );
1009+ BOOST_CHECK ( pools.front ()->statistics ->_24h_deposit_amount_a == 1000u );
1010+ BOOST_CHECK ( pools.front ()->statistics ->_24h_deposit_amount_b == 1200u );
1011+ BOOST_CHECK ( pools.front ()->statistics ->_24h_deposit_share_amount == 1200u );
1012+ BOOST_CHECK_EQUAL ( pools.front ()->statistics ->total_deposit_count , 2u );
1013+ BOOST_CHECK ( pools.front ()->statistics ->total_deposit_amount_a == 1000u );
1014+ BOOST_CHECK ( pools.front ()->statistics ->total_deposit_amount_b == 1200u );
1015+ BOOST_CHECK ( pools.front ()->statistics ->total_deposit_share_amount == 1200u );
1016+ BOOST_CHECK_EQUAL ( pools.front ()->statistics ->_24h_withdrawal_count , 1u );
1017+ BOOST_CHECK_EQUAL ( pools.front ()->statistics ->total_withdrawal_count , 1u );
9711018
9721019 generate_blocks ( db.head_block_time () + fc::days (2 ) );
9731020
9741021 BOOST_CHECK_EQUAL ( ticker._24h_exchange_a2b_count , 0u );
9751022 BOOST_CHECK_EQUAL ( ticker.total_exchange_a2b_count , 1u );
9761023 BOOST_CHECK_EQUAL ( ticker._24h_exchange_b2a_count , 0u );
9771024 BOOST_CHECK_EQUAL ( ticker.total_exchange_b2a_count , 1u );
1025+ BOOST_CHECK_EQUAL ( ticker._24h_deposit_count , 0u );
1026+ BOOST_CHECK ( ticker._24h_deposit_amount_a == 0u );
1027+ BOOST_CHECK ( ticker._24h_deposit_amount_b == 0u );
1028+ BOOST_CHECK ( ticker._24h_deposit_share_amount == 0u );
1029+ BOOST_CHECK_EQUAL ( ticker.total_deposit_count , 2u );
1030+ BOOST_CHECK ( ticker.total_deposit_amount_a == 1000u );
1031+ BOOST_CHECK ( ticker.total_deposit_amount_b == 1200u );
1032+ BOOST_CHECK ( ticker.total_deposit_share_amount == 1200u );
1033+ BOOST_CHECK_EQUAL ( ticker._24h_withdrawal_count , 0u );
1034+ BOOST_CHECK_EQUAL ( ticker.total_withdrawal_count , 1u );
9781035
9791036 // Check history API
9801037 graphene::app::history_api hist_api (app);
9811038 auto head_time = db.head_block_time ();
9821039
983- // all histories
1040+ // all histories : 1:create, 2:deposit, 3:deposit, 4:exchange, 5:exchange, 6:withdrawal
9841041 auto histories = hist_api.get_liquidity_pool_history ( lp_id );
985- BOOST_CHECK_EQUAL ( histories.size (), 4u );
1042+ BOOST_CHECK_EQUAL ( histories.size (), 6u );
9861043
9871044 // limit = 3
9881045 histories = hist_api.get_liquidity_pool_history ( lp_id, {}, {}, 3 );
9891046 BOOST_CHECK_EQUAL ( histories.size (), 3u );
9901047
9911048 // only deposits
992- histories = hist_api.get_liquidity_pool_history ( lp_id, {}, {}, {}, 59 );
993- BOOST_CHECK_EQUAL ( histories.size (), 1u );
1049+ histories = hist_api.get_liquidity_pool_history ( lp_id, {}, {}, {}, 61 );
1050+ BOOST_CHECK_EQUAL ( histories.size (), 2u );
9941051
9951052 // time too early
9961053 histories = hist_api.get_liquidity_pool_history ( lp_id, head_time - fc::days (3 ) );
@@ -1004,16 +1061,17 @@ BOOST_AUTO_TEST_CASE( liquidity_pool_exchange_test )
10041061 histories = hist_api.get_liquidity_pool_history ( lp_id, {}, head_time - fc::days (3 ), {}, 63 );
10051062 BOOST_CHECK_EQUAL ( histories.size (), 2u );
10061063
1007- // start = 2, limit = 3, so result sequence == {1,2}
1064+ // start = 2, limit = 3, so result sequence == {2,1}
1065+ // note: range is (stop, start]
10081066 histories = hist_api.get_liquidity_pool_history_by_sequence ( lp_id, 2 , {}, 3 );
10091067 BOOST_CHECK_EQUAL ( histories.size (), 2u );
10101068
10111069 // start = 2, limit = 1, so result sequence == {2}
10121070 histories = hist_api.get_liquidity_pool_history_by_sequence ( lp_id, 2 , {}, 1 );
10131071 BOOST_CHECK_EQUAL ( histories.size (), 1u );
10141072
1015- // start = 3 , limit is default, but exchange only, so result sequence == {3 }
1016- histories = hist_api.get_liquidity_pool_history_by_sequence ( lp_id, 3 , head_time - fc::days (3 ), {}, 63 );
1073+ // start = 4 , limit is default, but exchange only, so result sequence == {4 }
1074+ histories = hist_api.get_liquidity_pool_history_by_sequence ( lp_id, 4 , head_time - fc::days (3 ), {}, 63 );
10171075 BOOST_CHECK_EQUAL ( histories.size (), 1u );
10181076
10191077 // Proceeds to the hard fork time that added white/blacklist checks for bitshares-core issue #2350
0 commit comments