11from decimal import Decimal
22
33from pyinjective .composer import Composer
4- from pyinjective .core .gas_limit_estimator import GasLimitEstimator
4+ from pyinjective .core .gas_limit_estimator import (
5+ DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT ,
6+ DERIVATIVE_ORDER_CREATION_GAS_LIMIT ,
7+ SPOT_ORDER_CANCELATION_GAS_LIMIT ,
8+ SPOT_ORDER_CREATION_GAS_LIMIT ,
9+ BatchCancelDerivativeOrdersGasLimitEstimator ,
10+ BatchCancelSpotOrdersGasLimitEstimator ,
11+ BatchCreateDerivativeLimitOrdersGasLimitEstimator ,
12+ BatchCreateSpotLimitOrdersGasLimitEstimator ,
13+ BatchUpdateOrdersGasLimitEstimator ,
14+ ExecGasLimitEstimator ,
15+ GasLimitEstimator ,
16+ )
517from pyinjective .core .market import BinaryOptionMarket
618from pyinjective .proto .cosmos .gov .v1beta1 import tx_pb2 as gov_tx_pb
719from pyinjective .proto .cosmwasm .wasm .v1 import tx_pb2 as wasm_tx_pb
@@ -44,8 +56,8 @@ def test_estimation_for_batch_create_spot_limit_orders(self):
4456 message = composer .msg_batch_create_spot_limit_orders (sender = "sender" , orders = orders )
4557 estimator = GasLimitEstimator .for_message (message = message )
4658
47- expected_order_gas_limit = 50000
48- expected_message_gas_limit = 15000
59+ expected_order_gas_limit = SPOT_ORDER_CREATION_GAS_LIMIT
60+ expected_message_gas_limit = BatchCreateSpotLimitOrdersGasLimitEstimator . GENERAL_MESSAGE_GAS_LIMIT
4961
5062 assert (expected_order_gas_limit * 2 ) + expected_message_gas_limit == estimator .gas_limit ()
5163
@@ -72,8 +84,8 @@ def test_estimation_for_batch_cancel_spot_orders(self):
7284 message = composer .msg_batch_cancel_spot_orders (sender = "sender" , orders_data = orders )
7385 estimator = GasLimitEstimator .for_message (message = message )
7486
75- expected_order_gas_limit = 50000
76- expected_message_gas_limit = 15000
87+ expected_order_gas_limit = SPOT_ORDER_CANCELATION_GAS_LIMIT
88+ expected_message_gas_limit = BatchCancelSpotOrdersGasLimitEstimator . GENERAL_MESSAGE_GAS_LIMIT
7789
7890 assert (expected_order_gas_limit * 3 ) + expected_message_gas_limit == estimator .gas_limit ()
7991
@@ -103,8 +115,8 @@ def test_estimation_for_batch_create_derivative_limit_orders(self):
103115 message = composer .msg_batch_create_derivative_limit_orders (sender = "sender" , orders = orders )
104116 estimator = GasLimitEstimator .for_message (message = message )
105117
106- expected_order_gas_limit = 70_000
107- expected_message_gas_limit = 15000
118+ expected_order_gas_limit = DERIVATIVE_ORDER_CREATION_GAS_LIMIT
119+ expected_message_gas_limit = BatchCreateDerivativeLimitOrdersGasLimitEstimator . GENERAL_MESSAGE_GAS_LIMIT
108120
109121 assert (expected_order_gas_limit * 2 ) + expected_message_gas_limit == estimator .gas_limit ()
110122
@@ -131,8 +143,8 @@ def test_estimation_for_batch_cancel_derivative_orders(self):
131143 message = composer .msg_batch_cancel_derivative_orders (sender = "sender" , orders_data = orders )
132144 estimator = GasLimitEstimator .for_message (message = message )
133145
134- expected_order_gas_limit = 60_000
135- expected_message_gas_limit = 15000
146+ expected_order_gas_limit = DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT
147+ expected_message_gas_limit = BatchCancelDerivativeOrdersGasLimitEstimator . GENERAL_MESSAGE_GAS_LIMIT
136148
137149 assert (expected_order_gas_limit * 3 ) + expected_message_gas_limit == estimator .gas_limit ()
138150
@@ -166,8 +178,8 @@ def test_estimation_for_batch_update_orders_to_create_spot_orders(self):
166178 )
167179 estimator = GasLimitEstimator .for_message (message = message )
168180
169- expected_order_gas_limit = 50_000
170- expected_message_gas_limit = 15_000
181+ expected_order_gas_limit = SPOT_ORDER_CREATION_GAS_LIMIT
182+ expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator . MESSAGE_GAS_LIMIT
171183
172184 assert (expected_order_gas_limit * 2 ) + expected_message_gas_limit == estimator .gas_limit ()
173185
@@ -203,8 +215,8 @@ def test_estimation_for_batch_update_orders_to_create_derivative_orders(self):
203215 )
204216 estimator = GasLimitEstimator .for_message (message = message )
205217
206- expected_order_gas_limit = 70_000
207- expected_message_gas_limit = 15_000
218+ expected_order_gas_limit = DERIVATIVE_ORDER_CREATION_GAS_LIMIT
219+ expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator . MESSAGE_GAS_LIMIT
208220
209221 assert (expected_order_gas_limit * 2 ) + expected_message_gas_limit == estimator .gas_limit ()
210222
@@ -260,8 +272,8 @@ def test_estimation_for_batch_update_orders_to_create_binary_orders(self, usdt_t
260272 )
261273 estimator = GasLimitEstimator .for_message (message = message )
262274
263- expected_order_gas_limit = 70_000
264- expected_message_gas_limit = 15_000
275+ expected_order_gas_limit = DERIVATIVE_ORDER_CREATION_GAS_LIMIT
276+ expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator . MESSAGE_GAS_LIMIT
265277
266278 assert (expected_order_gas_limit * 2 ) + expected_message_gas_limit == estimator .gas_limit ()
267279
@@ -294,8 +306,8 @@ def test_estimation_for_batch_update_orders_to_cancel_spot_orders(self):
294306 )
295307 estimator = GasLimitEstimator .for_message (message = message )
296308
297- expected_order_gas_limit = 50_000
298- expected_message_gas_limit = 15_000
309+ expected_order_gas_limit = SPOT_ORDER_CANCELATION_GAS_LIMIT
310+ expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator . MESSAGE_GAS_LIMIT
299311
300312 assert (expected_order_gas_limit * 3 ) + expected_message_gas_limit == estimator .gas_limit ()
301313
@@ -328,8 +340,8 @@ def test_estimation_for_batch_update_orders_to_cancel_derivative_orders(self):
328340 )
329341 estimator = GasLimitEstimator .for_message (message = message )
330342
331- expected_order_gas_limit = 60_000
332- expected_message_gas_limit = 15_000
343+ expected_order_gas_limit = DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT
344+ expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator . MESSAGE_GAS_LIMIT
333345
334346 assert (expected_order_gas_limit * 3 ) + expected_message_gas_limit == estimator .gas_limit ()
335347
@@ -363,8 +375,8 @@ def test_estimation_for_batch_update_orders_to_cancel_binary_orders(self):
363375 )
364376 estimator = GasLimitEstimator .for_message (message = message )
365377
366- expected_order_gas_limit = 60_000
367- expected_message_gas_limit = 15_000
378+ expected_order_gas_limit = DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT
379+ expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator . MESSAGE_GAS_LIMIT
368380
369381 assert (expected_order_gas_limit * 3 ) + expected_message_gas_limit == estimator .gas_limit ()
370382
@@ -383,8 +395,8 @@ def test_estimation_for_batch_update_orders_to_cancel_all_for_spot_market(self):
383395 )
384396 estimator = GasLimitEstimator .for_message (message = message )
385397
386- expected_gas_limit = 40_000 * 20
387- expected_message_gas_limit = 15_000
398+ expected_gas_limit = BatchUpdateOrdersGasLimitEstimator . CANCEL_ALL_SPOT_MARKET_GAS_LIMIT * 20
399+ expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator . MESSAGE_GAS_LIMIT
388400
389401 assert expected_gas_limit + expected_message_gas_limit == estimator .gas_limit ()
390402
@@ -403,8 +415,8 @@ def test_estimation_for_batch_update_orders_to_cancel_all_for_derivative_market(
403415 )
404416 estimator = GasLimitEstimator .for_message (message = message )
405417
406- expected_gas_limit = 50_000 * 20
407- expected_message_gas_limit = 15_000
418+ expected_gas_limit = BatchUpdateOrdersGasLimitEstimator . CANCEL_ALL_DERIVATIVE_MARKET_GAS_LIMIT * 20
419+ expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator . MESSAGE_GAS_LIMIT
408420
409421 assert expected_gas_limit + expected_message_gas_limit == estimator .gas_limit ()
410422
@@ -423,8 +435,8 @@ def test_estimation_for_batch_update_orders_to_cancel_all_for_binary_options_mar
423435 )
424436 estimator = GasLimitEstimator .for_message (message = message )
425437
426- expected_gas_limit = 50_000 * 20
427- expected_message_gas_limit = 15_000
438+ expected_gas_limit = BatchUpdateOrdersGasLimitEstimator . CANCEL_ALL_DERIVATIVE_MARKET_GAS_LIMIT * 20
439+ expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator . MESSAGE_GAS_LIMIT
428440
429441 assert expected_gas_limit + expected_message_gas_limit == estimator .gas_limit ()
430442
@@ -452,9 +464,9 @@ def test_estimation_for_exec_message(self):
452464
453465 estimator = GasLimitEstimator .for_message (message = message )
454466
455- expected_order_gas_limit = 50_000
456- expected_inner_message_gas_limit = 15_000
457- expected_exec_message_gas_limit = 8_000
467+ expected_order_gas_limit = SPOT_ORDER_CREATION_GAS_LIMIT
468+ expected_inner_message_gas_limit = BatchUpdateOrdersGasLimitEstimator . MESSAGE_GAS_LIMIT
469+ expected_exec_message_gas_limit = ExecGasLimitEstimator . DEFAULT_GAS_LIMIT
458470
459471 assert (
460472 expected_order_gas_limit + expected_inner_message_gas_limit + expected_exec_message_gas_limit
0 commit comments