forked from IntersectMBO/cardano-node-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request IntersectMBO#2876 from IntersectMBO/plutusv3_no_datum
feat(tests): add PlutusV3 test for spending without datum
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import logging | ||
|
||
import pytest | ||
from cardano_clusterlib import clusterlib | ||
|
||
from cardano_node_tests.cluster_management import cluster_management | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.fixture | ||
def cluster( | ||
cluster_manager: cluster_management.ClusterManager, | ||
) -> clusterlib.ClusterLib: | ||
"""Return instance of `clusterlib.ClusterLib`.""" | ||
return cluster_manager.get(use_resources=[cluster_management.Resources.PLUTUS]) |
104 changes: 104 additions & 0 deletions
104
cardano_node_tests/tests/tests_plutus_v3/test_spend_build.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
"""Tests for spending with Plutus using `transaction build`.""" | ||
|
||
import logging | ||
|
||
import allure | ||
import pytest | ||
from cardano_clusterlib import clusterlib | ||
|
||
from cardano_node_tests.cluster_management import cluster_management | ||
from cardano_node_tests.tests import common | ||
from cardano_node_tests.tests import plutus_common | ||
from cardano_node_tests.tests.tests_plutus import spend_build | ||
from cardano_node_tests.utils import helpers | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
pytestmark = [ | ||
common.SKIPIF_PLUTUSV3_UNUSABLE, | ||
pytest.mark.plutus, | ||
] | ||
|
||
|
||
@pytest.fixture | ||
def payment_addrs( | ||
cluster_manager: cluster_management.ClusterManager, | ||
cluster: clusterlib.ClusterLib, | ||
) -> list[clusterlib.AddressRecord]: | ||
"""Create new payment addresses.""" | ||
addrs = common.get_payment_addrs( | ||
name_template=common.get_test_id(cluster), | ||
cluster_manager=cluster_manager, | ||
cluster_obj=cluster, | ||
num=3, | ||
fund_idx=[0], | ||
amount=1_000_000_000, | ||
) | ||
return addrs | ||
|
||
|
||
class TestBuildLocking: | ||
"""Tests for Tx output locking using Plutus smart contracts and `transaction build`.""" | ||
|
||
@allure.link(helpers.get_vcs_link()) | ||
@pytest.mark.smoke | ||
@pytest.mark.testnets | ||
@pytest.mark.dbsync | ||
def test_txout_locking_no_datum( | ||
self, | ||
cluster: clusterlib.ClusterLib, | ||
payment_addrs: list[clusterlib.AddressRecord], | ||
): | ||
"""Test locking a Tx output with a Plutus script and spending the locked UTxO. | ||
No datum is provided. Datum for spending scripts is optional in PlutusV3. | ||
Uses `cardano-cli transaction build` command for building the transactions. | ||
* create a Tx output without a datum hash at the script address | ||
* check that the expected amount was locked at the script address | ||
* spend the locked UTxO without providing a datum | ||
* check that the expected amount was spent | ||
* check expected fees | ||
* check expected Plutus cost | ||
* (optional) check transactions in db-sync | ||
""" | ||
temp_template = common.get_test_id(cluster) | ||
|
||
# No datum is provided | ||
plutus_op = plutus_common.PlutusOp( | ||
script_file=plutus_common.ALWAYS_SUCCEEDS["v3"].script_file, | ||
redeemer_cbor_file=plutus_common.REDEEMER_42_CBOR, | ||
execution_cost=plutus_common.ALWAYS_SUCCEEDS["v3"].execution_cost, | ||
) | ||
|
||
script_utxos, collateral_utxos, tx_output_fund = spend_build._build_fund_script( | ||
temp_template=temp_template, | ||
cluster_obj=cluster, | ||
payment_addr=payment_addrs[0], | ||
dst_addr=payment_addrs[1], | ||
plutus_op=plutus_op, | ||
) | ||
|
||
__, tx_output, plutus_costs = spend_build._build_spend_locked_txin( | ||
temp_template=temp_template, | ||
cluster_obj=cluster, | ||
payment_addr=payment_addrs[0], | ||
dst_addr=payment_addrs[1], | ||
script_utxos=script_utxos, | ||
collateral_utxos=collateral_utxos, | ||
plutus_op=plutus_op, | ||
amount=2_000_000, | ||
) | ||
|
||
# Check expected fees | ||
expected_fee_fund = 168_845 | ||
assert helpers.is_in_interval(tx_output_fund.fee, expected_fee_fund, frac=0.15) | ||
|
||
expected_fee = 170_782 | ||
assert tx_output and helpers.is_in_interval(tx_output.fee, expected_fee, frac=0.15) | ||
|
||
plutus_common.check_plutus_costs( | ||
plutus_costs=plutus_costs, | ||
expected_costs=[plutus_common.ALWAYS_SUCCEEDS["v3"].execution_cost], | ||
) |