Skip to content

Commit fd12616

Browse files
committed
(fix) Fix failing tests
1 parent b14afd2 commit fd12616

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

pyinjective/composer_v2.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,9 +1122,7 @@ def msg_batch_liquidate_positions(
11221122
sender: str,
11231123
liquidations: List[injective_exchange_tx_v2_pb.LiquidatePositionData],
11241124
) -> injective_exchange_tx_v2_pb.MsgBatchLiquidatePositions:
1125-
return injective_exchange_tx_v2_pb.MsgBatchLiquidatePositions(
1126-
sender=sender, liquidations=liquidations
1127-
)
1125+
return injective_exchange_tx_v2_pb.MsgBatchLiquidatePositions(sender=sender, liquidations=liquidations)
11281126

11291127
def msg_emergency_settle_market(
11301128
self,

tests/test_composer_v2.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
from pyinjective.constant import INJ_DECIMALS
99
from pyinjective.core.network import Network
1010
from pyinjective.core.token import Token
11-
from pyinjective.proto.injective.exchange.v2 import order_pb2 as injective_order_v2_pb
12-
from pyinjective.proto.injective.exchange.v2 import proposal_pb2 as injective_proposal_v2_pb
11+
from pyinjective.proto.injective.exchange.v2 import (
12+
order_pb2 as injective_order_v2_pb,
13+
proposal_pb2 as injective_proposal_v2_pb,
14+
)
1315
from pyinjective.proto.injective.oracle.v1beta1 import oracle_pb2 as injective_oracle_pb
1416
from pyinjective.proto.injective.permissions.v1beta1 import permissions_pb2 as permissions_pb
1517

@@ -28,12 +30,14 @@ def basic_composer(self):
2830
return composer
2931

3032
def test_permissions_action_enum_mirrors_proto(self):
31-
# IntFlag excludes zero-valued members from iteration (zero means "no flags set"),
32-
# so we compare only the non-zero proto keys.
33-
proto_non_zero_keys = [n for n in permissions_pb.Action.keys() if permissions_pb.Action.Value(n) != 0]
34-
assert [m.name for m in Composer.PERMISSIONS_ACTION] == proto_non_zero_keys
35-
for name in proto_non_zero_keys:
33+
proto_keys = list(permissions_pb.Action.keys())
34+
# Bracket access works for all members including zero-valued ones across all Python versions.
35+
for name in proto_keys:
3636
assert Composer.PERMISSIONS_ACTION[name].value == permissions_pb.Action.Value(name)
37+
# IntFlag iteration excludes zero-valued members in Python >=3.11 but includes them in
38+
# Python <=3.10, so we filter by value on both sides to get a version-independent comparison.
39+
proto_non_zero_names = [n for n in proto_keys if permissions_pb.Action.Value(n) != 0]
40+
assert [m.name for m in Composer.PERMISSIONS_ACTION if m.value != 0] == proto_non_zero_names
3741

3842
def test_order_type_enum_mirrors_proto(self):
3943
proto_keys = list(injective_order_v2_pb.OrderType.keys())
@@ -51,7 +55,9 @@ def test_cross_margin_eligibility_enum_mirrors_proto(self):
5155
proto_keys = list(injective_proposal_v2_pb.CrossMarginEligibility.keys())
5256
assert [m.name for m in Composer.CROSS_MARGIN_ELIGIBILITY] == proto_keys
5357
for name in proto_keys:
54-
assert Composer.CROSS_MARGIN_ELIGIBILITY[name].value == injective_proposal_v2_pb.CrossMarginEligibility.Value(name)
58+
assert Composer.CROSS_MARGIN_ELIGIBILITY[
59+
name
60+
].value == injective_proposal_v2_pb.CrossMarginEligibility.Value(name)
5561

5662
def test_order_type_enum_accepted_for_order_type_param(self, basic_composer):
5763
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"

0 commit comments

Comments
 (0)