diff --git a/cardano_node_tests/tests/delegation.py b/cardano_node_tests/tests/delegation.py index 93fda82f1..def0e25ed 100644 --- a/cardano_node_tests/tests/delegation.py +++ b/cardano_node_tests/tests/delegation.py @@ -152,7 +152,7 @@ def delegate_stake_addr( pool_id: str = "", cold_vkey: pl.Path | None = None, amount: int = 100_000_000, - use_build_cmd: bool = False, + build_method: str = clusterlib_utils.BuildMethods.BUILD_RAW, ) -> DelegationOut: """Submit registration certificate and delegate a stake address to a pool.""" # Create key pairs and addresses @@ -214,30 +214,20 @@ def delegate_stake_addr( signing_key_files=[pool_user.payment.skey_file, pool_user.stake.skey_file], ) - if use_build_cmd: - tx_raw_output = cluster_obj.g_transaction.build_tx( - src_address=src_address, - tx_name=f"{temp_template}_reg_deleg", - tx_files=tx_files, - fee_buffer=2_000_000, - witness_override=len(tx_files.signing_key_files), - ) - tx_signed = cluster_obj.g_transaction.sign_tx( - tx_body_file=tx_raw_output.out_file, - signing_key_files=tx_files.signing_key_files, - tx_name=f"{temp_template}_reg_deleg", - ) - cluster_obj.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins) - else: - tx_raw_output = cluster_obj.g_transaction.send_tx( - src_address=src_address, tx_name=f"{temp_template}_reg_deleg", tx_files=tx_files - ) + tx_output = clusterlib_utils.build_and_submit_tx( + cluster_obj=cluster_obj, + name_template=f"{temp_template}_reg_deleg", + src_address=src_address, + tx_files=tx_files, + build_method=build_method, + witness_override=len(tx_files.signing_key_files), + ) # Check that the balance for source address was correctly updated deposit = cluster_obj.g_query.get_address_deposit() if stake_addr_reg_cert_file else 0 assert ( cluster_obj.g_query.get_address_balance(src_address) - == src_init_balance - deposit - tx_raw_output.fee + == src_init_balance - deposit - tx_output.fee ), f"Incorrect balance for source address `{src_address}`" # Check that the stake address was delegated @@ -246,7 +236,7 @@ def delegate_stake_addr( assert stake_addr_info.delegation == pool_id, "Stake address delegated to wrong pool" assert stake_addr_info.vote_delegation == "alwaysAbstain" - return DelegationOut(pool_user=pool_user, pool_id=pool_id, tx_raw_output=tx_raw_output) + return DelegationOut(pool_user=pool_user, pool_id=pool_id, tx_raw_output=tx_output) def delegate_multisig_stake_addr( diff --git a/cardano_node_tests/tests/test_delegation.py b/cardano_node_tests/tests/test_delegation.py index 31030f835..e353bcc2c 100644 --- a/cardano_node_tests/tests/test_delegation.py +++ b/cardano_node_tests/tests/test_delegation.py @@ -132,7 +132,7 @@ class TestDelegateAddr: """Tests for stake address delegation.""" @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.dbsync @pytest.mark.smoke @pytest.mark.testnets @@ -140,7 +140,7 @@ def test_delegate_using_pool_id( self, cluster_manager: cluster_management.ClusterManager, cluster_and_pool: tuple[clusterlib.ClusterLib, str], - use_build_cmd: bool, + build_method: str, ): """Submit registration certificate and delegate to pool using pool id. @@ -162,7 +162,7 @@ def test_delegate_using_pool_id( addrs_data=cluster_manager.cache.addrs_data, temp_template=temp_template, pool_id=pool_id, - use_build_cmd=use_build_cmd, + build_method=build_method, ) tx_db_record = dbsync_utils.check_tx( @@ -176,14 +176,14 @@ def test_delegate_using_pool_id( ) @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.dbsync @pytest.mark.smoke def test_delegate_using_vkey( self, cluster_manager: cluster_management.ClusterManager, cluster_use_pool: tuple[clusterlib.ClusterLib, str], - use_build_cmd: bool, + build_method: str, ): """Submit registration certificate and delegate to pool using cold vkey. @@ -206,7 +206,7 @@ def test_delegate_using_vkey( addrs_data=cluster_manager.cache.addrs_data, temp_template=temp_template, cold_vkey=node_cold.vkey_file, - use_build_cmd=use_build_cmd, + build_method=build_method, ) tx_db_record = dbsync_utils.check_tx( @@ -852,7 +852,7 @@ def test_undelegate( assert still_rewards_epoch in db_reward_epochs @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.dbsync @pytest.mark.parametrize( "stake_cert", @@ -866,7 +866,7 @@ def test_addr_delegation_deregistration( pool_users_cluster_and_pool: list[clusterlib.PoolUser], pool_users_disposable_cluster_and_pool: list[clusterlib.PoolUser], stake_cert: str, - use_build_cmd: bool, + build_method: str, ): """Submit delegation and deregistration certificates in single TX. @@ -956,37 +956,19 @@ def test_addr_delegation_deregistration( signing_key_files=[user_payment.skey_file, user_registered.stake.skey_file], ) - if use_build_cmd: - - def _build_deleg_dereg() -> clusterlib.TxRawOutput: - return cluster.g_transaction.build_tx( - src_address=user_payment.address, - tx_name=f"{temp_template}_deleg_dereg", - tx_files=tx_files, - fee_buffer=2_000_000, - witness_override=len(tx_files.signing_key_files), - ) - - tx_raw_output_deleg: clusterlib.TxRawOutput = common.match_blocker( - func=_build_deleg_dereg - ) - tx_signed = cluster.g_transaction.sign_tx( - tx_body_file=tx_raw_output_deleg.out_file, - signing_key_files=tx_files.signing_key_files, - tx_name=f"{temp_template}_deleg_dereg", - ) - try: - cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output_deleg.txins) - except clusterlib.CLIError as exc: - if "ValueNotConservedUTxO" in str(exc): - issues.cli_942.finish_test() - raise - else: - tx_raw_output_deleg = cluster.g_transaction.send_tx( + try: + tx_raw_output_deleg = clusterlib_utils.build_and_submit_tx( + cluster_obj=cluster, + name_template=f"{temp_template}_deleg_dereg", src_address=user_payment.address, - tx_name=f"{temp_template}_deleg_dereg", tx_files=tx_files, + build_method=build_method, + witness_override=len(tx_files.signing_key_files), ) + except clusterlib.CLIError as exc: + if "ValueNotConservedUTxO" in str(exc): + issues.cli_942.finish_test() + raise # Check that the balance for source address was correctly updated and that the key # deposit was returned @@ -1092,7 +1074,7 @@ def test_delegate_addr_with_wrong_key( assert "MissingVKeyWitnessesUTXOW" in err_msg, err_msg @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets def test_delegate_unknown_addr( @@ -1100,7 +1082,7 @@ def test_delegate_unknown_addr( cluster_and_pool: tuple[clusterlib.ClusterLib, str], pool_users_cluster_and_pool: list[clusterlib.PoolUser], pool_users_disposable_cluster_and_pool: list[clusterlib.PoolUser], - use_build_cmd: bool, + build_method: str, ): """Try to delegate unknown stake address. @@ -1127,33 +1109,22 @@ def test_delegate_unknown_addr( ) with pytest.raises(clusterlib.CLIError) as excinfo: - if use_build_cmd: - tx_raw_output = cluster.g_transaction.build_tx( - src_address=user_payment.address, - tx_name=f"{temp_template}_deleg_unknown", - tx_files=tx_files, - fee_buffer=2_000_000, - witness_override=len(tx_files.signing_key_files), - ) - tx_signed = cluster.g_transaction.sign_tx( - tx_body_file=tx_raw_output.out_file, - signing_key_files=tx_files.signing_key_files, - tx_name=f"{temp_template}_deleg_unknown", - ) - cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins) - else: - cluster.g_transaction.send_tx( - src_address=user_payment.address, - tx_name=f"{temp_template}_deleg_unknown", - tx_files=tx_files, - ) + clusterlib_utils.build_and_submit_tx( + cluster_obj=cluster, + name_template=f"{temp_template}_deleg_unknown", + src_address=user_payment.address, + tx_files=tx_files, + build_method=build_method, + witness_override=len(tx_files.signing_key_files), + ) + err_msg = str(excinfo.value) assert ( "StakeDelegationImpossibleDELEG" in err_msg or "StakeKeyNotRegisteredDELEG" in err_msg ), err_msg @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets def test_delegate_deregistered_addr( @@ -1161,7 +1132,7 @@ def test_delegate_deregistered_addr( cluster_and_pool: tuple[clusterlib.ClusterLib, str], pool_users_cluster_and_pool: list[clusterlib.PoolUser], pool_users_disposable_cluster_and_pool: list[clusterlib.PoolUser], - use_build_cmd: bool, + build_method: str, ): """Try to delegate deregistered stake address. @@ -1207,26 +1178,15 @@ def test_delegate_deregistered_addr( ) with pytest.raises(clusterlib.CLIError) as excinfo: - if use_build_cmd: - tx_raw_output = cluster.g_transaction.build_tx( - src_address=user_payment.address, - tx_name=f"{temp_template}_deleg_dereg", - tx_files=tx_files, - fee_buffer=2_000_000, - witness_override=len(tx_files.signing_key_files), - ) - tx_signed = cluster.g_transaction.sign_tx( - tx_body_file=tx_raw_output.out_file, - signing_key_files=tx_files.signing_key_files, - tx_name=f"{temp_template}_deleg_dereg", - ) - cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins) - else: - cluster.g_transaction.send_tx( - src_address=user_payment.address, - tx_name=f"{temp_template}_deleg_dereg", - tx_files=tx_files, - ) + clusterlib_utils.build_and_submit_tx( + cluster_obj=cluster, + name_template=f"{temp_template}_deleg_dereg", + src_address=user_payment.address, + tx_files=tx_files, + build_method=build_method, + witness_override=len(tx_files.signing_key_files), + ) + err_msg = str(excinfo.value) assert ( "StakeDelegationImpossibleDELEG" in err_msg or "StakeKeyNotRegisteredDELEG" in err_msg diff --git a/cardano_node_tests/tests/test_native_tokens.py b/cardano_node_tests/tests/test_native_tokens.py index 1781dbde5..7b7728c54 100644 --- a/cardano_node_tests/tests/test_native_tokens.py +++ b/cardano_node_tests/tests/test_native_tokens.py @@ -136,7 +136,7 @@ class TestMinting: @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.parametrize("aname_type", ("asset_name", "empty_asset_name")) @pytest.mark.smoke @pytest.mark.testnets @@ -146,7 +146,7 @@ def test_minting_and_burning_witnesses( cluster: clusterlib.ClusterLib, issuers_addrs: list[clusterlib.AddressRecord], aname_type: str, - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Test minting and burning of tokens, sign the transaction using witnesses. @@ -207,7 +207,7 @@ def test_minting_and_burning_witnesses( new_tokens=[token_mint], temp_template=f"{temp_template}_mint", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method= build_method, ) token_utxo = cluster.g_query.get_utxo(tx_raw_output=tx_out_mint, coins=[token]) @@ -220,7 +220,7 @@ def test_minting_and_burning_witnesses( new_tokens=[token_burn], temp_template=f"{temp_template}_burn", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method= build_method, ) token_utxo = cluster.g_query.get_utxo(tx_raw_output=tx_out_burn, coins=[token]) @@ -242,7 +242,7 @@ def test_minting_and_burning_witnesses( @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.parametrize("aname_type", ("asset_name", "empty_asset_name")) @pytest.mark.smoke @pytest.mark.testnets @@ -252,7 +252,7 @@ def test_minting_and_burning_sign( cluster: clusterlib.ClusterLib, issuers_addrs: list[clusterlib.AddressRecord], aname_type: str, - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Test minting and burning of tokens, sign the transaction using skeys. @@ -306,7 +306,7 @@ def test_minting_and_burning_sign( new_tokens=[token_mint], temp_template=f"{temp_template}_mint", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method ) token_utxo = cluster.g_query.get_utxo(tx_raw_output=tx_out_mint, coins=[token]) @@ -319,7 +319,7 @@ def test_minting_and_burning_sign( new_tokens=[token_burn], temp_template=f"{temp_template}_burn", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method ) token_utxo = cluster.g_query.get_utxo(tx_raw_output=tx_out_mint, coins=[token]) @@ -337,7 +337,7 @@ def test_minting_and_burning_sign( @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets @pytest.mark.dbsync @@ -345,7 +345,7 @@ def test_minting_multiple_scripts( self, cluster: clusterlib.ClusterLib, issuers_addrs: list[clusterlib.AddressRecord], - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Test minting of tokens using several different scripts in single transaction. @@ -363,7 +363,7 @@ def test_minting_multiple_scripts( """ temp_template = common.get_test_id(cluster) - expected_fee = MINT_MULTIPLE_FEE[1] if use_build_cmd else MINT_MULTIPLE_FEE[0] + expected_fee = MINT_MULTIPLE_FEE[1] if build_method == clusterlib_utils.BuildMethods.BUILD else MINT_MULTIPLE_FEE[0] num_of_scripts = 5 amount = 5 @@ -416,7 +416,7 @@ def test_minting_multiple_scripts( new_tokens=tokens_mint, temp_template=f"{temp_template}_mint", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, ) mint_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_out_mint) @@ -433,7 +433,7 @@ def test_minting_multiple_scripts( new_tokens=tokens_burn, temp_template=f"{temp_template}_burn", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, ) burn_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_out_burn) @@ -457,7 +457,7 @@ def test_minting_multiple_scripts( @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets @pytest.mark.dbsync @@ -465,7 +465,7 @@ def test_minting_burning_diff_tokens_single_tx( self, cluster: clusterlib.ClusterLib, issuers_addrs: list[clusterlib.AddressRecord], - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Test minting one token and burning other token in single transaction. @@ -518,7 +518,7 @@ def test_minting_burning_diff_tokens_single_tx( new_tokens=[tokens_mint[0]], temp_template=f"{temp_template}_mint", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, sign_incrementally=True, ) @@ -532,7 +532,7 @@ def test_minting_burning_diff_tokens_single_tx( new_tokens=[token_burn1, tokens_mint[1]], temp_template=f"{temp_template}_mint_burn", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, sign_incrementally=True, ) @@ -553,7 +553,7 @@ def test_minting_burning_diff_tokens_single_tx( new_tokens=[token_burn2], temp_template=f"{temp_template}_burn", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, sign_incrementally=True, ) @@ -571,7 +571,7 @@ def test_minting_burning_diff_tokens_single_tx( @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets @pytest.mark.dbsync @@ -579,7 +579,7 @@ def test_minting_burning_same_token_single_tx( self, cluster: clusterlib.ClusterLib, issuers_addrs: list[clusterlib.AddressRecord], - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Test minting one token and burning the same token in single transaction. @@ -635,7 +635,7 @@ def test_minting_burning_same_token_single_tx( ), ] - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: tx_output = cluster.g_transaction.build_tx( src_address=token_mint_addr.address, tx_name=f"{temp_template}_mint_burn", @@ -646,7 +646,7 @@ def test_minting_burning_same_token_single_tx( mint=mint, witness_override=len(tx_files.signing_key_files), ) - else: + elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW: fee = cluster.g_transaction.calculate_tx_fee( src_address=token_mint_addr.address, tx_name=f"{temp_template}_mint_burn", @@ -660,11 +660,21 @@ def test_minting_burning_same_token_single_tx( src_address=token_mint_addr.address, tx_name=f"{temp_template}_mint_burn", txouts=txouts, - # Token minting and burning in the same TX mint=mint, tx_files=tx_files, fee=fee, ) + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + tx_output = cluster.g_transaction.build_estimate_tx( + src_address=token_mint_addr.address, + tx_name=f"{temp_template}_mint_burn", + txouts=txouts, + mint=mint, + tx_files=tx_files, + witness_count_add=len(tx_files.signing_key_files), + ) + else: + pytest.skip(f"Unsupported build method: {build_method}") out_file_signed = cluster.g_transaction.sign_tx( tx_body_file=tx_output.out_file, @@ -692,7 +702,7 @@ def test_minting_burning_same_token_single_tx( @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.parametrize("tokens_db", MINT_BURN_WITNESS_PARAMS) @pytest.mark.smoke @pytest.mark.testnets @@ -705,7 +715,7 @@ def test_bundle_minting_and_burning_witnesses( issuers_addrs: list[clusterlib.AddressRecord], multisig_script_policyid: tuple[pl.Path, str], tokens_db: tuple[int, int, int], - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Test minting and burning multiple different tokens that are in single bundle. @@ -723,7 +733,7 @@ def test_bundle_minting_and_burning_witnesses( amount = 5 tokens_num, expected_fee_raw, expected_fee_build = tokens_db - expected_fee = expected_fee_build if use_build_cmd else expected_fee_raw + expected_fee = expected_fee_build if build_method == clusterlib_utils.BuildMethods.BUILD else expected_fee_raw token_mint_addr = issuers_addrs[0] script, policyid = multisig_script_policyid @@ -750,7 +760,7 @@ def _mint_tokens() -> clusterlib.TxRawOutput: new_tokens=tokens_to_mint, temp_template=f"{temp_template}_mint", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, ) if tokens_num >= 500: @@ -816,7 +826,7 @@ def _mint_tokens() -> clusterlib.TxRawOutput: new_tokens=tokens_to_burn, temp_template=f"{temp_template}_burn", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, ) burn_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_out_burn) @@ -841,7 +851,7 @@ def _mint_tokens() -> clusterlib.TxRawOutput: @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.parametrize("tokens_db", MINT_BURN_SIGN_PARAMS) @pytest.mark.smoke @pytest.mark.testnets @@ -854,7 +864,7 @@ def test_bundle_minting_and_burning_sign( issuers_addrs: list[clusterlib.AddressRecord], simple_script_policyid: tuple[pl.Path, str], tokens_db: tuple[int, int, int], - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Test minting and burning multiple different tokens that are in single bundle. @@ -872,7 +882,7 @@ def test_bundle_minting_and_burning_sign( amount = 5 tokens_num, expected_fee_raw, expected_fee_build = tokens_db - expected_fee = expected_fee_build if use_build_cmd else expected_fee_raw + expected_fee = expected_fee_build if build_method == clusterlib_utils.BuildMethods.BUILD else expected_fee_raw token_mint_addr = issuers_addrs[0] issuer_addr = issuers_addrs[1] @@ -900,7 +910,7 @@ def _mint_tokens() -> clusterlib.TxRawOutput: new_tokens=tokens_to_mint, temp_template=f"{temp_template}_mint", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, ) if tokens_num >= 500: @@ -966,7 +976,7 @@ def _mint_tokens() -> clusterlib.TxRawOutput: new_tokens=tokens_to_burn, temp_template=f"{temp_template}_burn", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, ) burn_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_out_burn) @@ -987,7 +997,7 @@ def _mint_tokens() -> clusterlib.TxRawOutput: @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets @pytest.mark.dbsync @@ -995,7 +1005,7 @@ def test_minting_and_partial_burning( self, cluster: clusterlib.ClusterLib, issuers_addrs: list[clusterlib.AddressRecord], - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Test minting and partial burning of tokens. @@ -1039,7 +1049,7 @@ def test_minting_and_partial_burning( new_tokens=[token_mint], temp_template=f"{temp_template}_mint", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, sign_incrementally=True, ) @@ -1071,7 +1081,7 @@ def test_minting_and_partial_burning( new_tokens=[final_burn], temp_template=f"{temp_template}_burn2", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, sign_incrementally=True, ) @@ -1086,7 +1096,7 @@ def test_minting_and_partial_burning( @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets @pytest.mark.dbsync @@ -1094,7 +1104,7 @@ def test_minting_unicode_asset_name( self, cluster: clusterlib.ClusterLib, issuers_addrs: list[clusterlib.AddressRecord], - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Test minting and burning of token with unicode non-ascii chars in its asset name. @@ -1140,7 +1150,7 @@ def test_minting_unicode_asset_name( new_tokens=[token_mint], temp_template=f"{temp_template}_mint", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, ) token_utxo = cluster.g_query.get_utxo(tx_raw_output=tx_out_mint, coins=[token]) @@ -1155,7 +1165,7 @@ def test_minting_unicode_asset_name( new_tokens=[token_burn], temp_template=f"{temp_template}_burn", submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, ) token_utxo = cluster.g_query.get_utxo(tx_raw_output=tx_out_burn, coins=[token]) @@ -1177,7 +1187,7 @@ class TestPolicies: """Tests for minting and burning tokens using minting policies.""" @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets @pytest.mark.dbsync @@ -1185,7 +1195,7 @@ def test_valid_policy_after( self, cluster: clusterlib.ClusterLib, issuers_addrs: list[clusterlib.AddressRecord], - use_build_cmd: bool, + build_method: str, ): """Test minting and burning of tokens after a given slot, check fees in Lovelace.""" expected_fee = 228_113 @@ -1230,7 +1240,7 @@ def test_valid_policy_after( temp_template=f"{temp_template}_mint", invalid_before=100, invalid_hereafter=cluster.g_query.get_slot_no() + 1_000, - use_build_cmd=use_build_cmd, + build_method=build_method, ) mint_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_out_mint) @@ -1248,7 +1258,7 @@ def test_valid_policy_after( temp_template=f"{temp_template}_burn", invalid_before=100, invalid_hereafter=cluster.g_query.get_slot_no() + 1_000, - use_build_cmd=use_build_cmd, + build_method=build_method, ) burn_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_out_burn) @@ -1269,7 +1279,7 @@ def test_valid_policy_after( dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_out_burn) @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets @pytest.mark.dbsync @@ -1277,7 +1287,7 @@ def test_valid_policy_before( self, cluster: clusterlib.ClusterLib, issuers_addrs: list[clusterlib.AddressRecord], - use_build_cmd: bool, + build_method: str, ): """Test minting and burning of tokens before a given slot, check fees in Lovelace.""" expected_fee = 228_113 @@ -1324,7 +1334,7 @@ def test_valid_policy_before( temp_template=f"{temp_template}_mint", invalid_before=100, invalid_hereafter=cluster.g_query.get_slot_no() + 1_000, - use_build_cmd=use_build_cmd, + build_method=build_method, ) mint_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_out_mint) @@ -1342,7 +1352,7 @@ def test_valid_policy_before( temp_template=f"{temp_template}_burn", invalid_before=100, invalid_hereafter=cluster.g_query.get_slot_no() + 1_000, - use_build_cmd=use_build_cmd, + build_method=build_method, ) burn_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_out_burn) @@ -1690,7 +1700,7 @@ def new_token( return new_token @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.parametrize("amount", (1, 10, 200, 2_000, 100_000)) @pytest.mark.smoke @pytest.mark.dbsync @@ -1700,7 +1710,7 @@ def test_transfer_tokens( payment_addrs: list[clusterlib.AddressRecord], new_token: clusterlib_utils.NativeTokenRec, amount: int, - use_build_cmd: bool, + build_method: str, ): """Test sending tokens to payment address. @@ -1738,7 +1748,7 @@ def test_transfer_tokens( tx_files = clusterlib.TxFiles(signing_key_files=[new_token.token_mint_addr.skey_file]) - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: # TODO: add ADA txout for change address - see node issue #3057 txouts.append(clusterlib.TxOut(address=src_address, amount=2_000_000)) @@ -1782,7 +1792,8 @@ def test_transfer_tokens( tx_name=temp_template, ) cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins) - else: + + elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW: tx_raw_output = cluster.g_transaction.send_tx( src_address=src_address, tx_name=temp_template, @@ -1790,6 +1801,25 @@ def test_transfer_tokens( tx_files=tx_files, ) + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + tx_raw_output = cluster.g_transaction.build_estimate_tx( + src_address=src_address, + tx_name=temp_template, + txouts=txouts, + tx_files=tx_files, + witness_count_add=len(tx_files.signing_key_files), + ) + tx_signed = cluster.g_transaction.sign_tx( + tx_body_file=tx_raw_output.out_file, + signing_key_files=tx_files.signing_key_files, + tx_name=temp_template, + ) + cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins) + + else: + pytest.skip(f"Unsupported build method: {build_method}") + + out_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_raw_output) out_src_utxos = clusterlib.filter_utxos(utxos=out_utxos, address=src_address) @@ -1823,7 +1853,7 @@ def test_transfer_tokens( blockers.finish_test(issues=xfail_issues) @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.dbsync def test_transfer_multiple_tokens( @@ -1831,7 +1861,7 @@ def test_transfer_multiple_tokens( cluster: clusterlib.ClusterLib, payment_addrs: list[clusterlib.AddressRecord], new_token: clusterlib_utils.NativeTokenRec, - use_build_cmd: bool, + build_method: str, ): """Test sending multiple different tokens to payment addresses. @@ -1904,7 +1934,7 @@ def test_transfer_multiple_tokens( signing_key_files=list({t.token_mint_addr.skey_file for t in new_tokens}) ) - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: # TODO: add ADA txout for change address txouts.append(clusterlib.TxOut(address=src_address, amount=4_000_000)) @@ -1951,7 +1981,8 @@ def test_transfer_multiple_tokens( tx_name=temp_template, ) cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins) - else: + + elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW: tx_raw_output = cluster.g_transaction.send_tx( src_address=src_address, tx_name=temp_template, @@ -1959,6 +1990,24 @@ def test_transfer_multiple_tokens( tx_files=tx_files, ) + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + tx_raw_output = cluster.g_transaction.build_estimate_tx( + src_address=src_address, + tx_name=temp_template, + txouts=txouts, + tx_files=tx_files, + witness_count_add=len(tx_files.signing_key_files), + ) + tx_signed = cluster.g_transaction.sign_tx( + tx_body_file=tx_raw_output.out_file, + signing_key_files=tx_files.signing_key_files, + tx_name=temp_template, + ) + cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins) + + else: + pytest.skip(f"Unsupported build method: {build_method}") + out_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_raw_output) out_src_utxos = clusterlib.filter_utxos(utxos=out_utxos, address=src_address) @@ -2001,7 +2050,7 @@ def test_transfer_multiple_tokens( blockers.finish_test(issues=xfail_issues) @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @common.SKIPIF_ON_TESTNET @pytest.mark.smoke def test_transfer_no_ada( @@ -2009,7 +2058,7 @@ def test_transfer_no_ada( cluster: clusterlib.ClusterLib, payment_addrs: list[clusterlib.AddressRecord], new_token: clusterlib_utils.NativeTokenRec, - use_build_cmd: bool, + build_method: str, ): """Try to create an UTxO with just native tokens, no ADA. Expect failure.""" temp_template = common.get_test_id(cluster) @@ -2021,7 +2070,7 @@ def test_transfer_no_ada( txouts = [clusterlib.TxOut(address=dst_address, amount=amount, coin=new_token.token)] tx_files = clusterlib.TxFiles(signing_key_files=[new_token.token_mint_addr.skey_file]) - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: expected_error = "Minimum required UTxO:" # TODO: add ADA txout for change address txouts.append(clusterlib.TxOut(address=src_address, amount=3500_000)) @@ -2035,7 +2084,7 @@ def test_transfer_no_ada( tx_files=tx_files, ) assert expected_error in str(excinfo.value) - else: + elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW: expected_error = "OutputTooSmallUTxO" try: @@ -2048,6 +2097,17 @@ def test_transfer_no_ada( except clusterlib.CLIError as err: if expected_error not in str(err): raise + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + expected_error = "Minimum required UTxO:" + + with pytest.raises(clusterlib.CLIError) as excinfo: + cluster.g_transaction.build_estimate_tx( + src_address=src_address, + tx_name=temp_template, + txouts=txouts, + tx_files=tx_files, + ) + assert expected_error in str(excinfo.value) @allure.link(helpers.get_vcs_link()) @hypothesis.given( @@ -2056,14 +2116,14 @@ def test_transfer_no_ada( @hypothesis.example(token_amount=NEW_TOKENS_NUM + 1) @hypothesis.example(token_amount=MAX_TOKEN_AMOUNT) @common.hypothesis_settings(max_examples=200) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke def test_transfer_invalid_token_amount( self, cluster: clusterlib.ClusterLib, payment_addrs: list[clusterlib.AddressRecord], new_token: clusterlib_utils.NativeTokenRec, - use_build_cmd: bool, + build_method: str, token_amount: int, ): """Test sending an invalid amount of tokens to payment address.""" @@ -2085,7 +2145,7 @@ def test_transfer_invalid_token_amount( tx_files = clusterlib.TxFiles(signing_key_files=[new_token.token_mint_addr.skey_file]) - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: with pytest.raises(clusterlib.CLIError) as excinfo: # Add ADA txout for change address - see node issue #3057 txouts.append(clusterlib.TxOut(address=src_address, amount=min_amount_lovelace)) @@ -2110,7 +2170,7 @@ def test_transfer_invalid_token_amount( or "Illegal Value in TxOut" in exc_val # In node 9.2.0+ or re.search(r"Negative quantity \(-[0-9]*\) in transaction output", exc_val) ), exc_val - else: + elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW: with pytest.raises(clusterlib.CLIError) as excinfo: try: logging.disable(logging.ERROR) @@ -2127,6 +2187,26 @@ def test_transfer_invalid_token_amount( exc_val = str(excinfo.value) assert "ValueNotConservedUTxO" in exc_val, exc_val + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + with pytest.raises(clusterlib.CLIError) as excinfo: + try: + logging.disable(logging.ERROR) + cluster.g_transaction.build_estimate_tx( + src_address=src_address, + tx_name=temp_template, + txouts=txouts, + tx_files=tx_files, + ) + finally: + logging.disable(logging.NOTSET) + + exc_val = str(excinfo.value) + # build-estimate tends to throw balancing errors + assert ( + "The transaction does not balance in its use of assets" in exc_val + or "ValueNotConservedUTxO" in exc_val + ), exc_val + @common.SKIPIF_TOKENS_UNUSABLE class TestNegative: @@ -2431,7 +2511,7 @@ class TestReferenceUTxO: """Tests for Simple Scripts V1 and V2 on reference UTxOs.""" @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.parametrize("script_version", ("simple_v1", "simple_v2")) @pytest.mark.smoke @pytest.mark.testnets @@ -2440,7 +2520,7 @@ def test_script_reference_utxo( self, cluster: clusterlib.ClusterLib, issuers_addrs: list[clusterlib.AddressRecord], - use_build_cmd: bool, + build_method: str, script_version: str, ): """Test minting and burning a token using reference script. @@ -2534,7 +2614,7 @@ def test_script_reference_utxo( ), ] - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: tx_raw_output = cluster.g_transaction.build_tx( src_address=token_mint_addr.address, tx_name=temp_template, @@ -2546,7 +2626,7 @@ def test_script_reference_utxo( invalid_before=invalid_before, witness_override=2, ) - else: + elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW: fee = cluster.g_transaction.calculate_tx_fee( src_address=token_mint_addr.address, tx_name=f"{temp_template}_mint_burn", @@ -2556,7 +2636,7 @@ def test_script_reference_utxo( invalid_hereafter=invalid_hereafter, invalid_before=invalid_before, # TODO: workaround for https://github.com/IntersectMBO/cardano-node/issues/1892 - witness_count_add=2, + witness_count_add=len(tx_files.signing_key_files), ) tx_raw_output = cluster.g_transaction.build_raw_tx( src_address=token_mint_addr.address, @@ -2569,6 +2649,17 @@ def test_script_reference_utxo( invalid_hereafter=invalid_hereafter, invalid_before=invalid_before, ) + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + cluster.g_transaction.build_estimate_tx( + src_address=token_mint_addr.address, + tx_name=f"{temp_template}_mint_burn", + txouts=txouts, + mint=mint, + tx_files=tx_files, + invalid_hereafter=invalid_hereafter, + invalid_before=invalid_before, + witness_count_add=len(tx_files.signing_key_files), + ) out_file_signed = cluster.g_transaction.sign_tx( tx_body_file=tx_raw_output.out_file, diff --git a/cardano_node_tests/tests/test_pools.py b/cardano_node_tests/tests/test_pools.py index cc758dd90..bef0ef57a 100644 --- a/cardano_node_tests/tests/test_pools.py +++ b/cardano_node_tests/tests/test_pools.py @@ -328,6 +328,120 @@ def _deregister_stake_pool_w_build( return pool_dereg_cert_file, tx_raw_output +def _register_stake_pool_w_build_est( + cluster_obj: clusterlib.ClusterLib, + pool_data: clusterlib.PoolData, + pool_owners: list[clusterlib.PoolUser], + vrf_vkey_file: clusterlib.FileType, + cold_key_pair: clusterlib.ColdKeyPair, + tx_name: str, + reward_account_vkey_file: clusterlib.FileType | None = None, + deposit: int | None = None, + destination_dir: clusterlib.FileType = ".", +) -> tuple[pl.Path, clusterlib.TxRawOutput]: + """Register a stake pool using a `transaction build-estimate` command.""" + + tx_name = f"{tx_name}_reg_pool" + pool_reg_cert_file = cluster_obj.g_stake_pool.gen_pool_registration_cert( + pool_data=pool_data, + vrf_vkey_file=vrf_vkey_file, + cold_vkey_file=cold_key_pair.vkey_file, + owner_stake_vkey_files=[p.stake.vkey_file for p in pool_owners], + reward_account_vkey_file=reward_account_vkey_file, + destination_dir=destination_dir, + ) + + signing_key_files = [ + *[p.payment.skey_file for p in pool_owners], + *[p.stake.skey_file for p in pool_owners], + cold_key_pair.skey_file, + ] + + # Build-estimate instead of build + tx_raw_output = cluster_obj.g_transaction.build_estimate_tx( + src_address=pool_owners[0].payment.address, + tx_name=tx_name, + tx_files=clusterlib.TxFiles( + certificate_files=[pool_reg_cert_file], + signing_key_files=signing_key_files, + ), + deposit=deposit, + witness_count_add=len(signing_key_files), + destination_dir=destination_dir, + ) + + tx_signed = cluster_obj.g_transaction.sign_tx( + tx_body_file=tx_raw_output.out_file, + signing_key_files=signing_key_files[:1], + tx_name=f"{tx_name}_sign0", + ) + tx_signed_inc = cluster_obj.g_transaction.sign_tx( + tx_file=tx_signed, + signing_key_files=signing_key_files[1:], + tx_name=f"{tx_name}_sign1", + ) + + cluster_obj.g_transaction.submit_tx(tx_file=tx_signed_inc, txins=tx_raw_output.txins) + + dbsync_utils.check_tx(cluster_obj=cluster_obj, tx_raw_output=tx_raw_output) + + return pool_reg_cert_file, tx_raw_output + + + +def _create_stake_pool_w_build_est( + cluster_obj: clusterlib.ClusterLib, + pool_data: clusterlib.PoolData, + pool_owners: list[clusterlib.PoolUser], + tx_name: str, + destination_dir: clusterlib.FileType = ".", +) -> clusterlib.PoolCreationOutput: + """Create and register a stake pool using a `transaction build-estimate` command.""" + + node_kes = cluster_obj.g_node.gen_kes_key_pair( + node_name=pool_data.pool_name, + destination_dir=destination_dir, + ) + LOGGER.debug(f"KES keys created - {node_kes.vkey_file}; {node_kes.skey_file}") + + node_vrf = cluster_obj.g_node.gen_vrf_key_pair( + node_name=pool_data.pool_name, + destination_dir=destination_dir, + ) + LOGGER.debug(f"VRF keys created - {node_vrf.vkey_file}; {node_vrf.skey_file}") + + node_cold = cluster_obj.g_node.gen_cold_key_pair_and_counter( + node_name=pool_data.pool_name, + destination_dir=destination_dir, + ) + LOGGER.debug( + "Cold keys created and counter created - " + f"{node_cold.vkey_file}; {node_cold.skey_file}; {node_cold.counter_file}" + ) + + pool_reg_cert_file, tx_raw_output = _register_stake_pool_w_build_est( + cluster_obj=cluster_obj, + pool_data=pool_data, + pool_owners=pool_owners, + vrf_vkey_file=node_vrf.vkey_file, + cold_key_pair=node_cold, + tx_name=tx_name, + destination_dir=destination_dir, + ) + + dbsync_utils.check_tx(cluster_obj=cluster_obj, tx_raw_output=tx_raw_output) + + return clusterlib.PoolCreationOutput( + stake_pool_id=cluster_obj.g_stake_pool.get_stake_pool_id(node_cold.vkey_file), + vrf_key_pair=node_vrf, + cold_key_pair=node_cold, + pool_reg_cert_file=pool_reg_cert_file, + pool_data=pool_data, + pool_owners=pool_owners, + tx_raw_output=tx_raw_output, + kes_key_pair=node_kes, + ) + def _create_register_pool( cluster_obj: clusterlib.ClusterLib, @@ -336,7 +450,7 @@ def _create_register_pool( pool_owners: list[clusterlib.PoolUser], pool_data: clusterlib.PoolData, request: FixtureRequest | None = None, - use_build_cmd: bool = False, + build_method: str = clusterlib_utils.BuildMethods.BUILD_RAW, ) -> clusterlib.PoolCreationOutput: """Create and register a stake pool. @@ -349,20 +463,31 @@ def _create_register_pool( src_init_balance = cluster_obj.g_query.get_address_balance(src_address) # Create and register pool - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: pool_creation_out = _create_stake_pool_w_build( cluster_obj=cluster_obj, pool_data=pool_data, pool_owners=pool_owners, tx_name=temp_template_reg, ) - else: + elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW: pool_creation_out = cluster_obj.g_stake_pool.create_stake_pool( - pool_data=pool_data, pool_owners=pool_owners, tx_name=temp_template_reg + pool_data=pool_data, + pool_owners=pool_owners, + tx_name=temp_template_reg, ) dbsync_utils.check_tx( cluster_obj=cluster_obj, tx_raw_output=pool_creation_out.tx_raw_output ) + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + pool_creation_out = _create_stake_pool_w_build_est( + cluster_obj=cluster_obj, + pool_data=pool_data, + pool_owners=pool_owners, + tx_name=temp_template_reg, + ) + else: + err = f"Unsupported build method '{build_method}'" # Deregister stake pool def _deregister(): @@ -404,7 +529,7 @@ def _create_register_pool_delegate_stake_tx( temp_dir: pl.Path, pool_data: clusterlib.PoolData, request: FixtureRequest | None = None, - use_build_cmd: bool = False, + build_method: str = clusterlib_utils.BuildMethods.BUILD_RAW, ) -> clusterlib.PoolCreationOutput: """Create and register a stake pool, delegate stake address - all in single TX. @@ -463,7 +588,7 @@ def _create_register_pool_delegate_stake_tx( ], ) - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: tx_raw_output = cluster_obj.g_transaction.build_tx( src_address=src_address, tx_name=temp_template_reg_deleg, @@ -477,11 +602,26 @@ def _create_register_pool_delegate_stake_tx( tx_name=temp_template_reg_deleg, ) cluster_obj.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins) - else: + + elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW: tx_raw_output = cluster_obj.g_transaction.send_tx( - src_address=src_address, tx_name=temp_template_reg_deleg, tx_files=tx_files + src_address=src_address, + tx_name=temp_template_reg_deleg, + tx_files=tx_files, + ) + + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + tx_raw_output = cluster_obj.g_transaction.build_estimate_tx( + src_address=src_address, + tx_name=temp_template_reg_deleg, + tx_files=tx_files, + fee_buffer=2_000_000, + witness_count_add=len(tx_files.signing_key_files), ) + else: + raise ValueError(f"Unsupported build method: {build_method}") + # Deregister stake pool def _deregister(): depoch = 1 if cluster_obj.time_to_epoch_end() >= DEREG_BUFFER_SEC else 2 @@ -535,7 +675,7 @@ def _create_register_pool_tx_delegate_stake_tx( temp_dir: pl.Path, pool_data: clusterlib.PoolData, request: FixtureRequest | None = None, - use_build_cmd: bool = False, + build_method: str = clusterlib_utils.BuildMethods.BUILD_RAW, ) -> clusterlib.PoolCreationOutput: """Create and register a stake pool - first TX; delegate stake address - second TX. @@ -549,7 +689,7 @@ def _create_register_pool_tx_delegate_stake_tx( pool_owners=pool_owners, pool_data=pool_data, request=request, - use_build_cmd=use_build_cmd, + build_method=build_method, ) # Create stake address registration certs @@ -585,13 +725,13 @@ def _create_register_pool_tx_delegate_stake_tx( ], ) - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: tx_raw_output = cluster_obj.g_transaction.build_tx( src_address=src_address, tx_name=f"{temp_template}_reg_deleg", tx_files=tx_files, fee_buffer=2_000_000, - witness_override=len(pool_owners) * 3, + witness_override=len(tx_files.signing_key_files), ) tx_signed = cluster_obj.g_transaction.sign_tx( tx_body_file=tx_raw_output.out_file, @@ -599,11 +739,25 @@ def _create_register_pool_tx_delegate_stake_tx( tx_name=f"{temp_template}_reg_deleg", ) cluster_obj.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins) - else: + + elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW: tx_raw_output = cluster_obj.g_transaction.send_tx( - src_address=src_address, tx_name=f"{temp_template}_reg_deleg", tx_files=tx_files + src_address=src_address, + tx_name=f"{temp_template}_reg_deleg", + tx_files=tx_files, + ) + + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + tx_raw_output = cluster_obj.g_transaction.build_estimate_tx( + src_address=src_address, + tx_name=f"{temp_template}_reg_deleg", + tx_files=tx_files, + witness_count_add=len(tx_files.signing_key_files), ) + else: + raise ValueError(f"Unsupported build method: {build_method}") + # Check that the balance for source address was correctly updated assert ( cluster_obj.g_query.get_address_balance(src_address) @@ -628,7 +782,7 @@ class TestStakePool: """General tests for stake pools.""" @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.testnets @pytest.mark.smoke @pytest.mark.dbsync @@ -637,7 +791,7 @@ def test_stake_pool_metadata( cluster_manager: cluster_management.ClusterManager, cluster: clusterlib.ClusterLib, request: FixtureRequest, - use_build_cmd: bool, + build_method: str, ): """Create and register a stake pool with metadata. @@ -676,7 +830,7 @@ def test_stake_pool_metadata( temp_dir=pl.Path(), pool_data=pool_data, request=request, - use_build_cmd=use_build_cmd, + build_method=build_method ) # Check `transaction view` command @@ -753,7 +907,7 @@ def test_stake_pool_not_avail_metadata( temp_dir=pl.Path(), pool_data=pool_data, request=request, - use_build_cmd=False, + build_method=clusterlib_utils.BuildMethods.BUILD_RAW ) # Check dbsync `PoolOffChainFetchError` table @@ -776,7 +930,7 @@ def _query_func(): ) @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.parametrize("no_of_addr", (1, 3)) @pytest.mark.testnets @pytest.mark.smoke @@ -787,7 +941,7 @@ def test_create_stake_pool( cluster: clusterlib.ClusterLib, no_of_addr: int, request: FixtureRequest, - use_build_cmd: bool, + build_method: str, ): """Create and register a stake pool (without metadata). @@ -821,11 +975,11 @@ def test_create_stake_pool( pool_owners=pool_owners, pool_data=pool_data, request=request, - use_build_cmd=use_build_cmd, + build_method=build_method ) @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.testnets @pytest.mark.dbsync @pytest.mark.smash @@ -833,7 +987,7 @@ def test_deregister_stake_pool( self, cluster_manager: cluster_management.ClusterManager, cluster: clusterlib.ClusterLib, - use_build_cmd: bool, + build_method: str, ): """Deregister stake pool. @@ -884,7 +1038,7 @@ def test_deregister_stake_pool( temp_template=temp_template, temp_dir=pl.Path(), pool_data=pool_data, - use_build_cmd=use_build_cmd, + build_method=build_method ) pool_owner = pool_owners[0] @@ -899,7 +1053,7 @@ def test_deregister_stake_pool( cluster_obj=cluster, start=5, stop=common.EPOCH_STOP_SEC_BUFFER ) depoch = cluster.g_query.get_epoch() + 1 - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: __, tx_raw_output = _deregister_stake_pool_w_build( cluster_obj=cluster, pool_owners=pool_owners, @@ -917,6 +1071,7 @@ def test_deregister_stake_pool( tx_name=temp_template, ) dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_raw_output) + assert ( cluster.g_query.get_pool_state(stake_pool_id=pool_creation_out.stake_pool_id).retiring == depoch @@ -1271,14 +1426,14 @@ def _deregister(): dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_raw_output) @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.testnets @pytest.mark.dbsync def test_update_stake_pool_metadata( self, cluster_manager: cluster_management.ClusterManager, cluster: clusterlib.ClusterLib, - use_build_cmd: bool, + build_method: str, request: FixtureRequest, ): """Update stake pool metadata. @@ -1352,7 +1507,7 @@ def test_update_stake_pool_metadata( pool_owners=pool_owners, pool_data=pool_data, request=request, - use_build_cmd=use_build_cmd, + build_method=build_method, ) # Make sure the update doesn't happen close to epoch boundary @@ -1362,7 +1517,7 @@ def test_update_stake_pool_metadata( update_epoch = cluster.g_query.get_epoch() # Update the pool metadata by resubmitting the pool registration certificate - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: _register_stake_pool_w_build( cluster_obj=cluster, pool_data=pool_data_updated, @@ -1372,6 +1527,16 @@ def test_update_stake_pool_metadata( tx_name=f"{temp_template}_rereg", deposit=0, # no additional deposit, the pool is already registered ) + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + _register_stake_pool_w_build_est( + cluster_obj=cluster, + pool_data=pool_data_updated, + pool_owners=pool_owners, + vrf_vkey_file=pool_creation_out.vrf_key_pair.vkey_file, + cold_key_pair=pool_creation_out.cold_key_pair, + tx_name=f"{temp_template}_rereg", + deposit=0, + ) else: __, tx_raw_output = cluster.g_stake_pool.register_stake_pool( pool_data=pool_data_updated, @@ -1402,14 +1567,14 @@ def test_update_stake_pool_metadata( ) @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.testnets @pytest.mark.dbsync def test_update_stake_pool_parameters( self, cluster_manager: cluster_management.ClusterManager, cluster: clusterlib.ClusterLib, - use_build_cmd: bool, + build_method: str, request: FixtureRequest, ): """Update stake pool parameters. @@ -1469,7 +1634,7 @@ def test_update_stake_pool_parameters( pool_owners=pool_owners, pool_data=pool_data, request=request, - use_build_cmd=use_build_cmd, + build_method=build_method, ) # Make sure the update doesn't happen close to epoch boundary @@ -1479,7 +1644,7 @@ def test_update_stake_pool_parameters( update_epoch = cluster.g_query.get_epoch() # Update the pool parameters by resubmitting the pool registration certificate - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: _register_stake_pool_w_build( cluster_obj=cluster, pool_data=pool_data_updated, @@ -1489,6 +1654,16 @@ def test_update_stake_pool_parameters( tx_name=f"{temp_template}_rereg", deposit=0, # no additional deposit, the pool is already registered ) + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + _register_stake_pool_w_build_est( + cluster_obj=cluster, + pool_data=pool_data_updated, + pool_owners=pool_owners, + vrf_vkey_file=pool_creation_out.vrf_key_pair.vkey_file, + cold_key_pair=pool_creation_out.cold_key_pair, + tx_name=f"{temp_template}_rereg", + deposit=0, + ) else: __, tx_raw_output = cluster.g_stake_pool.register_stake_pool( pool_data=pool_data_updated, @@ -2100,7 +2275,7 @@ def test_pool_registration_missing_payment_skey( assert "MissingVKeyWitnessesUTXOW" in str(excinfo.value) @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets def test_pool_deregistration_not_registered( @@ -2108,7 +2283,7 @@ def test_pool_deregistration_not_registered( cluster: clusterlib.ClusterLib, pool_users: list[clusterlib.PoolUser], pool_data: clusterlib.PoolData, - use_build_cmd: bool, + build_method: str, ): """Try to deregister pool that is not registered. @@ -2130,7 +2305,7 @@ def test_pool_deregistration_not_registered( ) with pytest.raises(clusterlib.CLIError) as excinfo: - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: tx_raw_output = cluster.g_transaction.build_tx( src_address=pool_users[0].payment.address, tx_name="deregister_unregistered", @@ -2143,6 +2318,16 @@ def test_pool_deregistration_not_registered( tx_name="deregister_unregistered", ) cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output.txins) + + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + cluster.g_transaction.build_estimate_tx( + src_address=pool_users[0].payment.address, + tx_name="deregister_unregistered", + tx_files=tx_files, + fee_buffer=2_000_000, + witness_count_add=len(tx_files.signing_key_files), + ) + else: cluster.g_transaction.send_tx( src_address=pool_users[0].payment.address, diff --git a/cardano_node_tests/tests/test_tx_negative.py b/cardano_node_tests/tests/test_tx_negative.py index c65a6acf8..8f4fff33d 100644 --- a/cardano_node_tests/tests/test_tx_negative.py +++ b/cardano_node_tests/tests/test_tx_negative.py @@ -209,7 +209,7 @@ def _submit_wrong_validity( temp_template: str, invalid_before: int | None = None, invalid_hereafter: int | None = None, - use_build_cmd=False, + build_method: str = clusterlib_utils.BuildMethods.BUILD_RAW, ) -> tuple[int | None, str, clusterlib.TxRawOutput | None]: """Try to build and submit a transaction with wrong validity interval.""" src_address = pool_users[0].payment.address @@ -222,7 +222,7 @@ def _submit_wrong_validity( slot_no = tx_output = None try: - if use_build_cmd: + if build_method == clusterlib_utils.BuildMethods.BUILD: tx_output = cluster_obj.g_transaction.build_tx( src_address=src_address, tx_name=temp_template, @@ -232,7 +232,7 @@ def _submit_wrong_validity( invalid_hereafter=invalid_hereafter, fee_buffer=1_000_000, ) - else: + elif build_method == clusterlib_utils.BuildMethods.BUILD_RAW: tx_output = cluster_obj.g_transaction.build_raw_tx( src_address=src_address, tx_name=temp_template, @@ -242,6 +242,20 @@ def _submit_wrong_validity( invalid_before=invalid_before, invalid_hereafter=invalid_hereafter, ) + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + tx_output = cluster_obj.g_transaction.build_estimate_tx( + src_address=src_address, + tx_name=temp_template, + txouts=txouts, + tx_files=tx_files, + fee_buffer=1_000_000, + invalid_before=invalid_before, + invalid_hereafter=invalid_hereafter, + witness_count_add=len(tx_files.signing_key_files), + ) + return None, "build_estimate_tx does not enforce validity interval", None + else: + raise ValueError(f"Unsupported build method: {build_method}") except clusterlib.CLIError as exc: exc_val = str(exc) if "SLOT must not" not in exc_val: @@ -288,14 +302,14 @@ def _get_validity_range( return loaded_invalid_before, loaded_invalid_hereafter @allure.link(helpers.get_vcs_link()) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD @pytest.mark.smoke @pytest.mark.testnets def test_past_ttl( self, cluster: clusterlib.ClusterLib, pool_users: list[clusterlib.PoolUser], - use_build_cmd: bool, + build_method: str, ): """Try to send a transaction with ttl in the past. @@ -307,7 +321,7 @@ def test_past_ttl( pool_users=pool_users, temp_template=temp_template, invalid_hereafter=cluster.g_query.get_slot_no() - 1, - use_build_cmd=use_build_cmd, + build_method=build_method, ) @allure.link(helpers.get_vcs_link()) @@ -315,14 +329,14 @@ def test_past_ttl( VERSIONS.transaction_era < VERSIONS.ALLEGRA, reason="runs only with Allegra+ TX", ) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD @pytest.mark.smoke @pytest.mark.testnets def test_before_negative_overflow( self, cluster: clusterlib.ClusterLib, pool_users: list[clusterlib.PoolUser], - use_build_cmd: bool, + build_method: str, ): """Try to send a transaction with negative `invalid_before` and check for int overflow. @@ -342,7 +356,7 @@ def test_before_negative_overflow( pool_users=pool_users, temp_template=temp_template, invalid_before=before_value, - use_build_cmd=use_build_cmd, + build_method=build_method, ) # In node versions >= 1.36.0 we are checking error from @@ -367,14 +381,14 @@ def test_before_negative_overflow( VERSIONS.transaction_era < VERSIONS.ALLEGRA, reason="runs only with Allegra+ TX", ) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD @pytest.mark.smoke @pytest.mark.testnets def test_before_positive_overflow( self, cluster: clusterlib.ClusterLib, pool_users: list[clusterlib.PoolUser], - use_build_cmd: bool, + build_method: str, ): """Try to send a transaction with `invalid_before` > `MAX_UINT64`. @@ -395,7 +409,7 @@ def test_before_positive_overflow( pool_users=pool_users, temp_template=temp_template, invalid_before=over_before_value, - use_build_cmd=use_build_cmd, + build_method=build_method ) # In node versions >= 1.36.0 we are checking error from @@ -420,14 +434,14 @@ def test_before_positive_overflow( VERSIONS.transaction_era < VERSIONS.ALLEGRA, reason="runs only with Allegra+ TX", ) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke @pytest.mark.testnets def test_before_too_high( self, cluster: clusterlib.ClusterLib, pool_users: list[clusterlib.PoolUser], - use_build_cmd: bool, + build_method: str, ): """Try to send a transaction with `invalid_before` > `MAX_INT64`. @@ -444,7 +458,7 @@ def test_before_too_high( pool_users=pool_users, temp_template=temp_template, invalid_before=before_value, - use_build_cmd=use_build_cmd, + build_method=build_method, ) assert "(OutsideValidityIntervalUTxO" in err_str, err_str @@ -458,7 +472,7 @@ def test_before_too_high( @hypothesis.example(before_value=1) @hypothesis.example(before_value=common.MAX_INT64) @common.hypothesis_settings(max_examples=200) - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD @pytest.mark.smoke @pytest.mark.testnets def test_pbt_before_negative_overflow( @@ -466,7 +480,7 @@ def test_pbt_before_negative_overflow( cluster: clusterlib.ClusterLib, pool_users: list[clusterlib.PoolUser], before_value: int, - use_build_cmd: bool, + build_method: str, ): """Try to send a transaction with negative `invalid_before` and check for int overflow. @@ -479,7 +493,7 @@ def test_pbt_before_negative_overflow( pool_users=pool_users, temp_template=temp_template, invalid_before=-before_value, - use_build_cmd=use_build_cmd, + build_method=build_method ) # In node versions >= 1.36.0 we are checking error from diff --git a/cardano_node_tests/tests/tests_conway/test_committee.py b/cardano_node_tests/tests/tests_conway/test_committee.py index 32af40f70..300dce37b 100644 --- a/cardano_node_tests/tests/tests_conway/test_committee.py +++ b/cardano_node_tests/tests/tests_conway/test_committee.py @@ -115,14 +115,14 @@ class TestCommittee: @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.testnets @pytest.mark.smoke def test_register_hot_key_no_cc_member( self, cluster: clusterlib.ClusterLib, pool_user: clusterlib.PoolUser, - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Try to submit a Hot Credential Authorization certificate without being a CC member. @@ -148,7 +148,7 @@ def test_register_hot_key_no_cc_member( name_template=f"{temp_template}_auth", src_address=pool_user.payment.address, submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, tx_files=tx_files_auth, ) err_str = str(excinfo.value) @@ -414,7 +414,7 @@ def _auth_hot_keys() -> None: @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.parametrize("threshold_type", ("fraction", "decimal")) @pytest.mark.dbsync @pytest.mark.smoke @@ -422,7 +422,7 @@ def test_update_committee_action( self, cluster: clusterlib.ClusterLib, pool_user: clusterlib.PoolUser, - use_build_cmd: bool, + build_method: str, submit_method: str, threshold_type: str, ): @@ -489,7 +489,7 @@ def test_update_committee_action( name_template=f"{temp_template}_bootstrap", src_address=pool_user.payment.address, submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, tx_files=tx_files, deposit=deposit_amt, ) @@ -505,7 +505,7 @@ def test_update_committee_action( name_template=temp_template, src_address=pool_user.payment.address, submit_method=submit_method, - use_build_cmd=use_build_cmd, + build_method=build_method, tx_files=tx_files, deposit=deposit_amt, ) diff --git a/cardano_node_tests/tests/tests_conway/test_treasury_donation.py b/cardano_node_tests/tests/tests_conway/test_treasury_donation.py index c0d83aab0..82fd749be 100644 --- a/cardano_node_tests/tests/tests_conway/test_treasury_donation.py +++ b/cardano_node_tests/tests/tests_conway/test_treasury_donation.py @@ -69,13 +69,13 @@ class TestTreasuryDonation: @allure.link(helpers.get_vcs_link()) @submit_utils.PARAM_SUBMIT_METHOD - @common.PARAM_USE_BUILD_CMD + @common.PARAM_BUILD_METHOD_NO_EST @pytest.mark.smoke def test_transfer_treasury_donation( self, cluster_treasury: clusterlib.ClusterLib, payment_addr_treasury: clusterlib.AddressRecord, - use_build_cmd: bool, + build_method: str, submit_method: str, ): """Send funds from payment address to the treasury. @@ -107,7 +107,7 @@ def test_transfer_treasury_donation( treasury_donation=amount, submit_method=submit_method, change_address=payment_addr_treasury.address, - use_build_cmd=use_build_cmd, + build_method=build_method, tx_files=tx_files, ) diff --git a/cardano_node_tests/utils/clusterlib_utils.py b/cardano_node_tests/utils/clusterlib_utils.py index 2dd0b4041..b1b22b06d 100644 --- a/cardano_node_tests/utils/clusterlib_utils.py +++ b/cardano_node_tests/utils/clusterlib_utils.py @@ -580,7 +580,7 @@ def mint_or_burn_witness( invalid_hereafter: int | None = None, invalid_before: int | None = None, submit_method: str = submit_utils.SubmitMethods.CLI, - use_build_cmd: bool = False, + build_method: str = BuildMethods.BUILD_RAW, sign_incrementally: bool = False, ) -> clusterlib.TxRawOutput: """Mint or burn tokens, depending on the `amount` value. Sign using witnesses. @@ -618,7 +618,7 @@ def mint_or_burn_witness( *mint_txouts, ] - if use_build_cmd: + if build_method == BuildMethods.BUILD: tx_output = cluster_obj.g_transaction.build_tx( src_address=token_mint_addr.address, tx_name=temp_template, @@ -629,12 +629,14 @@ def mint_or_burn_witness( invalid_before=invalid_before, witness_override=len(signing_key_files), ) - else: + elif build_method == BuildMethods.BUILD_RAW: fee = cluster_obj.g_transaction.calculate_tx_fee( src_address=token_mint_addr.address, tx_name=temp_template, txouts=txouts, mint=mint, + invalid_hereafter=invalid_hereafter, + invalid_before=invalid_before, # TODO: workaround for https://github.com/IntersectMBO/cardano-node/issues/1892 witness_count_add=int(len(signing_key_files) * 1.5), ) @@ -647,6 +649,18 @@ def mint_or_burn_witness( invalid_hereafter=invalid_hereafter, invalid_before=invalid_before, ) + elif build_method == BuildMethods.BUILD_EST: + tx_output = cluster_obj.g_transaction.build_estimate_tx( + src_address=token_mint_addr.address, + tx_name=temp_template, + txouts=txouts, + mint=mint, + invalid_hereafter=invalid_hereafter, + invalid_before=invalid_before, + witness_count_add=len(signing_key_files), + ) + else: + raise ValueError(f"Unsupported build method: {build_method}") # Sign incrementally (just to check that it works) if sign_incrementally and len(signing_key_files) >= 1: @@ -704,7 +718,7 @@ def mint_or_burn_sign( new_tokens: list[NativeTokenRec], temp_template: str, submit_method: str = submit_utils.SubmitMethods.CLI, - use_build_cmd: bool = False, + build_method: str = BuildMethods.BUILD_RAW, sign_incrementally: bool = False, ) -> clusterlib.TxRawOutput: """Mint or burn tokens, depending on the `amount` value. Sign using skeys. @@ -741,7 +755,7 @@ def mint_or_burn_sign( *mint_txouts, ] - if use_build_cmd: + if build_method == BuildMethods.BUILD: tx_output = cluster_obj.g_transaction.build_tx( src_address=token_mint_addr.address, tx_name=temp_template, @@ -750,7 +764,7 @@ def mint_or_burn_sign( mint=mint, witness_override=len(signing_key_files), ) - else: + elif build_method == BuildMethods.BUILD_RAW: fee = cluster_obj.g_transaction.calculate_tx_fee( src_address=token_mint_addr.address, tx_name=temp_template, @@ -766,6 +780,16 @@ def mint_or_burn_sign( mint=mint, fee=fee, ) + elif build_method == BuildMethods.BUILD_EST: + tx_output = cluster_obj.g_transaction.build_estimate_tx( + src_address=token_mint_addr.address, + tx_name=temp_template, + txouts=txouts, + mint=mint, + witness_count_add=len(signing_key_files), + ) + else: + raise ValueError(f"Unsupported build method: {build_method}") # Sign incrementally (just to check that it works) if sign_incrementally and len(signing_key_files) >= 1: