Skip to content

Commit 8febafa

Browse files
committed
chore: added unit tests for the GTB gas estimation using gas heuristics
1 parent 26cf36a commit 8febafa

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

tests/core/test_gas_heuristics_gas_limit_estimator.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
from decimal import Decimal
23

34
import pytest
@@ -13,6 +14,7 @@
1314
DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT,
1415
DERIVATIVE_ORDER_CREATION_GAS_LIMIT,
1516
EXTERNAL_TRANSFER_GAS_LIMIT,
17+
GTB_ORDERS_GAS_MULTIPLIER,
1618
INCREASE_POSITION_MARGIN_TRANSFER_GAS_LIMIT,
1719
POST_ONLY_BINARY_OPTIONS_ORDER_CREATION_GAS_LIMIT,
1820
POST_ONLY_DERIVATIVE_ORDER_CREATION_GAS_LIMIT,
@@ -498,6 +500,44 @@ def test_estimation_for_create_spot_limit_order(self, basic_composer, inj_usdt_s
498500

499501
assert expected_gas_cost == estimator.gas_limit()
500502

503+
def test_estimation_for_create_gtb_spot_limit_order(self, basic_composer, inj_usdt_spot_market):
504+
composer = basic_composer
505+
market_id = inj_usdt_spot_market.id
506+
507+
message = composer.msg_create_spot_limit_order_v2(
508+
market_id=market_id,
509+
sender="senders",
510+
subaccount_id="subaccount_id",
511+
fee_recipient="fee_recipient",
512+
price=Decimal("7.523"),
513+
quantity=Decimal("0.01"),
514+
order_type="BUY",
515+
expiration_block=1234567,
516+
)
517+
estimator = GasHeuristicsGasLimitEstimator.for_message(message=message)
518+
519+
expected_gas_cost = math.ceil(Decimal(SPOT_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER))
520+
521+
assert expected_gas_cost == estimator.gas_limit()
522+
523+
po_order_message = composer.msg_create_spot_limit_order_v2(
524+
market_id=market_id,
525+
sender="senders",
526+
subaccount_id="subaccount_id",
527+
fee_recipient="fee_recipient",
528+
price=Decimal("7.523"),
529+
quantity=Decimal("0.01"),
530+
order_type="BUY_PO",
531+
expiration_block=1234567,
532+
)
533+
estimator = GasHeuristicsGasLimitEstimator.for_message(message=po_order_message)
534+
535+
expected_gas_cost = math.ceil(
536+
Decimal(POST_ONLY_SPOT_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER)
537+
)
538+
539+
assert expected_gas_cost == estimator.gas_limit()
540+
501541
def test_estimation_for_create_spot_market_order(self, basic_composer, inj_usdt_spot_market):
502542
composer = basic_composer
503543
market_id = inj_usdt_spot_market.id
@@ -569,6 +609,46 @@ def test_estimation_for_create_derivative_limit_order(self, basic_composer, btc_
569609

570610
assert expected_gas_cost == estimator.gas_limit()
571611

612+
def test_estimation_for_create_gtb_derivative_limit_order(self, basic_composer, btc_usdt_perp_market):
613+
composer = basic_composer
614+
market_id = btc_usdt_perp_market.id
615+
616+
message = composer.msg_create_derivative_limit_order_v2(
617+
market_id=market_id,
618+
sender="senders",
619+
subaccount_id="subaccount_id",
620+
fee_recipient="fee_recipient",
621+
price=Decimal("7.523"),
622+
quantity=Decimal("0.01"),
623+
margin=Decimal("7.523") * Decimal("0.01"),
624+
order_type="BUY",
625+
expiration_block=1234567,
626+
)
627+
estimator = GasHeuristicsGasLimitEstimator.for_message(message=message)
628+
629+
expected_gas_cost = math.ceil(Decimal(DERIVATIVE_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER))
630+
631+
assert expected_gas_cost == estimator.gas_limit()
632+
633+
po_order_message = composer.msg_create_derivative_limit_order_v2(
634+
market_id=market_id,
635+
sender="senders",
636+
subaccount_id="subaccount_id",
637+
fee_recipient="fee_recipient",
638+
price=Decimal("7.523"),
639+
quantity=Decimal("0.01"),
640+
margin=Decimal("7.523") * Decimal("0.01"),
641+
order_type="BUY_PO",
642+
expiration_block=1234567,
643+
)
644+
estimator = GasHeuristicsGasLimitEstimator.for_message(message=po_order_message)
645+
646+
expected_gas_cost = math.ceil(
647+
Decimal(POST_ONLY_DERIVATIVE_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER)
648+
)
649+
650+
assert expected_gas_cost == estimator.gas_limit()
651+
572652
def test_estimation_for_create_derivative_market_order(self, basic_composer, btc_usdt_perp_market):
573653
composer = basic_composer
574654
market_id = btc_usdt_perp_market.id
@@ -641,6 +721,48 @@ def test_estimation_for_create_binary_options_limit_order(self, basic_composer,
641721

642722
assert expected_gas_cost == estimator.gas_limit()
643723

724+
def test_estimation_for_create_gtb_binary_options_limit_order(self, basic_composer, first_match_bet_market):
725+
composer = basic_composer
726+
market_id = first_match_bet_market.id
727+
728+
message = composer.msg_create_binary_options_limit_order_v2(
729+
market_id=market_id,
730+
sender="senders",
731+
subaccount_id="subaccount_id",
732+
fee_recipient="fee_recipient",
733+
price=Decimal("0.5"),
734+
quantity=Decimal("10"),
735+
margin=Decimal("0.5") * Decimal("10"),
736+
order_type="BUY",
737+
expiration_block=1234567,
738+
)
739+
estimator = GasHeuristicsGasLimitEstimator.for_message(message=message)
740+
741+
expected_gas_cost = math.ceil(
742+
Decimal(BINARY_OPTIONS_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER)
743+
)
744+
745+
assert expected_gas_cost == estimator.gas_limit()
746+
747+
po_order_message = composer.msg_create_binary_options_limit_order_v2(
748+
market_id=market_id,
749+
sender="senders",
750+
subaccount_id="subaccount_id",
751+
fee_recipient="fee_recipient",
752+
price=Decimal("0.5"),
753+
quantity=Decimal("10"),
754+
margin=Decimal("0.5") * Decimal("10"),
755+
order_type="BUY_PO",
756+
expiration_block=1234567,
757+
)
758+
estimator = GasHeuristicsGasLimitEstimator.for_message(message=po_order_message)
759+
760+
expected_gas_cost = math.ceil(
761+
Decimal(POST_ONLY_BINARY_OPTIONS_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER)
762+
)
763+
764+
assert expected_gas_cost == estimator.gas_limit()
765+
644766
def test_estimation_for_create_binary_options_market_order(self, basic_composer, first_match_bet_market):
645767
composer = basic_composer
646768
market_id = first_match_bet_market.id

0 commit comments

Comments
 (0)