1
+ #include < boost/test/unit_test.hpp>
2
+ #include < graphene/chain/market_object.hpp>
3
+ #include < graphene/chain/hardfork.hpp>
4
+ #include " ../common/database_fixture.hpp"
5
+
6
+
7
+ using namespace graphene ::chain;
8
+ using namespace graphene ::chain::test;
9
+ using namespace graphene ::chain::detail;
10
+
11
+ namespace graphene { namespace chain {namespace detail {
12
+ const trade_statistics_object* get_trade_statistics (const database &db, const account_id_type& account_id, const asset_id_type &asset_id);
13
+ }}}
14
+
15
+ namespace fc
16
+ {
17
+ template <typename Ch, typename T>
18
+ std::basic_ostream<Ch>& operator <<(std::basic_ostream<Ch>& os, safe<T> const & sf)
19
+ {
20
+ os << sf.value ;
21
+ return os;
22
+ }
23
+ }
24
+
25
+ struct dynamic_market_fee_database_fixture : database_fixture
26
+ {
27
+ const share_type core_precision = asset::scaled_precision( asset_id_type()(db).precision );
28
+
29
+ dynamic_market_fee_database_fixture ()
30
+ : database_fixture(HARDFORK_DYNAMIC_FEE_TIME - 100 )
31
+ {}
32
+
33
+ asset core_asset (int64_t x )
34
+ {
35
+ return asset ( x*core_precision );
36
+ };
37
+
38
+ void issue_asset ()
39
+ {
40
+ try
41
+ {
42
+ ACTORS ((alice)(bob)(izzy)(jill));
43
+
44
+ fund ( alice, core_asset (1000000 ) );
45
+ fund ( bob, core_asset (1000000 ) );
46
+ fund ( izzy, core_asset (1000000 ) );
47
+ fund ( jill, core_asset (1000000 ) );
48
+
49
+ price price (asset (1 , asset_id_type (1 )), asset (1 ));
50
+
51
+ asset_object izzycoin = create_user_issued_asset ( " IZZYCOIN" , izzy, charge_market_fee, price, 2 );
52
+
53
+ asset_object jillcoin = create_user_issued_asset ( " JILLCOIN" , jill, charge_market_fee, price, 2 );
54
+
55
+ // Alice and Bob create some coins
56
+ issue_uia ( alice, izzycoin.amount ( 100000 ) );
57
+ issue_uia ( bob, jillcoin.amount ( 100000 ) );
58
+ }
59
+ FC_LOG_AND_RETHROW ()
60
+ }
61
+ };
62
+
63
+ BOOST_FIXTURE_TEST_SUITE ( dynamic_market_fee_tests, dynamic_market_fee_database_fixture )
64
+
65
+ BOOST_AUTO_TEST_CASE(adjust_trade_statistics_test_before_HARDFORK_DYNAMIC_FEE_TIME_hf)
66
+ {
67
+ try
68
+ {
69
+ issue_asset ();
70
+ return ;
71
+ const asset_object &jillcoin = get_asset (" JILLCOIN" );
72
+ const asset_object &izzycoin = get_asset (" IZZYCOIN" );
73
+
74
+ GET_ACTOR (alice);
75
+ GET_ACTOR (bob);
76
+
77
+ // Alice and Bob place orders which match
78
+ create_sell_order ( alice_id, izzycoin.amount (100 ), jillcoin.amount (300 ) );
79
+ create_sell_order ( bob_id, jillcoin.amount (300 ), izzycoin.amount (100 ) );
80
+ {
81
+ const auto alice_izzycoin_tso = get_trade_statistics (db, alice_id, izzycoin.get_id ());
82
+ const auto alice_jillcoin_tso = get_trade_statistics (db, alice_id, jillcoin.get_id ());
83
+
84
+ BOOST_CHECK (alice_izzycoin_tso == nullptr );
85
+ BOOST_CHECK (alice_jillcoin_tso == nullptr );
86
+
87
+ const auto bob_izzycoin_tso = get_trade_statistics (db, bob_id, izzycoin.get_id ());
88
+ const auto bob_jillcoin_tso = get_trade_statistics (db, bob_id, jillcoin.get_id ());
89
+
90
+ BOOST_CHECK (bob_izzycoin_tso == nullptr );
91
+ BOOST_CHECK (bob_jillcoin_tso == nullptr );
92
+ }
93
+ } FC_LOG_AND_RETHROW ()
94
+ }
95
+
96
+ BOOST_AUTO_TEST_CASE (adjust_trade_statistics_test_after_HARDFORK_DYNAMIC_FEE_TIME_hf)
97
+ {
98
+ try
99
+ {
100
+ issue_asset ();
101
+
102
+ generate_blocks (HARDFORK_DYNAMIC_FEE_TIME);
103
+
104
+ const asset_object &jillcoin = get_asset (" JILLCOIN" );
105
+ const asset_object &izzycoin = get_asset (" IZZYCOIN" );
106
+
107
+ GET_ACTOR (alice);
108
+ GET_ACTOR (bob);
109
+
110
+ set_expiration ( db, trx );
111
+
112
+ // Alice and Bob place orders which match
113
+ create_sell_order ( alice_id, izzycoin.amount (100 ), jillcoin.amount (300 ) );
114
+ create_sell_order ( bob_id, jillcoin.amount (300 ), izzycoin.amount (100 ) );
115
+ {
116
+ const auto alice_jillcoin_tso = get_trade_statistics (db, alice_id, jillcoin.get_id ());
117
+ BOOST_CHECK_EQUAL (alice_jillcoin_tso->total_volume .amount , 300 );
118
+
119
+ const auto bob_izzycoin_tso = get_trade_statistics (db, bob_id, izzycoin.get_id ());
120
+ BOOST_CHECK_EQUAL (bob_izzycoin_tso->total_volume .amount , 100 );
121
+ }
122
+ // Alice and Bob place orders which match
123
+ // trade_statistics should be updated
124
+ create_sell_order ( alice_id, izzycoin.amount (100 ), jillcoin.amount (300 ) );
125
+ create_sell_order ( bob_id, jillcoin.amount (300 ), izzycoin.amount (100 ) );
126
+ {
127
+ const auto alice_jillcoin_tso = get_trade_statistics (db, alice_id, jillcoin.get_id ());
128
+ BOOST_CHECK_EQUAL (alice_jillcoin_tso->total_volume .amount , 600 );
129
+
130
+ const auto bob_izzycoin_tso = get_trade_statistics (db, bob_id, izzycoin.get_id ());
131
+ BOOST_CHECK_EQUAL (bob_izzycoin_tso->total_volume .amount , 200 );
132
+ }
133
+ }
134
+ FC_LOG_AND_RETHROW ()
135
+ }
136
+ BOOST_AUTO_TEST_SUITE_END ()
0 commit comments