1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-07 05:51:38 +00:00

tests(python): bump Stellar SDK version

fixes a problem with outdated python 3.11 dependencies
This commit is contained in:
matejcik 2023-10-11 11:46:37 +02:00 committed by matejcik
parent 0071e0f683
commit f7aec0aeb1
3 changed files with 60 additions and 80 deletions

View File

@ -1,5 +1,5 @@
hidapi >= 0.7.99.post20 hidapi >= 0.7.99.post20
web3 >= 4.8 web3 >= 4.8
Pillow Pillow
stellar-sdk>=4.0.0,<6.0.0 stellar-sdk>=6
rlp>=1.1.0 ; python_version<'3.7' rlp>=1.1.0 ; python_version<'3.7'

View File

@ -52,6 +52,7 @@ try:
CreatePassiveSellOffer, CreatePassiveSellOffer,
HashMemo, HashMemo,
IdMemo, IdMemo,
LiquidityPoolAsset,
ManageBuyOffer, ManageBuyOffer,
ManageData, ManageData,
ManageSellOffer, ManageSellOffer,
@ -69,7 +70,6 @@ try:
TransactionEnvelope, TransactionEnvelope,
TrustLineEntryFlag, TrustLineEntryFlag,
) )
from stellar_sdk.xdr.signer_key_type import SignerKeyType
HAVE_STELLAR_SDK = True HAVE_STELLAR_SDK = True
DEFAULT_NETWORK_PASSPHRASE = Network.PUBLIC_NETWORK_PASSPHRASE DEFAULT_NETWORK_PASSPHRASE = Network.PUBLIC_NETWORK_PASSPHRASE
@ -92,7 +92,7 @@ def from_envelope(
raise RuntimeError("Stellar SDK not available") raise RuntimeError("Stellar SDK not available")
parsed_tx = envelope.transaction 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") raise ValueError("Timebounds are mandatory")
memo_type = messages.StellarMemoType.NONE memo_type = messages.StellarMemoType.NONE
@ -122,8 +122,8 @@ def from_envelope(
source_account=parsed_tx.source.account_id, source_account=parsed_tx.source.account_id,
fee=parsed_tx.fee, fee=parsed_tx.fee,
sequence_number=parsed_tx.sequence, sequence_number=parsed_tx.sequence,
timebounds_start=parsed_tx.time_bounds.min_time, timebounds_start=parsed_tx.preconditions.time_bounds.min_time,
timebounds_end=parsed_tx.time_bounds.max_time, timebounds_end=parsed_tx.preconditions.time_bounds.max_time,
memo_type=memo_type, memo_type=memo_type,
memo_text=memo_text, memo_text=memo_text,
memo_id=memo_id, memo_id=memo_id,
@ -202,20 +202,14 @@ def _read_operation(op: "Operation") -> "StellarMessageType":
home_domain=op.home_domain, home_domain=op.home_domain,
) )
if op.signer: if op.signer:
signer_type = op.signer.signer_key.signer_key.type 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")
operation.signer_type = messages.StellarSignerType(signer_type.value) 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 operation.signer_weight = op.signer.weight
return operation return operation
if isinstance(op, ChangeTrust): if isinstance(op, ChangeTrust):
if isinstance(op.asset, LiquidityPoolAsset):
raise ValueError("Liquidity pool assets are not supported")
return messages.StellarChangeTrustOp( return messages.StellarChangeTrustOp(
source_account=source_account, source_account=source_account,
asset=_read_asset(op.asset), asset=_read_asset(op.asset),

View File

@ -14,12 +14,15 @@
# You should have received a copy of the License along with this library. # You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import warnings
import pytest import pytest
try: try:
from stellar_sdk import ( from stellar_sdk import (
Account, Account,
Asset, Asset,
AuthorizationFlag,
MuxedAccount, MuxedAccount,
Network, Network,
TransactionBuilder, TransactionBuilder,
@ -39,7 +42,7 @@ BASE_FEE = 200
def make_default_tx(default_op: bool = False, **kwargs) -> TransactionBuilder: 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 = { default_params = {
"source_account": source_account, "source_account": source_account,
"network_passphrase": Network.TESTNET_NETWORK_PASSPHRASE, "network_passphrase": Network.TESTNET_NETWORK_PASSPHRASE,
@ -126,6 +129,9 @@ def test_memo_return_hash():
def test_time_bounds_missing(): def test_time_bounds_missing():
tx = make_default_tx(default_op=True) tx = make_default_tx(default_op=True)
tx.time_bounds = None tx.time_bounds = None
with warnings.catch_warnings():
# ignore warning about missing time bounds
warnings.filterwarnings("ignore", message=r".*TimeBounds.*")
envelope = tx.build() envelope = tx.build()
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -150,8 +156,7 @@ def test_multiple_operations():
.append_payment_op( .append_payment_op(
destination=destination, destination=destination,
amount=amount, amount=amount,
asset_code=asset_code, asset=Asset(asset_code, asset_issuer),
asset_issuer=asset_issuer,
source=operation2_source, source=operation2_source,
) )
.build() .build()
@ -214,8 +219,7 @@ def test_payment_native_asset():
envelope = tx.append_payment_op( envelope = tx.append_payment_op(
destination=destination, destination=destination,
amount=amount, amount=amount,
asset_code=asset_code, asset=Asset(asset_code, asset_issuer),
asset_issuer=asset_issuer,
source=operation_source, source=operation_source,
).build() ).build()
@ -241,8 +245,7 @@ def test_payment_alpha4_asset():
envelope = tx.append_payment_op( envelope = tx.append_payment_op(
destination=destination, destination=destination,
amount=amount, amount=amount,
asset_code=asset_code, asset=Asset(asset_code, asset_issuer),
asset_issuer=asset_issuer,
source=operation_source, source=operation_source,
).build() ).build()
@ -268,8 +271,7 @@ def test_payment_alpha12_asset():
envelope = tx.append_payment_op( envelope = tx.append_payment_op(
destination=destination, destination=destination,
amount=amount, amount=amount,
asset_code=asset_code, asset=Asset(asset_code, asset_issuer),
asset_issuer=asset_issuer,
source=operation_source, source=operation_source,
).build() ).build()
@ -303,11 +305,9 @@ def test_path_payment_strict_receive():
envelope = tx.append_path_payment_strict_receive_op( envelope = tx.append_path_payment_strict_receive_op(
destination=destination, destination=destination,
send_code=send_code, send_asset=Asset(send_code, send_issuer),
send_issuer=send_issuer,
send_max=send_max, send_max=send_max,
dest_code=dest_code, dest_asset=Asset(dest_code, dest_issuer),
dest_issuer=dest_issuer,
dest_amount=dest_amount, dest_amount=dest_amount,
path=[path_asset1, path_asset2], path=[path_asset1, path_asset2],
source=operation_source, source=operation_source,
@ -345,10 +345,8 @@ def test_manage_sell_offer_new_offer():
operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V"
envelope = tx.append_manage_sell_offer_op( envelope = tx.append_manage_sell_offer_op(
selling_code=selling_code, selling=Asset(selling_code, selling_issuer),
selling_issuer=selling_issuer, buying=Asset(buying_code, buying_issuer),
buying_code=buying_code,
buying_issuer=buying_issuer,
amount=amount, amount=amount,
price=price, price=price,
source=operation_source, source=operation_source,
@ -380,10 +378,8 @@ def test_manage_sell_offer_update_offer():
operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V"
envelope = tx.append_manage_sell_offer_op( envelope = tx.append_manage_sell_offer_op(
selling_code=selling_code, selling=Asset(selling_code, selling_issuer),
selling_issuer=selling_issuer, buying=Asset(buying_code, buying_issuer),
buying_code=buying_code,
buying_issuer=buying_issuer,
amount=amount, amount=amount,
price=price, price=price,
offer_id=offer_id, offer_id=offer_id,
@ -415,10 +411,8 @@ def test_create_passive_sell_offer():
operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V"
envelope = tx.append_create_passive_sell_offer_op( envelope = tx.append_create_passive_sell_offer_op(
selling_code=selling_code, selling=Asset(selling_code, selling_issuer),
selling_issuer=selling_issuer, buying=Asset(buying_code, buying_issuer),
buying_code=buying_code,
buying_issuer=buying_issuer,
amount=amount, amount=amount,
price=price, price=price,
source=operation_source, source=operation_source,
@ -441,8 +435,11 @@ def test_set_options():
tx = make_default_tx() tx = make_default_tx()
operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V"
inflation_dest = "GAXN7HZQTHIPW7N2HGPAXMR42LPJ5VLYXMCCOX4D3JC4CQZGID3UYUPF" inflation_dest = "GAXN7HZQTHIPW7N2HGPAXMR42LPJ5VLYXMCCOX4D3JC4CQZGID3UYUPF"
clear_flags = 1 clear_flags = AuthorizationFlag.AUTHORIZATION_REQUIRED
set_flags = 6 set_flags = (
AuthorizationFlag.AUTHORIZATION_IMMUTABLE
| AuthorizationFlag.AUTHORIZATION_REVOCABLE
)
master_weight = 255 master_weight = 255
low_threshold = 10 low_threshold = 10
med_threshold = 20 med_threshold = 20
@ -553,8 +550,7 @@ def test_change_trust():
operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V"
envelope = tx.append_change_trust_op( envelope = tx.append_change_trust_op(
asset_code=asset_code, asset=Asset(asset_code, asset_issuer),
asset_issuer=asset_issuer,
limit=limit, limit=limit,
source=operation_source, source=operation_source,
).build() ).build()
@ -575,6 +571,11 @@ def test_allow_trust():
trustor = "GCSJ7MFIIGIRMAS4R3VT5FIFIAOXNMGDI5HPYTWS5X7HH74FSJ6STSGF" trustor = "GCSJ7MFIIGIRMAS4R3VT5FIFIAOXNMGDI5HPYTWS5X7HH74FSJ6STSGF"
operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V"
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( envelope = tx.append_allow_trust_op(
trustor=trustor, trustor=trustor,
asset_code=asset_code, asset_code=asset_code,
@ -671,10 +672,8 @@ def test_manage_buy_offer_new_offer():
operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V"
envelope = tx.append_manage_buy_offer_op( envelope = tx.append_manage_buy_offer_op(
selling_code=selling_code, selling=Asset(selling_code, selling_issuer),
selling_issuer=selling_issuer, buying=Asset(buying_code, buying_issuer),
buying_code=buying_code,
buying_issuer=buying_issuer,
amount=amount, amount=amount,
price=price, price=price,
source=operation_source, source=operation_source,
@ -706,10 +705,8 @@ def test_manage_buy_offer_update_offer():
operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V"
envelope = tx.append_manage_buy_offer_op( envelope = tx.append_manage_buy_offer_op(
selling_code=selling_code, selling=Asset(selling_code, selling_issuer),
selling_issuer=selling_issuer, buying=Asset(buying_code, buying_issuer),
buying_code=buying_code,
buying_issuer=buying_issuer,
amount=amount, amount=amount,
price=price, price=price,
offer_id=offer_id, offer_id=offer_id,
@ -749,11 +746,9 @@ def test_path_payment_strict_send():
envelope = tx.append_path_payment_strict_send_op( envelope = tx.append_path_payment_strict_send_op(
destination=destination, destination=destination,
send_code=send_code, send_asset=Asset(send_code, send_issuer),
send_issuer=send_issuer,
send_amount=send_amount, send_amount=send_amount,
dest_code=dest_code, dest_asset=Asset(dest_code, dest_issuer),
dest_issuer=dest_issuer,
dest_min=dest_min, dest_min=dest_min,
path=[path_asset1, path_asset2], path=[path_asset1, path_asset2],
source=operation_source, source=operation_source,
@ -793,8 +788,7 @@ def test_payment_muxed_account_not_support_raise():
envelope = tx.append_payment_op( envelope = tx.append_payment_op(
destination=destination, destination=destination,
amount=amount, amount=amount,
asset_code=asset_code, asset=Asset(asset_code, asset_issuer),
asset_issuer=asset_issuer,
source=operation_source, source=operation_source,
).build() ).build()
@ -823,11 +817,9 @@ def test_path_payment_strict_send_muxed_account_not_support_raise():
envelope = tx.append_path_payment_strict_send_op( envelope = tx.append_path_payment_strict_send_op(
destination=destination, destination=destination,
send_code=send_code, send_asset=Asset(send_code, send_issuer),
send_issuer=send_issuer,
send_amount=send_amount, send_amount=send_amount,
dest_code=dest_code, dest_asset=Asset(dest_code, dest_issuer),
dest_issuer=dest_issuer,
dest_min=dest_min, dest_min=dest_min,
path=[path_asset1, path_asset2], path=[path_asset1, path_asset2],
source=operation_source, 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( envelope = tx.append_path_payment_strict_receive_op(
destination=destination, destination=destination,
send_code=send_code, send_asset=Asset(send_code, send_issuer),
send_issuer=send_issuer,
send_max=send_max, send_max=send_max,
dest_code=dest_code, dest_asset=Asset(dest_code, dest_issuer),
dest_issuer=dest_issuer,
dest_amount=dest_amount, dest_amount=dest_amount,
path=[path_asset1, path_asset2], path=[path_asset1, path_asset2],
source=operation_source, source=operation_source,
@ -900,8 +890,7 @@ def test_op_source_muxed_account_not_support_raise():
envelope = tx.append_payment_op( envelope = tx.append_payment_op(
destination=destination, destination=destination,
amount=amount, amount=amount,
asset_code=asset_code, asset=Asset(asset_code, asset_issuer),
asset_issuer=asset_issuer,
source=operation_source, source=operation_source,
).build() ).build()
@ -910,9 +899,7 @@ def test_op_source_muxed_account_not_support_raise():
def test_tx_source_muxed_account_not_support_raise(): def test_tx_source_muxed_account_not_support_raise():
source_account = Account( source_account = Account(account=MuxedAccount(TX_SOURCE, 123456), sequence=SEQUENCE)
account_id=MuxedAccount(TX_SOURCE, 123456), sequence=SEQUENCE
)
destination = "GDNSSYSCSSJ76FER5WEEXME5G4MTCUBKDRQSKOYP36KUKVDB2VCMERS6" destination = "GDNSSYSCSSJ76FER5WEEXME5G4MTCUBKDRQSKOYP36KUKVDB2VCMERS6"
amount = "50.0111" amount = "50.0111"
asset_code = "XLM" asset_code = "XLM"
@ -929,8 +916,7 @@ def test_tx_source_muxed_account_not_support_raise():
.append_payment_op( .append_payment_op(
destination=destination, destination=destination,
amount=amount, amount=amount,
asset_code=asset_code, asset=Asset(asset_code, asset_issuer),
asset_issuer=asset_issuer,
source=operation_source, source=operation_source,
) )
.build() .build()