@@ -80,6 +80,98 @@ BOOST_AUTO_TEST_CASE( feed_limit_logic_test )
80
80
}
81
81
}
82
82
83
+ BOOST_AUTO_TEST_CASE (limit_order_update_test)
84
+ {
85
+ try {
86
+ ACTORS ((nathan));
87
+ const auto & bitusd = create_bitasset (" USDBIT" , nathan.id );
88
+ const auto & munee = create_user_issued_asset (" MUNEE" );
89
+ const auto & core = asset_id_type ()(db);
90
+
91
+ update_feed_producers (bitusd, {nathan_id});
92
+ price_feed current_feed;
93
+ current_feed.settlement_price = bitusd.amount (200 ) / core.amount (100 );
94
+ current_feed.maintenance_collateral_ratio = 1750 ;
95
+ publish_feed (bitusd, nathan, current_feed);
96
+
97
+ transfer (committee_account, nathan_id, asset (1500 ));
98
+ issue_uia (nathan, munee.amount (100 ));
99
+ borrow (nathan_id, bitusd.amount (100 ), asset (500 ));
100
+
101
+ auto expiration = db.head_block_time () + 1000 ;
102
+ auto sell_price = price (asset (500 ), bitusd.amount (1000 ));
103
+ limit_order_id_type order_id = create_sell_order (nathan, asset (500 ), bitusd.amount (1000 ), expiration)->id ;
104
+ BOOST_REQUIRE_EQUAL (order_id (db).for_sale .value , 500 );
105
+ BOOST_REQUIRE_EQUAL (fc::json::to_string (order_id (db).sell_price ), fc::json::to_string (sell_price));
106
+ BOOST_REQUIRE_EQUAL (order_id (db).expiration .sec_since_epoch (), expiration.sec_since_epoch ());
107
+
108
+ // Cannot update order without changing anything
109
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id), fc::assert_exception);
110
+ // Cannot update order to use inverted price assets
111
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, price (bitusd.amount (2 ), asset (1 ))), fc::assert_exception);
112
+ // Cannot update order to use different assets
113
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, price (bitusd.amount (2 ), munee.amount (1 ))), fc::assert_exception);
114
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, price (munee.amount (2 ), bitusd.amount (1 ))), fc::assert_exception);
115
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, price (asset (2 ), munee.amount (1 ))), fc::assert_exception);
116
+ // Cannot update order to expire in the past
117
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, {}, {}, db.head_block_time () - 10 ), fc::assert_exception);
118
+ // Cannot update order to add more funds than seller has
119
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, {}, asset (501 )), fc::assert_exception);
120
+ // Cannot update order to remove more funds than order has
121
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, {}, asset (-501 )), fc::assert_exception);
122
+ // Cannot update order to remove all funds in order
123
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, {}, asset (-500 )), fc::assert_exception);
124
+ // Cannot update order to add or remove different kind of funds
125
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, {}, bitusd.amount (50 )), fc::assert_exception);
126
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, {}, bitusd.amount (-50 )), fc::assert_exception);
127
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, {}, munee.amount (50 )), fc::assert_exception);
128
+ GRAPHENE_REQUIRE_THROW (update_limit_order (order_id, {}, munee.amount (-50 )), fc::assert_exception);
129
+
130
+ // Try changing price
131
+ sell_price.base = asset (501 );
132
+ update_limit_order (order_id, sell_price);
133
+ BOOST_REQUIRE_EQUAL (fc::json::to_string (order_id (db).sell_price ), fc::json::to_string (sell_price));
134
+ sell_price.base = asset (500 );
135
+ sell_price.quote = bitusd.amount (999 );
136
+ update_limit_order (order_id, sell_price);
137
+ BOOST_REQUIRE_EQUAL (fc::json::to_string (order_id (db).sell_price ), fc::json::to_string (sell_price));
138
+ sell_price.quote = bitusd.amount (1000 );
139
+ update_limit_order (order_id, sell_price);
140
+ BOOST_REQUIRE_EQUAL (fc::json::to_string (order_id (db).sell_price ), fc::json::to_string (sell_price));
141
+
142
+ // Try changing expiration
143
+ expiration += 50 ;
144
+ update_limit_order (order_id, {}, {}, expiration);
145
+ BOOST_REQUIRE_EQUAL (order_id (db).expiration .sec_since_epoch (), expiration.sec_since_epoch ());
146
+ expiration -= 100 ;
147
+ update_limit_order (order_id, {}, {}, expiration);
148
+ BOOST_REQUIRE_EQUAL (order_id (db).expiration .sec_since_epoch (), expiration.sec_since_epoch ());
149
+
150
+ // Try adding funds
151
+ update_limit_order (order_id, {}, asset (50 ));
152
+ BOOST_REQUIRE_EQUAL (order_id (db).amount_for_sale ().amount .value , 550 );
153
+ BOOST_REQUIRE_EQUAL (db.get_balance (nathan_id, core.get_id ()).amount .value , 450 );
154
+
155
+ // Try removing funds
156
+ update_limit_order (order_id, {}, asset (-100 ));
157
+ BOOST_REQUIRE_EQUAL (order_id (db).amount_for_sale ().amount .value , 450 );
158
+ BOOST_REQUIRE_EQUAL (db.get_balance (nathan_id, core.get_id ()).amount .value , 550 );
159
+
160
+ // Try changing everything at once
161
+ expiration += 50 ;
162
+ sell_price.base = asset (499 );
163
+ sell_price.quote = bitusd.amount (1001 );
164
+ update_limit_order (order_id, sell_price, 50 , expiration);
165
+ BOOST_REQUIRE_EQUAL (fc::json::to_string (order_id (db).sell_price ), fc::json::to_string (sell_price));
166
+ BOOST_REQUIRE_EQUAL (order_id (db).expiration .sec_since_epoch (), expiration.sec_since_epoch ());
167
+ BOOST_REQUIRE_EQUAL (order_id (db).amount_for_sale ().amount .value , 500 );
168
+ BOOST_REQUIRE_EQUAL (db.get_balance (nathan_id, core.get_id ()).amount .value , 500 );
169
+ } catch (fc::exception & e) {
170
+ edump ((e.to_detail_string ()));
171
+ throw ;
172
+ }
173
+ }
174
+
83
175
BOOST_AUTO_TEST_CASE ( call_order_update_test )
84
176
{
85
177
try {
0 commit comments