From f7aec0aeb1654268cddbf9f9c359c4edb0349f9b Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 11 Oct 2023 11:46:37 +0200 Subject: [PATCH] tests(python): bump Stellar SDK version fixes a problem with outdated python 3.11 dependencies --- python/requirements-optional.txt | 2 +- python/src/trezorlib/stellar.py | 22 +++--- python/tests/test_stellar.py | 116 ++++++++++++++----------------- 3 files changed, 60 insertions(+), 80 deletions(-) diff --git a/python/requirements-optional.txt b/python/requirements-optional.txt index 77de05af39..c758712f42 100644 --- a/python/requirements-optional.txt +++ b/python/requirements-optional.txt @@ -1,5 +1,5 @@ hidapi >= 0.7.99.post20 web3 >= 4.8 Pillow -stellar-sdk>=4.0.0,<6.0.0 +stellar-sdk>=6 rlp>=1.1.0 ; python_version<'3.7' diff --git a/python/src/trezorlib/stellar.py b/python/src/trezorlib/stellar.py index 27b988dcec..4e880277a3 100644 --- a/python/src/trezorlib/stellar.py +++ b/python/src/trezorlib/stellar.py @@ -52,6 +52,7 @@ try: CreatePassiveSellOffer, HashMemo, IdMemo, + LiquidityPoolAsset, ManageBuyOffer, ManageData, ManageSellOffer, @@ -69,7 +70,6 @@ try: TransactionEnvelope, TrustLineEntryFlag, ) - from stellar_sdk.xdr.signer_key_type import SignerKeyType HAVE_STELLAR_SDK = True DEFAULT_NETWORK_PASSPHRASE = Network.PUBLIC_NETWORK_PASSPHRASE @@ -92,7 +92,7 @@ def from_envelope( raise RuntimeError("Stellar SDK not available") parsed_tx = envelope.transaction - if parsed_tx.time_bounds is None: + if parsed_tx.preconditions is None or parsed_tx.preconditions.time_bounds is None: raise ValueError("Timebounds are mandatory") memo_type = messages.StellarMemoType.NONE @@ -122,8 +122,8 @@ def from_envelope( source_account=parsed_tx.source.account_id, fee=parsed_tx.fee, sequence_number=parsed_tx.sequence, - timebounds_start=parsed_tx.time_bounds.min_time, - timebounds_end=parsed_tx.time_bounds.max_time, + timebounds_start=parsed_tx.preconditions.time_bounds.min_time, + timebounds_end=parsed_tx.preconditions.time_bounds.max_time, memo_type=memo_type, memo_text=memo_text, memo_id=memo_id, @@ -202,20 +202,14 @@ def _read_operation(op: "Operation") -> "StellarMessageType": home_domain=op.home_domain, ) if op.signer: - signer_type = op.signer.signer_key.signer_key.type - if signer_type == SignerKeyType.SIGNER_KEY_TYPE_ED25519: - signer_key = op.signer.signer_key.signer_key.ed25519.uint256 - elif signer_type == SignerKeyType.SIGNER_KEY_TYPE_HASH_X: - signer_key = op.signer.signer_key.signer_key.hash_x.uint256 - elif signer_type == SignerKeyType.SIGNER_KEY_TYPE_PRE_AUTH_TX: - signer_key = op.signer.signer_key.signer_key.pre_auth_tx.uint256 - else: - raise ValueError("Unsupported signer key type") + signer_type = op.signer.signer_key.signer_key_type operation.signer_type = messages.StellarSignerType(signer_type.value) - operation.signer_key = signer_key + operation.signer_key = op.signer.signer_key.signer_key operation.signer_weight = op.signer.weight return operation if isinstance(op, ChangeTrust): + if isinstance(op.asset, LiquidityPoolAsset): + raise ValueError("Liquidity pool assets are not supported") return messages.StellarChangeTrustOp( source_account=source_account, asset=_read_asset(op.asset), diff --git a/python/tests/test_stellar.py b/python/tests/test_stellar.py index 143afc130f..ad98cc6597 100644 --- a/python/tests/test_stellar.py +++ b/python/tests/test_stellar.py @@ -14,12 +14,15 @@ # You should have received a copy of the License along with this library. # If not, see . +import warnings + import pytest try: from stellar_sdk import ( Account, Asset, + AuthorizationFlag, MuxedAccount, Network, TransactionBuilder, @@ -39,7 +42,7 @@ BASE_FEE = 200 def make_default_tx(default_op: bool = False, **kwargs) -> TransactionBuilder: - source_account = Account(account_id=TX_SOURCE, sequence=SEQUENCE) + source_account = Account(account=TX_SOURCE, sequence=SEQUENCE) default_params = { "source_account": source_account, "network_passphrase": Network.TESTNET_NETWORK_PASSPHRASE, @@ -126,7 +129,10 @@ def test_memo_return_hash(): def test_time_bounds_missing(): tx = make_default_tx(default_op=True) tx.time_bounds = None - envelope = tx.build() + with warnings.catch_warnings(): + # ignore warning about missing time bounds + warnings.filterwarnings("ignore", message=r".*TimeBounds.*") + envelope = tx.build() with pytest.raises(ValueError): stellar.from_envelope(envelope) @@ -150,8 +156,7 @@ def test_multiple_operations(): .append_payment_op( destination=destination, amount=amount, - asset_code=asset_code, - asset_issuer=asset_issuer, + asset=Asset(asset_code, asset_issuer), source=operation2_source, ) .build() @@ -214,8 +219,7 @@ def test_payment_native_asset(): envelope = tx.append_payment_op( destination=destination, amount=amount, - asset_code=asset_code, - asset_issuer=asset_issuer, + asset=Asset(asset_code, asset_issuer), source=operation_source, ).build() @@ -241,8 +245,7 @@ def test_payment_alpha4_asset(): envelope = tx.append_payment_op( destination=destination, amount=amount, - asset_code=asset_code, - asset_issuer=asset_issuer, + asset=Asset(asset_code, asset_issuer), source=operation_source, ).build() @@ -268,8 +271,7 @@ def test_payment_alpha12_asset(): envelope = tx.append_payment_op( destination=destination, amount=amount, - asset_code=asset_code, - asset_issuer=asset_issuer, + asset=Asset(asset_code, asset_issuer), source=operation_source, ).build() @@ -303,11 +305,9 @@ def test_path_payment_strict_receive(): envelope = tx.append_path_payment_strict_receive_op( destination=destination, - send_code=send_code, - send_issuer=send_issuer, + send_asset=Asset(send_code, send_issuer), send_max=send_max, - dest_code=dest_code, - dest_issuer=dest_issuer, + dest_asset=Asset(dest_code, dest_issuer), dest_amount=dest_amount, path=[path_asset1, path_asset2], source=operation_source, @@ -345,10 +345,8 @@ def test_manage_sell_offer_new_offer(): operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" envelope = tx.append_manage_sell_offer_op( - selling_code=selling_code, - selling_issuer=selling_issuer, - buying_code=buying_code, - buying_issuer=buying_issuer, + selling=Asset(selling_code, selling_issuer), + buying=Asset(buying_code, buying_issuer), amount=amount, price=price, source=operation_source, @@ -380,10 +378,8 @@ def test_manage_sell_offer_update_offer(): operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" envelope = tx.append_manage_sell_offer_op( - selling_code=selling_code, - selling_issuer=selling_issuer, - buying_code=buying_code, - buying_issuer=buying_issuer, + selling=Asset(selling_code, selling_issuer), + buying=Asset(buying_code, buying_issuer), amount=amount, price=price, offer_id=offer_id, @@ -415,10 +411,8 @@ def test_create_passive_sell_offer(): operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" envelope = tx.append_create_passive_sell_offer_op( - selling_code=selling_code, - selling_issuer=selling_issuer, - buying_code=buying_code, - buying_issuer=buying_issuer, + selling=Asset(selling_code, selling_issuer), + buying=Asset(buying_code, buying_issuer), amount=amount, price=price, source=operation_source, @@ -441,8 +435,11 @@ def test_set_options(): tx = make_default_tx() operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" inflation_dest = "GAXN7HZQTHIPW7N2HGPAXMR42LPJ5VLYXMCCOX4D3JC4CQZGID3UYUPF" - clear_flags = 1 - set_flags = 6 + clear_flags = AuthorizationFlag.AUTHORIZATION_REQUIRED + set_flags = ( + AuthorizationFlag.AUTHORIZATION_IMMUTABLE + | AuthorizationFlag.AUTHORIZATION_REVOCABLE + ) master_weight = 255 low_threshold = 10 med_threshold = 20 @@ -553,8 +550,7 @@ def test_change_trust(): operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" envelope = tx.append_change_trust_op( - asset_code=asset_code, - asset_issuer=asset_issuer, + asset=Asset(asset_code, asset_issuer), limit=limit, source=operation_source, ).build() @@ -575,12 +571,17 @@ def test_allow_trust(): trustor = "GCSJ7MFIIGIRMAS4R3VT5FIFIAOXNMGDI5HPYTWS5X7HH74FSJ6STSGF" operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" - envelope = tx.append_allow_trust_op( - trustor=trustor, - asset_code=asset_code, - authorize=TrustLineEntryFlag.AUTHORIZED_FLAG, - source=operation_source, - ).build() + with warnings.catch_warnings(): + # ignore warnings about append_trust_line_flags being a deprecated op, + # Trezor doesn't currently support the alternative + warnings.filterwarnings("ignore", message=r".*append_set_trust_line_flags_op.*") + warnings.filterwarnings("ignore", message=r".*SetTrustLineFlags.*") + envelope = tx.append_allow_trust_op( + trustor=trustor, + asset_code=asset_code, + authorize=TrustLineEntryFlag.AUTHORIZED_FLAG, + source=operation_source, + ).build() tx, operations = stellar.from_envelope(envelope) assert len(operations) == 1 @@ -671,10 +672,8 @@ def test_manage_buy_offer_new_offer(): operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" envelope = tx.append_manage_buy_offer_op( - selling_code=selling_code, - selling_issuer=selling_issuer, - buying_code=buying_code, - buying_issuer=buying_issuer, + selling=Asset(selling_code, selling_issuer), + buying=Asset(buying_code, buying_issuer), amount=amount, price=price, source=operation_source, @@ -706,10 +705,8 @@ def test_manage_buy_offer_update_offer(): operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" envelope = tx.append_manage_buy_offer_op( - selling_code=selling_code, - selling_issuer=selling_issuer, - buying_code=buying_code, - buying_issuer=buying_issuer, + selling=Asset(selling_code, selling_issuer), + buying=Asset(buying_code, buying_issuer), amount=amount, price=price, offer_id=offer_id, @@ -749,11 +746,9 @@ def test_path_payment_strict_send(): envelope = tx.append_path_payment_strict_send_op( destination=destination, - send_code=send_code, - send_issuer=send_issuer, + send_asset=Asset(send_code, send_issuer), send_amount=send_amount, - dest_code=dest_code, - dest_issuer=dest_issuer, + dest_asset=Asset(dest_code, dest_issuer), dest_min=dest_min, path=[path_asset1, path_asset2], source=operation_source, @@ -793,8 +788,7 @@ def test_payment_muxed_account_not_support_raise(): envelope = tx.append_payment_op( destination=destination, amount=amount, - asset_code=asset_code, - asset_issuer=asset_issuer, + asset=Asset(asset_code, asset_issuer), source=operation_source, ).build() @@ -823,11 +817,9 @@ def test_path_payment_strict_send_muxed_account_not_support_raise(): envelope = tx.append_path_payment_strict_send_op( destination=destination, - send_code=send_code, - send_issuer=send_issuer, + send_asset=Asset(send_code, send_issuer), send_amount=send_amount, - dest_code=dest_code, - dest_issuer=dest_issuer, + dest_asset=Asset(dest_code, dest_issuer), dest_min=dest_min, path=[path_asset1, path_asset2], source=operation_source, @@ -858,11 +850,9 @@ def test_path_payment_strict_receive_muxed_account_not_support_raise(): envelope = tx.append_path_payment_strict_receive_op( destination=destination, - send_code=send_code, - send_issuer=send_issuer, + send_asset=Asset(send_code, send_issuer), send_max=send_max, - dest_code=dest_code, - dest_issuer=dest_issuer, + dest_asset=Asset(dest_code, dest_issuer), dest_amount=dest_amount, path=[path_asset1, path_asset2], source=operation_source, @@ -900,8 +890,7 @@ def test_op_source_muxed_account_not_support_raise(): envelope = tx.append_payment_op( destination=destination, amount=amount, - asset_code=asset_code, - asset_issuer=asset_issuer, + asset=Asset(asset_code, asset_issuer), source=operation_source, ).build() @@ -910,9 +899,7 @@ def test_op_source_muxed_account_not_support_raise(): def test_tx_source_muxed_account_not_support_raise(): - source_account = Account( - account_id=MuxedAccount(TX_SOURCE, 123456), sequence=SEQUENCE - ) + source_account = Account(account=MuxedAccount(TX_SOURCE, 123456), sequence=SEQUENCE) destination = "GDNSSYSCSSJ76FER5WEEXME5G4MTCUBKDRQSKOYP36KUKVDB2VCMERS6" amount = "50.0111" asset_code = "XLM" @@ -929,8 +916,7 @@ def test_tx_source_muxed_account_not_support_raise(): .append_payment_op( destination=destination, amount=amount, - asset_code=asset_code, - asset_issuer=asset_issuer, + asset=Asset(asset_code, asset_issuer), source=operation_source, ) .build()