Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions cardano_node_tests/tests/delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
123 changes: 43 additions & 80 deletions cardano_node_tests/tests/test_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ 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
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.

Expand All @@ -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(
Expand All @@ -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.

Expand All @@ -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(
Expand Down Expand Up @@ -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",
Expand All @@ -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.

Expand Down Expand Up @@ -956,38 +956,23 @@ 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(
def _build_and_submit() -> clusterlib.TxRawOutput:
return 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),
)

try:
tx_raw_output_deleg = common.match_blocker(func=_build_and_submit)
except clusterlib.CLIError as exc:
if "ValueNotConservedUTxO" in str(exc):
issues.cli_942.finish_test()
raise
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also check for blockers from common.match_blocker, if using transaction build.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed


# Check that the balance for source address was correctly updated and that the key
# deposit was returned
assert (
Expand Down Expand Up @@ -1092,15 +1077,15 @@ 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(
self,
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.

Expand All @@ -1127,41 +1112,30 @@ 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(
self,
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.

Expand Down Expand Up @@ -1207,26 +1181,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
Expand Down
Loading