From 4070d26bd36fb3b2db818a18bbe6a991aca4500e Mon Sep 17 00:00:00 2001 From: Jun Luo <4catcode@gmail.com> Date: Thu, 28 Nov 2024 09:05:21 +0800 Subject: [PATCH 1/2] Fix mypy warnings. --- pyproject.toml | 6 +- stellar_contract_bindings/cli.py | 39 +---- stellar_contract_bindings/metadata.py | 6 +- stellar_contract_bindings/python.py | 36 +++-- stellar_contract_bindings/utils.py | 46 ++++++ tests/client.py | 158 ++++++++++---------- tests/contracts/contracts/python/src/lib.rs | 4 +- tests/test_client.py | 4 +- uv.lock | 41 +++++ 9 files changed, 205 insertions(+), 135 deletions(-) create mode 100644 stellar_contract_bindings/utils.py diff --git a/pyproject.toml b/pyproject.toml index 52c0ab0..455c1e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,4 +19,8 @@ Issues = "https://github.com/lightsail-network/stellar-contract-bindings/issues" CI = "https://github.com/lightsail-network/stellar-contract-bindings/actions" [dependency-groups] -dev = ["black>=24.10.0", "pytest>=8.3.3"] \ No newline at end of file +dev = [ + "black>=24.10.0", + "mypy>=1.13.0", + "pytest>=8.3.3", +] diff --git a/stellar_contract_bindings/cli.py b/stellar_contract_bindings/cli.py index 064a1bc..d94edd4 100644 --- a/stellar_contract_bindings/cli.py +++ b/stellar_contract_bindings/cli.py @@ -1,40 +1,13 @@ import os import click -from stellar_sdk import SorobanServer -from stellar_sdk import xdr, Address, StrKey +from stellar_sdk import StrKey -from .python import generate_binding - - -def get_contract_wasm_by_hash(wasm_hash: bytes, rpc_url: str) -> bytes: - with SorobanServer(rpc_url) as server: - key = xdr.LedgerKey( - xdr.LedgerEntryType.CONTRACT_CODE, - contract_code=xdr.LedgerKeyContractCode(hash=xdr.Hash(wasm_hash)), - ) - resp = server.get_ledger_entries([key]) - if not resp.entries: - raise ValueError(f"Wasm not found, wasm id: {wasm_hash.hex()}") - data = xdr.LedgerEntryData.from_xdr(resp.entries[0].xdr) - return data.contract_code.code - - -def get_wasm_hash_by_contract_id(contract_id: str, rpc_url: str) -> bytes: - with SorobanServer(rpc_url) as server: - key = xdr.LedgerKey( - xdr.LedgerEntryType.CONTRACT_DATA, - contract_data=xdr.LedgerKeyContractData( - contract=Address(contract_id).to_xdr_sc_address(), - key=xdr.SCVal(xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE), - durability=xdr.ContractDataDurability.PERSISTENT, - ), - ) - resp = server.get_ledger_entries([key]) - if not resp.entries: - raise ValueError(f"Contract not found, contract id: {contract_id}") - data = xdr.LedgerEntryData.from_xdr(resp.entries[0].xdr) - return data.contract_data.val.instance.executable.wasm_hash.hash +from stellar_contract_bindings.python import generate_binding +from stellar_contract_bindings.utils import ( + get_wasm_hash_by_contract_id, + get_contract_wasm_by_hash, +) @click.group() diff --git a/stellar_contract_bindings/metadata.py b/stellar_contract_bindings/metadata.py index 33cb3f9..0d8889b 100644 --- a/stellar_contract_bindings/metadata.py +++ b/stellar_contract_bindings/metadata.py @@ -31,13 +31,13 @@ def parse_contract_metadata(wasm: Union[bytes, str]) -> ContractMetaData: for name, content in custom_sections: if name == "contractenvmetav0": metadata.env_meta_bytes = content - metadata.env_meta = parse_entries(content, xdr.SCEnvMetaEntry) + metadata.env_meta = parse_entries(content, xdr.SCEnvMetaEntry) # type: ignore[assignment] if name == "contractspecv0": metadata.spec_bytes = content - metadata.spec = parse_entries(content, xdr.SCSpecEntry) + metadata.spec = parse_entries(content, xdr.SCSpecEntry) # type: ignore[assignment] if name == "contractmetav0": metadata.meta_bytes = content - metadata.meta = parse_entries(content, xdr.SCMetaEntry) + metadata.meta = parse_entries(content, xdr.SCMetaEntry) # type: ignore[assignment] return metadata diff --git a/stellar_contract_bindings/python.py b/stellar_contract_bindings/python.py index 4389209..3ee36de 100644 --- a/stellar_contract_bindings/python.py +++ b/stellar_contract_bindings/python.py @@ -63,8 +63,8 @@ def to_py_type(td: xdr.SCSpecTypeDef): if t == xdr.SCSpecType.SC_SPEC_TYPE_OPTION: return f"Optional[{to_py_type(td.option.value_type)}]" if t == xdr.SCSpecType.SC_SPEC_TYPE_RESULT: - t = td.result.ok_type - return to_py_type(t) + ok_t = td.result.ok_type + return to_py_type(ok_t) if t == xdr.SCSpecType.SC_SPEC_TYPE_VEC: return f"List[{to_py_type(td.vec.element_type)}]" if t == xdr.SCSpecType.SC_SPEC_TYPE_MAP: @@ -244,8 +244,7 @@ def from_scval(cls, val: xdr.SCVal): return cls(scval.from_uint32(val)) """ - template = Template(template) - rendered_code = template.render(entry=entry) + rendered_code = Template(template).render(entry=entry) return rendered_code @@ -266,8 +265,7 @@ def from_scval(cls, val: xdr.SCVal): return cls(scval.from_uint32(val)) """ - template = Template(template) - rendered_code = template.render(entry=entry) + rendered_code = Template(template).render(entry=entry) return rendered_code @@ -311,8 +309,7 @@ def __hash__(self) -> int: return hash(({% for field in entry.fields %}self.{{ field.name.decode() }}{% if not loop.last %}, {% endif %}{% endfor %})) """ - template = Template(template) - rendered_code = template.render( + rendered_code = Template(template).render( entry=entry, to_py_type=to_py_type, to_scval=to_scval, @@ -350,8 +347,7 @@ def __hash__(self) -> int: return hash(self.value) """ - template = Template(template) - rendered_code = template.render( + rendered_code = Template(template).render( entry=entry, to_py_type=to_py_type, to_scval=to_scval, from_scval=from_scval ) return rendered_code @@ -369,8 +365,7 @@ class {{ entry.name.decode() }}Kind(Enum): {%- endfor %} """ - kind_enum_template = Template(kind_enum_template) - kind_enum_rendered_code = kind_enum_template.render(entry=entry, xdr=xdr) + kind_enum_rendered_code = Template(kind_enum_template).render(entry=entry, xdr=xdr) template = """ class {{ entry.name.decode() }}: @@ -404,8 +399,10 @@ def to_scval(self) -> xdr.SCVal: {%- else %} if self.kind == {{ entry.name.decode() }}Kind.{{ case.tuple_case.name.decode() }}: {%- if len(case.tuple_case.type) == 1 %} + assert self.{{ camel_to_snake(case.tuple_case.name.decode()) }} is not None return scval.to_enum(self.kind.name, {{ to_scval(case.tuple_case.type[0], 'self.' ~ camel_to_snake(case.tuple_case.name.decode())) }}) {%- else %} + assert isinstance(self.{{ camel_to_snake(case.tuple_case.name.decode()) }}, tuple) return scval.to_enum(self.kind.name, [ {%- for t in case.tuple_case.type %} {{ to_scval(t, 'self.' + camel_to_snake(case.tuple_case.name.decode()) + '[' + loop.index0|string + ']') }}{% if not loop.last %},{% endif %} @@ -427,8 +424,10 @@ def from_scval(cls, val: xdr.SCVal): {%- else %} if kind == {{ entry.name.decode() }}Kind.{{ case.tuple_case.name.decode() }}: {%- if len(case.tuple_case.type) == 1 %} + assert elements[1] is not None and isinstance(elements[1], xdr.SCVal) return cls(kind, {{ camel_to_snake(case.tuple_case.name.decode()) }}={{ from_scval(case.tuple_case.type[0], 'elements[1]') }}) {%- else %} + assert elements[1] is not None and isinstance(elements[1], tuple) return cls(kind, {{ camel_to_snake(case.tuple_case.name.decode()) }}=( {%- for i, t in enumerate(case.tuple_case.type) %} {{ from_scval(t, 'elements[1][' + loop.index0|string + ']') }}{% if not loop.last %},{% endif %} @@ -460,8 +459,7 @@ def __hash__(self) -> int: {%- endfor %} return hash(self.kind) """ - template = Template(template) - union_rendered_code = template.render( + union_rendered_code = Template(template).render( entry=entry, to_py_type=to_py_type, to_scval=to_scval, @@ -478,7 +476,7 @@ def render_client(entries: List[xdr.SCSpecFunctionV0]): template = ''' class Client(ContractClient): {%- for entry in entries %} - def {{ entry.name.sc_symbol.decode() }}(self, {% for param in entry.inputs %}{{ param.name.decode() }}: {{ to_py_type(param.type) }}, {% endfor %} source: Union[str, MuxedAccount] = NULL_ACCOUNT, signer: Keypair = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, simulate: bool = True, restore: bool = True) -> AssembledTransaction[{{ parse_result_type(entry.outputs) }}]: + def {{ entry.name.sc_symbol.decode() }}(self, {% for param in entry.inputs %}{{ param.name.decode() }}: {{ to_py_type(param.type) }}, {% endfor %} source: Union[str, MuxedAccount] = NULL_ACCOUNT, signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, simulate: bool = True, restore: bool = True) -> AssembledTransaction[{{ parse_result_type(entry.outputs) }}]: {%- if entry.doc %} """{{ entry.doc.decode() }}""" {%- endif %} @@ -487,7 +485,7 @@ def {{ entry.name.sc_symbol.decode() }}(self, {% for param in entry.inputs %}{{ class ClientAsync(ContractClientAsync): {%- for entry in entries %} - async def {{ entry.name.sc_symbol.decode() }}(self, {% for param in entry.inputs %}{{ param.name.decode() }}: {{ to_py_type(param.type) }}, {% endfor %} source: Union[str, MuxedAccount] = NULL_ACCOUNT, signer: Keypair = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, simulate: bool = True, restore: bool = True) -> AssembledTransactionAsync[{{ parse_result_type(entry.outputs) }}]: + async def {{ entry.name.sc_symbol.decode() }}(self, {% for param in entry.inputs %}{{ param.name.decode() }}: {{ to_py_type(param.type) }}, {% endfor %} source: Union[str, MuxedAccount] = NULL_ACCOUNT, signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, simulate: bool = True, restore: bool = True) -> AssembledTransactionAsync[{{ parse_result_type(entry.outputs) }}]: {%- if entry.doc %} """{{ entry.doc.decode() }}""" {%- endif %} @@ -513,8 +511,7 @@ def parse_result_xdr_fn(output: List[xdr.SCSpecTypeDef]): "Tuple return type is not supported, please report this issue" ) - template = Template(template) - client_rendered_code = template.render( + client_rendered_code = Template(template).render( entries=entries, to_py_type=to_py_type, to_scval=to_scval, @@ -549,7 +546,8 @@ def generate_binding(wasm: bytes) -> str: function_specs: List[xdr.SCSpecFunctionV0] = [ spec.function_v0 for spec in specs - if spec.kind == xdr.SCSpecEntryKind.SC_SPEC_ENTRY_FUNCTION_V0 and not spec.function_v0.name.sc_symbol.decode().startswith("__") + if spec.kind == xdr.SCSpecEntryKind.SC_SPEC_ENTRY_FUNCTION_V0 + and not spec.function_v0.name.sc_symbol.decode().startswith("__") ] generated.append(render_client(function_specs)) return "\n".join(generated) diff --git a/stellar_contract_bindings/utils.py b/stellar_contract_bindings/utils.py new file mode 100644 index 0000000..9a2697a --- /dev/null +++ b/stellar_contract_bindings/utils.py @@ -0,0 +1,46 @@ +from stellar_sdk import SorobanServer +from stellar_sdk import xdr, Address + + +def get_contract_wasm_by_hash(wasm_hash: bytes, rpc_url: str) -> bytes: + """Get the contract wasm by wasm hash. + + :param wasm_hash: The wasm hash. + :param rpc_url: The Soroban RPC URL. + :return: The contract wasm. + :raises ValueError: If wasm not found. + """ + with SorobanServer(rpc_url) as server: + key = xdr.LedgerKey( + xdr.LedgerEntryType.CONTRACT_CODE, + contract_code=xdr.LedgerKeyContractCode(hash=xdr.Hash(wasm_hash)), + ) + resp = server.get_ledger_entries([key]) + if not resp.entries: + raise ValueError(f"Wasm not found, wasm id: {wasm_hash.hex()}") + data = xdr.LedgerEntryData.from_xdr(resp.entries[0].xdr) + return data.contract_code.code + + +def get_wasm_hash_by_contract_id(contract_id: str, rpc_url: str) -> bytes: + """Get the wasm hash by contract id. + + :param contract_id: The contract id. + :param rpc_url: The Soroban RPC URL. + :return: The wasm hash. + :raises ValueError: If contract not found. + """ + with SorobanServer(rpc_url) as server: + key = xdr.LedgerKey( + xdr.LedgerEntryType.CONTRACT_DATA, + contract_data=xdr.LedgerKeyContractData( + contract=Address(contract_id).to_xdr_sc_address(), + key=xdr.SCVal(xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE), + durability=xdr.ContractDataDurability.PERSISTENT, + ), + ) + resp = server.get_ledger_entries([key]) + if not resp.entries: + raise ValueError(f"Contract not found, contract id: {contract_id}") + data = xdr.LedgerEntryData.from_xdr(resp.entries[0].xdr) + return data.contract_data.val.instance.executable.wasm_hash.hash diff --git a/tests/client.py b/tests/client.py index 33ff4b7..101fde1 100644 --- a/tests/client.py +++ b/tests/client.py @@ -1,4 +1,4 @@ -# This file was generated by stellar_contract_bindings v0.1.0b0 and stellar_sdk v12.0.0b6. +# This file was generated by stellar_contract_bindings v0.1.0b1 and stellar_sdk v12.0.0b6. # Client is used to interact with the contract on the Stellar network synchronously, # while ClientAsync is used to interact with the contract on the Stellar network asynchronously. # If you don't need to interact with the contract asynchronously, you can remove the ClientAsync class and its methods. @@ -165,12 +165,16 @@ def __init__( def to_scval(self) -> xdr.SCVal: if self.kind == ComplexEnumKind.Struct: + assert self.struct is not None return scval.to_enum(self.kind.name, self.struct.to_scval()) if self.kind == ComplexEnumKind.Tuple: + assert self.tuple is not None return scval.to_enum(self.kind.name, self.tuple.to_scval()) if self.kind == ComplexEnumKind.Enum: + assert self.enum is not None return scval.to_enum(self.kind.name, self.enum.to_scval()) if self.kind == ComplexEnumKind.Asset: + assert isinstance(self.asset, tuple) return scval.to_enum( self.kind.name, [scval.to_address(self.asset[0]), scval.to_int128(self.asset[1])], @@ -183,12 +187,16 @@ def from_scval(cls, val: xdr.SCVal): elements = scval.from_enum(val) kind = ComplexEnumKind(elements[0]) if kind == ComplexEnumKind.Struct: + assert elements[1] is not None and isinstance(elements[1], xdr.SCVal) return cls(kind, struct=Test.from_scval(elements[1])) if kind == ComplexEnumKind.Tuple: + assert elements[1] is not None and isinstance(elements[1], xdr.SCVal) return cls(kind, tuple=TupleStruct.from_scval(elements[1])) if kind == ComplexEnumKind.Enum: + assert elements[1] is not None and isinstance(elements[1], xdr.SCVal) return cls(kind, enum=SimpleEnum.from_scval(elements[1])) if kind == ComplexEnumKind.Asset: + assert elements[1] is not None and isinstance(elements[1], tuple) return cls( kind, asset=( @@ -242,7 +250,7 @@ def hello( self, hello: str, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -265,7 +273,7 @@ def hello( def void( self, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -290,7 +298,7 @@ def val( a: int, b: xdr.SCVal, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -314,7 +322,7 @@ def u32_fail_on_even( self, u32_: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -338,7 +346,7 @@ def u32( self, u32: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -362,7 +370,7 @@ def i32( self, i32: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -386,7 +394,7 @@ def u64( self, u64: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -410,7 +418,7 @@ def i64( self, i64: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -434,7 +442,7 @@ def strukt_hel( self, strukt: Test, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -461,7 +469,7 @@ def strukt( self, strukt: Test, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -485,7 +493,7 @@ def simple( self, simple: SimpleEnum, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -509,7 +517,7 @@ def complex( self, complex: ComplexEnum, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -533,7 +541,7 @@ def address( self, address: Address, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -553,11 +561,11 @@ def address( restore=restore, ) - def bytes( + def bytes_( self, - bytes: bytes, + bytes_: bytes, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -565,8 +573,8 @@ def bytes( restore: bool = True, ) -> AssembledTransaction[bytes]: return self.invoke( - "bytes", - [scval.to_bytes(bytes)], + "bytes_", + [scval.to_bytes(bytes_)], parse_result_xdr_fn=lambda v: scval.from_bytes(v), source=source, signer=signer, @@ -581,7 +589,7 @@ def bytes_n( self, bytes_n: bytes, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -605,7 +613,7 @@ def card( self, card: RoyalCard, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -629,7 +637,7 @@ def boolean( self, boolean: bool, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -653,7 +661,7 @@ def not_( self, boolean: bool, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -678,7 +686,7 @@ def i128( self, i128: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -702,7 +710,7 @@ def u128( self, u128: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -727,7 +735,7 @@ def multi_args( a: int, b: bool, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -751,7 +759,7 @@ def map( self, map: Dict[int, bool], source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -782,7 +790,7 @@ def vec( self, vec: List[int], source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -808,7 +816,7 @@ def tuple( self, tuple: Tuple[str, int], source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -838,7 +846,7 @@ def tuple( def empty_tuple( self, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -862,7 +870,7 @@ def option( self, option: Optional[int], source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -891,7 +899,7 @@ def u256( self, u256: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -915,7 +923,7 @@ def i256( self, i256: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -939,7 +947,7 @@ def string( self, string: bytes, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -963,7 +971,7 @@ def tuple_strukt( self, tuple_strukt: TupleStruct, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -987,7 +995,7 @@ def tuple_strukt_nested( self, tuple_strukt: Tuple[Test, SimpleEnum], source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1018,7 +1026,7 @@ def timepoint( self, timepoint: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1042,7 +1050,7 @@ def duration( self, duration: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1068,7 +1076,7 @@ async def hello( self, hello: str, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1091,7 +1099,7 @@ async def hello( async def void( self, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1116,7 +1124,7 @@ async def val( a: int, b: xdr.SCVal, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1140,7 +1148,7 @@ async def u32_fail_on_even( self, u32_: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1164,7 +1172,7 @@ async def u32( self, u32: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1188,7 +1196,7 @@ async def i32( self, i32: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1212,7 +1220,7 @@ async def u64( self, u64: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1236,7 +1244,7 @@ async def i64( self, i64: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1260,7 +1268,7 @@ async def strukt_hel( self, strukt: Test, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1287,7 +1295,7 @@ async def strukt( self, strukt: Test, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1311,7 +1319,7 @@ async def simple( self, simple: SimpleEnum, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1335,7 +1343,7 @@ async def complex( self, complex: ComplexEnum, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1359,7 +1367,7 @@ async def address( self, address: Address, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1379,11 +1387,11 @@ async def address( restore=restore, ) - async def bytes( + async def bytes_( self, - bytes: bytes, + bytes_: bytes, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1391,8 +1399,8 @@ async def bytes( restore: bool = True, ) -> AssembledTransactionAsync[bytes]: return await self.invoke( - "bytes", - [scval.to_bytes(bytes)], + "bytes_", + [scval.to_bytes(bytes_)], parse_result_xdr_fn=lambda v: scval.from_bytes(v), source=source, signer=signer, @@ -1407,7 +1415,7 @@ async def bytes_n( self, bytes_n: bytes, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1431,7 +1439,7 @@ async def card( self, card: RoyalCard, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1455,7 +1463,7 @@ async def boolean( self, boolean: bool, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1479,7 +1487,7 @@ async def not_( self, boolean: bool, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1504,7 +1512,7 @@ async def i128( self, i128: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1528,7 +1536,7 @@ async def u128( self, u128: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1553,7 +1561,7 @@ async def multi_args( a: int, b: bool, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1577,7 +1585,7 @@ async def map( self, map: Dict[int, bool], source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1608,7 +1616,7 @@ async def vec( self, vec: List[int], source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1634,7 +1642,7 @@ async def tuple( self, tuple: Tuple[str, int], source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1664,7 +1672,7 @@ async def tuple( async def empty_tuple( self, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1688,7 +1696,7 @@ async def option( self, option: Optional[int], source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1717,7 +1725,7 @@ async def u256( self, u256: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1741,7 +1749,7 @@ async def i256( self, i256: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1765,7 +1773,7 @@ async def string( self, string: bytes, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1789,7 +1797,7 @@ async def tuple_strukt( self, tuple_strukt: TupleStruct, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1813,7 +1821,7 @@ async def tuple_strukt_nested( self, tuple_strukt: Tuple[Test, SimpleEnum], source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1844,7 +1852,7 @@ async def timepoint( self, timepoint: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, @@ -1868,7 +1876,7 @@ async def duration( self, duration: int, source: Union[str, MuxedAccount] = NULL_ACCOUNT, - signer: Keypair = None, + signer: Optional[Keypair] = None, base_fee: int = 100, transaction_timeout: int = 300, submit_timeout: int = 30, diff --git a/tests/contracts/contracts/python/src/lib.rs b/tests/contracts/contracts/python/src/lib.rs index 6bf3bab..8bad4ce 100644 --- a/tests/contracts/contracts/python/src/lib.rs +++ b/tests/contracts/contracts/python/src/lib.rs @@ -116,8 +116,8 @@ impl Contract { address } - pub fn bytes(_env: Env, bytes: Bytes) -> Bytes { - bytes + pub fn bytes_(_env: Env, bytes_: Bytes) -> Bytes { + bytes_ } pub fn bytes_n(_env: Env, bytes_n: BytesN<9>) -> BytesN<9> { diff --git a/tests/test_client.py b/tests/test_client.py index d17c76d..81c70d2 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -4,7 +4,7 @@ from .client import * -CONTRACT_ID = "CCCEM6UHXEVHVXDN4E4G3IIN5LTUJ2NVVSRR3WCQHKP6GROQFGRN3HIE" +CONTRACT_ID = "CCD5T5M6IQQZ752CFTVEDGY6VKHLJK5HHAO7UA3BRHZC2IFSA5IHOSJ4" RPC_URL = "https://soroban-testnet.stellar.org" NETWORK_PASSPHRASE = Network.TESTNET_NETWORK_PASSPHRASE @@ -126,7 +126,7 @@ def test_address(self): assert result.result() == address def test_bytes(self): - result = self.client.bytes(b"123") + result = self.client.bytes_(b"123") assert result.result() == b"123" def test_bytes_n(self): diff --git a/uv.lock b/uv.lock index 534454d..38bda28 100644 --- a/uv.lock +++ b/uv.lock @@ -347,6 +347,45 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/ae/95/3e07c33ffb26f5823b45a1c30db8acea44763198c2bd393e07e884f3295f/mnemonic-0.20-py3-none-any.whl", hash = "sha256:acd2168872d0379e7a10873bb3e12bf6c91b35de758135c4fbd1015ef18fafc5", size = 62028 }, ] +[[package]] +name = "mypy" +version = "1.13.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "mypy-extensions" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/e8/21/7e9e523537991d145ab8a0a2fd98548d67646dc2aaaf6091c31ad883e7c1/mypy-1.13.0.tar.gz", hash = "sha256:0291a61b6fbf3e6673e3405cfcc0e7650bebc7939659fdca2702958038bd835e", size = 3152532 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5e/8c/206de95a27722b5b5a8c85ba3100467bd86299d92a4f71c6b9aa448bfa2f/mypy-1.13.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6607e0f1dd1fb7f0aca14d936d13fd19eba5e17e1cd2a14f808fa5f8f6d8f60a", size = 11020731 }, + { url = "https://files.pythonhosted.org/packages/ab/bb/b31695a29eea76b1569fd28b4ab141a1adc9842edde080d1e8e1776862c7/mypy-1.13.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8a21be69bd26fa81b1f80a61ee7ab05b076c674d9b18fb56239d72e21d9f4c80", size = 10184276 }, + { url = "https://files.pythonhosted.org/packages/a5/2d/4a23849729bb27934a0e079c9c1aad912167d875c7b070382a408d459651/mypy-1.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7b2353a44d2179846a096e25691d54d59904559f4232519d420d64da6828a3a7", size = 12587706 }, + { url = "https://files.pythonhosted.org/packages/5c/c3/d318e38ada50255e22e23353a469c791379825240e71b0ad03e76ca07ae6/mypy-1.13.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:0730d1c6a2739d4511dc4253f8274cdd140c55c32dfb0a4cf8b7a43f40abfa6f", size = 13105586 }, + { url = "https://files.pythonhosted.org/packages/4a/25/3918bc64952370c3dbdbd8c82c363804678127815febd2925b7273d9482c/mypy-1.13.0-cp310-cp310-win_amd64.whl", hash = "sha256:c5fc54dbb712ff5e5a0fca797e6e0aa25726c7e72c6a5850cfd2adbc1eb0a372", size = 9632318 }, + { url = "https://files.pythonhosted.org/packages/d0/19/de0822609e5b93d02579075248c7aa6ceaddcea92f00bf4ea8e4c22e3598/mypy-1.13.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:581665e6f3a8a9078f28d5502f4c334c0c8d802ef55ea0e7276a6e409bc0d82d", size = 10939027 }, + { url = "https://files.pythonhosted.org/packages/c8/71/6950fcc6ca84179137e4cbf7cf41e6b68b4a339a1f5d3e954f8c34e02d66/mypy-1.13.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3ddb5b9bf82e05cc9a627e84707b528e5c7caaa1c55c69e175abb15a761cec2d", size = 10108699 }, + { url = "https://files.pythonhosted.org/packages/26/50/29d3e7dd166e74dc13d46050b23f7d6d7533acf48f5217663a3719db024e/mypy-1.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:20c7ee0bc0d5a9595c46f38beb04201f2620065a93755704e141fcac9f59db2b", size = 12506263 }, + { url = "https://files.pythonhosted.org/packages/3f/1d/676e76f07f7d5ddcd4227af3938a9c9640f293b7d8a44dd4ff41d4db25c1/mypy-1.13.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:3790ded76f0b34bc9c8ba4def8f919dd6a46db0f5a6610fb994fe8efdd447f73", size = 12984688 }, + { url = "https://files.pythonhosted.org/packages/9c/03/5a85a30ae5407b1d28fab51bd3e2103e52ad0918d1e68f02a7778669a307/mypy-1.13.0-cp311-cp311-win_amd64.whl", hash = "sha256:51f869f4b6b538229c1d1bcc1dd7d119817206e2bc54e8e374b3dfa202defcca", size = 9626811 }, + { url = "https://files.pythonhosted.org/packages/fb/31/c526a7bd2e5c710ae47717c7a5f53f616db6d9097caf48ad650581e81748/mypy-1.13.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:5c7051a3461ae84dfb5dd15eff5094640c61c5f22257c8b766794e6dd85e72d5", size = 11077900 }, + { url = "https://files.pythonhosted.org/packages/83/67/b7419c6b503679d10bd26fc67529bc6a1f7a5f220bbb9f292dc10d33352f/mypy-1.13.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:39bb21c69a5d6342f4ce526e4584bc5c197fd20a60d14a8624d8743fffb9472e", size = 10074818 }, + { url = "https://files.pythonhosted.org/packages/ba/07/37d67048786ae84e6612575e173d713c9a05d0ae495dde1e68d972207d98/mypy-1.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:164f28cb9d6367439031f4c81e84d3ccaa1e19232d9d05d37cb0bd880d3f93c2", size = 12589275 }, + { url = "https://files.pythonhosted.org/packages/1f/17/b1018c6bb3e9f1ce3956722b3bf91bff86c1cefccca71cec05eae49d6d41/mypy-1.13.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a4c1bfcdbce96ff5d96fc9b08e3831acb30dc44ab02671eca5953eadad07d6d0", size = 13037783 }, + { url = "https://files.pythonhosted.org/packages/cb/32/cd540755579e54a88099aee0287086d996f5a24281a673f78a0e14dba150/mypy-1.13.0-cp312-cp312-win_amd64.whl", hash = "sha256:a0affb3a79a256b4183ba09811e3577c5163ed06685e4d4b46429a271ba174d2", size = 9726197 }, + { url = "https://files.pythonhosted.org/packages/11/bb/ab4cfdc562cad80418f077d8be9b4491ee4fb257440da951b85cbb0a639e/mypy-1.13.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:a7b44178c9760ce1a43f544e595d35ed61ac2c3de306599fa59b38a6048e1aa7", size = 11069721 }, + { url = "https://files.pythonhosted.org/packages/59/3b/a393b1607cb749ea2c621def5ba8c58308ff05e30d9dbdc7c15028bca111/mypy-1.13.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:5d5092efb8516d08440e36626f0153b5006d4088c1d663d88bf79625af3d1d62", size = 10063996 }, + { url = "https://files.pythonhosted.org/packages/d1/1f/6b76be289a5a521bb1caedc1f08e76ff17ab59061007f201a8a18cc514d1/mypy-1.13.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:de2904956dac40ced10931ac967ae63c5089bd498542194b436eb097a9f77bc8", size = 12584043 }, + { url = "https://files.pythonhosted.org/packages/a6/83/5a85c9a5976c6f96e3a5a7591aa28b4a6ca3a07e9e5ba0cec090c8b596d6/mypy-1.13.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:7bfd8836970d33c2105562650656b6846149374dc8ed77d98424b40b09340ba7", size = 13036996 }, + { url = "https://files.pythonhosted.org/packages/b4/59/c39a6f752f1f893fccbcf1bdd2aca67c79c842402b5283563d006a67cf76/mypy-1.13.0-cp313-cp313-win_amd64.whl", hash = "sha256:9f73dba9ec77acb86457a8fc04b5239822df0c14a082564737833d2963677dbc", size = 9737709 }, + { url = "https://files.pythonhosted.org/packages/5f/d4/b33ddd40dad230efb317898a2d1c267c04edba73bc5086bf77edeb410fb2/mypy-1.13.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:0246bcb1b5de7f08f2826451abd947bf656945209b140d16ed317f65a17dc7dc", size = 11013906 }, + { url = "https://files.pythonhosted.org/packages/f4/e6/f414bca465b44d01cd5f4a82761e15044bedd1bf8025c5af3cc64518fac5/mypy-1.13.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:7f5b7deae912cf8b77e990b9280f170381fdfbddf61b4ef80927edd813163732", size = 10180657 }, + { url = "https://files.pythonhosted.org/packages/38/e9/fc3865e417722f98d58409770be01afb961e2c1f99930659ff4ae7ca8b7e/mypy-1.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7029881ec6ffb8bc233a4fa364736789582c738217b133f1b55967115288a2bc", size = 12586394 }, + { url = "https://files.pythonhosted.org/packages/2e/35/f4d8b6d2cb0b3dad63e96caf159419dda023f45a358c6c9ac582ccaee354/mypy-1.13.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:3e38b980e5681f28f033f3be86b099a247b13c491f14bb8b1e1e134d23bb599d", size = 13103591 }, + { url = "https://files.pythonhosted.org/packages/22/1d/80594aef135f921dd52e142fa0acd19df197690bd0cde42cea7b88cf5aa2/mypy-1.13.0-cp39-cp39-win_amd64.whl", hash = "sha256:a6789be98a2017c912ae6ccb77ea553bbaf13d27605d2ca20a76dfbced631b24", size = 9634690 }, + { url = "https://files.pythonhosted.org/packages/3b/86/72ce7f57431d87a7ff17d442f521146a6585019eb8f4f31b7c02801f78ad/mypy-1.13.0-py3-none-any.whl", hash = "sha256:9c250883f9fd81d212e0952c92dbfcc96fc237f4b7c92f56ac81fd48460b3e5a", size = 2647043 }, +] + [[package]] name = "mypy-extensions" version = "1.0.0" @@ -589,6 +628,7 @@ dependencies = [ [package.dev-dependencies] dev = [ { name = "black" }, + { name = "mypy" }, { name = "pytest" }, ] @@ -602,6 +642,7 @@ requires-dist = [ [package.metadata.requires-dev] dev = [ { name = "black", specifier = ">=24.10.0" }, + { name = "mypy", specifier = ">=1.13.0" }, { name = "pytest", specifier = ">=8.3.3" }, ] From a1477529f0e012a69b36802d6a97a81757cb64a0 Mon Sep 17 00:00:00 2001 From: Jun Luo <4catcode@gmail.com> Date: Thu, 28 Nov 2024 09:22:29 +0800 Subject: [PATCH 2/2] Fix mypy warnings. --- stellar_contract_bindings/python.py | 2 +- tests/client.py | 44 ++++++++++----------- tests/contracts/contracts/python/src/lib.rs | 14 +++---- tests/test_client.py | 16 ++++---- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/stellar_contract_bindings/python.py b/stellar_contract_bindings/python.py index 3ee36de..757b8ea 100644 --- a/stellar_contract_bindings/python.py +++ b/stellar_contract_bindings/python.py @@ -427,7 +427,7 @@ def from_scval(cls, val: xdr.SCVal): assert elements[1] is not None and isinstance(elements[1], xdr.SCVal) return cls(kind, {{ camel_to_snake(case.tuple_case.name.decode()) }}={{ from_scval(case.tuple_case.type[0], 'elements[1]') }}) {%- else %} - assert elements[1] is not None and isinstance(elements[1], tuple) + assert elements[1] is not None and isinstance(elements[1], list) return cls(kind, {{ camel_to_snake(case.tuple_case.name.decode()) }}=( {%- for i, t in enumerate(case.tuple_case.type) %} {{ from_scval(t, 'elements[1][' + loop.index0|string + ']') }}{% if not loop.last %},{% endif %} diff --git a/tests/client.py b/tests/client.py index 101fde1..6177dca 100644 --- a/tests/client.py +++ b/tests/client.py @@ -17,8 +17,8 @@ NULL_ACCOUNT = "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF" -class Test: - """This is from the rust doc above the struct Test""" +class SimpleStruct: + """This is from the rust doc above the struct SimpleStruct""" a: int b: bool @@ -48,7 +48,7 @@ def from_scval(cls, val: xdr.SCVal): ) def __eq__(self, other: object) -> bool: - if not isinstance(other, Test): + if not isinstance(other, SimpleStruct): return NotImplemented return self.a == other.a and self.b == other.b and self.c == other.c @@ -114,7 +114,7 @@ def from_scval(cls, val: xdr.SCVal): class TupleStruct: - def __init__(self, value: Tuple[Test, SimpleEnum]): + def __init__(self, value: Tuple[SimpleStruct, SimpleEnum]): self.value = value def to_scval(self) -> xdr.SCVal: @@ -126,7 +126,7 @@ def to_scval(self) -> xdr.SCVal: def from_scval(cls, val: xdr.SCVal): elements = scval.from_tuple_struct(val) values = ( - Test.from_scval(elements[0]), + SimpleStruct.from_scval(elements[0]), SimpleEnum.from_scval(elements[1]), ) return cls(values) @@ -152,7 +152,7 @@ class ComplexEnum: def __init__( self, kind: ComplexEnumKind, - struct: Optional[Test] = None, + struct: Optional[SimpleStruct] = None, tuple: Optional[TupleStruct] = None, enum: Optional[SimpleEnum] = None, asset: Optional[Tuple[Address, int]] = None, @@ -188,7 +188,7 @@ def from_scval(cls, val: xdr.SCVal): kind = ComplexEnumKind(elements[0]) if kind == ComplexEnumKind.Struct: assert elements[1] is not None and isinstance(elements[1], xdr.SCVal) - return cls(kind, struct=Test.from_scval(elements[1])) + return cls(kind, struct=SimpleStruct.from_scval(elements[1])) if kind == ComplexEnumKind.Tuple: assert elements[1] is not None and isinstance(elements[1], xdr.SCVal) return cls(kind, tuple=TupleStruct.from_scval(elements[1])) @@ -196,7 +196,7 @@ def from_scval(cls, val: xdr.SCVal): assert elements[1] is not None and isinstance(elements[1], xdr.SCVal) return cls(kind, enum=SimpleEnum.from_scval(elements[1])) if kind == ComplexEnumKind.Asset: - assert elements[1] is not None and isinstance(elements[1], tuple) + assert elements[1] is not None and isinstance(elements[1], list) return cls( kind, asset=( @@ -440,7 +440,7 @@ def i64( def strukt_hel( self, - strukt: Test, + strukt: SimpleStruct, source: Union[str, MuxedAccount] = NULL_ACCOUNT, signer: Optional[Keypair] = None, base_fee: int = 100, @@ -467,7 +467,7 @@ def strukt_hel( def strukt( self, - strukt: Test, + strukt: SimpleStruct, source: Union[str, MuxedAccount] = NULL_ACCOUNT, signer: Optional[Keypair] = None, base_fee: int = 100, @@ -475,11 +475,11 @@ def strukt( submit_timeout: int = 30, simulate: bool = True, restore: bool = True, - ) -> AssembledTransaction[Test]: + ) -> AssembledTransaction[SimpleStruct]: return self.invoke( "strukt", [strukt.to_scval()], - parse_result_xdr_fn=lambda v: Test.from_scval(v), + parse_result_xdr_fn=lambda v: SimpleStruct.from_scval(v), source=source, signer=signer, base_fee=base_fee, @@ -993,7 +993,7 @@ def tuple_strukt( def tuple_strukt_nested( self, - tuple_strukt: Tuple[Test, SimpleEnum], + tuple_strukt: Tuple[SimpleStruct, SimpleEnum], source: Union[str, MuxedAccount] = NULL_ACCOUNT, signer: Optional[Keypair] = None, base_fee: int = 100, @@ -1001,7 +1001,7 @@ def tuple_strukt_nested( submit_timeout: int = 30, simulate: bool = True, restore: bool = True, - ) -> AssembledTransaction[Tuple[Test, SimpleEnum]]: + ) -> AssembledTransaction[Tuple[SimpleStruct, SimpleEnum]]: return self.invoke( "tuple_strukt_nested", [ @@ -1010,7 +1010,7 @@ def tuple_strukt_nested( ) ], parse_result_xdr_fn=lambda v: ( - Test.from_scval(scval.from_tuple_struct(v)[0]), + SimpleStruct.from_scval(scval.from_tuple_struct(v)[0]), SimpleEnum.from_scval(scval.from_tuple_struct(v)[1]), ), source=source, @@ -1266,7 +1266,7 @@ async def i64( async def strukt_hel( self, - strukt: Test, + strukt: SimpleStruct, source: Union[str, MuxedAccount] = NULL_ACCOUNT, signer: Optional[Keypair] = None, base_fee: int = 100, @@ -1293,7 +1293,7 @@ async def strukt_hel( async def strukt( self, - strukt: Test, + strukt: SimpleStruct, source: Union[str, MuxedAccount] = NULL_ACCOUNT, signer: Optional[Keypair] = None, base_fee: int = 100, @@ -1301,11 +1301,11 @@ async def strukt( submit_timeout: int = 30, simulate: bool = True, restore: bool = True, - ) -> AssembledTransactionAsync[Test]: + ) -> AssembledTransactionAsync[SimpleStruct]: return await self.invoke( "strukt", [strukt.to_scval()], - parse_result_xdr_fn=lambda v: Test.from_scval(v), + parse_result_xdr_fn=lambda v: SimpleStruct.from_scval(v), source=source, signer=signer, base_fee=base_fee, @@ -1819,7 +1819,7 @@ async def tuple_strukt( async def tuple_strukt_nested( self, - tuple_strukt: Tuple[Test, SimpleEnum], + tuple_strukt: Tuple[SimpleStruct, SimpleEnum], source: Union[str, MuxedAccount] = NULL_ACCOUNT, signer: Optional[Keypair] = None, base_fee: int = 100, @@ -1827,7 +1827,7 @@ async def tuple_strukt_nested( submit_timeout: int = 30, simulate: bool = True, restore: bool = True, - ) -> AssembledTransactionAsync[Tuple[Test, SimpleEnum]]: + ) -> AssembledTransactionAsync[Tuple[SimpleStruct, SimpleEnum]]: return await self.invoke( "tuple_strukt_nested", [ @@ -1836,7 +1836,7 @@ async def tuple_strukt_nested( ) ], parse_result_xdr_fn=lambda v: ( - Test.from_scval(scval.from_tuple_struct(v)[0]), + SimpleStruct.from_scval(scval.from_tuple_struct(v)[0]), SimpleEnum.from_scval(scval.from_tuple_struct(v)[1]), ), source=source, diff --git a/tests/contracts/contracts/python/src/lib.rs b/tests/contracts/contracts/python/src/lib.rs index 8bad4ce..6855a6b 100644 --- a/tests/contracts/contracts/python/src/lib.rs +++ b/tests/contracts/contracts/python/src/lib.rs @@ -7,9 +7,9 @@ use soroban_sdk::{ #[contract] pub struct Contract; -/// This is from the rust doc above the struct Test +/// This is from the rust doc above the struct SimpleStruct #[contracttype] -pub struct Test { +pub struct SimpleStruct { pub a: u32, pub b: bool, pub c: Symbol, @@ -33,11 +33,11 @@ pub enum RoyalCard { } #[contracttype] -pub struct TupleStruct(Test, SimpleEnum); +pub struct TupleStruct(SimpleStruct, SimpleEnum); #[contracttype] pub enum ComplexEnum { - Struct(Test), + Struct(SimpleStruct), Tuple(TupleStruct), Enum(SimpleEnum), Asset(Address, i128), @@ -96,11 +96,11 @@ impl Contract { } /// Example contract method which takes a struct - pub fn strukt_hel(env: Env, strukt: Test) -> Vec { + pub fn strukt_hel(env: Env, strukt: SimpleStruct) -> Vec { vec![&env, symbol_short!("Hello"), strukt.c] } - pub fn strukt(_env: Env, strukt: Test) -> Test { + pub fn strukt(_env: Env, strukt: SimpleStruct) -> SimpleStruct { strukt } @@ -190,7 +190,7 @@ impl Contract { tuple_strukt } - pub fn tuple_strukt_nested(_env: Env, tuple_strukt: (Test, SimpleEnum)) -> (Test, SimpleEnum) { + pub fn tuple_strukt_nested(_env: Env, tuple_strukt: (SimpleStruct, SimpleEnum)) -> (SimpleStruct, SimpleEnum) { tuple_strukt } diff --git a/tests/test_client.py b/tests/test_client.py index 81c70d2..464f1cb 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -4,7 +4,7 @@ from .client import * -CONTRACT_ID = "CCD5T5M6IQQZ752CFTVEDGY6VKHLJK5HHAO7UA3BRHZC2IFSA5IHOSJ4" +CONTRACT_ID = "CAYIWC3Y2KK4FXINTF3QFNBOUHGJ673QNG46EX462EYR4EYCFSYVAR4O" RPC_URL = "https://soroban-testnet.stellar.org" NETWORK_PASSPHRASE = Network.TESTNET_NETWORK_PASSPHRASE @@ -66,12 +66,12 @@ def test_i64(self): assert result.result() == -34543534 def test_strukt_hel(self): - strukt = Test(123, True, "world") + strukt = SimpleStruct(123, True, "world") result = self.client.strukt_hel(strukt) assert result.result() == ["Hello", "world"] def test_strukt(self): - strukt = Test(123, True, "world") + strukt = SimpleStruct(123, True, "world") result = self.client.strukt(strukt) assert result.result() == strukt @@ -82,7 +82,7 @@ def test_simple(self): def test_complex_struct(self): complex_struct = ComplexEnum( - ComplexEnumKind.Struct, struct=Test(123, True, "world") + ComplexEnumKind.Struct, struct=SimpleStruct(123, True, "world") ) result = self.client.complex(complex_struct) assert result.result() == complex_struct @@ -91,7 +91,7 @@ def test_complex_tuple(self): complex_tuple = ComplexEnum( ComplexEnumKind.Tuple, tuple=TupleStruct( - (Test(123, True, "world"), SimpleEnum(SimpleEnumKind.Third)) + (SimpleStruct(123, True, "world"), SimpleEnum(SimpleEnumKind.Third)) ), ) result = self.client.complex(complex_tuple) @@ -204,12 +204,14 @@ def test_string(self): assert result.result() == b"hello" def test_tuple_strukt(self): - t = TupleStruct((Test(1, False, "hello"), SimpleEnum(SimpleEnumKind.First))) + t = TupleStruct( + (SimpleStruct(1, False, "hello"), SimpleEnum(SimpleEnumKind.First)) + ) result = self.client.tuple_strukt(t) assert result.result() == t def test_tuple_strukt_nested(self): - t = (Test(1, False, "hello"), SimpleEnum(SimpleEnumKind.First)) + t = (SimpleStruct(1, False, "hello"), SimpleEnum(SimpleEnumKind.First)) result = self.client.tuple_strukt_nested(t) assert result.result() == t