Skip to content

Commit

Permalink
Merge pull request #2021 from input-output-hk/submit_api_plutusv1_min…
Browse files Browse the repository at this point in the history
…t_build

Add submit API support to PlutusV1 mint build tests
  • Loading branch information
mkoura authored Nov 9, 2023
2 parents 16faf6d + 95c5274 commit f8162b8
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 12 deletions.
10 changes: 9 additions & 1 deletion cardano_node_tests/tests/tests_plutus/mint_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cardano_node_tests.tests import plutus_common
from cardano_node_tests.utils import clusterlib_utils
from cardano_node_tests.utils import submit_utils

LOGGER = logging.getLogger(__name__)

Expand All @@ -17,6 +18,7 @@ def _fund_issuer(
minting_cost: plutus_common.ScriptCost,
amount: int,
collateral_utxo_num: int = 1,
submit_method: str = submit_utils.SubmitMethods.CLI,
) -> tp.Tuple[tp.List[clusterlib.UTXOData], tp.List[clusterlib.UTXOData], clusterlib.TxRawOutput]:
"""Fund the token issuer."""
single_collateral_amount = minting_cost.collateral // collateral_utxo_num
Expand Down Expand Up @@ -50,7 +52,13 @@ def _fund_issuer(
signing_key_files=tx_files.signing_key_files,
tx_name=f"{temp_template}_step1",
)
cluster_obj.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_output.txins)

submit_utils.submit_tx(
submit_method=submit_method,
cluster_obj=cluster_obj,
tx_file=tx_signed,
txins=tx_output.txins,
)

issuer_balance = cluster_obj.g_query.get_address_balance(issuer_addr.address)
assert (
Expand Down
80 changes: 71 additions & 9 deletions cardano_node_tests/tests/tests_plutus/test_mint_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from cardano_node_tests.utils import clusterlib_utils
from cardano_node_tests.utils import dbsync_utils
from cardano_node_tests.utils import helpers
from cardano_node_tests.utils import submit_utils
from cardano_node_tests.utils import tx_view
from cardano_node_tests.utils.versions import VERSIONS

Expand Down Expand Up @@ -98,12 +99,14 @@ def past_horizon_funds(
@allure.link(helpers.get_vcs_link())
@pytest.mark.dbsync
@pytest.mark.testnets
@submit_utils.PARAM_SUBMIT_METHOD
@common.PARAM_PLUTUS_VERSION
def test_minting_one_token(
self,
cluster: clusterlib.ClusterLib,
payment_addrs: tp.List[clusterlib.AddressRecord],
plutus_version: str,
submit_method: str,
):
"""Test minting a token with a Plutus script.
Expand Down Expand Up @@ -146,6 +149,7 @@ def test_minting_one_token(
minting_cost=minting_cost,
amount=script_fund,
collateral_utxo_num=2,
submit_method=submit_method,
)

# Step 2: mint the "qacoin"
Expand Down Expand Up @@ -194,7 +198,13 @@ def test_minting_one_token(
signing_key_files=tx_files_step2.signing_key_files,
tx_name=f"{temp_template}_step2",
)
cluster.g_transaction.submit_tx(tx_file=tx_signed_step2, txins=mint_utxos)

submit_utils.submit_tx(
submit_method=submit_method,
cluster_obj=cluster,
tx_file=tx_signed_step2,
txins=mint_utxos,
)

assert (
cluster.g_query.get_address_balance(issuer_addr.address)
Expand Down Expand Up @@ -230,8 +240,12 @@ def test_minting_one_token(
@allure.link(helpers.get_vcs_link())
@pytest.mark.dbsync
@pytest.mark.testnets
@submit_utils.PARAM_SUBMIT_METHOD
def test_time_range_minting(
self, cluster: clusterlib.ClusterLib, payment_addrs: tp.List[clusterlib.AddressRecord]
self,
cluster: clusterlib.ClusterLib,
payment_addrs: tp.List[clusterlib.AddressRecord],
submit_method: str,
):
"""Test minting a token with a time constraints Plutus script.
Expand Down Expand Up @@ -270,6 +284,7 @@ def test_time_range_minting(
issuer_addr=issuer_addr,
minting_cost=minting_cost,
amount=script_fund,
submit_method=submit_method,
)

# Step 2: mint the "qacoin"
Expand Down Expand Up @@ -329,7 +344,13 @@ def test_time_range_minting(
signing_key_files=tx_files_step2.signing_key_files,
tx_name=f"{temp_template}_step2",
)
cluster.g_transaction.submit_tx(tx_file=tx_signed_step2, txins=mint_utxos)

submit_utils.submit_tx(
submit_method=submit_method,
cluster_obj=cluster,
tx_file=tx_signed_step2,
txins=mint_utxos,
)

assert (
cluster.g_query.get_address_balance(issuer_addr.address)
Expand Down Expand Up @@ -365,6 +386,7 @@ def test_time_range_minting(
@allure.link(helpers.get_vcs_link())
@pytest.mark.dbsync
@pytest.mark.testnets
@submit_utils.PARAM_SUBMIT_METHOD
@pytest.mark.parametrize(
"plutus_version",
(
Expand All @@ -377,6 +399,7 @@ def test_two_scripts_minting(
cluster: clusterlib.ClusterLib,
payment_addrs: tp.List[clusterlib.AddressRecord],
plutus_version: str,
submit_method: str,
):
"""Test minting two tokens with two different Plutus scripts.
Expand Down Expand Up @@ -461,7 +484,13 @@ def test_two_scripts_minting(
signing_key_files=tx_files_step1.signing_key_files,
tx_name=f"{temp_template}_step1",
)
cluster.g_transaction.submit_tx(tx_file=tx_signed_step1, txins=tx_output_step1.txins)

submit_utils.submit_tx(
submit_method=submit_method,
cluster_obj=cluster,
tx_file=tx_signed_step1,
txins=tx_output_step1.txins,
)

out_utxos_step1 = cluster.g_query.get_utxo(tx_raw_output=tx_output_step1)

Expand Down Expand Up @@ -562,7 +591,13 @@ def test_two_scripts_minting(
signing_key_files=tx_files_step2.signing_key_files,
tx_name=f"{temp_template}_step2",
)
cluster.g_transaction.submit_tx(tx_file=tx_signed_step2, txins=mint_utxos)

submit_utils.submit_tx(
submit_method=submit_method,
cluster_obj=cluster,
tx_file=tx_signed_step2,
txins=mint_utxos,
)

out_utxos_step2 = cluster.g_query.get_utxo(tx_raw_output=tx_output_step2)

Expand Down Expand Up @@ -613,8 +648,12 @@ def test_two_scripts_minting(
)
@pytest.mark.dbsync
@pytest.mark.testnets
@submit_utils.PARAM_SUBMIT_METHOD
def test_minting_context_equivalence(
self, cluster: clusterlib.ClusterLib, payment_addrs: tp.List[clusterlib.AddressRecord]
self,
cluster: clusterlib.ClusterLib,
payment_addrs: tp.List[clusterlib.AddressRecord],
submit_method: str,
):
"""Test context equivalence while minting a token.
Expand Down Expand Up @@ -654,6 +693,7 @@ def test_minting_context_equivalence(
issuer_addr=issuer_addr,
minting_cost=minting_cost,
amount=script_fund,
submit_method=submit_method,
)

# Step 2: mint the "qacoin"
Expand Down Expand Up @@ -753,7 +793,13 @@ def test_minting_context_equivalence(
signing_key_files=tx_files_step2.signing_key_files,
tx_name=f"{temp_template}_step2",
)
cluster.g_transaction.submit_tx(tx_file=tx_signed_step2, txins=mint_utxos)

submit_utils.submit_tx(
submit_method=submit_method,
cluster_obj=cluster,
tx_file=tx_signed_step2,
txins=mint_utxos,
)

assert (
cluster.g_query.get_address_balance(issuer_addr.address)
Expand Down Expand Up @@ -789,6 +835,7 @@ def test_minting_context_equivalence(
@allure.link(helpers.get_vcs_link())
@pytest.mark.dbsync
@pytest.mark.testnets
@submit_utils.PARAM_SUBMIT_METHOD
@pytest.mark.parametrize(
"key",
(
Expand All @@ -801,6 +848,7 @@ def test_witness_redeemer(
cluster: clusterlib.ClusterLib,
payment_addrs: tp.List[clusterlib.AddressRecord],
key: str,
submit_method: str,
):
"""Test minting a token with a Plutus script.
Expand Down Expand Up @@ -847,6 +895,7 @@ def test_witness_redeemer(
issuer_addr=issuer_addr,
minting_cost=minting_cost,
amount=script_fund,
submit_method=submit_method,
)

# Step 2: mint the "qacoin"
Expand Down Expand Up @@ -905,7 +954,13 @@ def test_witness_redeemer(
signing_key_files=[signing_key_golden],
tx_name=f"{temp_template}_step2_sign1",
)
cluster.g_transaction.submit_tx(tx_file=tx_signed_step2_inc, txins=mint_utxos)

submit_utils.submit_tx(
submit_method=submit_method,
cluster_obj=cluster,
tx_file=tx_signed_step2_inc,
txins=mint_utxos,
)

assert (
cluster.g_query.get_address_balance(issuer_addr.address)
Expand Down Expand Up @@ -1062,12 +1117,14 @@ class TestCollateralOutput:
"""Tests for collateral output."""

@allure.link(helpers.get_vcs_link())
@submit_utils.PARAM_SUBMIT_METHOD
@common.PARAM_PLUTUS_VERSION
def test_duplicated_collateral(
self,
cluster: clusterlib.ClusterLib,
payment_addrs: tp.List[clusterlib.AddressRecord],
plutus_version: str,
submit_method: str,
):
"""Test minting a token with a Plutus script while using the same collateral input twice.
Expand Down Expand Up @@ -1166,7 +1223,12 @@ def test_duplicated_collateral(
)

try:
cluster.g_transaction.submit_tx(tx_file=tx_signed_step2, txins=mint_utxos)
submit_utils.submit_tx(
submit_method=submit_method,
cluster_obj=cluster,
tx_file=tx_signed_step2,
txins=mint_utxos,
)
except clusterlib.CLIError as exc:
if "IncorrectTotalCollateralField" not in str(exc):
raise
Expand Down
13 changes: 11 additions & 2 deletions cardano_node_tests/tests/tests_plutus/test_mint_negative_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from cardano_node_tests.tests.tests_plutus.mint_build import _fund_issuer
from cardano_node_tests.utils import clusterlib_utils
from cardano_node_tests.utils import helpers
from cardano_node_tests.utils import submit_api
from cardano_node_tests.utils import submit_utils

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -86,10 +88,12 @@ def fund_issuer_long_asset_name(

@allure.link(helpers.get_vcs_link())
@pytest.mark.testnets
@submit_utils.PARAM_SUBMIT_METHOD
def test_witness_redeemer_missing_signer(
self,
cluster: clusterlib.ClusterLib,
payment_addrs: tp.List[clusterlib.AddressRecord],
submit_method: str,
):
"""Test minting a token with a Plutus script with invalid signers.
Expand Down Expand Up @@ -167,8 +171,13 @@ def test_witness_redeemer_missing_signer(
signing_key_files=tx_files_step2.signing_key_files,
tx_name=f"{temp_template}_step2",
)
with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_transaction.submit_tx(tx_file=tx_signed_step2, txins=mint_utxos)
with pytest.raises((clusterlib.CLIError, submit_api.SubmitApiError)) as excinfo:
submit_utils.submit_tx(
submit_method=submit_method,
cluster_obj=cluster,
tx_file=tx_signed_step2,
txins=mint_utxos,
)
assert "MissingRequiredSigners" in str(excinfo.value)

@allure.link(helpers.get_vcs_link())
Expand Down

0 comments on commit f8162b8

Please sign in to comment.