Skip to content

Commit

Permalink
Merge pull request #2685 from IntersectMBO/return_tokens_collateral
Browse files Browse the repository at this point in the history
feat(tests): add test to return collateral with tokens
  • Loading branch information
mkoura authored Oct 22, 2024
2 parents 122eb2a + 3377857 commit 7e75ca9
Showing 1 changed file with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import allure
import pytest
from cardano_clusterlib import clusterlib
from packaging import version

from cardano_node_tests.cluster_management import cluster_management
from cardano_node_tests.tests import common
Expand Down Expand Up @@ -232,11 +233,28 @@ def test_with_total_return_collateral(
tx_view.check_tx_view(cluster_obj=cluster, tx_raw_output=tx_output_redeem)

@allure.link(helpers.get_vcs_link())
@pytest.mark.parametrize(
"use_return_collateral",
(
True,
pytest.param(
False,
marks=pytest.mark.skipif(
VERSIONS.cli < version.parse("10.0.0.0"),
reason="not supported in cardano-cli < 10.0.0.0",
),
),
),
ids=("using_return_collateral", "without_return_collateral"),
)
@pytest.mark.smoke
@pytest.mark.testnets
@pytest.mark.dbsync
def test_collateral_with_tokens(
self, cluster: clusterlib.ClusterLib, payment_addrs: tp.List[clusterlib.AddressRecord]
self,
cluster: clusterlib.ClusterLib,
payment_addrs: tp.List[clusterlib.AddressRecord],
use_return_collateral: bool,
):
"""Test failing script using collaterals with tokens.
Expand All @@ -256,14 +274,20 @@ def test_collateral_with_tokens(
assert plutus_op.datum_file
assert plutus_op.redeemer_cbor_file

redeem_cost = plutus_common.compute_cost(
execution_cost=plutus_op.execution_cost,
protocol_params=cluster.g_query.get_protocol_params(),
)

token_amount = 100
amount_for_collateral = redeem_cost.collateral * 4
return_collateral_amount = amount_for_collateral - redeem_cost.collateral

if use_return_collateral:
redeem_cost = plutus_common.compute_cost(
execution_cost=plutus_op.execution_cost,
protocol_params=cluster.g_query.get_protocol_params(),
)
total_collateral_amount = redeem_cost.collateral
amount_for_collateral = total_collateral_amount * 4
return_collateral_amount = amount_for_collateral - total_collateral_amount
else:
total_collateral_amount = None
amount_for_collateral = None
return_collateral_amount = 0

# Create the token
token_rand = clusterlib.get_rand_str(5)
Expand Down Expand Up @@ -291,15 +315,19 @@ def test_collateral_with_tokens(

# Spend the "locked" UTxO

txouts_return_collateral = [
clusterlib.TxOut(
address=dst_addr.address,
amount=return_collateral_amount,
),
clusterlib.TxOut(
address=dst_addr.address, amount=token_amount, coin=tokens_rec[0].coin
),
]
txouts_return_collateral = (
[
clusterlib.TxOut(
address=dst_addr.address,
amount=return_collateral_amount,
),
clusterlib.TxOut(
address=dst_addr.address, amount=token_amount, coin=tokens_rec[0].coin
),
]
if return_collateral_amount
else []
)

try:
tx_output_redeem = self._build_spend_locked_txin(
Expand All @@ -310,7 +338,7 @@ def test_collateral_with_tokens(
script_utxos=script_utxos,
collateral_utxos=collateral_utxos,
plutus_op=plutus_op,
total_collateral_amount=redeem_cost.collateral,
total_collateral_amount=total_collateral_amount,
return_collateral_txouts=txouts_return_collateral,
)
except clusterlib.CLIError as exc:
Expand Down

0 comments on commit 7e75ca9

Please sign in to comment.