diff --git a/cardano_node_tests/tests/test_delegation.py b/cardano_node_tests/tests/test_delegation.py index 3d448529b..991f436eb 100644 --- a/cardano_node_tests/tests/test_delegation.py +++ b/cardano_node_tests/tests/test_delegation.py @@ -395,6 +395,123 @@ def _get_pool_id(idx: int) -> str: # TODO: check delegation in db-sync + @allure.link(helpers.get_vcs_link()) + @common.PARAM_USE_BUILD_CMD + @pytest.mark.dbsync + @pytest.mark.smoke + def test_deregister_registered( + self, + cluster: clusterlib.ClusterLib, + pool_users: tp.List[clusterlib.PoolUser], + pool_users_disposable: tp.List[clusterlib.PoolUser], + use_build_cmd: bool, + ): + """Deregister a registered stake address. + + * create stake address registration cert + * register and stake address + * create stake address deregistration cert + * deregister stake address + * check that the balance for source address was correctly updated + * (optional) check records in db-sync + """ + temp_template = f"{common.get_test_id(cluster)}_{use_build_cmd}" + + user_registered = pool_users_disposable[0] + user_payment = pool_users[0].payment + src_init_balance = cluster.g_query.get_address_balance(user_payment.address) + + # Create stake address registration cert + stake_addr_reg_cert_file = cluster.g_stake_address.gen_stake_addr_registration_cert( + addr_name=f"{temp_template}_addr0", stake_vkey_file=user_registered.stake.vkey_file + ) + + # Register stake address + tx_files_reg = clusterlib.TxFiles( + certificate_files=[stake_addr_reg_cert_file], + signing_key_files=[user_payment.skey_file, user_registered.stake.skey_file], + ) + + if use_build_cmd: + tx_raw_output_reg = cluster.g_transaction.build_tx( + src_address=user_payment.address, + tx_name=f"{temp_template}_reg", + tx_files=tx_files_reg, + fee_buffer=2_000_000, + witness_override=len(tx_files_reg.signing_key_files), + ) + tx_signed = cluster.g_transaction.sign_tx( + tx_body_file=tx_raw_output_reg.out_file, + signing_key_files=tx_files_reg.signing_key_files, + tx_name=f"{temp_template}_reg", + ) + cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output_reg.txins) + else: + tx_raw_output_reg = cluster.g_transaction.send_tx( + src_address=user_payment.address, + tx_name=f"{temp_template}_reg", + tx_files=tx_files_reg, + ) + + assert cluster.g_query.get_stake_addr_info( + user_registered.stake.address + ).address, f"Stake address is NOT registered: {user_registered.stake.address}" + + # Create stake address deregistration cert + stake_addr_dereg_cert_file = cluster.g_stake_address.gen_stake_addr_deregistration_cert( + addr_name=f"{temp_template}_addr0", stake_vkey_file=user_registered.stake.vkey_file + ) + + # Deregister stake address + tx_files_dereg = clusterlib.TxFiles( + certificate_files=[stake_addr_dereg_cert_file], + signing_key_files=[user_payment.skey_file, user_registered.stake.skey_file], + ) + + if use_build_cmd: + tx_raw_output_dereg = cluster.g_transaction.build_tx( + src_address=user_payment.address, + tx_name=f"{temp_template}_dereg", + tx_files=tx_files_dereg, + fee_buffer=2_000_000, + witness_override=len(tx_files_dereg.signing_key_files), + ) + tx_signed = cluster.g_transaction.sign_tx( + tx_body_file=tx_raw_output_dereg.out_file, + signing_key_files=tx_files_dereg.signing_key_files, + tx_name=f"{temp_template}_dereg", # TODO: should be reg_dereg + ) + cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_raw_output_dereg.txins) + else: + tx_raw_output_dereg = cluster.g_transaction.send_tx( + src_address=user_payment.address, + tx_name=f"{temp_template}_reg_dereg", + tx_files=tx_files_dereg, + ) + + assert not cluster.g_query.get_stake_addr_info( + user_registered.stake.address + ).address, f"Stake address is registered: {user_registered.stake.address}" + + # Check that the balance for source address was correctly updated + assert ( + cluster.g_query.get_address_balance(user_payment.address) + == src_init_balance - tx_raw_output_reg.fee - tx_raw_output_dereg.fee + ), f"Incorrect balance for source address `{user_payment.address}`" + + # Check records in db-sync + tx_db_record_reg = dbsync_utils.check_tx( + cluster_obj=cluster, tx_raw_output=tx_raw_output_reg + ) + if tx_db_record_reg: + assert user_registered.stake.address in tx_db_record_reg.stake_registration + + tx_db_record_dereg = dbsync_utils.check_tx( + cluster_obj=cluster, tx_raw_output=tx_raw_output_dereg + ) + if tx_db_record_dereg: + assert user_registered.stake.address in tx_db_record_dereg.stake_deregistration + @allure.link(helpers.get_vcs_link()) @pytest.mark.order(7) @pytest.mark.dbsync