|
| 1 | +"""Tests for spending with Plutus using `transaction build`.""" |
| 2 | + |
| 3 | +import logging |
| 4 | + |
| 5 | +import allure |
| 6 | +import pytest |
| 7 | +from cardano_clusterlib import clusterlib |
| 8 | + |
| 9 | +from cardano_node_tests.cluster_management import cluster_management |
| 10 | +from cardano_node_tests.tests import common |
| 11 | +from cardano_node_tests.tests import plutus_common |
| 12 | +from cardano_node_tests.tests.tests_plutus import spend_build |
| 13 | +from cardano_node_tests.utils import helpers |
| 14 | + |
| 15 | +LOGGER = logging.getLogger(__name__) |
| 16 | + |
| 17 | +pytestmark = [ |
| 18 | + common.SKIPIF_PLUTUSV3_UNUSABLE, |
| 19 | + pytest.mark.plutus, |
| 20 | +] |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture |
| 24 | +def payment_addrs( |
| 25 | + cluster_manager: cluster_management.ClusterManager, |
| 26 | + cluster: clusterlib.ClusterLib, |
| 27 | +) -> list[clusterlib.AddressRecord]: |
| 28 | + """Create new payment addresses.""" |
| 29 | + addrs = common.get_payment_addrs( |
| 30 | + name_template=common.get_test_id(cluster), |
| 31 | + cluster_manager=cluster_manager, |
| 32 | + cluster_obj=cluster, |
| 33 | + num=3, |
| 34 | + fund_idx=[0], |
| 35 | + amount=1_000_000_000, |
| 36 | + ) |
| 37 | + return addrs |
| 38 | + |
| 39 | + |
| 40 | +class TestBuildLocking: |
| 41 | + """Tests for Tx output locking using Plutus smart contracts and `transaction build`.""" |
| 42 | + |
| 43 | + @allure.link(helpers.get_vcs_link()) |
| 44 | + @pytest.mark.smoke |
| 45 | + @pytest.mark.testnets |
| 46 | + @pytest.mark.dbsync |
| 47 | + def test_txout_locking_no_datum( |
| 48 | + self, |
| 49 | + cluster: clusterlib.ClusterLib, |
| 50 | + payment_addrs: list[clusterlib.AddressRecord], |
| 51 | + ): |
| 52 | + """Test locking a Tx output with a Plutus script and spending the locked UTxO. |
| 53 | +
|
| 54 | + No datum is provided. Datum for spending scripts is optional in PlutusV3. |
| 55 | +
|
| 56 | + Uses `cardano-cli transaction build` command for building the transactions. |
| 57 | +
|
| 58 | + * create a Tx output without a datum hash at the script address |
| 59 | + * check that the expected amount was locked at the script address |
| 60 | + * spend the locked UTxO without providing a datum |
| 61 | + * check that the expected amount was spent |
| 62 | + * check expected fees |
| 63 | + * check expected Plutus cost |
| 64 | + * (optional) check transactions in db-sync |
| 65 | + """ |
| 66 | + temp_template = common.get_test_id(cluster) |
| 67 | + |
| 68 | + # No datum is provided |
| 69 | + plutus_op = plutus_common.PlutusOp( |
| 70 | + script_file=plutus_common.ALWAYS_SUCCEEDS["v3"].script_file, |
| 71 | + redeemer_cbor_file=plutus_common.REDEEMER_42_CBOR, |
| 72 | + execution_cost=plutus_common.ALWAYS_SUCCEEDS["v3"].execution_cost, |
| 73 | + ) |
| 74 | + |
| 75 | + script_utxos, collateral_utxos, tx_output_fund = spend_build._build_fund_script( |
| 76 | + temp_template=temp_template, |
| 77 | + cluster_obj=cluster, |
| 78 | + payment_addr=payment_addrs[0], |
| 79 | + dst_addr=payment_addrs[1], |
| 80 | + plutus_op=plutus_op, |
| 81 | + ) |
| 82 | + |
| 83 | + __, tx_output, plutus_costs = spend_build._build_spend_locked_txin( |
| 84 | + temp_template=temp_template, |
| 85 | + cluster_obj=cluster, |
| 86 | + payment_addr=payment_addrs[0], |
| 87 | + dst_addr=payment_addrs[1], |
| 88 | + script_utxos=script_utxos, |
| 89 | + collateral_utxos=collateral_utxos, |
| 90 | + plutus_op=plutus_op, |
| 91 | + amount=2_000_000, |
| 92 | + ) |
| 93 | + |
| 94 | + # Check expected fees |
| 95 | + expected_fee_fund = 168_845 |
| 96 | + assert helpers.is_in_interval(tx_output_fund.fee, expected_fee_fund, frac=0.15) |
| 97 | + |
| 98 | + expected_fee = 170_782 |
| 99 | + assert tx_output and helpers.is_in_interval(tx_output.fee, expected_fee, frac=0.15) |
| 100 | + |
| 101 | + plutus_common.check_plutus_costs( |
| 102 | + plutus_costs=plutus_costs, |
| 103 | + expected_costs=[plutus_common.ALWAYS_SUCCEEDS["v3"].execution_cost], |
| 104 | + ) |
0 commit comments