diff --git a/cardano_node_tests/tests/test_native_tokens.py b/cardano_node_tests/tests/test_native_tokens.py index 1781dbde5..659da850f 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,11 @@ 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 +420,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 +437,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 +461,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 +469,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 +522,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 +536,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 +557,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 +575,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 +583,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 +639,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 +650,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 +664,22 @@ 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: + msg = f"Unsupported build method: {build_method}" + raise ValueError(msg) out_file_signed = cluster.g_transaction.sign_tx( tx_body_file=tx_output.out_file, @@ -692,7 +707,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 +720,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 +738,11 @@ 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 +769,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 +835,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 +860,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 +873,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 +891,11 @@ 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 +923,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 +989,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 +1010,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 +1018,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 +1062,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 +1094,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 +1109,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 +1117,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 +1163,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 +1178,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 +1200,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 +1208,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 +1253,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 +1271,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 +1292,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 +1300,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 +1347,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 +1365,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 +1713,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 +1723,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 +1761,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 +1805,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 +1814,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: + msg = f"Unsupported build method: {build_method}" + raise ValueError(msg) + 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 +1866,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 +1874,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 +1947,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 +1994,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 +2003,25 @@ 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: + msg = f"Unsupported build method: {build_method}" + raise ValueError(msg) + 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 +2064,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 +2072,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 +2084,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 +2098,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 +2111,20 @@ 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) + else: + msg = f"Unsupported build method: {build_method}" + raise ValueError(msg) @allure.link(helpers.get_vcs_link()) @hypothesis.given( @@ -2056,14 +2133,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 +2162,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 +2187,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 +2204,28 @@ 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) + # TODO: refine once CLI issue #1199 is fixed + # At this point we don't know the exact error string from build-estimate. + # Fail explicitly so we can capture and refine later. + pytest.fail(f"Unexpected error for build-estimate (CLI issue #1199): {exc_val}") + else: + msg = f"Unsupported build method: {build_method}" + raise ValueError(msg) + @common.SKIPIF_TOKENS_UNUSABLE class TestNegative: @@ -2431,7 +2530,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 +2539,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 +2633,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 +2645,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 +2655,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 +2668,20 @@ def test_script_reference_utxo( invalid_hereafter=invalid_hereafter, invalid_before=invalid_before, ) + elif build_method == clusterlib_utils.BuildMethods.BUILD_EST: + tx_raw_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, + invalid_hereafter=invalid_hereafter, + invalid_before=invalid_before, + witness_count_add=len(tx_files.signing_key_files), + ) + else: + msg = f"Unsupported build method: {build_method}" + raise ValueError(msg) out_file_signed = cluster.g_transaction.sign_tx( tx_body_file=tx_raw_output.out_file, diff --git a/cardano_node_tests/utils/clusterlib_utils.py b/cardano_node_tests/utils/clusterlib_utils.py index bb87b4e6b..3464c6644 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,19 @@ 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: + msg = f"Unsupported build method: {build_method}" + raise ValueError(msg) # Sign incrementally (just to check that it works) if sign_incrementally and len(signing_key_files) >= 1: @@ -704,7 +719,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 +756,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 +765,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 +781,17 @@ 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: + msg = f"Unsupported build method: {build_method}" + raise ValueError(msg) # Sign incrementally (just to check that it works) if sign_incrementally and len(signing_key_files) >= 1: