Skip to content

Commit

Permalink
Merge pull request #81 from multiversx/token-transfer-tx-for-notarizing
Browse files Browse the repository at this point in the history
Added support for notarizing transactions for token transfer factory
  • Loading branch information
popenta authored Jul 9, 2024
2 parents 5af44f9 + d81bee2 commit 28dea03
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ def create_transaction_for_transfer(self,
native_amount: Optional[int] = None,
token_transfers: Optional[Sequence[ITokenTransfer]] = None,
data: Optional[bytes] = None) -> Transaction:
if not native_amount and not token_transfers:
raise BadUsageError("No native token amount or token transfers provided")

if token_transfers and data:
raise BadUsageError("Can't set data field when sending esdt tokens")

if native_amount and not token_transfers:
if (native_amount and not token_transfers) or data:
native_amount = native_amount if native_amount else 0
return self.create_transaction_for_native_token_transfer(
sender=sender,
receiver=receiver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ def test_create_transaction_for_multiple_nft_transfers(self):
assert transaction.data.decode() == "MultiESDTNFTTransfer@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@02@4e46542d313233343536@0a@01@544553542d393837363534@01@01"
assert transaction.gas_limit == 1_466_000

def test_create_transaction_for_token_transfer_with_errors(self):
with pytest.raises(BadUsageError, match="No native token amount or token transfers provided"):
self.transfer_factory.create_transaction_for_transfer(
sender=self.alice,
receiver=self.bob
)
second_transaction = self.transfer_factory.create_transaction_for_transfer(
sender=self.alice,
receiver=self.bob,
token_transfers=[first_transfer, second_transfer]
)
assert second_transaction == transaction

def test_create_transaction_for_token_transfer_with_errors(self):
with pytest.raises(BadUsageError, match="Can't set data field when sending esdt tokens"):
nft = Token("NFT-123456", 10)
transfer = TokenTransfer(nft, 1)
Expand All @@ -115,6 +116,46 @@ def test_create_transaction_for_token_transfer_with_errors(self):
data="hello".encode()
)

def test_create_transaction_for_native_transfer(self):
transaction = self.transfer_factory.create_transaction_for_transfer(
sender=self.alice,
receiver=self.bob,
native_amount=1000000000000000000,
)

assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"
assert transaction.receiver == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"
assert transaction.value == 1000000000000000000
assert transaction.chain_id == "D"
assert transaction.gas_limit == 50_000

def test_create_transaction_for_native_transfer_and_set_data_field(self):
transaction = self.transfer_factory.create_transaction_for_transfer(
sender=self.alice,
receiver=self.bob,
native_amount=1000000000000000000,
data="hello".encode()
)

assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"
assert transaction.receiver == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"
assert transaction.value == 1000000000000000000
assert transaction.chain_id == "D"
assert transaction.gas_limit == 57_500

def test_create_transaction_for_notarizing(self):
transaction = self.transfer_factory.create_transaction_for_transfer(
sender=self.alice,
receiver=self.bob,
data="hello".encode()
)

assert transaction.sender == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"
assert transaction.receiver == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"
assert transaction.value == 0
assert transaction.chain_id == "D"
assert transaction.gas_limit == 57_500

def test_create_transaction_for_token_transfer(self):
first_nft = Token("NFT-123456", 10)
first_transfer = TokenTransfer(first_nft, 1)
Expand Down

0 comments on commit 28dea03

Please sign in to comment.