cardano_node_tests.tests.tests_plutus package
Submodules
cardano_node_tests.tests.tests_plutus.conftest module
- cardano_node_tests.tests.tests_plutus.conftest.cluster(cluster_manager: ClusterManager) ClusterLib[source]
Return instance of clusterlib.ClusterLib.
cardano_node_tests.tests.tests_plutus.mint_build module
cardano_node_tests.tests.tests_plutus.mint_raw module
cardano_node_tests.tests.tests_plutus.spend_build module
cardano_node_tests.tests.tests_plutus.spend_raw module
cardano_node_tests.tests.tests_plutus.test_delegation module
Tests for delegation of Plutus script stake address.
Stake address registration
Stake address delegation
Rewards withdrawal
Stake address deregistration
- class cardano_node_tests.tests.tests_plutus.test_delegation.TestDelegateAddr[source]
Bases:
objectTests for address delegation to stake pools.
- test_delegate_deregister(cluster_lock_42stake: tuple[ClusterLib, str], pool_user: PoolUserScript, plutus_version: str, build_method: str, use_reference_script: bool)[source]
Register, delegate and deregister Plutus script stake address.
The stake address registration and delegation happen in single transaction.
Submit registration certificate and delegate stake address to pool
Check that the stake address was delegated
Withdraw rewards to payment address and deregister stake address
Check that the key deposit was returned and rewards withdrawn
Check that the stake address is no longer delegated
(optional) Check records in db-sync
- test_register_delegate_deregister(cluster_lock_42stake: tuple[ClusterLib, str], pool_user: PoolUserScript, plutus_version: str, build_method: str)[source]
Register, delegate and deregister Plutus script stake address.
The stake address registration and delegation happen in two separate transactions.
Submit registration certificate for a stake address
Delegate stake address to pool
Check that the stake address was delegated
Withdraw rewards to payment address and deregister stake address
Check that the key deposit was returned and rewards withdrawn
Check that the stake address is no longer delegated
(optional) Check records in db-sync
- class cardano_node_tests.tests.tests_plutus.test_delegation.TestRegisterAddr[source]
Bases:
objectTests for address registration.
- pytestmark = [Mark(name='skipif', args=(False,), kwargs={'reason': "cannot use `build` with Tx era 'conway': "})][source]
- test_register_deregister(cluster_lock_42stake: tuple[ClusterLib, str], pool_user: PoolUserScript, plutus_version: str, build_method: str)[source]
Register and deregister Plutus script stake address.
Submit registration certificate for a stake address
Check that the stake address was registered
Deregister the stake address
Check that the key deposit was returned and rewards withdrawn
Check that the stake address is no longer registered
(optional) Check records in db-sync
- cardano_node_tests.tests.tests_plutus.test_delegation.cluster_lock_42stake(cluster_manager: ClusterManager) tuple[ClusterLib, str][source]
Make sure just one staking Plutus test run at a time.
Plutus script always has the same address. When one script is used in multiple tests that are running in parallel, the balances etc. don’t add up.
- cardano_node_tests.tests.tests_plutus.test_delegation.delegate_stake_addr(cluster_obj: ClusterLib, temp_template: str, txins: list[UTXOData], collaterals: list[UTXOData], pool_user: PoolUserScript, pool_id: str, redeemer_file: Path, reference_script_utxos: list[UTXOData] | None, build_method: str) tuple[TxRawOutput, list[dict]][source]
Delegate a stake address to a pool.
- cardano_node_tests.tests.tests_plutus.test_delegation.deregister_stake_addr(cluster_obj: ClusterLib, temp_template: str, txins: list[UTXOData], collaterals: list[UTXOData], pool_user: PoolUserScript, redeemer_file: Path, reference_script_utxos: list[UTXOData] | None, build_method: str) tuple[TxRawOutput, list[dict]][source]
Deregister stake address.
- cardano_node_tests.tests.tests_plutus.test_delegation.pool_user(cluster_manager: ClusterManager, cluster_lock_42stake: tuple[ClusterLib, str]) PoolUserScript[source]
Create pool user.
- cardano_node_tests.tests.tests_plutus.test_delegation.register_delegate_stake_addr(cluster_obj: ClusterLib, temp_template: str, txins: list[UTXOData], collaterals: list[UTXOData], pool_user: PoolUserScript, pool_id: str, redeemer_file: Path, reference_script_utxos: list[UTXOData] | None, build_method: str) tuple[TxRawOutput, list[dict]][source]
Submit registration certificate and delegate to pool.
- cardano_node_tests.tests.tests_plutus.test_delegation.register_stake_addr(cluster_obj: ClusterLib, temp_template: str, txins: list[UTXOData], collaterals: list[UTXOData], pool_user: PoolUserScript, redeemer_file: Path, reference_script_utxos: list[UTXOData] | None, build_method: str) tuple[TxRawOutput, list[dict]][source]
Register a stake address.
cardano_node_tests.tests.tests_plutus.test_lobster module
Tests for the “Lobster Challenge”.
See https://github.com/input-output-hk/lobster-challenge
- class cardano_node_tests.tests.tests_plutus.test_lobster.TestLobsterChallenge[source]
Bases:
object- pytestmark = [Mark(name='skipif', args=(False,), kwargs={'reason': "cannot use `build` with Tx era 'conway': "})][source]
- test_lobster_name(cluster: ClusterLib, payment_addrs: list[AddressRecord])[source]
Test the Lobster Challenge.
Uses cardano-cli transaction build command for building the transactions.
Fund token issuer and create a UTxO for collateral
Mint the LobsterNFT token
Deploy the LobsterNFT token to address of lobster spending script
Generate random votes and determine the expected final value
Perform voting and check that the final value matches the expected value
(optional) Check transactions in db-sync
- cardano_node_tests.tests.tests_plutus.test_lobster.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment address.
cardano_node_tests.tests.tests_plutus.test_mint_build module
Tests for minting with Plutus using transaction build.
- class cardano_node_tests.tests.tests_plutus.test_mint_build.TestBuildMinting[source]
Bases:
objectTests for minting using Plutus smart contracts and transaction build.
- past_horizon_funds(cluster_manager: ClusterManager, cluster: ClusterLib, payment_addrs: list[AddressRecord]) tuple[list[UTXOData], list[UTXOData], TxRawOutput][source]
Create UTxOs for test_ttl_horizon.
- test_minting_context_equivalence(cluster: ClusterLib, payment_addrs: list[AddressRecord], submit_method: str)[source]
Test context equivalence while minting a token.
Uses cardano-cli transaction build command for building the transactions.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Generate a dummy redeemer and a dummy Tx
Derive the correct redeemer from the dummy Tx
Mint the token using the derived redeemer
Check that the token was minted and collateral UTxO was not spent
Check expected Plutus cost
(optional) Check transactions in db-sync
- test_minting_missing_txout(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str, submit_method: str)[source]
Test minting a token with a Plutus script without providing TxOut for the token.
Uses cardano-cli transaction build command for building the transactions.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Mint the token using a Plutus script
Check that the token was minted and collateral UTxO was not spent
- test_minting_one_token(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str, submit_method: str)[source]
Test minting a token with a Plutus script.
Uses cardano-cli transaction build command for building the transactions.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Mint the token using a Plutus script
Check that the token was minted and collateral UTxO was not spent
Check expected fees
Check expected Plutus cost
(optional) Check transactions in db-sync
- test_time_range_minting(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str, submit_method: str)[source]
Test minting a token with a time constraints Plutus script.
Uses cardano-cli transaction build command for building the transactions.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Mint the token using a Plutus script
Check that the token was minted and collateral UTxO was not spent
Check expected fees
Check expected Plutus cost
(optional) Check transactions in db-sync
- test_ttl_horizon(cluster: ClusterLib, payment_addrs: list[AddressRecord], past_horizon_funds: tuple[list[UTXOData], list[UTXOData], TxRawOutput], plutus_version: str, ttl_offset: int)[source]
Test minting a token with ttl far in the future.
Uses cardano-cli transaction build command for building the transactions.
Try to mint a token using a Plutus script when ttl is set far in the future
Check that minting failed because of ‘PastHorizon’ failure when ttl is too far in the future
- test_two_scripts_minting(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str, submit_method: str)[source]
Test minting two tokens with two different Plutus scripts.
Uses cardano-cli transaction build command for building the transactions.
Fund the token issuer and create a UTxO for collaterals
Check that the expected amount was transferred to token issuer’s address
Mint the tokens using two different Plutus scripts
Check that the tokens were minted and collateral UTxOs were not spent
Check transaction view output
Check expected fees
Check expected Plutus cost
(optional) Check transactions in db-sync
- test_witness_redeemer(cluster: ClusterLib, payment_addrs: list[AddressRecord], key: str, plutus_version: str, submit_method: str)[source]
Test minting a token with a Plutus script.
Uses cardano-cli transaction build command for building the transactions.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Mint the token using a Plutus script with required signer
Check that the token was minted and collateral UTxO was not spent
Check expected fees
Check expected Plutus cost
(optional) Check transactions in db-sync
- class cardano_node_tests.tests.tests_plutus.test_mint_build.TestCollateralOutput[source]
Bases:
objectTests for collateral output.
- test_duplicated_collateral(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str, submit_method: str)[source]
Test minting a token with a Plutus script while using the same collateral input twice.
Tests https://github.com/IntersectMBO/cardano-node/issues/4744
Uses cardano-cli transaction build command for building the transactions.
Fund the token issuer and create a UTxO for collateral and possibly reference script
Check that the expected amount was transferred to token issuer’s address
Mint the token using a Plutus script and the same collateral UTxO listed twice
Check that the token was minted and collateral UTxO was not spent
Check that the return collateral amount is the expected
- cardano_node_tests.tests.tests_plutus.test_mint_build.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment address.
cardano_node_tests.tests.tests_plutus.test_mint_negative_build module
Negative tests for minting with Plutus using transaction build.
- class cardano_node_tests.tests.tests_plutus.test_mint_negative_build.TestBuildMintingNegative[source]
Bases:
objectTests for minting with Plutus using transaction build that are expected to fail.
- fund_issuer_long_asset_name(cluster: ClusterLib, payment_addrs: list[AddressRecord]) tuple[list[UTXOData], list[UTXOData], list[AddressRecord]][source]
Fund the token issuer and create the collateral UTxO.
- test_asset_name_too_long(cluster: ClusterLib, fund_issuer_long_asset_name: tuple[list[UTXOData], list[UTXOData], list[AddressRecord]]) None[source]
Test minting token with asset name exceeding maximum length and min-UTXO calculation.
Expect failure.
Property-based test using Hypothesis to generate asset names longer than 32 bytes (maximum allowed length for Cardano native token asset names).
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded token issuer address with collateral UTxO
Generate random asset name (minimum 33 characters)
Encode asset name to hex and create minting policy
Attempt to build transaction minting token with oversized asset name
Check that transaction building fails with “bytestring should be no longer than 32 bytes” error
Attempt to calculate minimum required UTXO for transaction output with oversized asset name
Check that min-UTXO calculation also fails with same error
- test_redeemer_with_simple_minting_script(cluster: ClusterLib, payment_addrs: list[AddressRecord])[source]
Test minting a token passing a redeemer for a simple minting script.
Expect failure.
Fund the token issuer and create a UTxO for collateral
Try to mint the token using a simple script passing a redeemer
Check that the minting failed because a Plutus script is expected
- test_time_range_missing_tx_validity(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting a token with a time constraints Plutus script and no TX validity.
Expect failure.
Uses cardano-cli transaction build command for building the transactions.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Try to mint the token using a Plutus script and a TX without validity interval
Check that the minting failed
- test_witness_redeemer_missing_signer(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str, submit_method: str)[source]
Test minting a token with a Plutus script with invalid signers.
Expect failure.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Try to mint the token using a Plutus script and a TX with signing key missing for the required signer
Check that the minting failed because the required signers were not provided
- cardano_node_tests.tests.tests_plutus.test_mint_negative_build.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment address.
cardano_node_tests.tests.tests_plutus.test_mint_negative_raw module
Negative tests for minting with Plutus using transaction build-raw.
- class cardano_node_tests.tests.tests_plutus.test_mint_negative_raw.TestMintingNegative[source]
Bases:
objectTests for minting with Plutus using transaction build-raw that are expected to fail.
- fund_execution_units_above_limit(cluster: ClusterLib, payment_addrs: list[AddressRecord], pparams: dict, request: SubRequest) tuple[list[UTXOData], list[UTXOData], PlutusOp][source]
- test_execution_units_above_limit(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_execution_units_above_limit: tuple[list[UTXOData], list[UTXOData], PlutusOp], pparams: dict) None[source]
Test minting a token when execution units are above the limit.
Expect failure.
Fund the token issuer and create a UTxO for collateral
Try to mint the token when execution units are set above the limits
Check that the minting failed because the execution units were too big
- test_low_budget(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting a token when budget is too low.
Expect failure.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Try to mint the token using a Plutus script when execution units are set to half of the expected values
Check that the minting failed because the budget was overspent
- test_low_fee(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting a token when fee is set too low.
Expect failure.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Try to mint a token using a Plutus script when fee is set lower than is the computed fee
Check that minting failed because the fee amount was too low
- test_time_range_missing_tx_validity(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting a token with a time constraints Plutus script and no TX validity.
Expect failure.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Try to mint the token using a Plutus script and a TX without validity interval
Check that the minting failed
- test_witness_redeemer_missing_signer(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting a token with a Plutus script with invalid signers.
Expect failure.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Try to mint the token using a Plutus script and a TX with signing key missing for the required signer
Check that the minting failed because the required signers were not provided
- class cardano_node_tests.tests.tests_plutus.test_mint_negative_raw.TestNegativeCollateral[source]
Bases:
objectTests for collaterals that are expected to fail.
- test_minting_with_insufficient_collateral(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting a token with a Plutus script with insufficient collateral.
Expect failure.
Fund the token issuer and create a UTxO for collateral with insufficient funds
Check that the expected amount was transferred to token issuer’s address
Mint the token using a Plutus script
Check that the minting failed because a collateral with insufficient funds was provided
- test_minting_with_invalid_collaterals(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting a token with a Plutus script with invalid collaterals.
Expect failure.
Fund the token issuer and create an UTxO for collateral with insufficient funds
Check that the expected amount was transferred to token issuer’s address
Mint the token using a Plutus script
Check that the minting failed because no valid collateral was provided
- cardano_node_tests.tests.tests_plutus.test_mint_negative_raw.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment address.
cardano_node_tests.tests.tests_plutus.test_mint_raw module
Tests for minting with Plutus using transaction build-raw.
- class cardano_node_tests.tests.tests_plutus.test_mint_raw.TestCollateralOutput[source]
Bases:
objectTests for collateral output.
- test_duplicated_collateral(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting a token with a Plutus script while using the same collateral input twice.
Tests https://github.com/IntersectMBO/cardano-node/issues/4744
Fund the token issuer and create a UTxO for collateral and possibly reference script
Check that the expected amount was transferred to token issuer’s address
Mint the token using a Plutus script and the same collateral UTxO listed twice
Check that the token was minted and collateral UTxO was not spent
- class cardano_node_tests.tests.tests_plutus.test_mint_raw.TestMinting[source]
Bases:
objectTests for minting using Plutus smart contracts.
- test_minting_context_equivalence(cluster: ClusterLib, payment_addrs: list[AddressRecord])[source]
Test context equivalence while minting a token.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Generate a dummy redeemer and a dummy Tx
Derive the correct redeemer from the dummy Tx
Mint the token using the derived redeemer
Check that the token was minted and collateral UTxO was not spent
(optional) Check transactions in db-sync
- test_minting_policy_executed_once1(cluster: ClusterLib, payment_addrs: list[AddressRecord])[source]
Test that minting policy is executed only once even when the same policy is used twice.
Test by minting two tokens while using the same Plutus script twice with two different redeemers.
The Plutus script used in this test takes the expected token name as redeemer. Even though the redeemer used for minting the first token doesn’t match the token name, the token gets minted anyway. That’s because only the last redeemer is used and all the other scripts with identical minting policy (and corresponding redeemers) are ignored. So it only matters that the last redeemer matches the last token name.
Fund the token issuer and create a UTxO for collateral - funds for fees and collateral are sufficient for just single minting script
Check that the expected amount was transferred to token issuer’s address
Mint the tokens using two identical Plutus scripts and two redeemers, where the first redeemer value is invalid
Check that the tokens were minted and collateral UTxOs were not spent, i.e. the first script and its redeemer were ignored
Check transaction view output
(optional) Check transactions in db-sync
- test_minting_policy_executed_once2(cluster: ClusterLib, payment_addrs: list[AddressRecord])[source]
Test that minting policy is executed only once even when the same policy is used twice.
Test minting two tokens while using one Plutus script and one redeemer.
The Plutus script used in this test takes the expected token name as redeemer. Even though the redeemer doesn’t match name of the first token, the token get’s minted anyway. That’s because it is only checked that the last token name matches the redeemer, and redeemer for the first token is not needed.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Mint the tokens using a redeemer value that doesn’t match the name of the first token
Check that the tokens were minted and collateral UTxOs were not spent, i.e. redeemer for the first token was not needed
Check transaction view output
(optional) Check transactions in db-sync
- test_minting_two_tokens(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting two tokens with a single Plutus script.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Mint the tokens using a Plutus script
Check that the tokens were minted and collateral UTxO was not spent
(optional) Check transactions in db-sync
- test_time_range_minting(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting a token with a time constraints Plutus script.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Mint the token using a Plutus script
Check that the token was minted and collateral UTxO was not spent
(optional) Check transactions in db-sync
- test_ttl_horizon(cluster: ClusterLib, payment_addrs: list[AddressRecord], ttl_offset: int, plutus_version: str)[source]
Test minting a token with ttl far in the future.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Try to mint a token using a Plutus script when ttl is set far in the future
Check that minting failed because of ‘PastHorizon’ failure when ttl is too far in the future
- test_two_scripts_minting(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test minting two tokens with two different Plutus scripts.
Fund the token issuer and create a UTxO for collaterals
Check that the expected amount was transferred to token issuer’s address
Mint the tokens using two different Plutus scripts
Check that the tokens were minted and collateral UTxOs were not spent
Check transaction view output
(optional) Check transactions in db-sync
- test_witness_redeemer(cluster: ClusterLib, payment_addrs: list[AddressRecord], key: str, plutus_version: str)[source]
Test minting a token with a Plutus script.
Fund the token issuer and create a UTxO for collateral
Check that the expected amount was transferred to token issuer’s address
Mint the token using a Plutus script with required signer
Check that the token was minted and collateral UTxO was not spent
(optional) Check transactions in db-sync
- cardano_node_tests.tests.tests_plutus.test_mint_raw.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment address.
cardano_node_tests.tests.tests_plutus.test_spend_build module
Tests for spending with Plutus using transaction build.
- class cardano_node_tests.tests.tests_plutus.test_spend_build.TestBuildLocking[source]
Bases:
objectTests for Tx output locking using Plutus smart contracts and transaction build.
- test_always_fails(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking a Tx output with a Plutus script and spending the locked UTxO.
Uses cardano-cli transaction build command for building the transactions.
Test with “always fails” script that fails for all datum / redeemer values.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Try to spend the locked UTxO
Check that the expected error was raised
- test_collateral_is_txin(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending the locked UTxO while using single UTxO for both collateral and Tx input.
Uses cardano-cli transaction build command for building the transactions.
Tests bug https://github.com/IntersectMBO/cardano-db-sync/issues/750
Create a Tx output with a datum hash at the script address and a collateral UTxO
Check that the expected amount was locked at the script address
Spend the locked UTxO while using the collateral UTxO both as collateral and as normal Tx input
Check that the expected amount was spent
(optional) Check transactions in db-sync
- test_context_equivalence(cluster: ClusterLib, pool_users: list[PoolUser])[source]
Test context equivalence while spending a locked UTxO.
Uses cardano-cli transaction build command for building the transactions.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Generate a dummy redeemer and a dummy Tx
Derive the correct redeemer from the dummy Tx
Spend the locked UTxO using the derived redeemer
Check that the expected amount was spent
(optional) Check transactions in db-sync
- test_guessing_game(cluster: ClusterLib, payment_addrs: list[AddressRecord], variant: str, plutus_version: str, embed_datum: bool)[source]
Test locking a Tx output with a Plutus script and spending the locked UTxO.
Uses cardano-cli transaction build command for building the transactions.
Test with “guessing game” scripts that expect specific datum and redeemer value. Test both typed and untyped redeemer and datum. Test passing datum and redeemer to cardano-cli as value, json file and cbor file.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Spend the locked UTxO
Check that the expected amount was spent
(optional) Check transactions in db-sync
- test_partial_spending(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending part of funds (Lovelace and native tokens) on a locked UTxO.
Uses cardano-cli transaction build command for building the transactions.
Create a Tx output that contains native tokens with a datum hash at the script address
Check that expected amounts of Lovelace and native tokens were locked at the script address
Spend the locked UTxO and create new locked UTxO with change
Check that the expected amounts of Lovelace and native tokens were spent
Check expected fees
Check expected Plutus cost
(optional) Check transactions in db-sync
- test_script_invalid(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test failing script together with the –script-invalid argument - collateral is taken.
Uses cardano-cli transaction build command for building the transactions.
Test with “always fails” script that fails for all datum / redeemer values.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Try to spend the locked UTxO
Check that the amount was not transferred and collateral UTxO was spent
- test_two_scripts_spending(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking two Tx outputs with two different Plutus scripts in single Tx.
Uses cardano-cli transaction build command for building the transactions.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Spend the locked UTxO
Check that the expected amount was spent
Check expected fees
Check expected Plutus cost
(optional) Check transactions in db-sync
- test_txout_locking(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking a Tx output with a Plutus script and spending the locked UTxO.
Uses cardano-cli transaction build command for building the transactions.
Corresponds to Exercise 3 for Alonzo Blue.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Spend the locked UTxO
Check that the expected amount was spent
Check expected fees
Check expected Plutus cost
(optional) Check transactions in db-sync
- test_txout_token_locking(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking a Tx output with a Plutus script and spending the locked UTxO.
Uses cardano-cli transaction build command for building the transactions.
Create a Tx output that contains native tokens with a datum hash at the script address
Check that expected amounts of Lovelace and native tokens were locked at the script address
Spend the locked UTxO
Check that the expected amounts of Lovelace and native tokens were spent
Check expected fees
Check expected Plutus cost
(optional) Check transactions in db-sync
- cardano_node_tests.tests.tests_plutus.test_spend_build.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment addresses.
- cardano_node_tests.tests.tests_plutus.test_spend_build.pool_users(cluster_manager: ClusterManager, cluster: ClusterLib) list[PoolUser][source]
Create new pool users.
cardano_node_tests.tests.tests_plutus.test_spend_compat_build module
Compatibility tests for spending with Plutus using transaction build.
- class cardano_node_tests.tests.tests_plutus.test_spend_compat_build.TestCompatibility[source]
Bases:
objectTests for checking compatibility with previous Tx eras.
- cardano_node_tests.tests.tests_plutus.test_spend_compat_build.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment addresses.
cardano_node_tests.tests.tests_plutus.test_spend_compat_raw module
Compatibility tests for spending with Plutus using transaction build-raw.
- class cardano_node_tests.tests.tests_plutus.test_spend_compat_raw.TestCompatibility[source]
Bases:
objectTests for checking compatibility with previous Tx eras.
- cardano_node_tests.tests.tests_plutus.test_spend_compat_raw.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment addresses.
cardano_node_tests.tests.tests_plutus.test_spend_datum_build module
Tests for datum while spending with Plutus using transaction build.
- class cardano_node_tests.tests.tests_plutus.test_spend_datum_build.TestDatum[source]
Bases:
objectTests for datum.
- test_datum_on_key_credential_address(cluster: ClusterLib, payment_addrs: list[AddressRecord])[source]
Test creating UTxO with datum on address with key credentials (non-script address).
Uses cardano-cli transaction build command for building the transactions.
Create transaction output with datum hash on non-script payment address
Build and submit transaction
Query created UTxO and verify datum hash is present
(optional) Check transaction records in db-sync
- test_embed_datum_without_pparams(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test ‘build –tx-out-datum-embed’ without providing protocol params file.
Uses cardano-cli transaction build command without protocol parameters file.
Create transaction with embedded datum using –tx-out-datum-embed-file flag
Build transaction without providing protocol parameters file
Sign and attempt to submit transaction
Check that transaction either succeeds or fails with PPViewHashesDontMatch error
- class cardano_node_tests.tests.tests_plutus.test_spend_datum_build.TestNegativeDatum[source]
Bases:
objectTests for Tx output locking using Plutus smart contracts with wrong datum.
- pbt_script_addresses(cluster: ClusterLib) dict[str, str][source]
Get Plutus script addresses.
Meant for property-based tests, so this expensive operation gets executed only once.
- test_lock_tx_invalid_datum(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str) None[source]
Test locking a Tx output with an invalid datum (property-based test).
Expect failure.
Property-based test using Hypothesis to generate random text strings as invalid datum values to test JSON parsing and validation.
Uses cardano-cli transaction build command for building the transactions.
Generate random text string as invalid datum value
Create malformed datum file with invalid JSON format
Attempt to build transaction with invalid datum file
Check that transaction building fails with JSON object error
- test_no_datum_txout(cluster: ClusterLib, payment_addrs: list[AddressRecord], address_type: str, plutus_version: str)[source]
Test using UTxO without datum hash in place of locked UTxO.
Expect failure, unless in era >= Conway.
Create a Tx output without a datum hash
Try to spend the UTxO like it was locked Plutus UTxO
Check that the expected error was raised
- test_too_big(cluster: ClusterLib, payment_addrs: list[AddressRecord], pbt_script_addresses: dict[str, str], plutus_version: str) None[source]
Try to lock a UTxO with datum that is too big (property-based test).
Property-based test using Hypothesis to generate random binary data >= 65 bytes to test datum size limits (maximum datum size is 64 bytes).
Uses cardano-cli transaction build command for building the transactions.
Generate random binary datum value (minimum 65 bytes)
Create datum file with oversized binary data
Attempt to build transaction locking UTxO with oversized datum
Check that transaction building fails with size error (on node < 1.36.0)
Expect failure on node version < 1.36.0.
- test_unlock_non_script_utxo(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Try to spend a non-script UTxO with datum as if it was script locked UTxO.
Expect failure.
Uses cardano-cli transaction build command for building the transactions.
Create regular UTxO at payment address with datum hash (non-script address)
Create collateral UTxO
Attempt to spend regular UTxO with Plutus script witness and redeemer
Check that spending fails with script hash not known error
- test_unlock_tx_wrong_datum(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking a Tx output and try to spend it with a wrong datum.
Uses cardano-cli transaction build command for building the transactions.
Lock funds at script address with typed datum (datum 42 typed)
Attempt to spend locked UTxO using different datum format (datum 42 untyped)
Check that spending fails with “wrong datum” error (unless in era >= Conway)
Expect failure, unless in era >= Conway.
- cardano_node_tests.tests.tests_plutus.test_spend_datum_build.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment addresses.
cardano_node_tests.tests.tests_plutus.test_spend_datum_raw module
Tests for datum while spending with Plutus using transaction build-raw.
- class cardano_node_tests.tests.tests_plutus.test_spend_datum_raw.TestDatum[source]
Bases:
objectTests for datum.
- test_datum_on_key_credential_address(cluster: ClusterLib, payment_addrs: list[AddressRecord])[source]
Test creating UTxO with datum on address with key credentials (non-script address).
Uses cardano-cli transaction build-raw command for building the transactions.
Create transaction output with datum hash on non-script payment address
Build raw transaction with calculated fee
Sign and submit transaction
Query created UTxO and verify datum hash is present
(optional) Check transaction records in db-sync
- class cardano_node_tests.tests.tests_plutus.test_spend_datum_raw.TestNegativeDatum[source]
Bases:
objectTests for Tx output locking using Plutus smart contracts with wrong datum.
- pbt_highest_utxo(cluster: ClusterLib, payment_addrs: list[AddressRecord]) UTXOData[source]
Get UTxO with highest amount of Lovelace.
Meant for property-based tests, so this expensive operation gets executed only once.
- pbt_script_addresses(cluster: ClusterLib) dict[str, str][source]
Get Plutus script addresses.
Meant for property-based tests, so this expensive operation gets executed only once.
- test_lock_tx_invalid_datum(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str) None[source]
Test locking a Tx output with an invalid datum (property-based test).
Expect failure.
Property-based test using Hypothesis to generate random text strings as invalid datum values to test JSON parsing and validation.
Uses cardano-cli transaction build-raw command for building the transactions.
Generate random text string as invalid datum value
Create malformed datum file with invalid JSON format
Attempt to build raw transaction with invalid datum file
Check that transaction building fails with JSON object error
- test_no_datum_txout(cluster: ClusterLib, payment_addrs: list[AddressRecord], address_type: str, plutus_version: str)[source]
Test using UTxO without datum hash in place of locked UTxO.
Expect failure.
Create a Tx output without a datum hash
Try to spend the UTxO like it was locked Plutus UTxO
Check that the expected error was raised
- test_too_big(cluster: ClusterLib, payment_addrs: list[AddressRecord], pbt_highest_utxo: UTXOData, pbt_script_addresses: dict[str, str], plutus_version: str) None[source]
Try to lock a UTxO with datum that is too big (property-based test).
Property-based test using Hypothesis to generate random binary data >= 65 bytes to test datum size limits (maximum datum size is 64 bytes).
Uses cardano-cli transaction build-raw command for building the transactions.
Generate random binary datum value (minimum 65 bytes)
Create datum file with oversized binary data
Attempt to build raw transaction locking UTxO with oversized datum
Check that transaction building fails with size error (on node < 1.36.0)
Expect failure on node version < 1.36.0.
- test_unlock_non_script_utxo(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Try to spend a non-script UTxO with datum as if it was script locked UTxO.
Expect failure.
Uses cardano-cli transaction build-raw command for building the transactions.
Create regular UTxO at payment address with datum hash (non-script address)
Create collateral UTxO
Attempt to spend regular UTxO with Plutus script witness and redeemer
Check that spending fails with MissingScriptWitnessesUTXOW error
- test_unlock_tx_wrong_datum(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking a Tx output and try to spend it with a wrong datum.
Expect failure.
Uses cardano-cli transaction build-raw command for building the transactions.
Lock funds at script address with typed datum (datum 42 typed)
Attempt to spend locked UTxO using different datum format (datum 42 untyped)
Check that spending fails with supplementary datums error
- cardano_node_tests.tests.tests_plutus.test_spend_datum_raw.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment addresses.
cardano_node_tests.tests.tests_plutus.test_spend_negative_build module
Negative tests for spending with Plutus using transaction build.
- class cardano_node_tests.tests.tests_plutus.test_spend_negative_build.TestNegative[source]
Bases:
objectTests for Tx output locking using Plutus smart contracts that are expected to fail.
- test_collateral_w_tokens(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending the locked UTxO while collateral contains native tokens.
Expect failure.
Uses cardano-cli transaction build command for building the transactions.
Create a collateral UTxO with native tokens
Try to spend the locked UTxO
Check that the expected error was raised
(optional) Check transactions in db-sync
- test_invalid_guessing_game(cluster: ClusterLib, payment_addrs: list[AddressRecord], variant: str, plutus_version: str)[source]
Test locking a Tx output with a Plutus script and spending the locked UTxO.
Uses cardano-cli transaction build command for building the transactions.
Test with “guessing game” script that expects specific datum and redeemer value. Test negative scenarios where datum or redeemer value is different than expected. Expect failure.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Try to spend the locked UTxO
Check that the amount was not transferred and collateral UTxO was not spent
- test_no_script(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending the locked UTxO while passing no Plutus script.
Expect failure.
Uses cardano-cli transaction build command for building the transactions.
Create a Tx output with a datum hash at the script address
Try to spend the locked UTxO using while passing no Plutus script
Check that the expected error was raised
(optional) Check transactions in db-sync
- test_same_collateral_txin(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending the locked UTxO while using the same UTxO as collateral.
Expect failure.
Uses cardano-cli transaction build command for building the transactions.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Try to spend the locked UTxO while using the same UTxO as collateral
Check that the expected error was raised
(optional) Check transactions in db-sync
- test_two_scripts_spending_one_fail(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking two Tx outputs with two different Plutus scripts in single Tx, one fails.
Uses cardano-cli transaction build command for building the transactions.
Create a Tx output with a datum hash at the script addresses
Try to spend the locked UTxOs
Check that the expected error was raised
- test_wrong_script(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending the locked UTxO while using wrong Plutus script.
Expect failure.
Uses cardano-cli transaction build command for building the transactions.
Create a Tx output with a datum hash at the script address
Try to spend the locked UTxO while using wrong Plutus script
Check that the expected error was raised
(optional) Check transactions in db-sync
- class cardano_node_tests.tests.tests_plutus.test_spend_negative_build.TestNegativeRedeemer[source]
Bases:
objectTests for Tx output locking using Plutus smart contracts with wrong redeemer.
- fund_script_guessing_game_v1(cluster: ClusterLib, payment_addrs: list[AddressRecord]) tuple[list[UTXOData], list[UTXOData]][source]
Fund a PlutusV1 script and create the locked UTxO and collateral UTxO.
Uses cardano-cli transaction build command for building the transactions.
- fund_script_guessing_game_v2(cluster: ClusterLib, payment_addrs: list[AddressRecord]) tuple[list[UTXOData], list[UTXOData]][source]
Fund a PlutusV2 script and create the locked UTxO and collateral UTxO.
Uses cardano-cli transaction build command for building the transactions.
- test_invalid_json(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test building transaction with malformed JSON in redeemer file.
Expect failure.
Property-based test using Hypothesis to generate random strings and create malformed JSON structures. Tests JSON parsing validation.
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random string value
Create redeemer file with invalid JSON structure (double-encoded string)
Attempt to build transaction with malformed redeemer JSON
Check that transaction building fails with “JSON object expected” error
- test_json_schema_typed_bytes_int_declared(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test building transaction with type mismatch declaring int as bytes in typed schema.
Expect failure.
Property-based test using Hypothesis to generate integer values and declare them as “bytes” in typed JSON schema format (constructor with fields). Tests JSON schema validation.
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random integer value
Create typed redeemer with {“bytes”: <int>} declaring int value as bytes type
Attempt to build transaction with schema-violating redeemer
Check that transaction building fails with schema type mismatch error
- test_json_schema_typed_int_bytes_declared(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test building transaction with type mismatch in typed redeemer JSON schema.
Expect failure.
Property-based test using Hypothesis to generate byte strings and declare them as “int” in typed JSON schema format (constructor with fields). Tests JSON schema validation.
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random byte string value (max 64 bytes)
Create typed redeemer with {“int”: <bytes_hex>} declaring bytes value as int type
Attempt to build transaction with schema-violating redeemer
Check that transaction building fails with schema type mismatch error
- test_json_schema_typed_invalid_type(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test building transaction with invalid field type name in typed JSON schema.
Expect failure.
Property-based test using Hypothesis to generate invalid type names (not “int”, “bytes”, “list”, “map”, or “string”). Tests JSON schema type validation for typed format.
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random type name (excluding valid types)
Create typed redeemer with invalid field type in constructor format
Attempt to build transaction with invalid schema type
Check that transaction building fails with “Expected a single field named” error
- test_json_schema_untyped_bytes_int_declared(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test building transaction with type mismatch declaring int as bytes in untyped schema.
Expect failure.
Property-based test using Hypothesis to generate integer values and declare them as “bytes” in untyped JSON schema format (simple key-value). Tests JSON schema validation.
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random integer value
Create untyped redeemer with {“bytes”: <int>} declaring int value as bytes type
Attempt to build transaction with schema-violating redeemer
Check that transaction building fails with schema type mismatch error
- test_json_schema_untyped_int_bytes_declared(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test building transaction with type mismatch in untyped redeemer JSON schema.
Expect failure.
Property-based test using Hypothesis to generate byte strings and declare them as “int” in untyped JSON schema format (simple key-value). Tests JSON schema validation.
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random byte string value (max 64 bytes)
Create untyped redeemer with {“int”: <bytes_hex>} declaring bytes value as int type
Attempt to build transaction with schema-violating redeemer
Check that transaction building fails with schema type mismatch error
- test_json_schema_untyped_invalid_type(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test building transaction with invalid field type name in untyped JSON schema.
Expect failure.
Property-based test using Hypothesis to generate invalid type names (not “int”, “bytes”, “list”, “map”, or “string”). Tests JSON schema type validation for untyped format.
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random type name (excluding valid types)
Create untyped redeemer with invalid field type as key
Attempt to build transaction with invalid schema type
Check that transaction building fails with “Expected a single field named” error
- test_too_big(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test spending locked UTxO with redeemer exceeding maximum byte size limit.
Expect failure.
Property-based test using Hypothesis to generate byte strings larger than 64 bytes (maximum allowed size for datum/redeemer byte strings).
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random byte string value (minimum 65 bytes, exceeding limit)
Create redeemer file with oversized bytes value
Attempt to spend locked UTxO with too large redeemer
Check that transaction building fails with “must consist of at most 64 bytes” or “Incorrect datum” error
- test_wrong_type(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test spending locked UTxO with redeemer of incorrect type (bytes instead of int).
Expect failure.
Property-based test using Hypothesis to generate random byte strings. The guessing game script expects an integer redeemer value.
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random byte string value (max 64 bytes)
Create redeemer file with bytes type instead of expected int
Attempt to spend locked UTxO with wrong type redeemer
Check that transaction building fails with “Incorrect datum. Expected 42.” error
- test_wrong_value_above_range(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test spending locked UTxO with redeemer value exceeding maximum allowed integer.
Expect failure.
Property-based test using Hypothesis to generate integer values above MAX_UINT64 (maximum allowed value for Plutus integer types).
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random integer redeemer value greater than MAX_UINT64
Attempt to spend locked UTxO with out-of-range redeemer
Check that transaction building fails with “Value out of range” or “Incorrect datum” error
- test_wrong_value_bellow_range(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test spending locked UTxO with redeemer value below minimum allowed integer.
Expect failure.
Property-based test using Hypothesis to generate integer values below MIN_INT_VAL (minimum allowed value for Plutus integer types).
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random integer redeemer value less than MIN_INT_VAL
Attempt to spend locked UTxO with out-of-range redeemer
Check that transaction building fails with “Value out of range” or “Incorrect datum” error
- test_wrong_value_inside_range(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData]], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData]], plutus_version: str) None[source]
Test spending locked UTxO with incorrect redeemer value within valid integer range.
Expect failure.
Property-based test using Hypothesis to generate random integer redeemer values (excluding 42) within the valid range. The guessing game script expects redeemer value 42.
Uses cardano-cli transaction build command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random integer redeemer value (not 42) within valid range
Create redeemer file with wrong value
Attempt to spend locked UTxO with incorrect redeemer
Check that transaction building fails with script evaluation error
- cardano_node_tests.tests.tests_plutus.test_spend_negative_build.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment addresses.
cardano_node_tests.tests.tests_plutus.test_spend_negative_raw module
Negative tests for spending with Plutus using transaction build-raw.
- class cardano_node_tests.tests.tests_plutus.test_spend_negative_raw.TestNegative[source]
Bases:
objectTests for Tx output locking using Plutus smart contracts that are expected to fail.
- fund_execution_units_above_limit(cluster: ClusterLib, payment_addrs: list[AddressRecord], request: SubRequest) tuple[list[UTXOData], list[UTXOData], PlutusOp][source]
- test_collateral_percent(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Try to spend locked UTxO while collateral is less than required.
Expect failure.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Create a collateral UTxO with amount of ADA less than required by collateralPercentage
Try to spend the UTxO
Check that the expected error was raised
(optional) Check transactions in db-sync
- test_collateral_w_tokens(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending the locked UTxO while collateral contains native tokens.
Expect failure.
Create a collateral UTxO with native tokens
Try to spend the locked UTxO
Check that the expected error was raised
(optional) Check transactions in db-sync
- test_execution_units_above_limit(cluster: ClusterLib, payment_addrs: list[AddressRecord], fund_execution_units_above_limit: tuple[list[UTXOData], list[UTXOData], PlutusOp], pparams: dict) None[source]
Test spending a locked UTxO with a Plutus script with execution units above the limit.
Expect failure.
Fund the script address and create a UTxO for collateral
Try to spend the locked UTxO when execution units are set above the limits
Check that failed because the execution units were too big
- test_invalid_guessing_game(cluster: ClusterLib, payment_addrs: list[AddressRecord], variant: str, plutus_version: str)[source]
Test locking a Tx output with a Plutus script and spending the locked UTxO.
Test with “guessing game” script that expects specific datum and redeemer value. Test negative scenarios where datum or redeemer value is different than expected. Expect failure.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Try to spend the locked UTxO
Check that the amount was not transferred and collateral UTxO was not spent
- test_no_script(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending the locked UTxO while passing no Plutus script.
Expect failure.
Create a Tx output with a datum hash at the script address
Try to spend the locked UTxO while passing no Plutus script
Check that the expected error was raised
(optional) Check transactions in db-sync
- test_same_collateral_txin(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending the locked UTxO while using the same UTxO as collateral.
Expect failure.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Try to spend the locked UTxO while using the same UTxO as collateral
Check that the expected error was raised
(optional) Check transactions in db-sync
- test_two_scripts_spending_one_fail(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking two Tx outputs with two different Plutus scripts in single Tx, one fails.
Expect failure.
Create a Tx output with a datum hash at the script addresses
Try to spend the locked UTxOs
Check that the expected error was raised
- test_wrong_script(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending the locked UTxO while using wrong Plutus script.
Expect failure.
Create a Tx output with a datum hash at the script address
Try to spend the locked UTxO while using wrong Plutus script
Check that the expected error was raised
(optional) Check transactions in db-sync
- class cardano_node_tests.tests.tests_plutus.test_spend_negative_raw.TestNegativeRedeemer[source]
Bases:
objectTests for Tx output locking using Plutus smart contracts with wrong redeemer.
- cost_per_unit(cluster: ClusterLib) ExecutionCost[source]
- fund_script_guessing_game_v1(cluster_manager: ClusterManager, cluster: ClusterLib) tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData][source]
- fund_script_guessing_game_v2(cluster_manager: ClusterManager, cluster: ClusterLib) tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData][source]
- test_invalid_json(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test building raw transaction with malformed JSON in redeemer.
Expect failure.
Property-based test using Hypothesis to generate random strings and create malformed JSON structures. Tests JSON parsing validation.
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random string value
Create malformed JSON redeemer (double-encoded string)
Calculate execution units and transaction fee
Attempt to build raw transaction with malformed redeemer JSON
Check that transaction building fails with JSON parsing error
- test_json_schema_typed_bytes_int_declared(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test building raw transaction with type mismatch declaring int as bytes in typed schema.
Expect failure.
Property-based test using Hypothesis to generate integer values and declare them as “bytes” in typed JSON schema format (constructor with fields). Tests JSON schema validation.
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random integer value
Create typed redeemer with {“bytes”: <int>} declaring int value as bytes type
Calculate execution units and transaction fee
Attempt to build raw transaction with schema-violating redeemer
Check that transaction building fails with schema type mismatch error
- test_json_schema_typed_int_bytes_declared(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test building raw transaction with type mismatch in typed redeemer JSON schema.
Expect failure.
Property-based test using Hypothesis to generate byte strings and declare them as “int” in typed JSON schema format (constructor with fields). Tests JSON schema validation.
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random byte string value (max 64 bytes)
Create typed redeemer with {“int”: <bytes_hex>} declaring bytes value as int type
Calculate execution units and transaction fee
Attempt to build raw transaction with schema-violating redeemer
Check that transaction building fails with schema type mismatch error
- test_json_schema_typed_invalid_type(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test building raw transaction with invalid field type name in typed JSON schema.
Expect failure.
Property-based test using Hypothesis to generate invalid type names (not “int”, “bytes”, “list”, “map”, or “string”). Tests JSON schema type validation for typed format.
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random type name (excluding valid types)
Create typed redeemer with invalid field type in constructor format
Calculate execution units and transaction fee
Attempt to build raw transaction with invalid schema type
Check that transaction building fails with “Expected a single field named” error
- test_json_schema_untyped_bytes_int_declared(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test building raw transaction with type mismatch declaring int as bytes.
Expect failure.
Property-based test using Hypothesis to generate integer values and declare them as “bytes” in untyped JSON schema format (simple key-value). Tests JSON schema validation.
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random integer value
Create untyped redeemer with {“bytes”: <int>} declaring int value as bytes type
Calculate execution units and transaction fee
Attempt to build raw transaction with schema-violating redeemer
Check that transaction building fails with schema type mismatch error
- test_json_schema_untyped_int_bytes_declared(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test building raw transaction with type mismatch in untyped redeemer JSON schema.
Expect failure.
Property-based test using Hypothesis to generate byte strings and declare them as “int” in untyped JSON schema format (simple key-value). Tests JSON schema validation.
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random byte string value (max 64 bytes)
Create untyped redeemer with {“int”: <bytes_hex>} declaring bytes value as int type
Calculate execution units and transaction fee
Attempt to build raw transaction with schema-violating redeemer
Check that transaction building fails with schema type mismatch error
- test_json_schema_untyped_invalid_type(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test building raw transaction with invalid field type name in untyped JSON schema.
Expect failure.
Property-based test using Hypothesis to generate invalid type names (not “int”, “bytes”, “list”, “map”, or “string”). Tests JSON schema type validation for untyped format.
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random type name (excluding valid types)
Create untyped redeemer with invalid field type as key
Calculate execution units and transaction fee
Attempt to build raw transaction with invalid schema type
Check that transaction building fails with “Expected a single field named” error
- test_too_big(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test spending locked UTxO with redeemer exceeding maximum byte size limit.
Property-based test using Hypothesis to generate byte strings larger than 64 bytes (maximum allowed size for datum/redeemer byte strings).
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random byte string value (minimum 65 bytes, exceeding limit)
Create redeemer file with oversized bytes value
Calculate execution units and transaction fee
Build raw transaction attempting to spend locked UTxO with too large redeemer
Sign and submit transaction
Check that transaction submission fails with ValidationTagMismatch error
Expect failure on node version < 1.36.0.
- test_wrong_type(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test spending locked UTxO with redeemer of incorrect type (bytes instead of int).
Expect failure.
Property-based test using Hypothesis to generate random byte strings. The guessing game script expects an integer redeemer value.
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random byte string value (max 64 bytes)
Create redeemer file with bytes type instead of expected int
Calculate execution units and transaction fee
Build raw transaction attempting to spend locked UTxO with wrong type redeemer
Sign and submit transaction
Check that transaction submission fails with ValidationTagMismatch error
- test_wrong_value_above_range(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test spending locked UTxO with redeemer value exceeding maximum allowed integer.
Property-based test using Hypothesis to generate integer values above MAX_UINT64 (maximum allowed value for Plutus integer types).
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random integer redeemer value greater than MAX_UINT64
Calculate execution units and transaction fee
Build raw transaction attempting to spend locked UTxO with out-of-range redeemer
Sign and submit transaction
Check that transaction submission fails with ValidationTagMismatch error
Expect failure on node version < 1.36.0.
- test_wrong_value_bellow_range(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test spending locked UTxO with redeemer value below minimum allowed integer.
Property-based test using Hypothesis to generate integer values below MIN_INT_VAL (minimum allowed value for Plutus integer types).
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random integer redeemer value less than MIN_INT_VAL
Calculate execution units and transaction fee
Build raw transaction attempting to spend locked UTxO with out-of-range redeemer
Sign and submit transaction
Check that transaction submission fails with ValidationTagMismatch error
Expect failure on node version < 1.36.0.
- test_wrong_value_inside_range(cluster: ClusterLib, fund_script_guessing_game_v1: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], fund_script_guessing_game_v2: tuple[list[UTXOData], list[UTXOData], list[AddressRecord], UTXOData], cost_per_unit: ExecutionCost, plutus_version: str) None[source]
Test spending locked UTxO with incorrect redeemer value within valid integer range.
Expect failure.
Property-based test using Hypothesis to generate random integer redeemer values (excluding 42) within the valid range. The guessing game script expects redeemer value 42.
Uses cardano-cli transaction build-raw command for building the transactions.
Use pre-funded script UTxO with datum 42 at guessing game script address
Generate random integer redeemer value (not 42) within valid range
Create redeemer file with wrong value
Calculate execution units and transaction fee
Build raw transaction attempting to spend locked UTxO with incorrect redeemer
Sign and submit transaction
Check that transaction submission fails with ValidationTagMismatch error
- cardano_node_tests.tests.tests_plutus.test_spend_negative_raw.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment addresses.
cardano_node_tests.tests.tests_plutus.test_spend_raw module
Tests for spending with Plutus using transaction build-raw.
- class cardano_node_tests.tests.tests_plutus.test_spend_raw.TestLocking[source]
Bases:
objectTests for Tx output locking using Plutus smart contracts.
- test_always_fails(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking a Tx output with a Plutus script and spending the locked UTxO.
Test with “always fails” script that fails for all datum / redeemer values.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Try to spend the locked UTxO
Check that the amount was not transferred, collateral UTxO was not spent and the expected error was raised
- test_collaterals(cluster: ClusterLib, payment_addrs: list[AddressRecord], scenario: str, plutus_version: str)[source]
Test dividing required collateral amount into multiple collateral UTxOs.
Test 3 scenarios: 1. maximum allowed number of collateral inputs 2. more collateral inputs than what is allowed 3. no collateral input
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Create multiple UTxOs for collateral
Spend the locked UTxO
Check that the expected amount was spent when success is expected
OR check that the amount was not transferred and collateral UTxO was not spent when failure is expected
(optional) Check transactions in db-sync
- test_context_equivalence(cluster: ClusterLib, pool_users: list[PoolUser])[source]
Test context equivalence while spending a locked UTxO.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Generate a dummy redeemer and a dummy Tx
Derive the correct redeemer from the dummy Tx
Spend the locked UTxO using the derived redeemer
Check that the expected amount was spent
(optional) Check transactions in db-sync
- test_guessing_game(cluster: ClusterLib, payment_addrs: list[AddressRecord], embed_datum: bool, variant: str, plutus_version: str)[source]
Test locking a Tx output with a Plutus script and spending the locked UTxO.
Test with “guessing game” scripts that expect specific datum and redeemer value. Test both typed and untyped redeemer and datum. Test passing datum and redeemer to cardano-cli as value, json file and cbor file.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Spend the locked UTxO
Check that the expected amount was spent
(optional) Check transactions in db-sync
- test_partial_spending(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test spending part of funds (Lovelace and native tokens) on a locked UTxO.
Create a Tx output that contains native tokens with a datum hash at the script address
Check that expected amounts of Lovelace and native tokens were locked at the script address
Spend the locked UTxO and create new locked UTxO with change
Check that the expected amounts of Lovelace and native tokens were spent
(optional) Check transactions in db-sync
- test_script_invalid(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test failing script together with the –script-invalid argument - collateral is taken.
Test with “always fails” script that fails for all datum / redeemer values.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Try to spend the locked UTxO
Check that the amount was not transferred and collateral UTxO was spent
- test_two_scripts_spending(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking two Tx outputs with two different Plutus scripts in single Tx.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Spend the locked UTxO
Check that the expected amount was spent
(optional) Check transactions in db-sync
- test_txout_locking(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking a Tx output with a Plutus script and spending the locked UTxO.
Corresponds to Exercise 3 for Alonzo Blue.
Create a Tx output with a datum hash at the script address
Check that the expected amount was locked at the script address
Spend the locked UTxO
Check that the expected amount was spent
(optional) Check transactions in db-sync
- test_txout_token_locking(cluster: ClusterLib, payment_addrs: list[AddressRecord], plutus_version: str)[source]
Test locking a Tx output with native tokens and spending the locked UTxO.
Create a Tx output that contains native tokens with a datum hash at the script address
Check that expected amounts of Lovelace and native tokens were locked at the script address
Spend the locked UTxO
Check that the expected amounts of Lovelace and native tokens were spent
(optional) Check transactions in db-sync
- cardano_node_tests.tests.tests_plutus.test_spend_raw.payment_addrs(cluster_manager: ClusterManager, cluster: ClusterLib) list[AddressRecord][source]
Create new payment addresses.
- cardano_node_tests.tests.tests_plutus.test_spend_raw.pool_users(cluster_manager: ClusterManager, cluster: ClusterLib) list[PoolUser][source]
Create new pool users.