Skip to content

Commit

Permalink
fix bytes type
Browse files Browse the repository at this point in the history
  • Loading branch information
deanstef committed Jun 16, 2022
1 parent ec1393a commit 0fb5ec8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
21 changes: 11 additions & 10 deletions smart_asa_asc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
BareCallActions,
Bytes,
CallConfig,
Concat,
Expr,
Global,
If,
Expand Down Expand Up @@ -61,10 +62,10 @@
UNDERLYING_ASA_UNIT_NAME = Bytes("S-ASA")
UNDERLYING_ASA_NAME = Bytes("SMART-ASA")
# FIXME
# UNDERLYING_ASA_URL = Concat(
# Bytes("smart-asa-app-id:"), Itob(Global.current_application_id())
# )
UNDERLYING_ASA_URL = Itob(Global.current_application_id())
UNDERLYING_ASA_URL = Concat(
Bytes("smart-asa-app-id:"), Itob(Global.current_application_id())
)
# UNDERLYING_ASA_URL = Itob(Global.current_application_id())
UNDERLYING_ASA_METADATA_HASH = Bytes("")
UNDERLYING_ASA_MANAGER_ADDR = Global.current_application_address()
UNDERLYING_ASA_RESERVE_ADDR = Global.current_application_address()
Expand Down Expand Up @@ -350,7 +351,7 @@ def asset_create(
unit_name: abi.String,
name: abi.String,
url: abi.String,
metadata_hash: abi.String, # FIXME: This was originally Byte in ARC-20
metadata_hash: abi.DynamicArray[abi.Byte],
manager_addr: abi.Address,
reserve_addr: abi.Address,
freeze_addr: abi.Address,
Expand Down Expand Up @@ -381,7 +382,7 @@ def asset_create(
App.globalPut(GlobalState.unit_name, unit_name.get()),
App.globalPut(GlobalState.name, name.get()),
App.globalPut(GlobalState.url, url.get()),
App.globalPut(GlobalState.metadata_hash, metadata_hash.get()),
App.globalPut(GlobalState.metadata_hash, metadata_hash.encode()),
App.globalPut(GlobalState.manager_addr, manager_addr.get()),
App.globalPut(GlobalState.reserve_addr, reserve_addr.get()),
App.globalPut(GlobalState.freeze_addr, freeze_addr.get()),
Expand All @@ -399,7 +400,7 @@ def asset_config(
unit_name: abi.String,
name: abi.String,
url: abi.String,
metadata_hash: abi.String, # FIXME: This was originally Byte in ARC-20
metadata_hash: abi.DynamicArray[abi.Byte],
manager_addr: abi.Address,
reserve_addr: abi.Address,
freeze_addr: abi.Address,
Expand Down Expand Up @@ -451,7 +452,7 @@ def asset_config(
App.globalPut(GlobalState.unit_name, unit_name.get()),
App.globalPut(GlobalState.name, name.get()),
App.globalPut(GlobalState.url, url.get()),
App.globalPut(GlobalState.metadata_hash, metadata_hash.get()),
App.globalPut(GlobalState.metadata_hash, metadata_hash.encode()),
App.globalPut(GlobalState.manager_addr, manager_addr.get()),
App.globalPut(GlobalState.reserve_addr, reserve_addr.get()),
App.globalPut(GlobalState.freeze_addr, freeze_addr.get()),
Expand Down Expand Up @@ -715,13 +716,13 @@ def get_url(asset: abi.Asset, *, output: abi.String) -> Expr:
def get_metadata_hash(
asset: abi.Asset,
*,
output: abi.String, # FIXME: This was originally Byte in ARC-20
output: abi.DynamicArray[abi.Byte],
) -> Expr:
return Seq(
# Preconditions
getter_preconditions(asset.asset_id()),
# Effects
output.set(App.globalGet(GlobalState.metadata_hash)),
output.decode(App.globalGet(GlobalState.metadata_hash)),
)


Expand Down
18 changes: 13 additions & 5 deletions smart_asa_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def smart_asa_create(
unit_name: str = "",
name: str = "",
url: str = "",
metadata_hash: str = "",
metadata_hash: bytes = b"",
manager_addr: Optional[Union[str, Account]] = None,
reserve_addr: Optional[Union[str, Account]] = None,
freeze_addr: Optional[Union[str, Account]] = None,
Expand Down Expand Up @@ -158,7 +158,7 @@ def smart_asa_config(
config_unit_name: Optional[str] = None,
config_name: Optional[str] = None,
config_url: Optional[str] = None,
config_metadata_hash: Optional[str] = None,
config_metadata_hash: Optional[bytes] = None,
config_manager_addr: Optional[Union[str, Account]] = None,
config_reserve_addr: Optional[Union[str, Account]] = None,
config_freeze_addr: Optional[Union[str, Account]] = None,
Expand All @@ -167,6 +167,16 @@ def smart_asa_config(
) -> int:

s_asa = get_smart_asa_params(manager.algod_client, asset_id)
if config_metadata_hash is None:
config_metadata_hash = bytes(
smart_asa_get(
smart_asa_contract=smart_asa_contract,
smart_asa_app=smart_asa_app,
caller=manager,
asset_id=asset_id,
getter="get_metadata_hash",
)
)

if config_manager_addr is None:
config_manager_addr = Account(address=s_asa["manager_addr"])
Expand All @@ -191,9 +201,7 @@ def smart_asa_config(
s_asa["unit_name"] if config_unit_name is None else config_unit_name,
s_asa["name"] if config_name is None else config_name,
s_asa["url"] if config_url is None else config_url,
s_asa["metadata_hash"]
if config_metadata_hash is None
else config_metadata_hash,
config_metadata_hash,
config_manager_addr,
config_reserve_addr,
config_freeze_addr,
Expand Down
19 changes: 11 additions & 8 deletions smart_asa_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def smart_asa_id(
creator=creator,
smart_asa_contract=smart_asa_contract,
total=100,
metadata_hash=b"XYZXYZ",
default_frozen=request.param,
)

Expand Down Expand Up @@ -507,7 +508,7 @@ def test_happy_path(
"unit_name": "NEW_TEST_!!!",
"name": "New Test !!!",
"url": "https://new_test.io",
"metadata_hash": "a" * 32,
"metadata_hash": b"a" * 32,
"total": 0,
"decimals": 100,
"frozen": False,
Expand Down Expand Up @@ -1964,13 +1965,15 @@ def test_happy_path(
print(
f"\n --- Getting 'metadata_hash' param of Smart ASA {smart_asa_app.app_id}..."
)
smart_asa = get_smart_asa_params(creator.algod_client, smart_asa_id)
assert smart_asa["metadata_hash"] == smart_asa_get(
smart_asa_contract=smart_asa_contract,
smart_asa_app=smart_asa_app,
caller=creator,
asset_id=smart_asa_id,
getter="get_metadata_hash",
# smart_asa = get_smart_asa_params(creator.algod_client, smart_asa_id_with_metadata)
assert b"XYZXYZ" == bytes(
smart_asa_get(
smart_asa_contract=smart_asa_contract,
smart_asa_app=smart_asa_app,
caller=creator,
asset_id=smart_asa_id,
getter="get_metadata_hash",
)
)

print(
Expand Down

0 comments on commit 0fb5ec8

Please sign in to comment.