Skip to content

Commit

Permalink
Merge pull request #61 from multiversx/fix-token-management-flags
Browse files Browse the repository at this point in the history
Fix flags when creating token management transactions
  • Loading branch information
popenta committed Dec 14, 2023
2 parents 50ce30d + 0c8a508 commit 7409dc1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
Expand Up @@ -4,7 +4,7 @@
from typing import List, Protocol

from multiversx_sdk_core.interfaces import IAddress
from multiversx_sdk_core.serializer import arg_to_string, args_to_strings
from multiversx_sdk_core.serializer import arg_to_string
from multiversx_sdk_core.transaction import Transaction
from multiversx_sdk_core.transaction_factories.transaction_builder import \
TransactionBuilder
Expand Down Expand Up @@ -44,6 +44,7 @@ class TokenManagementTransactionsFactory:
def __init__(self, config: IConfig):
self._config = config
self._true_as_hex = arg_to_string("true")
self._false_as_hex = arg_to_string("false")

def create_transaction_for_issuing_fungible(
self,
Expand All @@ -67,12 +68,12 @@ def create_transaction_for_issuing_fungible(
arg_to_string(token_ticker),
arg_to_string(initial_supply),
arg_to_string(num_decimals),
*([arg_to_string("canFreeze"), self._true_as_hex] if can_freeze else []),
*([arg_to_string("canWipe"), self._true_as_hex] if can_wipe else []),
*([arg_to_string("canPause"), self._true_as_hex] if can_pause else []),
*([arg_to_string("canChangeOwner"), self._true_as_hex] if can_change_owner else []),
*(args_to_strings(["canUpgrade", str(can_upgrade).lower()])),
*(args_to_strings(["canAddSpecialRoles", str(can_add_special_roles).lower()]))
*([arg_to_string("canFreeze"), self._true_as_hex if can_freeze else self._false_as_hex]),
*([arg_to_string("canWipe"), self._true_as_hex if can_wipe else self._false_as_hex]),
*([arg_to_string("canPause"), self._true_as_hex if can_pause else self._false_as_hex]),
*([arg_to_string("canChangeOwner"), self._true_as_hex if can_change_owner else self._false_as_hex]),
*([arg_to_string("canUpgrade"), self._true_as_hex if can_upgrade else self._false_as_hex]),
*([arg_to_string("canAddSpecialRoles"), self._true_as_hex if can_add_special_roles else self._false_as_hex])
]

return TransactionBuilder(
Expand Down Expand Up @@ -112,13 +113,13 @@ def create_transaction_for_issuing_semi_fungible(
"issueSemiFungible",
arg_to_string(token_name),
arg_to_string(token_ticker),
*([arg_to_string("canFreeze"), self._true_as_hex] if can_freeze else []),
*([arg_to_string("canWipe"), self._true_as_hex] if can_wipe else []),
*([arg_to_string("canPause"), self._true_as_hex] if can_pause else []),
*([arg_to_string("canTransferNFTCreateRole"), self._true_as_hex] if can_transfer_nft_create_role else []),
*([arg_to_string("canChangeOwner"), self._true_as_hex] if can_change_owner else []),
*(args_to_strings(["canUpgrade", str(can_upgrade).lower()])),
*(args_to_strings(["canAddSpecialRoles", str(can_add_special_roles).lower()]))
*([arg_to_string("canFreeze"), self._true_as_hex if can_freeze else self._false_as_hex]),
*([arg_to_string("canWipe"), self._true_as_hex if can_wipe else self._false_as_hex]),
*([arg_to_string("canPause"), self._true_as_hex if can_pause else self._false_as_hex]),
*([arg_to_string("canTransferNFTCreateRole"), self._true_as_hex if can_transfer_nft_create_role else self._false_as_hex]),
*([arg_to_string("canChangeOwner"), self._true_as_hex if can_change_owner else self._false_as_hex]),
*([arg_to_string("canUpgrade"), self._true_as_hex if can_upgrade else self._false_as_hex]),
*([arg_to_string("canAddSpecialRoles"), self._true_as_hex if can_add_special_roles else self._false_as_hex])
]

return TransactionBuilder(
Expand Down Expand Up @@ -150,13 +151,13 @@ def create_transaction_for_issuing_non_fungible(
"issueNonFungible",
arg_to_string(token_name),
arg_to_string(token_ticker),
*([arg_to_string("canFreeze"), self._true_as_hex] if can_freeze else []),
*([arg_to_string("canWipe"), self._true_as_hex] if can_wipe else []),
*([arg_to_string("canPause"), self._true_as_hex] if can_pause else []),
*([arg_to_string("canTransferNFTCreateRole"), self._true_as_hex] if can_transfer_nft_create_role else []),
*([arg_to_string("canChangeOwner"), self._true_as_hex] if can_change_owner else []),
*(args_to_strings(["canUpgrade", str(can_upgrade).lower()])),
*(args_to_strings(["canAddSpecialRoles", str(can_add_special_roles).lower()]))
*([arg_to_string("canFreeze"), self._true_as_hex if can_freeze else self._false_as_hex]),
*([arg_to_string("canWipe"), self._true_as_hex if can_wipe else self._false_as_hex]),
*([arg_to_string("canPause"), self._true_as_hex if can_pause else self._false_as_hex]),
*([arg_to_string("canTransferNFTCreateRole"), self._true_as_hex if can_transfer_nft_create_role else self._false_as_hex]),
*([arg_to_string("canChangeOwner"), self._true_as_hex if can_change_owner else self._false_as_hex]),
*([arg_to_string("canUpgrade"), self._true_as_hex if can_upgrade else self._false_as_hex]),
*([arg_to_string("canAddSpecialRoles"), self._true_as_hex if can_add_special_roles else self._false_as_hex])
]

return TransactionBuilder(
Expand Down Expand Up @@ -190,13 +191,13 @@ def create_transaction_for_registering_meta_esdt(
arg_to_string(token_name),
arg_to_string(token_ticker),
arg_to_string(num_decimals),
*([arg_to_string("canFreeze"), self._true_as_hex] if can_freeze else []),
*([arg_to_string("canWipe"), self._true_as_hex] if can_wipe else []),
*([arg_to_string("canPause"), self._true_as_hex] if can_pause else []),
*([arg_to_string("canTransferNFTCreateRole"), self._true_as_hex] if can_transfer_nft_create_role else []),
*([arg_to_string("canChangeOwner"), self._true_as_hex] if can_change_owner else []),
*([arg_to_string("canUpgrade"), self._true_as_hex] if can_upgrade else []),
*([arg_to_string("canAddSpecialRoles"), self._true_as_hex] if can_add_special_roles else []),
*([arg_to_string("canFreeze"), self._true_as_hex if can_freeze else self._false_as_hex]),
*([arg_to_string("canWipe"), self._true_as_hex if can_wipe else self._false_as_hex]),
*([arg_to_string("canPause"), self._true_as_hex if can_pause else self._false_as_hex]),
*([arg_to_string("canTransferNFTCreateRole"), self._true_as_hex if can_transfer_nft_create_role else self._false_as_hex]),
*([arg_to_string("canChangeOwner"), self._true_as_hex if can_change_owner else self._false_as_hex]),
*([arg_to_string("canUpgrade"), self._true_as_hex if can_upgrade else self._false_as_hex]),
*([arg_to_string("canAddSpecialRoles"), self._true_as_hex if can_add_special_roles else self._false_as_hex])
]

return TransactionBuilder(
Expand Down
Expand Up @@ -37,12 +37,12 @@ def test_create_transaction_for_issuing_fungible():
can_wipe=True,
can_pause=True,
can_change_owner=True,
can_upgrade=True,
can_add_special_roles=True
can_upgrade=False,
can_add_special_roles=False
)

assert transaction.data
assert transaction.data.decode() == "issue@4652414e4b@4652414e4b@64@@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565"
assert transaction.data.decode() == "issue@4652414e4b@4652414e4b@64@@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365"
assert transaction.sender == frank.to_bech32()
assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"
assert transaction.amount == 50000000000000000
Expand All @@ -58,12 +58,12 @@ def test_create_transaction_for_issuing_semi_fungible():
can_pause=True,
can_transfer_nft_create_role=True,
can_change_owner=True,
can_upgrade=True,
can_add_special_roles=True
can_upgrade=False,
can_add_special_roles=False
)

assert transaction.data
assert transaction.data.decode() == "issueSemiFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565"
assert transaction.data.decode() == "issueSemiFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365"
assert transaction.sender == frank.to_bech32()
assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"
assert transaction.amount == 50000000000000000
Expand All @@ -79,12 +79,12 @@ def test_create_transaction_for_issuing_non_fungible():
can_pause=True,
can_transfer_nft_create_role=True,
can_change_owner=True,
can_upgrade=True,
can_add_special_roles=True
can_upgrade=False,
can_add_special_roles=False
)

assert transaction.data
assert transaction.data.decode() == "issueNonFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565"
assert transaction.data.decode() == "issueNonFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365"
assert transaction.sender == frank.to_bech32()
assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"
assert transaction.amount == 50000000000000000
Expand All @@ -101,12 +101,12 @@ def test_create_transaction_for_registering_meta_esdt():
can_pause=True,
can_transfer_nft_create_role=True,
can_change_owner=True,
can_upgrade=True,
can_add_special_roles=True
can_upgrade=False,
can_add_special_roles=False
)

assert transaction.data
assert transaction.data.decode() == "registerMetaESDT@4652414e4b@4652414e4b@0a@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565"
assert transaction.data.decode() == "registerMetaESDT@4652414e4b@4652414e4b@0a@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365"
assert transaction.sender == frank.to_bech32()
assert transaction.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"
assert transaction.amount == 50000000000000000
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "multiversx-sdk-core"
version = "0.7.3"
version = "0.7.4"
authors = [
{ name="MultiversX" },
]
Expand Down

0 comments on commit 7409dc1

Please sign in to comment.