Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): add test to return collateral with tokens #2685

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading