Skip to content

Commit

Permalink
add extra check and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Oct 25, 2024
1 parent 600892b commit 50a4803
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from enum import Enum
from typing import List, Protocol
from typing import Optional, Protocol

from multiversx_sdk.core.errors import BadUsageError
from multiversx_sdk.core.interfaces import IAddress
Expand Down Expand Up @@ -70,7 +70,7 @@ def create_transaction_for_issuing_fungible(
) -> Transaction:
self._notify_about_unsetting_burn_role_globally()

parts: List[str] = [
parts: list[str] = [
"issue",
arg_to_string(token_name),
arg_to_string(token_ticker),
Expand Down Expand Up @@ -117,7 +117,7 @@ def create_transaction_for_issuing_semi_fungible(
) -> Transaction:
self._notify_about_unsetting_burn_role_globally()

parts: List[str] = [
parts: list[str] = [
"issueSemiFungible",
arg_to_string(token_name),
arg_to_string(token_ticker),
Expand Down Expand Up @@ -155,7 +155,7 @@ def create_transaction_for_issuing_non_fungible(
) -> Transaction:
self._notify_about_unsetting_burn_role_globally()

parts: List[str] = [
parts: list[str] = [
"issueNonFungible",
arg_to_string(token_name),
arg_to_string(token_ticker),
Expand Down Expand Up @@ -194,7 +194,7 @@ def create_transaction_for_registering_meta_esdt(
) -> Transaction:
self._notify_about_unsetting_burn_role_globally()

parts: List[str] = [
parts: list[str] = [
"registerMetaESDT",
arg_to_string(token_name),
arg_to_string(token_ticker),
Expand Down Expand Up @@ -228,7 +228,7 @@ def create_transaction_for_registering_and_setting_roles(
) -> Transaction:
self._notify_about_unsetting_burn_role_globally()

parts: List[str] = [
parts: list[str] = [
"registerAndSetAllRoles",
arg_to_string(token_name),
arg_to_string(token_ticker),
Expand All @@ -251,7 +251,7 @@ def create_transaction_for_setting_burn_role_globally(
sender: IAddress,
token_identifier: str
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"setBurnRoleGlobally",
arg_to_string(token_identifier)
]
Expand All @@ -271,7 +271,7 @@ def create_transaction_for_unsetting_burn_role_globally(
sender: IAddress,
token_identifier: str
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"unsetBurnRoleGlobally",
arg_to_string(token_identifier)
]
Expand All @@ -295,7 +295,7 @@ def create_transaction_for_setting_special_role_on_fungible_token(
add_role_local_burn: bool,
add_role_esdt_transfer_role: bool
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"setSpecialRole",
arg_to_string(token_identifier),
user.to_hex(),
Expand Down Expand Up @@ -323,7 +323,7 @@ def create_transaction_for_unsetting_special_role_on_fungible_token(
remove_role_local_burn: bool,
remove_role_esdt_transfer_role: bool
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"unSetSpecialRole",
arg_to_string(token_identifier),
user.to_hex(),
Expand Down Expand Up @@ -357,7 +357,7 @@ def create_transaction_for_setting_special_role_on_semi_fungible_token(
add_role_esdt_modify_creator: bool = False,
add_role_nft_recreate: bool = False,
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"setSpecialRole",
arg_to_string(token_identifier),
user.to_hex(),
Expand Down Expand Up @@ -396,7 +396,7 @@ def create_transaction_for_unsetting_special_role_on_semi_fungible_token(
remove_role_esdt_modify_creator: bool = False,
remove_role_nft_recreate: bool = False,
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"unSetSpecialRole",
arg_to_string(token_identifier),
user.to_hex(),
Expand Down Expand Up @@ -436,7 +436,7 @@ def create_transaction_for_setting_special_role_on_non_fungible_token(
add_role_esdt_modify_creator: bool = False,
add_role_nft_recreate: bool = False,
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"setSpecialRole",
arg_to_string(token_identifier),
user.to_hex(),
Expand Down Expand Up @@ -477,7 +477,7 @@ def create_transaction_for_unsetting_special_role_on_non_fungible_token(
remove_role_esdt_modify_creator: bool = False,
remove_role_nft_recreate: bool = False,
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"unSetSpecialRole",
arg_to_string(token_identifier),
user.to_hex(),
Expand Down Expand Up @@ -511,12 +511,12 @@ def create_transaction_for_creating_nft(
royalties: int,
hash: str,
attributes: bytes,
uris: List[str]
uris: list[str]
) -> Transaction:
if not uris:
raise BadUsageError("No URIs provided")

parts: List[str] = [
parts: list[str] = [
"ESDTNFTCreate",
arg_to_string(token_identifier),
arg_to_string(initial_quantity),
Expand Down Expand Up @@ -546,7 +546,7 @@ def create_transaction_for_pausing(
sender: IAddress,
token_identifier: str
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"pause",
arg_to_string(token_identifier)
]
Expand All @@ -566,7 +566,7 @@ def create_transaction_for_unpausing(
sender: IAddress,
token_identifier: str
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"unPause",
arg_to_string(token_identifier)
]
Expand All @@ -587,7 +587,7 @@ def create_transaction_for_freezing(
user: IAddress,
token_identifier: str
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"freeze",
arg_to_string(token_identifier),
user.to_hex()
Expand All @@ -609,7 +609,7 @@ def create_transaction_for_unfreezing(
user: IAddress,
token_identifier: str
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"unFreeze",
arg_to_string(token_identifier),
user.to_hex()
Expand All @@ -631,7 +631,7 @@ def create_transaction_for_wiping(
user: IAddress,
token_identifier: str
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"wipe",
arg_to_string(token_identifier),
user.to_hex()
Expand All @@ -653,7 +653,7 @@ def create_transaction_for_local_minting(
token_identifier: str,
supply_to_mint: int
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"ESDTLocalMint",
arg_to_string(token_identifier),
arg_to_string(supply_to_mint)
Expand All @@ -675,7 +675,7 @@ def create_transaction_for_local_burning(
token_identifier: str,
supply_to_burn: int
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"ESDTLocalBurn",
arg_to_string(token_identifier),
arg_to_string(supply_to_burn)
Expand All @@ -698,7 +698,7 @@ def create_transaction_for_updating_attributes(
token_nonce: int,
attributes: bytes
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"ESDTNFTUpdateAttributes",
arg_to_string(token_identifier),
arg_to_string(token_nonce),
Expand All @@ -722,7 +722,7 @@ def create_transaction_for_adding_quantity(
token_nonce: int,
quantity_to_add: int
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"ESDTNFTAddQuantity",
arg_to_string(token_identifier),
arg_to_string(token_nonce),
Expand All @@ -746,7 +746,7 @@ def create_transaction_for_burning_quantity(
token_nonce: int,
quantity_to_burn: int
) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"ESDTNFTBurn",
arg_to_string(token_identifier),
arg_to_string(token_nonce),
Expand All @@ -768,7 +768,7 @@ def create_transaction_for_modifying_royalties(self,
token_identifier: str,
token_nonce: int,
new_royalties: int) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"ESDTModifyRoyalties",
arg_to_string(token_identifier),
arg_to_string(token_nonce),
Expand All @@ -789,11 +789,11 @@ def create_transaction_for_setting_new_uris(self,
sender: IAddress,
token_identifier: str,
token_nonce: int,
new_uris: List[str]) -> Transaction:
new_uris: list[str]) -> Transaction:
if not new_uris:
raise BadUsageError("No URIs provided")

parts: List[str] = [
parts: list[str] = [
"ESDTSetNewURIs",
arg_to_string(token_identifier),
arg_to_string(token_nonce),
Expand All @@ -814,7 +814,7 @@ def create_transaction_for_modifying_creator(self,
sender: IAddress,
token_identifier: str,
token_nonce: int) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"ESDTModifyCreator",
arg_to_string(token_identifier),
arg_to_string(token_nonce)
Expand All @@ -838,8 +838,8 @@ def create_transaction_for_updating_metadata(self,
new_royalties: int,
new_hash: str,
new_attributes: bytes,
new_uris: List[str]) -> Transaction:
parts: List[str] = [
new_uris: list[str]) -> Transaction:
parts: list[str] = [
"ESDTMetaDataUpdate",
arg_to_string(token_identifier),
arg_to_string(token_nonce),
Expand Down Expand Up @@ -868,8 +868,8 @@ def create_transaction_for_nft_metadata_recreate(self,
new_royalties: int,
new_hash: str,
new_attributes: bytes,
new_uris: List[str]) -> Transaction:
parts: List[str] = [
new_uris: list[str]) -> Transaction:
parts: list[str] = [
"ESDTMetaDataRecreate",
arg_to_string(token_identifier),
arg_to_string(token_nonce),
Expand All @@ -893,7 +893,7 @@ def create_transaction_for_nft_metadata_recreate(self,
def create_transaction_for_changing_token_to_dynamic(self,
sender: IAddress,
token_identifier: str) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"changeToDynamic",
arg_to_string(token_identifier)
]
Expand All @@ -911,7 +911,7 @@ def create_transaction_for_changing_token_to_dynamic(self,
def create_transaction_for_updating_token_id(self,
sender: IAddress,
token_identifier: str) -> Transaction:
parts: List[str] = [
parts: list[str] = [
"updateTokenID",
arg_to_string(token_identifier)
]
Expand All @@ -931,8 +931,11 @@ def create_transaction_for_registering_dynamic_token(self,
token_name: str,
token_ticker: str,
token_type: TokenType,
denominator: int = None) -> Transaction:
parts: List[str] = [
denominator: Optional[int] = None) -> Transaction:
if token_type == TokenType.FNG:
raise Exception("Cannot register fungible token as dynamic")

parts: list[str] = [
"registerDynamic",
arg_to_string(token_name),
arg_to_string(token_ticker),
Expand All @@ -957,8 +960,11 @@ def create_transaction_for_registering_dynamic_and_setting_roles(self,
token_name: str,
token_ticker: str,
token_type: TokenType,
denominator: int = None) -> Transaction:
parts: List[str] = [
denominator: Optional[int] = None) -> Transaction:
if token_type == TokenType.FNG:
raise Exception("Cannot register fungible token as dynamic")

parts: list[str] = [
"registerAndSetAllRolesDynamic",
arg_to_string(token_name),
arg_to_string(token_ticker),
Expand Down
Loading

0 comments on commit 50a4803

Please sign in to comment.