Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Python and Pillow #3336

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ stdenvNoCC.mkDerivation ({
# install other python versions for tox testing
# NOTE: running e.g. "python3" in the shell runs the first version in the following list,
# and poetry uses the default version (currently 3.10)
python311
python310
python39
python38
Expand Down
167 changes: 64 additions & 103 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["SatoshiLabs <[email protected]>"]

[tool.poetry.dependencies]
# all
python = "^3.7"
python = "^3.8"
trezor = {path = "./python", develop = true}
scons = "*"
protobuf = "*"
Expand Down Expand Up @@ -54,7 +54,7 @@ click = "^8"
ed25519 = "^1.4"
requests = "^2.31"
termcolor = "*"
Pillow = "^9"
Pillow = ">=10.0.1"

# crypto
ecdsa = "^0.16"
Expand Down
2 changes: 1 addition & 1 deletion python/requirements-optional.txt
Original file line number Diff line number Diff line change
@@ -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'
22 changes: 8 additions & 14 deletions python/src/trezorlib/stellar.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
CreatePassiveSellOffer,
HashMemo,
IdMemo,
LiquidityPoolAsset,
ManageBuyOffer,
ManageData,
ManageSellOffer,
Expand All @@ -69,7 +70,6 @@
TransactionEnvelope,
TrustLineEntryFlag,
)
from stellar_sdk.xdr.signer_key_type import SignerKeyType

HAVE_STELLAR_SDK = True
DEFAULT_NETWORK_PASSPHRASE = Network.PUBLIC_NETWORK_PASSPHRASE
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
116 changes: 51 additions & 65 deletions python/tests/test_stellar.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
# 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>.

import warnings

import pytest

try:
from stellar_sdk import (
Account,
Asset,
AuthorizationFlag,
MuxedAccount,
Network,
TransactionBuilder,
Expand All @@ -39,7 +42,7 @@


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,
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand All @@ -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"
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion python/tools/toiftool/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
python = ">=3.8"
trezor = ">=0.13"
click = ">=7.0,<9.0"
Pillow = "^9"
Pillow = ">=10.0.1"

[build-system]
requires = ["poetry-core"]
Expand Down
Loading
Loading