python: fix encoding errors in Stellar

pull/889/head
Michail Brynard 4 years ago committed by matejcik
parent b56a16d483
commit c2635a4773

@ -113,7 +113,7 @@ def parse_transaction_bytes(tx_bytes):
# text
if tx.memo_type == MEMO_TYPE_TEXT:
tx.memo_text = unpacker.unpack_string()
tx.memo_text = unpacker.unpack_string().decode()
# id (64-bit uint)
if tx.memo_type == MEMO_TYPE_ID:
tx.memo_id = unpacker.unpack_uhyper()
@ -229,7 +229,7 @@ def _parse_operation_bytes(unpacker):
# home domain
if unpacker.unpack_bool():
op.home_domain = unpacker.unpack_string()
op.home_domain = unpacker.unpack_string().decode()
# signer
if unpacker.unpack_bool():
@ -254,9 +254,9 @@ def _parse_operation_bytes(unpacker):
)
if op.asset_type == ASSET_TYPE_ALPHA4:
op.asset_code = unpacker.unpack_fstring(4)
op.asset_code = unpacker.unpack_fstring(4).decode()
if op.asset_type == ASSET_TYPE_ALPHA12:
op.asset_code = unpacker.unpack_fstring(12)
op.asset_code = unpacker.unpack_fstring(12).decode()
op.is_authorized = unpacker.unpack_bool()
@ -272,7 +272,7 @@ def _parse_operation_bytes(unpacker):
if type == OP_MANAGE_DATA:
op = messages.StellarManageDataOp(
source_account=source_account, key=unpacker.unpack_string()
source_account=source_account, key=unpacker.unpack_string().decode()
)
# Only set value if the field is present
@ -296,11 +296,11 @@ def _xdr_read_asset(unpacker):
asset = messages.StellarAssetType(type=unpacker.unpack_uint())
if asset.type == ASSET_TYPE_ALPHA4:
asset.code = unpacker.unpack_fstring(4)
asset.code = unpacker.unpack_fstring(4).decode()
asset.issuer = _xdr_read_address(unpacker)
if asset.type == ASSET_TYPE_ALPHA12:
asset.code = unpacker.unpack_fstring(12)
asset.code = unpacker.unpack_fstring(12).decode()
asset.issuer = _xdr_read_address(unpacker)
return asset

@ -51,7 +51,7 @@ def test_stellar_parse_transaction_bytes_memo_text():
assert tx.timebounds_start is None
assert tx.timebounds_end is None
assert tx.memo_type == stellar.MEMO_TYPE_TEXT
assert tx.memo_text == b"example memo"
assert tx.memo_text == "example memo"
assert tx.memo_id is None
assert tx.memo_hash is None
assert tx.num_operations == len(operations)
@ -162,7 +162,7 @@ def test_stellar_parse_operation_bytes_payment_custom4():
== "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
)
assert op.asset.type == stellar.ASSET_TYPE_ALPHA4
assert op.asset.code == b"TEST"
assert op.asset.code == "TEST"
assert op.asset.issuer == "GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC"
assert op.amount == 500111000
@ -181,7 +181,7 @@ def test_stellar_parse_operation_bytes_payment_custom7():
)
assert op.asset.type == stellar.ASSET_TYPE_ALPHA12
# asset codes are either 4 or 12 characters, so this will be null-padded at the end
assert op.asset.code == b"SEVENXX\x00\x00\x00\x00\x00"
assert op.asset.code == "SEVENXX\x00\x00\x00\x00\x00"
assert op.asset.issuer == "GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC"
assert op.amount == 500111000
@ -208,7 +208,7 @@ def test_stellar_parse_operation_bytes_path_payment_none():
)
assert op.destination_asset.type == stellar.ASSET_TYPE_ALPHA4
# asset codes are either 4 or 12 characters, so this will be null-padded at the end
assert op.destination_asset.code == b"JPY\x00"
assert op.destination_asset.code == "JPY\x00"
assert (
op.destination_asset.issuer
== "GDCPWFVXCG65ZS6OKZE5VIGCOUWQXJIDYKYLRVMAYA3OBKT3ZPDMNTIJ"
@ -239,7 +239,7 @@ def test_stellar_parse_operation_bytes_path_payment_one():
)
assert op.destination_asset.type == stellar.ASSET_TYPE_ALPHA4
# asset codes are either 4 or 12 characters, so this will be null-padded at the end
assert op.destination_asset.code == b"JPY\x00"
assert op.destination_asset.code == "JPY\x00"
assert (
op.destination_asset.issuer
== "GDCPWFVXCG65ZS6OKZE5VIGCOUWQXJIDYKYLRVMAYA3OBKT3ZPDMNTIJ"
@ -248,7 +248,7 @@ def test_stellar_parse_operation_bytes_path_payment_one():
assert len(op.paths) == 1
assert op.paths[0].type == stellar.ASSET_TYPE_ALPHA4
assert op.paths[0].code == b"PTH1"
assert op.paths[0].code == "PTH1"
assert (
op.paths[0].issuer == "GDGP656XZHPLCYT5XFYN4NH3WELG77EWXZ7KFX5BX77WRNSQIUEJXAJK"
)
@ -267,7 +267,7 @@ def test_stellar_parse_operation_bytes_manage_offer_new():
assert op.buying_asset.type == stellar.ASSET_TYPE_ALPHA4
# asset codes are either 4 or 12 characters, so this will be null-padded at the end
assert op.buying_asset.code == b"USD\x00"
assert op.buying_asset.code == "USD\x00"
assert (
op.buying_asset.issuer
== "GADEAA7R7K2HPZXIPQGUWCNLKQXUOQSMS6YZ6JQYO6DDLAQZZVIXG74A"
@ -292,7 +292,7 @@ def test_stellar_parse_operation_bytes_passive_offer_new():
assert op.buying_asset.type == stellar.ASSET_TYPE_ALPHA4
# asset codes are either 4 or 12 characters, so this will be null-padded at the end
assert op.buying_asset.code == b"USD\x00"
assert op.buying_asset.code == "USD\x00"
assert (
op.buying_asset.issuer
== "GADEAA7R7K2HPZXIPQGUWCNLKQXUOQSMS6YZ6JQYO6DDLAQZZVIXG74A"
@ -328,7 +328,7 @@ def test_stellar_parse_operation_bytes_change_trust_add():
assert op.source_account is None
assert op.asset.type == stellar.ASSET_TYPE_ALPHA4
assert op.asset.code == b"USD\x00"
assert op.asset.code == "USD\x00"
assert op.asset.issuer == "GCSJ7MFIIGIRMAS4R3VT5FIFIAOXNMGDI5HPYTWS5X7HH74FSJ6STSGF"
assert op.limit == 10000000000
@ -344,7 +344,7 @@ def test_stellar_parse_operation_bytes_allow_trust_allow():
assert op.source_account is None
assert op.asset_type == stellar.ASSET_TYPE_ALPHA4
assert op.asset_code == b"JPY\x00"
assert op.asset_code == "JPY\x00"
assert (
op.trusted_account == "GBTUGHW45HYSG23ONAXSVN66KMOF2X5YDY3KQBCTTT62RISCLKSQLYF4"
@ -375,7 +375,7 @@ def test_stellar_parse_operation_bytes_manage_data_set_simple():
assert isinstance(op, messages.StellarManageDataOp)
assert op.source_account is None
assert op.key == b"test data"
assert op.key == "test data"
assert op.value == b"asdf"

Loading…
Cancel
Save